id
int32 0
24.9k
| repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
|
---|---|---|---|---|---|---|---|---|---|---|---|
4,800 | samvera-labs/geo_works | app/models/concerns/geo_works/image_file_behavior.rb | GeoWorks.ImageFileBehavior.image_work | def image_work
parents.select do |parent|
parent.class.included_modules.include?(::GeoWorks::ImageWorkBehavior)
end.to_a
end | ruby | def image_work
parents.select do |parent|
parent.class.included_modules.include?(::GeoWorks::ImageWorkBehavior)
end.to_a
end | [
"def",
"image_work",
"parents",
".",
"select",
"do",
"|",
"parent",
"|",
"parent",
".",
"class",
".",
"included_modules",
".",
"include?",
"(",
"::",
"GeoWorks",
"::",
"ImageWorkBehavior",
")",
"end",
".",
"to_a",
"end"
] | Retrieve the Image Work of which this Object is a member
@return [GeoWorks::ImageWork] | [
"Retrieve",
"the",
"Image",
"Work",
"of",
"which",
"this",
"Object",
"is",
"a",
"member"
] | df1eff35fd01469a623fafeb9d71b44fd6160ca8 | https://github.com/samvera-labs/geo_works/blob/df1eff35fd01469a623fafeb9d71b44fd6160ca8/app/models/concerns/geo_works/image_file_behavior.rb#L8-L12 |
4,801 | phatworx/rails_paginate | lib/rails_paginate/pagers/slider.rb | RailsPaginate::Pagers.Slider.visible_pages | def visible_pages
visible = []
last_inserted = 0
splited = false
(1..pages).each do |page|
# insert
if visible? page
visible << page
last_inserted = page
splited = false
else
# need splitter
if not splited and outer > 0 and last_inserted < page
visible << nil
splited = true
end
end
end
visible
end | ruby | def visible_pages
visible = []
last_inserted = 0
splited = false
(1..pages).each do |page|
# insert
if visible? page
visible << page
last_inserted = page
splited = false
else
# need splitter
if not splited and outer > 0 and last_inserted < page
visible << nil
splited = true
end
end
end
visible
end | [
"def",
"visible_pages",
"visible",
"=",
"[",
"]",
"last_inserted",
"=",
"0",
"splited",
"=",
"false",
"(",
"1",
"..",
"pages",
")",
".",
"each",
"do",
"|",
"page",
"|",
"# insert",
"if",
"visible?",
"page",
"visible",
"<<",
"page",
"last_inserted",
"=",
"page",
"splited",
"=",
"false",
"else",
"# need splitter",
"if",
"not",
"splited",
"and",
"outer",
">",
"0",
"and",
"last_inserted",
"<",
"page",
"visible",
"<<",
"nil",
"splited",
"=",
"true",
"end",
"end",
"end",
"visible",
"end"
] | build array with all visible pages | [
"build",
"array",
"with",
"all",
"visible",
"pages"
] | ae8cbc12030853b236dc2cbf6ede8700fb835771 | https://github.com/phatworx/rails_paginate/blob/ae8cbc12030853b236dc2cbf6ede8700fb835771/lib/rails_paginate/pagers/slider.rb#L14-L33 |
4,802 | phatworx/rails_paginate | lib/rails_paginate/pagers/slider.rb | RailsPaginate::Pagers.Slider.visible? | def visible?(page)
# outer
if outer > 0
return true if outer >= page
return true if (pages - outer) < page
end
# current page
return true if current_page == page
# inner
return true if inner_range.include? page
false
end | ruby | def visible?(page)
# outer
if outer > 0
return true if outer >= page
return true if (pages - outer) < page
end
# current page
return true if current_page == page
# inner
return true if inner_range.include? page
false
end | [
"def",
"visible?",
"(",
"page",
")",
"# outer",
"if",
"outer",
">",
"0",
"return",
"true",
"if",
"outer",
">=",
"page",
"return",
"true",
"if",
"(",
"pages",
"-",
"outer",
")",
"<",
"page",
"end",
"# current page",
"return",
"true",
"if",
"current_page",
"==",
"page",
"# inner",
"return",
"true",
"if",
"inner_range",
".",
"include?",
"page",
"false",
"end"
] | looks should this page visible | [
"looks",
"should",
"this",
"page",
"visible"
] | ae8cbc12030853b236dc2cbf6ede8700fb835771 | https://github.com/phatworx/rails_paginate/blob/ae8cbc12030853b236dc2cbf6ede8700fb835771/lib/rails_paginate/pagers/slider.rb#L41-L55 |
4,803 | Mik-die/mongoid_globalize | lib/mongoid_globalize/class_methods.rb | Mongoid::Globalize.ClassMethods.required_attributes | def required_attributes
validators.map{ |v| v.attributes if v.is_a?(Mongoid::Validations::PresenceValidator) }.flatten.compact
end | ruby | def required_attributes
validators.map{ |v| v.attributes if v.is_a?(Mongoid::Validations::PresenceValidator) }.flatten.compact
end | [
"def",
"required_attributes",
"validators",
".",
"map",
"{",
"|",
"v",
"|",
"v",
".",
"attributes",
"if",
"v",
".",
"is_a?",
"(",
"Mongoid",
"::",
"Validations",
"::",
"PresenceValidator",
")",
"}",
".",
"flatten",
".",
"compact",
"end"
] | Return Array of attribute names with presence validations | [
"Return",
"Array",
"of",
"attribute",
"names",
"with",
"presence",
"validations"
] | 458105154574950aed98119fd54ffaae4e1a55ee | https://github.com/Mik-die/mongoid_globalize/blob/458105154574950aed98119fd54ffaae4e1a55ee/lib/mongoid_globalize/class_methods.rb#L47-L49 |
4,804 | Mik-die/mongoid_globalize | lib/mongoid_globalize/methods.rb | Mongoid::Globalize.Methods.translated_attributes | def translated_attributes
@translated_attributes ||= translated_attribute_names.inject({}) do |attrs, name|
attrs.merge(name.to_s => translation.send(name))
end
end | ruby | def translated_attributes
@translated_attributes ||= translated_attribute_names.inject({}) do |attrs, name|
attrs.merge(name.to_s => translation.send(name))
end
end | [
"def",
"translated_attributes",
"@translated_attributes",
"||=",
"translated_attribute_names",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"attrs",
",",
"name",
"|",
"attrs",
".",
"merge",
"(",
"name",
".",
"to_s",
"=>",
"translation",
".",
"send",
"(",
"name",
")",
")",
"end",
"end"
] | Returns translations for current locale. Is used for initial mixing into
@attributes hash. Actual translations are in @translated_attributes hash.
Return Hash | [
"Returns",
"translations",
"for",
"current",
"locale",
".",
"Is",
"used",
"for",
"initial",
"mixing",
"into"
] | 458105154574950aed98119fd54ffaae4e1a55ee | https://github.com/Mik-die/mongoid_globalize/blob/458105154574950aed98119fd54ffaae4e1a55ee/lib/mongoid_globalize/methods.rb#L90-L94 |
4,805 | Mik-die/mongoid_globalize | lib/mongoid_globalize/methods.rb | Mongoid::Globalize.Methods.translation_for | def translation_for(locale)
@translation_caches ||= {}
# Need to temporary switch of merging, because #translations uses
# #attributes method too, to avoid stack level too deep error.
@stop_merging_translated_attributes = true
unless @translation_caches[locale]
_translation = translations.find_by_locale(locale)
_translation ||= translations.build(:locale => locale)
@translation_caches[locale] = _translation
end
@stop_merging_translated_attributes = false
@translation_caches[locale]
end | ruby | def translation_for(locale)
@translation_caches ||= {}
# Need to temporary switch of merging, because #translations uses
# #attributes method too, to avoid stack level too deep error.
@stop_merging_translated_attributes = true
unless @translation_caches[locale]
_translation = translations.find_by_locale(locale)
_translation ||= translations.build(:locale => locale)
@translation_caches[locale] = _translation
end
@stop_merging_translated_attributes = false
@translation_caches[locale]
end | [
"def",
"translation_for",
"(",
"locale",
")",
"@translation_caches",
"||=",
"{",
"}",
"# Need to temporary switch of merging, because #translations uses\r",
"# #attributes method too, to avoid stack level too deep error.\r",
"@stop_merging_translated_attributes",
"=",
"true",
"unless",
"@translation_caches",
"[",
"locale",
"]",
"_translation",
"=",
"translations",
".",
"find_by_locale",
"(",
"locale",
")",
"_translation",
"||=",
"translations",
".",
"build",
"(",
":locale",
"=>",
"locale",
")",
"@translation_caches",
"[",
"locale",
"]",
"=",
"_translation",
"end",
"@stop_merging_translated_attributes",
"=",
"false",
"@translation_caches",
"[",
"locale",
"]",
"end"
] | Returns instance of Translation for given locale.
Param String or Symbol | [
"Returns",
"instance",
"of",
"Translation",
"for",
"given",
"locale",
".",
"Param",
"String",
"or",
"Symbol"
] | 458105154574950aed98119fd54ffaae4e1a55ee | https://github.com/Mik-die/mongoid_globalize/blob/458105154574950aed98119fd54ffaae4e1a55ee/lib/mongoid_globalize/methods.rb#L146-L158 |
4,806 | Mik-die/mongoid_globalize | lib/mongoid_globalize/methods.rb | Mongoid::Globalize.Methods.used_locales | def used_locales
locales = globalize.stash.keys.concat(globalize.stash.keys).concat(translations.translated_locales)
locales.uniq!
locales
end | ruby | def used_locales
locales = globalize.stash.keys.concat(globalize.stash.keys).concat(translations.translated_locales)
locales.uniq!
locales
end | [
"def",
"used_locales",
"locales",
"=",
"globalize",
".",
"stash",
".",
"keys",
".",
"concat",
"(",
"globalize",
".",
"stash",
".",
"keys",
")",
".",
"concat",
"(",
"translations",
".",
"translated_locales",
")",
"locales",
".",
"uniq!",
"locales",
"end"
] | Return Array with locales, used for translation of this document | [
"Return",
"Array",
"with",
"locales",
"used",
"for",
"translation",
"of",
"this",
"document"
] | 458105154574950aed98119fd54ffaae4e1a55ee | https://github.com/Mik-die/mongoid_globalize/blob/458105154574950aed98119fd54ffaae4e1a55ee/lib/mongoid_globalize/methods.rb#L172-L176 |
4,807 | Mik-die/mongoid_globalize | lib/mongoid_globalize/methods.rb | Mongoid::Globalize.Methods.prepare_translations! | def prepare_translations!
@stop_merging_translated_attributes = true
translated_attribute_names.each do |name|
@attributes.delete name.to_s
@changed_attributes.delete name.to_s if @changed_attributes
end
globalize.prepare_translations!
end | ruby | def prepare_translations!
@stop_merging_translated_attributes = true
translated_attribute_names.each do |name|
@attributes.delete name.to_s
@changed_attributes.delete name.to_s if @changed_attributes
end
globalize.prepare_translations!
end | [
"def",
"prepare_translations!",
"@stop_merging_translated_attributes",
"=",
"true",
"translated_attribute_names",
".",
"each",
"do",
"|",
"name",
"|",
"@attributes",
".",
"delete",
"name",
".",
"to_s",
"@changed_attributes",
".",
"delete",
"name",
".",
"to_s",
"if",
"@changed_attributes",
"end",
"globalize",
".",
"prepare_translations!",
"end"
] | Before save callback. Cleans @attributes hash from translated attributes
and prepares them for persisting. | [
"Before",
"save",
"callback",
".",
"Cleans"
] | 458105154574950aed98119fd54ffaae4e1a55ee | https://github.com/Mik-die/mongoid_globalize/blob/458105154574950aed98119fd54ffaae4e1a55ee/lib/mongoid_globalize/methods.rb#L180-L187 |
4,808 | sportngin/ical_importer | lib/ical_importer/single_event_builder.rb | IcalImporter.SingleEventBuilder.build | def build
# handle recuring events
@local_event.tap do |le|
if @event.rrule.present?
@rrule = @event.rrule.first # only support recurrence on one schedule
# set out new event's basic rucurring properties
le.attributes = recurrence_attributes
set_date_exclusion
frequency_set
else # make sure we remove this if it changed
le.attributes = non_recurrence_attributes
end
end
end | ruby | def build
# handle recuring events
@local_event.tap do |le|
if @event.rrule.present?
@rrule = @event.rrule.first # only support recurrence on one schedule
# set out new event's basic rucurring properties
le.attributes = recurrence_attributes
set_date_exclusion
frequency_set
else # make sure we remove this if it changed
le.attributes = non_recurrence_attributes
end
end
end | [
"def",
"build",
"# handle recuring events",
"@local_event",
".",
"tap",
"do",
"|",
"le",
"|",
"if",
"@event",
".",
"rrule",
".",
"present?",
"@rrule",
"=",
"@event",
".",
"rrule",
".",
"first",
"# only support recurrence on one schedule",
"# set out new event's basic rucurring properties",
"le",
".",
"attributes",
"=",
"recurrence_attributes",
"set_date_exclusion",
"frequency_set",
"else",
"# make sure we remove this if it changed",
"le",
".",
"attributes",
"=",
"non_recurrence_attributes",
"end",
"end",
"end"
] | Get single-occurrence events built and get a lits of recurrence
events, these must be build last | [
"Get",
"single",
"-",
"occurrence",
"events",
"built",
"and",
"get",
"a",
"lits",
"of",
"recurrence",
"events",
"these",
"must",
"be",
"build",
"last"
] | 4a78590e973c3f1695797fd7d5f5b0cd93a86c52 | https://github.com/sportngin/ical_importer/blob/4a78590e973c3f1695797fd7d5f5b0cd93a86c52/lib/ical_importer/single_event_builder.rb#L12-L26 |
4,809 | r7kamura/jsonism | lib/jsonism/definer.rb | Jsonism.Definer.define_methods_into | def define_methods_into(client)
links.each do |link|
@client.define_singleton_method(link.method_signature) do |params = {}, headers = {}|
Request.call(client: client, headers: headers, link: link, params: params)
end
end
end | ruby | def define_methods_into(client)
links.each do |link|
@client.define_singleton_method(link.method_signature) do |params = {}, headers = {}|
Request.call(client: client, headers: headers, link: link, params: params)
end
end
end | [
"def",
"define_methods_into",
"(",
"client",
")",
"links",
".",
"each",
"do",
"|",
"link",
"|",
"@client",
".",
"define_singleton_method",
"(",
"link",
".",
"method_signature",
")",
"do",
"|",
"params",
"=",
"{",
"}",
",",
"headers",
"=",
"{",
"}",
"|",
"Request",
".",
"call",
"(",
"client",
":",
"client",
",",
"headers",
":",
"headers",
",",
"link",
":",
"link",
",",
"params",
":",
"params",
")",
"end",
"end",
"end"
] | Defines methods into client
@example
client.list_app
client.info_app(id: 1) | [
"Defines",
"methods",
"into",
"client"
] | 4e3bcc5413aed3cfadb5f9b23e6e5dc2eb4d8790 | https://github.com/r7kamura/jsonism/blob/4e3bcc5413aed3cfadb5f9b23e6e5dc2eb4d8790/lib/jsonism/definer.rb#L79-L85 |
4,810 | samvera-labs/geo_works | app/helpers/geo_works/bounding_box_helper.rb | GeoWorks.BoundingBoxHelper.bbox | def bbox(property)
markup = ''
markup << %(<div id='bbox'></div>)
markup << bbox_display_inputs
markup << bbox_script_tag(property)
markup.html_safe
end | ruby | def bbox(property)
markup = ''
markup << %(<div id='bbox'></div>)
markup << bbox_display_inputs
markup << bbox_script_tag(property)
markup.html_safe
end | [
"def",
"bbox",
"(",
"property",
")",
"markup",
"=",
"''",
"markup",
"<<",
"%(<div id='bbox'></div>)",
"markup",
"<<",
"bbox_display_inputs",
"markup",
"<<",
"bbox_script_tag",
"(",
"property",
")",
"markup",
".",
"html_safe",
"end"
] | Builds HTML string for bounding box selector tool.
Calls boundingBoxSelector javascript function and
passes the id of the location input element that it binds to.
@param [Symbol] name of property that holds bounding box string
@return[String] | [
"Builds",
"HTML",
"string",
"for",
"bounding",
"box",
"selector",
"tool",
".",
"Calls",
"boundingBoxSelector",
"javascript",
"function",
"and",
"passes",
"the",
"id",
"of",
"the",
"location",
"input",
"element",
"that",
"it",
"binds",
"to",
"."
] | df1eff35fd01469a623fafeb9d71b44fd6160ca8 | https://github.com/samvera-labs/geo_works/blob/df1eff35fd01469a623fafeb9d71b44fd6160ca8/app/helpers/geo_works/bounding_box_helper.rb#L9-L15 |
4,811 | blinkist/grantinee | lib/grantinee/cli.rb | Grantinee.CLI.process_database_param | def process_database_param
unless @options[:config] || Grantinee.configuration.configured?
Grantinee::Engine.detect_active_record_connection!
unless Grantinee.configuration.configured?
raise "No configuration file found. Please use the -c option"\
" to pass a configuration file."
end
end
require options[:config]
rescue StandardError, LoadError => error
puts error
exit
end | ruby | def process_database_param
unless @options[:config] || Grantinee.configuration.configured?
Grantinee::Engine.detect_active_record_connection!
unless Grantinee.configuration.configured?
raise "No configuration file found. Please use the -c option"\
" to pass a configuration file."
end
end
require options[:config]
rescue StandardError, LoadError => error
puts error
exit
end | [
"def",
"process_database_param",
"unless",
"@options",
"[",
":config",
"]",
"||",
"Grantinee",
".",
"configuration",
".",
"configured?",
"Grantinee",
"::",
"Engine",
".",
"detect_active_record_connection!",
"unless",
"Grantinee",
".",
"configuration",
".",
"configured?",
"raise",
"\"No configuration file found. Please use the -c option\"",
"\" to pass a configuration file.\"",
"end",
"end",
"require",
"options",
"[",
":config",
"]",
"rescue",
"StandardError",
",",
"LoadError",
"=>",
"error",
"puts",
"error",
"exit",
"end"
] | Database configuration file | [
"Database",
"configuration",
"file"
] | ba0c9a8ccaf377c2484c814d39359f01f7e56ded | https://github.com/blinkist/grantinee/blob/ba0c9a8ccaf377c2484c814d39359f01f7e56ded/lib/grantinee/cli.rb#L110-L124 |
4,812 | blinkist/grantinee | lib/grantinee/cli.rb | Grantinee.CLI.process_verbosity_param | def process_verbosity_param
return unless @options[:verbose]
log_levels = %w[debug info warn error fatal unknown]
@logger.level = log_levels.index(@options[:verbose])
end | ruby | def process_verbosity_param
return unless @options[:verbose]
log_levels = %w[debug info warn error fatal unknown]
@logger.level = log_levels.index(@options[:verbose])
end | [
"def",
"process_verbosity_param",
"return",
"unless",
"@options",
"[",
":verbose",
"]",
"log_levels",
"=",
"%w[",
"debug",
"info",
"warn",
"error",
"fatal",
"unknown",
"]",
"@logger",
".",
"level",
"=",
"log_levels",
".",
"index",
"(",
"@options",
"[",
":verbose",
"]",
")",
"end"
] | Explicit verbose mode, overrides configuration value | [
"Explicit",
"verbose",
"mode",
"overrides",
"configuration",
"value"
] | ba0c9a8ccaf377c2484c814d39359f01f7e56ded | https://github.com/blinkist/grantinee/blob/ba0c9a8ccaf377c2484c814d39359f01f7e56ded/lib/grantinee/cli.rb#L132-L136 |
4,813 | IntrepidPursuits/danger-shellcheck | lib/shellcheck/plugin.rb | Danger.DangerShellcheck.report | def report(file_path)
raise 'ShellCheck summary file not found' unless File.file?(file_path)
shellcheck_summary = JSON.parse(File.read(file_path), symbolize_names: true)
run_summary(shellcheck_summary)
end | ruby | def report(file_path)
raise 'ShellCheck summary file not found' unless File.file?(file_path)
shellcheck_summary = JSON.parse(File.read(file_path), symbolize_names: true)
run_summary(shellcheck_summary)
end | [
"def",
"report",
"(",
"file_path",
")",
"raise",
"'ShellCheck summary file not found'",
"unless",
"File",
".",
"file?",
"(",
"file_path",
")",
"shellcheck_summary",
"=",
"JSON",
".",
"parse",
"(",
"File",
".",
"read",
"(",
"file_path",
")",
",",
"symbolize_names",
":",
"true",
")",
"run_summary",
"(",
"shellcheck_summary",
")",
"end"
] | Reads a file with JSON ShellCheck summary and reports it.
@param [String] file_path Path for ShellCheck summary in JSON format.
@return [void] | [
"Reads",
"a",
"file",
"with",
"JSON",
"ShellCheck",
"summary",
"and",
"reports",
"it",
"."
] | b6e02ed40cde8036721c8692c2e27d858b85fb1b | https://github.com/IntrepidPursuits/danger-shellcheck/blob/b6e02ed40cde8036721c8692c2e27d858b85fb1b/lib/shellcheck/plugin.rb#L41-L45 |
4,814 | IntrepidPursuits/danger-shellcheck | lib/shellcheck/plugin.rb | Danger.DangerShellcheck.parse_files | def parse_files(shellcheck_summary)
shellcheck_summary.each do |element|
file = element[:file]
@files.add(file)
level = element[:level]
message = format_violation(file, element)
if level == 'error'
@error_count += 1
fail(message, sticky: false)
else
if level == 'warning'
@warning_count += 1
elsif level == 'info'
@info_count += 1
else
@style_count += 1
end
warn(message, sticky: false)
end
end
end | ruby | def parse_files(shellcheck_summary)
shellcheck_summary.each do |element|
file = element[:file]
@files.add(file)
level = element[:level]
message = format_violation(file, element)
if level == 'error'
@error_count += 1
fail(message, sticky: false)
else
if level == 'warning'
@warning_count += 1
elsif level == 'info'
@info_count += 1
else
@style_count += 1
end
warn(message, sticky: false)
end
end
end | [
"def",
"parse_files",
"(",
"shellcheck_summary",
")",
"shellcheck_summary",
".",
"each",
"do",
"|",
"element",
"|",
"file",
"=",
"element",
"[",
":file",
"]",
"@files",
".",
"add",
"(",
"file",
")",
"level",
"=",
"element",
"[",
":level",
"]",
"message",
"=",
"format_violation",
"(",
"file",
",",
"element",
")",
"if",
"level",
"==",
"'error'",
"@error_count",
"+=",
"1",
"fail",
"(",
"message",
",",
"sticky",
":",
"false",
")",
"else",
"if",
"level",
"==",
"'warning'",
"@warning_count",
"+=",
"1",
"elsif",
"level",
"==",
"'info'",
"@info_count",
"+=",
"1",
"else",
"@style_count",
"+=",
"1",
"end",
"warn",
"(",
"message",
",",
"sticky",
":",
"false",
")",
"end",
"end",
"end"
] | A method that takes the ShellCheck summary and parses any violations found | [
"A",
"method",
"that",
"takes",
"the",
"ShellCheck",
"summary",
"and",
"parses",
"any",
"violations",
"found"
] | b6e02ed40cde8036721c8692c2e27d858b85fb1b | https://github.com/IntrepidPursuits/danger-shellcheck/blob/b6e02ed40cde8036721c8692c2e27d858b85fb1b/lib/shellcheck/plugin.rb#L68-L90 |
4,815 | samvera-labs/geo_works | spec/support/features/session_helpers.rb | Features.SessionHelpers.sign_up_with | def sign_up_with(email, password)
Capybara.exact = true
visit new_user_registration_path
fill_in 'Email', with: email
fill_in 'Password', with: password
fill_in 'Password confirmation', with: password
click_button 'Sign up'
end | ruby | def sign_up_with(email, password)
Capybara.exact = true
visit new_user_registration_path
fill_in 'Email', with: email
fill_in 'Password', with: password
fill_in 'Password confirmation', with: password
click_button 'Sign up'
end | [
"def",
"sign_up_with",
"(",
"email",
",",
"password",
")",
"Capybara",
".",
"exact",
"=",
"true",
"visit",
"new_user_registration_path",
"fill_in",
"'Email'",
",",
"with",
":",
"email",
"fill_in",
"'Password'",
",",
"with",
":",
"password",
"fill_in",
"'Password confirmation'",
",",
"with",
":",
"password",
"click_button",
"'Sign up'",
"end"
] | Poltergeist-friendly sign-up
Use this in feature tests | [
"Poltergeist",
"-",
"friendly",
"sign",
"-",
"up",
"Use",
"this",
"in",
"feature",
"tests"
] | df1eff35fd01469a623fafeb9d71b44fd6160ca8 | https://github.com/samvera-labs/geo_works/blob/df1eff35fd01469a623fafeb9d71b44fd6160ca8/spec/support/features/session_helpers.rb#L16-L23 |
4,816 | samvera-labs/geo_works | spec/support/features/session_helpers.rb | Features.SessionHelpers.sign_in | def sign_in(who = :user)
user = if who.instance_of?(User)
who
else
FactoryGirl.build(:user).tap(&:save!)
end
visit new_user_session_path
fill_in 'Email', with: user.email
fill_in 'Password', with: user.password
click_button 'Log in'
expect(page).not_to have_text 'Invalid email or password.'
end | ruby | def sign_in(who = :user)
user = if who.instance_of?(User)
who
else
FactoryGirl.build(:user).tap(&:save!)
end
visit new_user_session_path
fill_in 'Email', with: user.email
fill_in 'Password', with: user.password
click_button 'Log in'
expect(page).not_to have_text 'Invalid email or password.'
end | [
"def",
"sign_in",
"(",
"who",
"=",
":user",
")",
"user",
"=",
"if",
"who",
".",
"instance_of?",
"(",
"User",
")",
"who",
"else",
"FactoryGirl",
".",
"build",
"(",
":user",
")",
".",
"tap",
"(",
":save!",
")",
"end",
"visit",
"new_user_session_path",
"fill_in",
"'Email'",
",",
"with",
":",
"user",
".",
"email",
"fill_in",
"'Password'",
",",
"with",
":",
"user",
".",
"password",
"click_button",
"'Log in'",
"expect",
"(",
"page",
")",
".",
"not_to",
"have_text",
"'Invalid email or password.'",
"end"
] | Poltergeist-friendly sign-in
Use this in feature tests | [
"Poltergeist",
"-",
"friendly",
"sign",
"-",
"in",
"Use",
"this",
"in",
"feature",
"tests"
] | df1eff35fd01469a623fafeb9d71b44fd6160ca8 | https://github.com/samvera-labs/geo_works/blob/df1eff35fd01469a623fafeb9d71b44fd6160ca8/spec/support/features/session_helpers.rb#L27-L38 |
4,817 | couchrest/couchrest_extended_document | lib/couchrest/support/couchrest.rb | CouchRest.Database.clear_extended_doc_fresh_cache | def clear_extended_doc_fresh_cache
::CouchRest::ExtendedDocument.subclasses.each{|klass| klass.req_design_doc_refresh if klass.respond_to?(:req_design_doc_refresh)}
end | ruby | def clear_extended_doc_fresh_cache
::CouchRest::ExtendedDocument.subclasses.each{|klass| klass.req_design_doc_refresh if klass.respond_to?(:req_design_doc_refresh)}
end | [
"def",
"clear_extended_doc_fresh_cache",
"::",
"CouchRest",
"::",
"ExtendedDocument",
".",
"subclasses",
".",
"each",
"{",
"|",
"klass",
"|",
"klass",
".",
"req_design_doc_refresh",
"if",
"klass",
".",
"respond_to?",
"(",
":req_design_doc_refresh",
")",
"}",
"end"
] | If the database is deleted, ensure that the design docs will be refreshed. | [
"If",
"the",
"database",
"is",
"deleted",
"ensure",
"that",
"the",
"design",
"docs",
"will",
"be",
"refreshed",
"."
] | 71511202ae10d3010dcf7b98fcba017cb37c76da | https://github.com/couchrest/couchrest_extended_document/blob/71511202ae10d3010dcf7b98fcba017cb37c76da/lib/couchrest/support/couchrest.rb#L13-L15 |
4,818 | imanel/odt2html | lib/odt2html/analyze_content.rb | ODT2HTML.AnalyzeContent.register_style | def register_style( element )
# get namespace prefix for this element
style_name = element.attribute("#{element.prefix}:style-name");
if (style_name != nil) then
style_name = style_name.value.tr_s('.','_')
if (@style_info[style_name] != nil) then
@style_info[style_name].block_used = true
end
end
return style_name
end | ruby | def register_style( element )
# get namespace prefix for this element
style_name = element.attribute("#{element.prefix}:style-name");
if (style_name != nil) then
style_name = style_name.value.tr_s('.','_')
if (@style_info[style_name] != nil) then
@style_info[style_name].block_used = true
end
end
return style_name
end | [
"def",
"register_style",
"(",
"element",
")",
"# get namespace prefix for this element",
"style_name",
"=",
"element",
".",
"attribute",
"(",
"\"#{element.prefix}:style-name\"",
")",
";",
"if",
"(",
"style_name",
"!=",
"nil",
")",
"then",
"style_name",
"=",
"style_name",
".",
"value",
".",
"tr_s",
"(",
"'.'",
",",
"'_'",
")",
"if",
"(",
"@style_info",
"[",
"style_name",
"]",
"!=",
"nil",
")",
"then",
"@style_info",
"[",
"style_name",
"]",
".",
"block_used",
"=",
"true",
"end",
"end",
"return",
"style_name",
"end"
] | Return the style name for this element, with periods
changed to underscores to make it valid CSS.
Side effect: registers this style as "having been used"
in the document | [
"Return",
"the",
"style",
"name",
"for",
"this",
"element",
"with",
"periods",
"changed",
"to",
"underscores",
"to",
"make",
"it",
"valid",
"CSS",
"."
] | ae155289a9290adef55a5eddfa7c9bfe8eeb7a34 | https://github.com/imanel/odt2html/blob/ae155289a9290adef55a5eddfa7c9bfe8eeb7a34/lib/odt2html/analyze_content.rb#L254-L264 |
4,819 | tachyons/luis | lib/luis/result.rb | Luis.Result.entities_of_type | def entities_of_type(type)
@entities.select { |entity| entity['type'] == type }.map { |entity| Entity.new entity }
end | ruby | def entities_of_type(type)
@entities.select { |entity| entity['type'] == type }.map { |entity| Entity.new entity }
end | [
"def",
"entities_of_type",
"(",
"type",
")",
"@entities",
".",
"select",
"{",
"|",
"entity",
"|",
"entity",
"[",
"'type'",
"]",
"==",
"type",
"}",
".",
"map",
"{",
"|",
"entity",
"|",
"Entity",
".",
"new",
"entity",
"}",
"end"
] | Entitities with specific type | [
"Entitities",
"with",
"specific",
"type"
] | ef22bd70a84b4a532b57c9cb57e5acdabb5baded | https://github.com/tachyons/luis/blob/ef22bd70a84b4a532b57c9cb57e5acdabb5baded/lib/luis/result.rb#L31-L33 |
4,820 | yoyo0906/ruby-adb-sdklib | lib/adb_sdklib/common.rb | AdbSdkLib.Common.convert_map_to_hash | def convert_map_to_hash(object, &block)
hash = Hash.new
i = object.entrySet.iterator
if block_given?
while i.hasNext
entry = i.next
yield hash, entry.getKey, entry.getValue
end
else
while i.hasNext
entry = i.next
hash[entry.getKey] = entry.getValue
end
end
hash
end | ruby | def convert_map_to_hash(object, &block)
hash = Hash.new
i = object.entrySet.iterator
if block_given?
while i.hasNext
entry = i.next
yield hash, entry.getKey, entry.getValue
end
else
while i.hasNext
entry = i.next
hash[entry.getKey] = entry.getValue
end
end
hash
end | [
"def",
"convert_map_to_hash",
"(",
"object",
",",
"&",
"block",
")",
"hash",
"=",
"Hash",
".",
"new",
"i",
"=",
"object",
".",
"entrySet",
".",
"iterator",
"if",
"block_given?",
"while",
"i",
".",
"hasNext",
"entry",
"=",
"i",
".",
"next",
"yield",
"hash",
",",
"entry",
".",
"getKey",
",",
"entry",
".",
"getValue",
"end",
"else",
"while",
"i",
".",
"hasNext",
"entry",
"=",
"i",
".",
"next",
"hash",
"[",
"entry",
".",
"getKey",
"]",
"=",
"entry",
".",
"getValue",
"end",
"end",
"hash",
"end"
] | Converts Java Map object to Ruby Hash object. | [
"Converts",
"Java",
"Map",
"object",
"to",
"Ruby",
"Hash",
"object",
"."
] | 9f8a5c88ee8e7b572600ca7919b506bfc0e8d105 | https://github.com/yoyo0906/ruby-adb-sdklib/blob/9f8a5c88ee8e7b572600ca7919b506bfc0e8d105/lib/adb_sdklib/common.rb#L78-L93 |
4,821 | ftomassetti/codemodels | lib/codemodels/parser.rb | CodeModels.Parser.parse_file | def parse_file(path,file_encoding=nil)
file_encoding = @internal_encoding unless file_encoding
code = IO.read(path,{ :encoding => file_encoding, :mode => 'rb'})
code = code.encode(@internal_encoding)
artifact = FileArtifact.new(path,code)
parse_artifact(artifact)
end | ruby | def parse_file(path,file_encoding=nil)
file_encoding = @internal_encoding unless file_encoding
code = IO.read(path,{ :encoding => file_encoding, :mode => 'rb'})
code = code.encode(@internal_encoding)
artifact = FileArtifact.new(path,code)
parse_artifact(artifact)
end | [
"def",
"parse_file",
"(",
"path",
",",
"file_encoding",
"=",
"nil",
")",
"file_encoding",
"=",
"@internal_encoding",
"unless",
"file_encoding",
"code",
"=",
"IO",
".",
"read",
"(",
"path",
",",
"{",
":encoding",
"=>",
"file_encoding",
",",
":mode",
"=>",
"'rb'",
"}",
")",
"code",
"=",
"code",
".",
"encode",
"(",
"@internal_encoding",
")",
"artifact",
"=",
"FileArtifact",
".",
"new",
"(",
"path",
",",
"code",
")",
"parse_artifact",
"(",
"artifact",
")",
"end"
] | Parse the file by producing an artifact corresponding to the file | [
"Parse",
"the",
"file",
"by",
"producing",
"an",
"artifact",
"corresponding",
"to",
"the",
"file"
] | fb08f1fe13dad5a20c32b59d88bc5e9f3faa60f2 | https://github.com/ftomassetti/codemodels/blob/fb08f1fe13dad5a20c32b59d88bc5e9f3faa60f2/lib/codemodels/parser.rb#L29-L35 |
4,822 | ftomassetti/codemodels | lib/codemodels/parser.rb | CodeModels.Parser.parse_string | def parse_string(code)
code = code.encode(@internal_encoding)
artifact = StringArtifact.new(code)
parse_artifact(artifact)
end | ruby | def parse_string(code)
code = code.encode(@internal_encoding)
artifact = StringArtifact.new(code)
parse_artifact(artifact)
end | [
"def",
"parse_string",
"(",
"code",
")",
"code",
"=",
"code",
".",
"encode",
"(",
"@internal_encoding",
")",
"artifact",
"=",
"StringArtifact",
".",
"new",
"(",
"code",
")",
"parse_artifact",
"(",
"artifact",
")",
"end"
] | Parse the file by producing an artifact corresponding to the string | [
"Parse",
"the",
"file",
"by",
"producing",
"an",
"artifact",
"corresponding",
"to",
"the",
"string"
] | fb08f1fe13dad5a20c32b59d88bc5e9f3faa60f2 | https://github.com/ftomassetti/codemodels/blob/fb08f1fe13dad5a20c32b59d88bc5e9f3faa60f2/lib/codemodels/parser.rb#L38-L42 |
4,823 | yoyo0906/ruby-adb-sdklib | lib/adb-sdklib.rb | AdbSdkLib.Adb.devices | def devices
devices = @adb.devices.map { |d|
serial = d.serial_number
(@devices.has_key?(serial) && same_jobject?(@devices[serial].jobject, d)) \
? @devices[serial] : Device.new(d)
}
@devices = DeviceList.new(devices)
return @devices
end | ruby | def devices
devices = @adb.devices.map { |d|
serial = d.serial_number
(@devices.has_key?(serial) && same_jobject?(@devices[serial].jobject, d)) \
? @devices[serial] : Device.new(d)
}
@devices = DeviceList.new(devices)
return @devices
end | [
"def",
"devices",
"devices",
"=",
"@adb",
".",
"devices",
".",
"map",
"{",
"|",
"d",
"|",
"serial",
"=",
"d",
".",
"serial_number",
"(",
"@devices",
".",
"has_key?",
"(",
"serial",
")",
"&&",
"same_jobject?",
"(",
"@devices",
"[",
"serial",
"]",
".",
"jobject",
",",
"d",
")",
")",
"?",
"@devices",
"[",
"serial",
"]",
":",
"Device",
".",
"new",
"(",
"d",
")",
"}",
"@devices",
"=",
"DeviceList",
".",
"new",
"(",
"devices",
")",
"return",
"@devices",
"end"
] | Get devices attached with ADB.
@return [DeviceList] List of devices | [
"Get",
"devices",
"attached",
"with",
"ADB",
"."
] | 9f8a5c88ee8e7b572600ca7919b506bfc0e8d105 | https://github.com/yoyo0906/ruby-adb-sdklib/blob/9f8a5c88ee8e7b572600ca7919b506bfc0e8d105/lib/adb-sdklib.rb#L89-L97 |
4,824 | envylabs/vaulted_billing | lib/vaulted_billing/credit_card.rb | VaultedBilling.CreditCard.attributes | def attributes
{
:vault_id => vault_id,
:currency => currency,
:card_number => card_number,
:cvv_number => cvv_number,
:expires_on => expires_on,
:first_name => first_name,
:last_name => last_name,
:street_address => street_address,
:locality => locality,
:region => region,
:postal_code => postal_code,
:country => country,
:phone => phone
}
end | ruby | def attributes
{
:vault_id => vault_id,
:currency => currency,
:card_number => card_number,
:cvv_number => cvv_number,
:expires_on => expires_on,
:first_name => first_name,
:last_name => last_name,
:street_address => street_address,
:locality => locality,
:region => region,
:postal_code => postal_code,
:country => country,
:phone => phone
}
end | [
"def",
"attributes",
"{",
":vault_id",
"=>",
"vault_id",
",",
":currency",
"=>",
"currency",
",",
":card_number",
"=>",
"card_number",
",",
":cvv_number",
"=>",
"cvv_number",
",",
":expires_on",
"=>",
"expires_on",
",",
":first_name",
"=>",
"first_name",
",",
":last_name",
"=>",
"last_name",
",",
":street_address",
"=>",
"street_address",
",",
":locality",
"=>",
"locality",
",",
":region",
"=>",
"region",
",",
":postal_code",
"=>",
"postal_code",
",",
":country",
"=>",
"country",
",",
":phone",
"=>",
"phone",
"}",
"end"
] | The unique, gateway-generated identifier for this credit card.
You may define any of the CreditCard attributes by passing a hash
with the attribute name as the key:
CreditCard.new(:card_number => '4111....') | [
"The",
"unique",
"gateway",
"-",
"generated",
"identifier",
"for",
"this",
"credit",
"card",
"."
] | a2d9689a6c500a3983100e657abe1606daa09d3a | https://github.com/envylabs/vaulted_billing/blob/a2d9689a6c500a3983100e657abe1606daa09d3a/lib/vaulted_billing/credit_card.rb#L67-L83 |
4,825 | phatworx/rails_paginate | lib/rails_paginate/helpers/array.rb | RailsPaginate::Helpers.Array.paginate | def paginate(*args)
options = args.extract_options!
per_page = options.delete(:per_page)
page = options.delete(:page) || 1
::RailsPaginate::Collection.new(self, args.first || page, per_page)
end | ruby | def paginate(*args)
options = args.extract_options!
per_page = options.delete(:per_page)
page = options.delete(:page) || 1
::RailsPaginate::Collection.new(self, args.first || page, per_page)
end | [
"def",
"paginate",
"(",
"*",
"args",
")",
"options",
"=",
"args",
".",
"extract_options!",
"per_page",
"=",
"options",
".",
"delete",
"(",
":per_page",
")",
"page",
"=",
"options",
".",
"delete",
"(",
":page",
")",
"||",
"1",
"::",
"RailsPaginate",
"::",
"Collection",
".",
"new",
"(",
"self",
",",
"args",
".",
"first",
"||",
"page",
",",
"per_page",
")",
"end"
] | paginate with options
page = active page
per_page = how much entries per page | [
"paginate",
"with",
"options"
] | ae8cbc12030853b236dc2cbf6ede8700fb835771 | https://github.com/phatworx/rails_paginate/blob/ae8cbc12030853b236dc2cbf6ede8700fb835771/lib/rails_paginate/helpers/array.rb#L8-L13 |
4,826 | topfunky/google-checkout | lib/google-checkout/command.rb | GoogleCheckout.Command.post | def post
# Create HTTP(S) POST command and set up Basic Authentication.
uri = URI.parse(url)
request = Net::HTTP::Post.new(uri.path)
request.basic_auth(@merchant_id, @merchant_key)
# Set up the HTTP connection object and the SSL layer.
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
https.cert_store = self.class.x509_store
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.verify_depth = 5
# Send the request to Google.
response = https.request(request, self.to_xml)
# NOTE Because Notification.parse() is used, the content of objects
# will be correctly parsed no matter what the HTTP response code
# is from the server.
case response
when Net::HTTPSuccess, Net::HTTPClientError
notification = Notification.parse(response.body)
if notification.error?
raise APIError, "#{notification.message} [in #{GoogleCheckout.production? ? 'production' : 'sandbox' }]"
end
return notification
when Net::HTTPRedirection, Net::HTTPServerError, Net::HTTPInformation
raise "Unexpected response code (#{response.class}): #{response.code} - #{response.message}"
else
raise "Unknown response code: #{response.code} - #{response.message}"
end
end | ruby | def post
# Create HTTP(S) POST command and set up Basic Authentication.
uri = URI.parse(url)
request = Net::HTTP::Post.new(uri.path)
request.basic_auth(@merchant_id, @merchant_key)
# Set up the HTTP connection object and the SSL layer.
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
https.cert_store = self.class.x509_store
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.verify_depth = 5
# Send the request to Google.
response = https.request(request, self.to_xml)
# NOTE Because Notification.parse() is used, the content of objects
# will be correctly parsed no matter what the HTTP response code
# is from the server.
case response
when Net::HTTPSuccess, Net::HTTPClientError
notification = Notification.parse(response.body)
if notification.error?
raise APIError, "#{notification.message} [in #{GoogleCheckout.production? ? 'production' : 'sandbox' }]"
end
return notification
when Net::HTTPRedirection, Net::HTTPServerError, Net::HTTPInformation
raise "Unexpected response code (#{response.class}): #{response.code} - #{response.message}"
else
raise "Unknown response code: #{response.code} - #{response.message}"
end
end | [
"def",
"post",
"# Create HTTP(S) POST command and set up Basic Authentication.",
"uri",
"=",
"URI",
".",
"parse",
"(",
"url",
")",
"request",
"=",
"Net",
"::",
"HTTP",
"::",
"Post",
".",
"new",
"(",
"uri",
".",
"path",
")",
"request",
".",
"basic_auth",
"(",
"@merchant_id",
",",
"@merchant_key",
")",
"# Set up the HTTP connection object and the SSL layer.",
"https",
"=",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"uri",
".",
"host",
",",
"uri",
".",
"port",
")",
"https",
".",
"use_ssl",
"=",
"true",
"https",
".",
"cert_store",
"=",
"self",
".",
"class",
".",
"x509_store",
"https",
".",
"verify_mode",
"=",
"OpenSSL",
"::",
"SSL",
"::",
"VERIFY_PEER",
"https",
".",
"verify_depth",
"=",
"5",
"# Send the request to Google.",
"response",
"=",
"https",
".",
"request",
"(",
"request",
",",
"self",
".",
"to_xml",
")",
"# NOTE Because Notification.parse() is used, the content of objects",
"# will be correctly parsed no matter what the HTTP response code",
"# is from the server.",
"case",
"response",
"when",
"Net",
"::",
"HTTPSuccess",
",",
"Net",
"::",
"HTTPClientError",
"notification",
"=",
"Notification",
".",
"parse",
"(",
"response",
".",
"body",
")",
"if",
"notification",
".",
"error?",
"raise",
"APIError",
",",
"\"#{notification.message} [in #{GoogleCheckout.production? ? 'production' : 'sandbox' }]\"",
"end",
"return",
"notification",
"when",
"Net",
"::",
"HTTPRedirection",
",",
"Net",
"::",
"HTTPServerError",
",",
"Net",
"::",
"HTTPInformation",
"raise",
"\"Unexpected response code (#{response.class}): #{response.code} - #{response.message}\"",
"else",
"raise",
"\"Unknown response code: #{response.code} - #{response.message}\"",
"end",
"end"
] | Sends the Command's XML to GoogleCheckout via HTTPS with Basic Auth.
Returns a GoogleCheckout::RequestReceived or a GoogleCheckout::Error object. | [
"Sends",
"the",
"Command",
"s",
"XML",
"to",
"GoogleCheckout",
"via",
"HTTPS",
"with",
"Basic",
"Auth",
"."
] | 66089cef799bd40f3ba4370f01f1b8dc10f92115 | https://github.com/topfunky/google-checkout/blob/66089cef799bd40f3ba4370f01f1b8dc10f92115/lib/google-checkout/command.rb#L40-L72 |
4,827 | topfunky/google-checkout | lib/google-checkout/command.rb | GoogleCheckout.SendBuyerMessage.to_xml | def to_xml # :nodoc:
xml = Builder::XmlMarkup.new
xml.instruct!
@xml = xml.tag!('send-buyer-message', {
:xmlns => "http://checkout.google.com/schema/2",
"google-order-number" => @google_order_number
}) do
xml.tag!("message", @message)
xml.tag!("send-email", true)
end
@xml
end | ruby | def to_xml # :nodoc:
xml = Builder::XmlMarkup.new
xml.instruct!
@xml = xml.tag!('send-buyer-message', {
:xmlns => "http://checkout.google.com/schema/2",
"google-order-number" => @google_order_number
}) do
xml.tag!("message", @message)
xml.tag!("send-email", true)
end
@xml
end | [
"def",
"to_xml",
"# :nodoc:",
"xml",
"=",
"Builder",
"::",
"XmlMarkup",
".",
"new",
"xml",
".",
"instruct!",
"@xml",
"=",
"xml",
".",
"tag!",
"(",
"'send-buyer-message'",
",",
"{",
":xmlns",
"=>",
"\"http://checkout.google.com/schema/2\"",
",",
"\"google-order-number\"",
"=>",
"@google_order_number",
"}",
")",
"do",
"xml",
".",
"tag!",
"(",
"\"message\"",
",",
"@message",
")",
"xml",
".",
"tag!",
"(",
"\"send-email\"",
",",
"true",
")",
"end",
"@xml",
"end"
] | Make a new message to send.
The last argument is the actual message.
Call +post+ on the resulting object to submit it to Google for sending. | [
"Make",
"a",
"new",
"message",
"to",
"send",
"."
] | 66089cef799bd40f3ba4370f01f1b8dc10f92115 | https://github.com/topfunky/google-checkout/blob/66089cef799bd40f3ba4370f01f1b8dc10f92115/lib/google-checkout/command.rb#L176-L187 |
4,828 | dropofwill/rtasklib | lib/rtasklib/taskrc.rb | Rtasklib.Taskrc.hash_to_model | def hash_to_model taskrc_hash
taskrc_hash.each do |attr, value|
add_model_attr(attr, value)
set_model_attr_value(attr, value)
end
config
end | ruby | def hash_to_model taskrc_hash
taskrc_hash.each do |attr, value|
add_model_attr(attr, value)
set_model_attr_value(attr, value)
end
config
end | [
"def",
"hash_to_model",
"taskrc_hash",
"taskrc_hash",
".",
"each",
"do",
"|",
"attr",
",",
"value",
"|",
"add_model_attr",
"(",
"attr",
",",
"value",
")",
"set_model_attr_value",
"(",
"attr",
",",
"value",
")",
"end",
"config",
"end"
] | Generate a dynamic Virtus model, with the attributes defined by the input
@param rc [Hash, Pathname] either a hash of attribute value pairs
or a Pathname to the raw taskrc file.
@raise [TypeError] if rc is not of type Hash, String, or Pathname
@raise [RuntimeError] if rc is a path and does not exist on the fs
Turn a hash of attribute => value pairs into a TaskrcModel object.
There can be only one TaskrcModel object per Taskrc, it's saved to the
instance variable `config`
@param taskrc_hash [Hash{Symbol=>String}]
@return [Models::TaskrcModel] the instance variable config
@api private | [
"Generate",
"a",
"dynamic",
"Virtus",
"model",
"with",
"the",
"attributes",
"defined",
"by",
"the",
"input"
] | c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c | https://github.com/dropofwill/rtasklib/blob/c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c/lib/rtasklib/taskrc.rb#L54-L60 |
4,829 | dropofwill/rtasklib | lib/rtasklib/taskrc.rb | Rtasklib.Taskrc.mappable_to_model | def mappable_to_model rc_file
rc_file.map! { |l| line_to_tuple(l) }.compact!
taskrc = Hash[rc_file]
hash_to_model(taskrc)
end | ruby | def mappable_to_model rc_file
rc_file.map! { |l| line_to_tuple(l) }.compact!
taskrc = Hash[rc_file]
hash_to_model(taskrc)
end | [
"def",
"mappable_to_model",
"rc_file",
"rc_file",
".",
"map!",
"{",
"|",
"l",
"|",
"line_to_tuple",
"(",
"l",
")",
"}",
".",
"compact!",
"taskrc",
"=",
"Hash",
"[",
"rc_file",
"]",
"hash_to_model",
"(",
"taskrc",
")",
"end"
] | Converts a .taskrc file path into a Hash that can be converted into a
TaskrcModel object
@param rc_file [String,Pathname] a valid pathname to a .taskrc file
@return [Models::TaskrcModel] the instance variable config
@api private | [
"Converts",
"a",
".",
"taskrc",
"file",
"path",
"into",
"a",
"Hash",
"that",
"can",
"be",
"converted",
"into",
"a",
"TaskrcModel",
"object"
] | c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c | https://github.com/dropofwill/rtasklib/blob/c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c/lib/rtasklib/taskrc.rb#L69-L73 |
4,830 | dropofwill/rtasklib | lib/rtasklib/taskrc.rb | Rtasklib.Taskrc.part_of_model_to_rc | def part_of_model_to_rc *attrs
attrs.map do |attr|
value = get_model_attr_value attr
hash_attr = get_rc_attr_from_hash attr.to_s
attr = "rc.#{hash_attr}=#{value}"
end
end | ruby | def part_of_model_to_rc *attrs
attrs.map do |attr|
value = get_model_attr_value attr
hash_attr = get_rc_attr_from_hash attr.to_s
attr = "rc.#{hash_attr}=#{value}"
end
end | [
"def",
"part_of_model_to_rc",
"*",
"attrs",
"attrs",
".",
"map",
"do",
"|",
"attr",
"|",
"value",
"=",
"get_model_attr_value",
"attr",
"hash_attr",
"=",
"get_rc_attr_from_hash",
"attr",
".",
"to_s",
"attr",
"=",
"\"rc.#{hash_attr}=#{value}\"",
"end",
"end"
] | Serialize the given attrs model back to the taskrc format
@param attrs [Array] a splat of attributes
@return [Array<String>] an array of CLI formatted strings
@api public | [
"Serialize",
"the",
"given",
"attrs",
"model",
"back",
"to",
"the",
"taskrc",
"format"
] | c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c | https://github.com/dropofwill/rtasklib/blob/c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c/lib/rtasklib/taskrc.rb#L99-L105 |
4,831 | dropofwill/rtasklib | lib/rtasklib/taskrc.rb | Rtasklib.Taskrc.path_exist? | def path_exist? path
if path.is_a? Pathname
return path.exist?
elsif path.is_a? String
return Pathname.new(path).exist?
else
return false
end
end | ruby | def path_exist? path
if path.is_a? Pathname
return path.exist?
elsif path.is_a? String
return Pathname.new(path).exist?
else
return false
end
end | [
"def",
"path_exist?",
"path",
"if",
"path",
".",
"is_a?",
"Pathname",
"return",
"path",
".",
"exist?",
"elsif",
"path",
".",
"is_a?",
"String",
"return",
"Pathname",
".",
"new",
"(",
"path",
")",
".",
"exist?",
"else",
"return",
"false",
"end",
"end"
] | Check whether a given object is a path and it exists on the file system
@param path [Object]
@return [Boolean]
@api private | [
"Check",
"whether",
"a",
"given",
"object",
"is",
"a",
"path",
"and",
"it",
"exists",
"on",
"the",
"file",
"system"
] | c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c | https://github.com/dropofwill/rtasklib/blob/c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c/lib/rtasklib/taskrc.rb#L192-L200 |
4,832 | quirkey/jim | lib/jim/index.rb | Jim.Index.find_all | def find_all(name, version = nil)
matched = []
find(name, version) {|p| matched << p }
matched
end | ruby | def find_all(name, version = nil)
matched = []
find(name, version) {|p| matched << p }
matched
end | [
"def",
"find_all",
"(",
"name",
",",
"version",
"=",
"nil",
")",
"matched",
"=",
"[",
"]",
"find",
"(",
"name",
",",
"version",
")",
"{",
"|",
"p",
"|",
"matched",
"<<",
"p",
"}",
"matched",
"end"
] | Find _all_ paths matching `name` and `version`. Returning an array. | [
"Find",
"_all_",
"paths",
"matching",
"name",
"and",
"version",
".",
"Returning",
"an",
"array",
"."
] | ad5dbf06527a1d0376055a02b58bb11b5a0ebc35 | https://github.com/quirkey/jim/blob/ad5dbf06527a1d0376055a02b58bb11b5a0ebc35/lib/jim/index.rb#L73-L77 |
4,833 | buren/honey_format | lib/honey_format/matrix/header.rb | HoneyFormat.Header.to_csv | def to_csv(columns: nil)
attributes = if columns
self.columns & columns.map(&:to_sym)
else
self.columns
end
::CSV.generate_line(attributes)
end | ruby | def to_csv(columns: nil)
attributes = if columns
self.columns & columns.map(&:to_sym)
else
self.columns
end
::CSV.generate_line(attributes)
end | [
"def",
"to_csv",
"(",
"columns",
":",
"nil",
")",
"attributes",
"=",
"if",
"columns",
"self",
".",
"columns",
"&",
"columns",
".",
"map",
"(",
":to_sym",
")",
"else",
"self",
".",
"columns",
"end",
"::",
"CSV",
".",
"generate_line",
"(",
"attributes",
")",
"end"
] | Header as CSV-string
@return [String] CSV-string representation. | [
"Header",
"as",
"CSV",
"-",
"string"
] | 5c54fba5f5ba044721afeef460a069af2018452c | https://github.com/buren/honey_format/blob/5c54fba5f5ba044721afeef460a069af2018452c/lib/honey_format/matrix/header.rb#L83-L91 |
4,834 | buren/honey_format | lib/honey_format/matrix/header.rb | HoneyFormat.Header.build_columns | def build_columns(header)
columns = header.each_with_index.map do |header_column, index|
convert_column(header_column, index).tap do |column|
maybe_raise_missing_column!(column)
end
end
@deduplicator.call(columns)
end | ruby | def build_columns(header)
columns = header.each_with_index.map do |header_column, index|
convert_column(header_column, index).tap do |column|
maybe_raise_missing_column!(column)
end
end
@deduplicator.call(columns)
end | [
"def",
"build_columns",
"(",
"header",
")",
"columns",
"=",
"header",
".",
"each_with_index",
".",
"map",
"do",
"|",
"header_column",
",",
"index",
"|",
"convert_column",
"(",
"header_column",
",",
"index",
")",
".",
"tap",
"do",
"|",
"column",
"|",
"maybe_raise_missing_column!",
"(",
"column",
")",
"end",
"end",
"@deduplicator",
".",
"call",
"(",
"columns",
")",
"end"
] | Convert original header
@param [Array<String>] header the original header
@return [Array<String>] converted columns | [
"Convert",
"original",
"header"
] | 5c54fba5f5ba044721afeef460a069af2018452c | https://github.com/buren/honey_format/blob/5c54fba5f5ba044721afeef460a069af2018452c/lib/honey_format/matrix/header.rb#L122-L130 |
4,835 | buren/honey_format | lib/honey_format/matrix/header.rb | HoneyFormat.Header.convert_column | def convert_column(column, index)
value = if converter_arity == 1
@converter.call(column)
else
@converter.call(column, index)
end
value.to_sym
end | ruby | def convert_column(column, index)
value = if converter_arity == 1
@converter.call(column)
else
@converter.call(column, index)
end
value.to_sym
end | [
"def",
"convert_column",
"(",
"column",
",",
"index",
")",
"value",
"=",
"if",
"converter_arity",
"==",
"1",
"@converter",
".",
"call",
"(",
"column",
")",
"else",
"@converter",
".",
"call",
"(",
"column",
",",
"index",
")",
"end",
"value",
".",
"to_sym",
"end"
] | Convert the column value
@param [String, Symbol] column the CSV header column value
@param [Integer] index the CSV header column index
@return [Symbol] the converted column | [
"Convert",
"the",
"column",
"value"
] | 5c54fba5f5ba044721afeef460a069af2018452c | https://github.com/buren/honey_format/blob/5c54fba5f5ba044721afeef460a069af2018452c/lib/honey_format/matrix/header.rb#L136-L143 |
4,836 | delagoya/mascot-dat | lib/mascot/dat.rb | Mascot.DAT.goto | def goto(key)
if @idx.has_key?(key.to_sym)
@dat_file.pos = @idx[key.to_sym]
else
raise Exception.new "Invalid DAT section \"#{key}\""
end
end | ruby | def goto(key)
if @idx.has_key?(key.to_sym)
@dat_file.pos = @idx[key.to_sym]
else
raise Exception.new "Invalid DAT section \"#{key}\""
end
end | [
"def",
"goto",
"(",
"key",
")",
"if",
"@idx",
".",
"has_key?",
"(",
"key",
".",
"to_sym",
")",
"@dat_file",
".",
"pos",
"=",
"@idx",
"[",
"key",
".",
"to_sym",
"]",
"else",
"raise",
"Exception",
".",
"new",
"\"Invalid DAT section \\\"#{key}\\\"\"",
"end",
"end"
] | Go to a section of the Mascot DAT file | [
"Go",
"to",
"a",
"section",
"of",
"the",
"Mascot",
"DAT",
"file"
] | c7c239e545687008b195047e72c77d09331d6a0e | https://github.com/delagoya/mascot-dat/blob/c7c239e545687008b195047e72c77d09331d6a0e/lib/mascot/dat.rb#L62-L68 |
4,837 | delagoya/mascot-dat | lib/mascot/dat.rb | Mascot.DAT.read_section | def read_section(key)
self.goto(key.to_sym)
# read past the initial boundary marker
tmp = @dat_file.readline
@dat_file.each do |l|
break if l =~ @boundary
tmp << l
end
tmp
end | ruby | def read_section(key)
self.goto(key.to_sym)
# read past the initial boundary marker
tmp = @dat_file.readline
@dat_file.each do |l|
break if l =~ @boundary
tmp << l
end
tmp
end | [
"def",
"read_section",
"(",
"key",
")",
"self",
".",
"goto",
"(",
"key",
".",
"to_sym",
")",
"# read past the initial boundary marker",
"tmp",
"=",
"@dat_file",
".",
"readline",
"@dat_file",
".",
"each",
"do",
"|",
"l",
"|",
"break",
"if",
"l",
"=~",
"@boundary",
"tmp",
"<<",
"l",
"end",
"tmp",
"end"
] | Read a section of the DAT file into memory. THIS IS NOT
RECOMMENDED UNLESS YOU KNOW WHAT YOU ARE DOING.
@param key [String or Symbol] The section name
@return [String] The section of the DAT file as a String. The section
includes the MIME boundary and content type
definition lines. | [
"Read",
"a",
"section",
"of",
"the",
"DAT",
"file",
"into",
"memory",
".",
"THIS",
"IS",
"NOT",
"RECOMMENDED",
"UNLESS",
"YOU",
"KNOW",
"WHAT",
"YOU",
"ARE",
"DOING",
"."
] | c7c239e545687008b195047e72c77d09331d6a0e | https://github.com/delagoya/mascot-dat/blob/c7c239e545687008b195047e72c77d09331d6a0e/lib/mascot/dat.rb#L77-L86 |
4,838 | usmu/usmu | lib/usmu/configuration.rb | Usmu.Configuration.excluded? | def excluded?(filename)
exclude.each do |f|
f += '**/*' if f.end_with? '/'
return true if File.fnmatch(f, filename, File::FNM_EXTGLOB | File::FNM_PATHNAME)
end
false
end | ruby | def excluded?(filename)
exclude.each do |f|
f += '**/*' if f.end_with? '/'
return true if File.fnmatch(f, filename, File::FNM_EXTGLOB | File::FNM_PATHNAME)
end
false
end | [
"def",
"excluded?",
"(",
"filename",
")",
"exclude",
".",
"each",
"do",
"|",
"f",
"|",
"f",
"+=",
"'**/*'",
"if",
"f",
".",
"end_with?",
"'/'",
"return",
"true",
"if",
"File",
".",
"fnmatch",
"(",
"f",
",",
"filename",
",",
"File",
"::",
"FNM_EXTGLOB",
"|",
"File",
"::",
"FNM_PATHNAME",
")",
"end",
"false",
"end"
] | Helper to determine if a filename is excluded according to the exclude configuration parameter.
@return [Boolean] | [
"Helper",
"to",
"determine",
"if",
"a",
"filename",
"is",
"excluded",
"according",
"to",
"the",
"exclude",
"configuration",
"parameter",
"."
] | 037bfe0daa995477c29662931236d7a60ca29730 | https://github.com/usmu/usmu/blob/037bfe0daa995477c29662931236d7a60ca29730/lib/usmu/configuration.rb#L141-L147 |
4,839 | sinefunc/pagination | lib/pagination/template.rb | Pagination.Template.render | def render
if engine.respond_to?(:render)
engine.render(Object.new, :items => items)
else
engine.result(binding)
end
end | ruby | def render
if engine.respond_to?(:render)
engine.render(Object.new, :items => items)
else
engine.result(binding)
end
end | [
"def",
"render",
"if",
"engine",
".",
"respond_to?",
"(",
":render",
")",
"engine",
".",
"render",
"(",
"Object",
".",
"new",
",",
":items",
"=>",
"items",
")",
"else",
"engine",
".",
"result",
"(",
"binding",
")",
"end",
"end"
] | Initialize with your paginated collection.
== Paramaters:
items::
a `Pagination::Collection` object return by `Pagination.paginate`.
Displayed the standard pagination markup as provided by the
`Pagination` library.
This uses Haml if Haml is required already. Else it uses ERB.
== Returns:
The actual HTML for the pagination. | [
"Initialize",
"with",
"your",
"paginated",
"collection",
"."
] | e4d8684676dab2d4d9755af334fd35958bbfc3c8 | https://github.com/sinefunc/pagination/blob/e4d8684676dab2d4d9755af334fd35958bbfc3c8/lib/pagination/template.rb#L31-L37 |
4,840 | nilium/ruby-snowmath | lib/snow-math/to_a.rb | Snow.ArraySupport.map! | def map!(&block)
return to_enum(:map!) unless block_given?
(0 ... self.length).each {
|index|
store(index, yield(fetch(index)))
}
self
end | ruby | def map!(&block)
return to_enum(:map!) unless block_given?
(0 ... self.length).each {
|index|
store(index, yield(fetch(index)))
}
self
end | [
"def",
"map!",
"(",
"&",
"block",
")",
"return",
"to_enum",
"(",
":map!",
")",
"unless",
"block_given?",
"(",
"0",
"...",
"self",
".",
"length",
")",
".",
"each",
"{",
"|",
"index",
"|",
"store",
"(",
"index",
",",
"yield",
"(",
"fetch",
"(",
"index",
")",
")",
")",
"}",
"self",
"end"
] | In the first form, iterates over all elements of the object, yields them
to the block given, and overwrites the element's value with the value
returned by the block.
In the second form, returns an Enumerator.
The return value of the block must be the same kind of object as was
yielded to the block. So, if yielded a Vec3, the block must return a Vec3.
If yielded a Numeric, it must return a Numeric.
call-seq:
map! { |elem| block } -> self
map! -> Enumerator | [
"In",
"the",
"first",
"form",
"iterates",
"over",
"all",
"elements",
"of",
"the",
"object",
"yields",
"them",
"to",
"the",
"block",
"given",
"and",
"overwrites",
"the",
"element",
"s",
"value",
"with",
"the",
"value",
"returned",
"by",
"the",
"block",
"."
] | ebac4e56494ff440004a07e7e2b97a2893e48b3a | https://github.com/nilium/ruby-snowmath/blob/ebac4e56494ff440004a07e7e2b97a2893e48b3a/lib/snow-math/to_a.rb#L80-L87 |
4,841 | payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/query_factory.rb | PaynetEasy::PaynetEasyApi::Query.QueryFactory.query | def query(api_query_name)
query_class = "#{api_query_name.camelize}Query"
query_file = "query/#{api_query_name.gsub('-', '_')}_query"
require query_file
PaynetEasy::PaynetEasyApi::Query.const_get(query_class).new(api_query_name)
end | ruby | def query(api_query_name)
query_class = "#{api_query_name.camelize}Query"
query_file = "query/#{api_query_name.gsub('-', '_')}_query"
require query_file
PaynetEasy::PaynetEasyApi::Query.const_get(query_class).new(api_query_name)
end | [
"def",
"query",
"(",
"api_query_name",
")",
"query_class",
"=",
"\"#{api_query_name.camelize}Query\"",
"query_file",
"=",
"\"query/#{api_query_name.gsub('-', '_')}_query\"",
"require",
"query_file",
"PaynetEasy",
"::",
"PaynetEasyApi",
"::",
"Query",
".",
"const_get",
"(",
"query_class",
")",
".",
"new",
"(",
"api_query_name",
")",
"end"
] | Create API query object by API query method
@param api_query_name [String] API query method name
@return [Prototype::Query] API query object | [
"Create",
"API",
"query",
"object",
"by",
"API",
"query",
"method"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/query_factory.rb#L11-L17 |
4,842 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.start | def start
puts "\n******************************************************************************************************************************************\n\n"
puts " JumpStarting....\n".purple
check_setup
execute_install_command
run_scripts_from_yaml(:run_after_install_command)
parse_template_dir
create_dirs
populate_files_from_whole_templates
populate_files_from_append_templates
populate_files_from_line_templates
remove_unwanted_files
run_scripts_from_yaml(:run_after_jumpstart)
check_for_strings_to_replace
run_scripts_from_yaml(:run_after_string_replace)
check_local_nginx_configuration
exit_with_success
end | ruby | def start
puts "\n******************************************************************************************************************************************\n\n"
puts " JumpStarting....\n".purple
check_setup
execute_install_command
run_scripts_from_yaml(:run_after_install_command)
parse_template_dir
create_dirs
populate_files_from_whole_templates
populate_files_from_append_templates
populate_files_from_line_templates
remove_unwanted_files
run_scripts_from_yaml(:run_after_jumpstart)
check_for_strings_to_replace
run_scripts_from_yaml(:run_after_string_replace)
check_local_nginx_configuration
exit_with_success
end | [
"def",
"start",
"puts",
"\"\\n******************************************************************************************************************************************\\n\\n\"",
"puts",
"\" JumpStarting....\\n\"",
".",
"purple",
"check_setup",
"execute_install_command",
"run_scripts_from_yaml",
"(",
":run_after_install_command",
")",
"parse_template_dir",
"create_dirs",
"populate_files_from_whole_templates",
"populate_files_from_append_templates",
"populate_files_from_line_templates",
"remove_unwanted_files",
"run_scripts_from_yaml",
"(",
":run_after_jumpstart",
")",
"check_for_strings_to_replace",
"run_scripts_from_yaml",
"(",
":run_after_string_replace",
")",
"check_local_nginx_configuration",
"exit_with_success",
"end"
] | Runs the configuration, generating the new project from the chosen template. | [
"Runs",
"the",
"configuration",
"generating",
"the",
"new",
"project",
"from",
"the",
"chosen",
"template",
"."
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L62-L79 |
4,843 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.check_install_path | def check_install_path
@install_path = JumpStart::LAUNCH_PATH if @install_path.nil? || @install_path.empty?
if File.directory?(FileUtils.join_paths(@install_path, @project_name))
puts "\nThe directory #{FileUtils.join_paths(@install_path, @project_name).red} already exists.\nAs this is the location you have specified for creating your new project jumpstart will now exit to avoid overwriting anything."
exit_normal
end
return true
end | ruby | def check_install_path
@install_path = JumpStart::LAUNCH_PATH if @install_path.nil? || @install_path.empty?
if File.directory?(FileUtils.join_paths(@install_path, @project_name))
puts "\nThe directory #{FileUtils.join_paths(@install_path, @project_name).red} already exists.\nAs this is the location you have specified for creating your new project jumpstart will now exit to avoid overwriting anything."
exit_normal
end
return true
end | [
"def",
"check_install_path",
"@install_path",
"=",
"JumpStart",
"::",
"LAUNCH_PATH",
"if",
"@install_path",
".",
"nil?",
"||",
"@install_path",
".",
"empty?",
"if",
"File",
".",
"directory?",
"(",
"FileUtils",
".",
"join_paths",
"(",
"@install_path",
",",
"@project_name",
")",
")",
"puts",
"\"\\nThe directory #{FileUtils.join_paths(@install_path, @project_name).red} already exists.\\nAs this is the location you have specified for creating your new project jumpstart will now exit to avoid overwriting anything.\"",
"exit_normal",
"end",
"return",
"true",
"end"
] | Sets the install path to executing directory if @install_path varibale is nil or empty. This should result in projects being created in directory from which the jumpstart command was called, if the template specified does not set this option.
Checks the install path set in @install_path.
Checks that a directory with the same name as the project does not already exist in the install path. | [
"Sets",
"the",
"install",
"path",
"to",
"executing",
"directory",
"if"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L141-L148 |
4,844 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.create_template | def create_template
if File.directory?(FileUtils.join_paths(JumpStart.templates_path, @template_name))
puts "\nThe directory #{FileUtils.join_paths(JumpStart.templates_path, @template_name).red} already exists. The template will not be created."
exit_normal
else
FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, @template_name, "/jumpstart_config"))
yaml = IO.read(FileUtils.join_paths(ROOT_PATH, "/source_templates/template_config.yml"))
File.open(FileUtils.join_paths(JumpStart.templates_path, @template_name, "/jumpstart_config", "#{@template_name}.yml"), 'w') do |file|
file.puts yaml
end
puts "The template #{@template_name.green} has been generated.\n"
end
end | ruby | def create_template
if File.directory?(FileUtils.join_paths(JumpStart.templates_path, @template_name))
puts "\nThe directory #{FileUtils.join_paths(JumpStart.templates_path, @template_name).red} already exists. The template will not be created."
exit_normal
else
FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, @template_name, "/jumpstart_config"))
yaml = IO.read(FileUtils.join_paths(ROOT_PATH, "/source_templates/template_config.yml"))
File.open(FileUtils.join_paths(JumpStart.templates_path, @template_name, "/jumpstart_config", "#{@template_name}.yml"), 'w') do |file|
file.puts yaml
end
puts "The template #{@template_name.green} has been generated.\n"
end
end | [
"def",
"create_template",
"if",
"File",
".",
"directory?",
"(",
"FileUtils",
".",
"join_paths",
"(",
"JumpStart",
".",
"templates_path",
",",
"@template_name",
")",
")",
"puts",
"\"\\nThe directory #{FileUtils.join_paths(JumpStart.templates_path, @template_name).red} already exists. The template will not be created.\"",
"exit_normal",
"else",
"FileUtils",
".",
"mkdir_p",
"(",
"FileUtils",
".",
"join_paths",
"(",
"JumpStart",
".",
"templates_path",
",",
"@template_name",
",",
"\"/jumpstart_config\"",
")",
")",
"yaml",
"=",
"IO",
".",
"read",
"(",
"FileUtils",
".",
"join_paths",
"(",
"ROOT_PATH",
",",
"\"/source_templates/template_config.yml\"",
")",
")",
"File",
".",
"open",
"(",
"FileUtils",
".",
"join_paths",
"(",
"JumpStart",
".",
"templates_path",
",",
"@template_name",
",",
"\"/jumpstart_config\"",
",",
"\"#{@template_name}.yml\"",
")",
",",
"'w'",
")",
"do",
"|",
"file",
"|",
"file",
".",
"puts",
"yaml",
"end",
"puts",
"\"The template #{@template_name.green} has been generated.\\n\"",
"end",
"end"
] | Creates a new blank template in whichever directory the default templates directory has been set to. | [
"Creates",
"a",
"new",
"blank",
"template",
"in",
"whichever",
"directory",
"the",
"default",
"templates",
"directory",
"has",
"been",
"set",
"to",
"."
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L151-L163 |
4,845 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.jumpstart_menu | def jumpstart_menu
puts "\n\n******************************************************************************************************************************************\n\n"
puts " JUMPSTART MENU\n".purple
puts " Here are your options:\n\n"
puts " 1".yellow + " Create a new project from an existing template.\n"
puts " 2".yellow + " Create a new template.\n"
puts " 3".yellow + " Set the default template.\n"
puts " 4".yellow + " Set the templates directory.\n\n"
puts " x".yellow + " Exit jumpstart.\n\n"
puts "******************************************************************************************************************************************\n\n"
jumpstart_menu_options
end | ruby | def jumpstart_menu
puts "\n\n******************************************************************************************************************************************\n\n"
puts " JUMPSTART MENU\n".purple
puts " Here are your options:\n\n"
puts " 1".yellow + " Create a new project from an existing template.\n"
puts " 2".yellow + " Create a new template.\n"
puts " 3".yellow + " Set the default template.\n"
puts " 4".yellow + " Set the templates directory.\n\n"
puts " x".yellow + " Exit jumpstart.\n\n"
puts "******************************************************************************************************************************************\n\n"
jumpstart_menu_options
end | [
"def",
"jumpstart_menu",
"puts",
"\"\\n\\n******************************************************************************************************************************************\\n\\n\"",
"puts",
"\" JUMPSTART MENU\\n\"",
".",
"purple",
"puts",
"\" Here are your options:\\n\\n\"",
"puts",
"\" 1\"",
".",
"yellow",
"+",
"\" Create a new project from an existing template.\\n\"",
"puts",
"\" 2\"",
".",
"yellow",
"+",
"\" Create a new template.\\n\"",
"puts",
"\" 3\"",
".",
"yellow",
"+",
"\" Set the default template.\\n\"",
"puts",
"\" 4\"",
".",
"yellow",
"+",
"\" Set the templates directory.\\n\\n\"",
"puts",
"\" x\"",
".",
"yellow",
"+",
"\" Exit jumpstart.\\n\\n\"",
"puts",
"\"******************************************************************************************************************************************\\n\\n\"",
"jumpstart_menu_options",
"end"
] | Displays options for the main jumpstart menu. | [
"Displays",
"options",
"for",
"the",
"main",
"jumpstart",
"menu",
"."
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L166-L177 |
4,846 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.jumpstart_menu_options | def jumpstart_menu_options
input = gets.chomp.strip.downcase
case
when input == "1"
new_project_from_template_menu
when input == "2"
new_template_menu
when input == "3"
set_default_template_menu
when input == "4"
templates_dir_menu
when input == "x"
exit_normal
else
puts "That command hasn't been understood. Try again!".red
jumpstart_menu_options
end
end | ruby | def jumpstart_menu_options
input = gets.chomp.strip.downcase
case
when input == "1"
new_project_from_template_menu
when input == "2"
new_template_menu
when input == "3"
set_default_template_menu
when input == "4"
templates_dir_menu
when input == "x"
exit_normal
else
puts "That command hasn't been understood. Try again!".red
jumpstart_menu_options
end
end | [
"def",
"jumpstart_menu_options",
"input",
"=",
"gets",
".",
"chomp",
".",
"strip",
".",
"downcase",
"case",
"when",
"input",
"==",
"\"1\"",
"new_project_from_template_menu",
"when",
"input",
"==",
"\"2\"",
"new_template_menu",
"when",
"input",
"==",
"\"3\"",
"set_default_template_menu",
"when",
"input",
"==",
"\"4\"",
"templates_dir_menu",
"when",
"input",
"==",
"\"x\"",
"exit_normal",
"else",
"puts",
"\"That command hasn't been understood. Try again!\"",
".",
"red",
"jumpstart_menu_options",
"end",
"end"
] | Captures user input for the main jumpstart menu and calls the appropriate method | [
"Captures",
"user",
"input",
"for",
"the",
"main",
"jumpstart",
"menu",
"and",
"calls",
"the",
"appropriate",
"method"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L180-L197 |
4,847 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.new_project_from_template_menu | def new_project_from_template_menu
puts "\n\n******************************************************************************************************************************************\n\n"
puts " CREATE A NEW JUMPSTART PROJECT FROM AN EXISTING TEMPLATE\n\n".purple
puts " Type a number for the template that you want.\n\n"
display_existing_templates
puts "\n b".yellow + " Back to main menu."
puts "\n x".yellow + " Exit jumpstart.\n\n"
puts "******************************************************************************************************************************************\n\n"
new_project_from_template_options
end | ruby | def new_project_from_template_menu
puts "\n\n******************************************************************************************************************************************\n\n"
puts " CREATE A NEW JUMPSTART PROJECT FROM AN EXISTING TEMPLATE\n\n".purple
puts " Type a number for the template that you want.\n\n"
display_existing_templates
puts "\n b".yellow + " Back to main menu."
puts "\n x".yellow + " Exit jumpstart.\n\n"
puts "******************************************************************************************************************************************\n\n"
new_project_from_template_options
end | [
"def",
"new_project_from_template_menu",
"puts",
"\"\\n\\n******************************************************************************************************************************************\\n\\n\"",
"puts",
"\" CREATE A NEW JUMPSTART PROJECT FROM AN EXISTING TEMPLATE\\n\\n\"",
".",
"purple",
"puts",
"\" Type a number for the template that you want.\\n\\n\"",
"display_existing_templates",
"puts",
"\"\\n b\"",
".",
"yellow",
"+",
"\" Back to main menu.\"",
"puts",
"\"\\n x\"",
".",
"yellow",
"+",
"\" Exit jumpstart.\\n\\n\"",
"puts",
"\"******************************************************************************************************************************************\\n\\n\"",
"new_project_from_template_options",
"end"
] | Displays options for the "create a new jumpstart project from an existing template" menu | [
"Displays",
"options",
"for",
"the",
"create",
"a",
"new",
"jumpstart",
"project",
"from",
"an",
"existing",
"template",
"menu"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L210-L219 |
4,848 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.new_project_from_template_options | def new_project_from_template_options
input = gets.chomp.strip.downcase
case
when input.to_i <= JumpStart.existing_templates.count && input.to_i > 0
@template_name = JumpStart.existing_templates[(input.to_i - 1)]
check_project_name
project = JumpStart::Base.new([@project_name, @template_name])
project.check_setup
project.start
when input == "b"
jumpstart_menu
when input == "x"
exit_normal
else
puts "That command hasn't been understood. Try again!".red
new_project_from_template_options
end
end | ruby | def new_project_from_template_options
input = gets.chomp.strip.downcase
case
when input.to_i <= JumpStart.existing_templates.count && input.to_i > 0
@template_name = JumpStart.existing_templates[(input.to_i - 1)]
check_project_name
project = JumpStart::Base.new([@project_name, @template_name])
project.check_setup
project.start
when input == "b"
jumpstart_menu
when input == "x"
exit_normal
else
puts "That command hasn't been understood. Try again!".red
new_project_from_template_options
end
end | [
"def",
"new_project_from_template_options",
"input",
"=",
"gets",
".",
"chomp",
".",
"strip",
".",
"downcase",
"case",
"when",
"input",
".",
"to_i",
"<=",
"JumpStart",
".",
"existing_templates",
".",
"count",
"&&",
"input",
".",
"to_i",
">",
"0",
"@template_name",
"=",
"JumpStart",
".",
"existing_templates",
"[",
"(",
"input",
".",
"to_i",
"-",
"1",
")",
"]",
"check_project_name",
"project",
"=",
"JumpStart",
"::",
"Base",
".",
"new",
"(",
"[",
"@project_name",
",",
"@template_name",
"]",
")",
"project",
".",
"check_setup",
"project",
".",
"start",
"when",
"input",
"==",
"\"b\"",
"jumpstart_menu",
"when",
"input",
"==",
"\"x\"",
"exit_normal",
"else",
"puts",
"\"That command hasn't been understood. Try again!\"",
".",
"red",
"new_project_from_template_options",
"end",
"end"
] | Captures user input for the "create a new jumpstart project from an existing template" menu and calls the appropriate method.
When the input matches a template number a project will be created from that template | [
"Captures",
"user",
"input",
"for",
"the",
"create",
"a",
"new",
"jumpstart",
"project",
"from",
"an",
"existing",
"template",
"menu",
"and",
"calls",
"the",
"appropriate",
"method",
".",
"When",
"the",
"input",
"matches",
"a",
"template",
"number",
"a",
"project",
"will",
"be",
"created",
"from",
"that",
"template"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L223-L240 |
4,849 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.new_template_menu | def new_template_menu
puts "\n\n******************************************************************************************************************************************\n\n"
puts " CREATE A NEW JUMPSTART TEMPLATE\n".purple
puts " Existing templates:\n"
display_existing_templates
puts "\n b".yellow + " Back to main menu."
puts "\n x".yellow + " Exit jumpstart.\n"
new_template_options
end | ruby | def new_template_menu
puts "\n\n******************************************************************************************************************************************\n\n"
puts " CREATE A NEW JUMPSTART TEMPLATE\n".purple
puts " Existing templates:\n"
display_existing_templates
puts "\n b".yellow + " Back to main menu."
puts "\n x".yellow + " Exit jumpstart.\n"
new_template_options
end | [
"def",
"new_template_menu",
"puts",
"\"\\n\\n******************************************************************************************************************************************\\n\\n\"",
"puts",
"\" CREATE A NEW JUMPSTART TEMPLATE\\n\"",
".",
"purple",
"puts",
"\" Existing templates:\\n\"",
"display_existing_templates",
"puts",
"\"\\n b\"",
".",
"yellow",
"+",
"\" Back to main menu.\"",
"puts",
"\"\\n x\"",
".",
"yellow",
"+",
"\" Exit jumpstart.\\n\"",
"new_template_options",
"end"
] | Displays output for the "create a new jumpstart template" menu | [
"Displays",
"output",
"for",
"the",
"create",
"a",
"new",
"jumpstart",
"template",
"menu"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L243-L251 |
4,850 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.new_template_options | def new_template_options
puts "\n Enter a unique name to create a new template, or enter an existing templates name (or number) to duplicate it.".yellow
input = gets.chomp.strip
case
when input.downcase == "b"
jumpstart_menu
when input.downcase == "x"
exit_normal
when JumpStart.existing_templates.include?(input)
puts "\n You have chosen to duplicate the " + input.green + " template." + "\n Please enter a name for the duplicate.".yellow
duplicate_template(input)
when input.to_i != 0 && input.to_i <= JumpStart.existing_templates.count
puts "\n You have chosen to duplicate the " + JumpStart.existing_templates[(input.to_i - 1)].green + " template." + "\n Please enter a name for the duplicate.".yellow
duplicate_template(JumpStart.existing_templates[(input.to_i - 1)])
when input.length < 3
puts "\n The template name ".red + input.red_bold + " is too short. Please enter a name that is at least 3 characters long.".red
new_template_options
when input.match(/^\W|\W$/)
puts "\n The template name ".red + input.red_bold + " begins or ends with an invalid character. Please enter a name that begins with a letter or a number.".red
new_template_options
else
FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config"))
FileUtils.cp(FileUtils.join_paths(ROOT_PATH, "source_templates/template_config.yml"), FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config", "#{input}.yml"))
puts "\n The template ".green + input.green_bold + " has been created in your default jumpstart template directory ".green + JumpStart.templates_path.green_bold + " ready for editing.".green
jumpstart_menu
end
end | ruby | def new_template_options
puts "\n Enter a unique name to create a new template, or enter an existing templates name (or number) to duplicate it.".yellow
input = gets.chomp.strip
case
when input.downcase == "b"
jumpstart_menu
when input.downcase == "x"
exit_normal
when JumpStart.existing_templates.include?(input)
puts "\n You have chosen to duplicate the " + input.green + " template." + "\n Please enter a name for the duplicate.".yellow
duplicate_template(input)
when input.to_i != 0 && input.to_i <= JumpStart.existing_templates.count
puts "\n You have chosen to duplicate the " + JumpStart.existing_templates[(input.to_i - 1)].green + " template." + "\n Please enter a name for the duplicate.".yellow
duplicate_template(JumpStart.existing_templates[(input.to_i - 1)])
when input.length < 3
puts "\n The template name ".red + input.red_bold + " is too short. Please enter a name that is at least 3 characters long.".red
new_template_options
when input.match(/^\W|\W$/)
puts "\n The template name ".red + input.red_bold + " begins or ends with an invalid character. Please enter a name that begins with a letter or a number.".red
new_template_options
else
FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config"))
FileUtils.cp(FileUtils.join_paths(ROOT_PATH, "source_templates/template_config.yml"), FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config", "#{input}.yml"))
puts "\n The template ".green + input.green_bold + " has been created in your default jumpstart template directory ".green + JumpStart.templates_path.green_bold + " ready for editing.".green
jumpstart_menu
end
end | [
"def",
"new_template_options",
"puts",
"\"\\n Enter a unique name to create a new template, or enter an existing templates name (or number) to duplicate it.\"",
".",
"yellow",
"input",
"=",
"gets",
".",
"chomp",
".",
"strip",
"case",
"when",
"input",
".",
"downcase",
"==",
"\"b\"",
"jumpstart_menu",
"when",
"input",
".",
"downcase",
"==",
"\"x\"",
"exit_normal",
"when",
"JumpStart",
".",
"existing_templates",
".",
"include?",
"(",
"input",
")",
"puts",
"\"\\n You have chosen to duplicate the \"",
"+",
"input",
".",
"green",
"+",
"\" template.\"",
"+",
"\"\\n Please enter a name for the duplicate.\"",
".",
"yellow",
"duplicate_template",
"(",
"input",
")",
"when",
"input",
".",
"to_i",
"!=",
"0",
"&&",
"input",
".",
"to_i",
"<=",
"JumpStart",
".",
"existing_templates",
".",
"count",
"puts",
"\"\\n You have chosen to duplicate the \"",
"+",
"JumpStart",
".",
"existing_templates",
"[",
"(",
"input",
".",
"to_i",
"-",
"1",
")",
"]",
".",
"green",
"+",
"\" template.\"",
"+",
"\"\\n Please enter a name for the duplicate.\"",
".",
"yellow",
"duplicate_template",
"(",
"JumpStart",
".",
"existing_templates",
"[",
"(",
"input",
".",
"to_i",
"-",
"1",
")",
"]",
")",
"when",
"input",
".",
"length",
"<",
"3",
"puts",
"\"\\n The template name \"",
".",
"red",
"+",
"input",
".",
"red_bold",
"+",
"\" is too short. Please enter a name that is at least 3 characters long.\"",
".",
"red",
"new_template_options",
"when",
"input",
".",
"match",
"(",
"/",
"\\W",
"\\W",
"/",
")",
"puts",
"\"\\n The template name \"",
".",
"red",
"+",
"input",
".",
"red_bold",
"+",
"\" begins or ends with an invalid character. Please enter a name that begins with a letter or a number.\"",
".",
"red",
"new_template_options",
"else",
"FileUtils",
".",
"mkdir_p",
"(",
"FileUtils",
".",
"join_paths",
"(",
"JumpStart",
".",
"templates_path",
",",
"input",
",",
"\"jumpstart_config\"",
")",
")",
"FileUtils",
".",
"cp",
"(",
"FileUtils",
".",
"join_paths",
"(",
"ROOT_PATH",
",",
"\"source_templates/template_config.yml\"",
")",
",",
"FileUtils",
".",
"join_paths",
"(",
"JumpStart",
".",
"templates_path",
",",
"input",
",",
"\"jumpstart_config\"",
",",
"\"#{input}.yml\"",
")",
")",
"puts",
"\"\\n The template \"",
".",
"green",
"+",
"input",
".",
"green_bold",
"+",
"\" has been created in your default jumpstart template directory \"",
".",
"green",
"+",
"JumpStart",
".",
"templates_path",
".",
"green_bold",
"+",
"\" ready for editing.\"",
".",
"green",
"jumpstart_menu",
"end",
"end"
] | Captures user input for "create a new jumpstart template" menu and calls the appropriate action.
If the template name provided meets the methods requirements then a directory of that name containing a jumpstart_config dir and matching yaml file are created. | [
"Captures",
"user",
"input",
"for",
"create",
"a",
"new",
"jumpstart",
"template",
"menu",
"and",
"calls",
"the",
"appropriate",
"action",
".",
"If",
"the",
"template",
"name",
"provided",
"meets",
"the",
"methods",
"requirements",
"then",
"a",
"directory",
"of",
"that",
"name",
"containing",
"a",
"jumpstart_config",
"dir",
"and",
"matching",
"yaml",
"file",
"are",
"created",
"."
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L255-L281 |
4,851 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.set_default_template_menu | def set_default_template_menu
puts "\n\n******************************************************************************************************************************************\n\n"
puts " SELECT A DEFAULT JUMPSTART TEMPLATE\n".purple
display_existing_templates
puts "\n b".yellow + " Back to main menu.\n\n"
puts " x".yellow + " Exit jumpstart.\n\n"
puts "******************************************************************************************************************************************\n\n"
set_default_template_options
end | ruby | def set_default_template_menu
puts "\n\n******************************************************************************************************************************************\n\n"
puts " SELECT A DEFAULT JUMPSTART TEMPLATE\n".purple
display_existing_templates
puts "\n b".yellow + " Back to main menu.\n\n"
puts " x".yellow + " Exit jumpstart.\n\n"
puts "******************************************************************************************************************************************\n\n"
set_default_template_options
end | [
"def",
"set_default_template_menu",
"puts",
"\"\\n\\n******************************************************************************************************************************************\\n\\n\"",
"puts",
"\" SELECT A DEFAULT JUMPSTART TEMPLATE\\n\"",
".",
"purple",
"display_existing_templates",
"puts",
"\"\\n b\"",
".",
"yellow",
"+",
"\" Back to main menu.\\n\\n\"",
"puts",
"\" x\"",
".",
"yellow",
"+",
"\" Exit jumpstart.\\n\\n\"",
"puts",
"\"******************************************************************************************************************************************\\n\\n\"",
"set_default_template_options",
"end"
] | Displays output for the "jumpstart default template options menu" | [
"Displays",
"output",
"for",
"the",
"jumpstart",
"default",
"template",
"options",
"menu"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L319-L327 |
4,852 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.set_default_template_options | def set_default_template_options
input = gets.chomp.strip
case
when input.to_i <= JumpStart.existing_templates.count && input.to_i > 0
JumpStart.default_template_name = JumpStart.existing_templates[(input.to_i - 1)]
JumpStart.dump_jumpstart_setup_yaml
puts " The default jumpstart template has been set to: ".green + JumpStart.default_template_name.green_bold
jumpstart_menu
when input.downcase == "b"
jumpstart_menu
when input.downcase == "x"
exit_normal
else
puts "That command hasn't been understood. Try again!".red
set_default_template_options
end
end | ruby | def set_default_template_options
input = gets.chomp.strip
case
when input.to_i <= JumpStart.existing_templates.count && input.to_i > 0
JumpStart.default_template_name = JumpStart.existing_templates[(input.to_i - 1)]
JumpStart.dump_jumpstart_setup_yaml
puts " The default jumpstart template has been set to: ".green + JumpStart.default_template_name.green_bold
jumpstart_menu
when input.downcase == "b"
jumpstart_menu
when input.downcase == "x"
exit_normal
else
puts "That command hasn't been understood. Try again!".red
set_default_template_options
end
end | [
"def",
"set_default_template_options",
"input",
"=",
"gets",
".",
"chomp",
".",
"strip",
"case",
"when",
"input",
".",
"to_i",
"<=",
"JumpStart",
".",
"existing_templates",
".",
"count",
"&&",
"input",
".",
"to_i",
">",
"0",
"JumpStart",
".",
"default_template_name",
"=",
"JumpStart",
".",
"existing_templates",
"[",
"(",
"input",
".",
"to_i",
"-",
"1",
")",
"]",
"JumpStart",
".",
"dump_jumpstart_setup_yaml",
"puts",
"\" The default jumpstart template has been set to: \"",
".",
"green",
"+",
"JumpStart",
".",
"default_template_name",
".",
"green_bold",
"jumpstart_menu",
"when",
"input",
".",
"downcase",
"==",
"\"b\"",
"jumpstart_menu",
"when",
"input",
".",
"downcase",
"==",
"\"x\"",
"exit_normal",
"else",
"puts",
"\"That command hasn't been understood. Try again!\"",
".",
"red",
"set_default_template_options",
"end",
"end"
] | Sets the default template to be used by JumpStart and writes it to a YAML file. | [
"Sets",
"the",
"default",
"template",
"to",
"be",
"used",
"by",
"JumpStart",
"and",
"writes",
"it",
"to",
"a",
"YAML",
"file",
"."
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L330-L346 |
4,853 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.templates_dir_menu | def templates_dir_menu
puts "\n\n******************************************************************************************************************************************\n\n"
puts " JUMPSTART TEMPLATES DIRECTORY OPTIONS\n".purple
puts " The JumpStart template directory is currently: " + JumpStart.templates_path.green
puts "\n 1".yellow + " Change the templates directory.\n"
puts " 2".yellow + " Reset the templates directory to default.\n\n"
puts " b".yellow + " Back to main menu.\n\n"
puts " x".yellow + " Exit jumpstart.\n\n"
puts "******************************************************************************************************************************************\n\n"
templates_dir_options
end | ruby | def templates_dir_menu
puts "\n\n******************************************************************************************************************************************\n\n"
puts " JUMPSTART TEMPLATES DIRECTORY OPTIONS\n".purple
puts " The JumpStart template directory is currently: " + JumpStart.templates_path.green
puts "\n 1".yellow + " Change the templates directory.\n"
puts " 2".yellow + " Reset the templates directory to default.\n\n"
puts " b".yellow + " Back to main menu.\n\n"
puts " x".yellow + " Exit jumpstart.\n\n"
puts "******************************************************************************************************************************************\n\n"
templates_dir_options
end | [
"def",
"templates_dir_menu",
"puts",
"\"\\n\\n******************************************************************************************************************************************\\n\\n\"",
"puts",
"\" JUMPSTART TEMPLATES DIRECTORY OPTIONS\\n\"",
".",
"purple",
"puts",
"\" The JumpStart template directory is currently: \"",
"+",
"JumpStart",
".",
"templates_path",
".",
"green",
"puts",
"\"\\n 1\"",
".",
"yellow",
"+",
"\" Change the templates directory.\\n\"",
"puts",
"\" 2\"",
".",
"yellow",
"+",
"\" Reset the templates directory to default.\\n\\n\"",
"puts",
"\" b\"",
".",
"yellow",
"+",
"\" Back to main menu.\\n\\n\"",
"puts",
"\" x\"",
".",
"yellow",
"+",
"\" Exit jumpstart.\\n\\n\"",
"puts",
"\"******************************************************************************************************************************************\\n\\n\"",
"templates_dir_options",
"end"
] | Displays output for the "jumpstart templates directory options" menu. | [
"Displays",
"output",
"for",
"the",
"jumpstart",
"templates",
"directory",
"options",
"menu",
"."
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L349-L359 |
4,854 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.templates_dir_options | def templates_dir_options
input = gets.chomp.strip.downcase
case
when input == "1"
puts " Please enter the absolute path for the directory that you would like to contain your jumpstart templates.".yellow
puts " e.g. /Users/your_name/projects/jumpstart_templates\n\n"
set_templates_dir
when input == "2"
reset_templates_dir_to_default_check
when input == "b"
jumpstart_menu
when input == "x"
exit_normal
else
puts " That command hasn't been understood. Try again!".red
templates_dir_options
end
end | ruby | def templates_dir_options
input = gets.chomp.strip.downcase
case
when input == "1"
puts " Please enter the absolute path for the directory that you would like to contain your jumpstart templates.".yellow
puts " e.g. /Users/your_name/projects/jumpstart_templates\n\n"
set_templates_dir
when input == "2"
reset_templates_dir_to_default_check
when input == "b"
jumpstart_menu
when input == "x"
exit_normal
else
puts " That command hasn't been understood. Try again!".red
templates_dir_options
end
end | [
"def",
"templates_dir_options",
"input",
"=",
"gets",
".",
"chomp",
".",
"strip",
".",
"downcase",
"case",
"when",
"input",
"==",
"\"1\"",
"puts",
"\" Please enter the absolute path for the directory that you would like to contain your jumpstart templates.\"",
".",
"yellow",
"puts",
"\" e.g. /Users/your_name/projects/jumpstart_templates\\n\\n\"",
"set_templates_dir",
"when",
"input",
"==",
"\"2\"",
"reset_templates_dir_to_default_check",
"when",
"input",
"==",
"\"b\"",
"jumpstart_menu",
"when",
"input",
"==",
"\"x\"",
"exit_normal",
"else",
"puts",
"\" That command hasn't been understood. Try again!\"",
".",
"red",
"templates_dir_options",
"end",
"end"
] | Captures user input for the "jumpstart templates directory options" menu and calls the appropriate method. | [
"Captures",
"user",
"input",
"for",
"the",
"jumpstart",
"templates",
"directory",
"options",
"menu",
"and",
"calls",
"the",
"appropriate",
"method",
"."
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L362-L379 |
4,855 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.set_templates_dir | def set_templates_dir
input = gets.chomp.strip
root_path = input.sub(/\/\w*\/*$/, '')
case
when input.downcase == "b"
jumpstart_menu
when input.downcase == "x"
exit_normal
when File.directory?(input)
puts "\n A directory of that name already exists, would you like to set it as your template directory anyway? (Nothing will be copied or removed.)".yellow
puts " Yes (" + "y".yellow + ") or No (" + "n".yellow + ")?"
set_templates_dir_to_existing_dir(input)
when File.directory?(root_path)
begin
Dir.chdir(root_path)
Dir.mkdir(input)
files_and_dirs = FileUtils.sort_contained_files_and_dirs(JumpStart.templates_path)
puts "\nCopying existing templates to #{input}"
files_and_dirs[:dirs].each {|x| FileUtils.mkdir_p(FileUtils.join_paths(input, x))}
files_and_dirs[:files].each {|x| FileUtils.cp(FileUtils.join_paths(JumpStart.templates_path, x), FileUtils.join_paths(input, x)) }
JumpStart.templates_path = input.to_s
JumpStart.dump_jumpstart_setup_yaml
puts "\n Transfer complete!".green
puts "\n The directory " + input.green + " has been set as the JumpStart templates directory."
jumpstart_menu
rescue
puts " It looks like you do not have the correct permissions to create a directory in #{root_path.red}"
end
else
puts " Couldn't find a directory of that name. Try again.".red
set_templates_dir
end
end | ruby | def set_templates_dir
input = gets.chomp.strip
root_path = input.sub(/\/\w*\/*$/, '')
case
when input.downcase == "b"
jumpstart_menu
when input.downcase == "x"
exit_normal
when File.directory?(input)
puts "\n A directory of that name already exists, would you like to set it as your template directory anyway? (Nothing will be copied or removed.)".yellow
puts " Yes (" + "y".yellow + ") or No (" + "n".yellow + ")?"
set_templates_dir_to_existing_dir(input)
when File.directory?(root_path)
begin
Dir.chdir(root_path)
Dir.mkdir(input)
files_and_dirs = FileUtils.sort_contained_files_and_dirs(JumpStart.templates_path)
puts "\nCopying existing templates to #{input}"
files_and_dirs[:dirs].each {|x| FileUtils.mkdir_p(FileUtils.join_paths(input, x))}
files_and_dirs[:files].each {|x| FileUtils.cp(FileUtils.join_paths(JumpStart.templates_path, x), FileUtils.join_paths(input, x)) }
JumpStart.templates_path = input.to_s
JumpStart.dump_jumpstart_setup_yaml
puts "\n Transfer complete!".green
puts "\n The directory " + input.green + " has been set as the JumpStart templates directory."
jumpstart_menu
rescue
puts " It looks like you do not have the correct permissions to create a directory in #{root_path.red}"
end
else
puts " Couldn't find a directory of that name. Try again.".red
set_templates_dir
end
end | [
"def",
"set_templates_dir",
"input",
"=",
"gets",
".",
"chomp",
".",
"strip",
"root_path",
"=",
"input",
".",
"sub",
"(",
"/",
"\\/",
"\\w",
"\\/",
"/",
",",
"''",
")",
"case",
"when",
"input",
".",
"downcase",
"==",
"\"b\"",
"jumpstart_menu",
"when",
"input",
".",
"downcase",
"==",
"\"x\"",
"exit_normal",
"when",
"File",
".",
"directory?",
"(",
"input",
")",
"puts",
"\"\\n A directory of that name already exists, would you like to set it as your template directory anyway? (Nothing will be copied or removed.)\"",
".",
"yellow",
"puts",
"\" Yes (\"",
"+",
"\"y\"",
".",
"yellow",
"+",
"\") or No (\"",
"+",
"\"n\"",
".",
"yellow",
"+",
"\")?\"",
"set_templates_dir_to_existing_dir",
"(",
"input",
")",
"when",
"File",
".",
"directory?",
"(",
"root_path",
")",
"begin",
"Dir",
".",
"chdir",
"(",
"root_path",
")",
"Dir",
".",
"mkdir",
"(",
"input",
")",
"files_and_dirs",
"=",
"FileUtils",
".",
"sort_contained_files_and_dirs",
"(",
"JumpStart",
".",
"templates_path",
")",
"puts",
"\"\\nCopying existing templates to #{input}\"",
"files_and_dirs",
"[",
":dirs",
"]",
".",
"each",
"{",
"|",
"x",
"|",
"FileUtils",
".",
"mkdir_p",
"(",
"FileUtils",
".",
"join_paths",
"(",
"input",
",",
"x",
")",
")",
"}",
"files_and_dirs",
"[",
":files",
"]",
".",
"each",
"{",
"|",
"x",
"|",
"FileUtils",
".",
"cp",
"(",
"FileUtils",
".",
"join_paths",
"(",
"JumpStart",
".",
"templates_path",
",",
"x",
")",
",",
"FileUtils",
".",
"join_paths",
"(",
"input",
",",
"x",
")",
")",
"}",
"JumpStart",
".",
"templates_path",
"=",
"input",
".",
"to_s",
"JumpStart",
".",
"dump_jumpstart_setup_yaml",
"puts",
"\"\\n Transfer complete!\"",
".",
"green",
"puts",
"\"\\n The directory \"",
"+",
"input",
".",
"green",
"+",
"\" has been set as the JumpStart templates directory.\"",
"jumpstart_menu",
"rescue",
"puts",
"\" It looks like you do not have the correct permissions to create a directory in #{root_path.red}\"",
"end",
"else",
"puts",
"\" Couldn't find a directory of that name. Try again.\"",
".",
"red",
"set_templates_dir",
"end",
"end"
] | Sets the path for templates to be used by JumpStart.
Copies templates in the existing template dir to the new location.
The folder specified must not exist yet, but it's parent should. | [
"Sets",
"the",
"path",
"for",
"templates",
"to",
"be",
"used",
"by",
"JumpStart",
".",
"Copies",
"templates",
"in",
"the",
"existing",
"template",
"dir",
"to",
"the",
"new",
"location",
".",
"The",
"folder",
"specified",
"must",
"not",
"exist",
"yet",
"but",
"it",
"s",
"parent",
"should",
"."
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L384-L416 |
4,856 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.set_templates_dir_to_existing_dir | def set_templates_dir_to_existing_dir(dir)
input = gets.chomp.strip.downcase
case
when input == "b"
jumpstart_menu
when input == "x"
exit_normal
when input == "y" || input == "yes"
JumpStart.templates_path = dir
JumpStart.dump_jumpstart_setup_yaml
puts "\n The directory ".green + dir.green_bold + " has been set as the JumpStart templates directory.".green
jumpstart_menu
when input == "n" || input == "no"
puts "\n The JumpStart templates directory has not been altered".yellow
jumpstart_menu
else
puts "\n The command has not been understood, try again!".red
set_templates_dir_to_existing_dir(dir)
end
end | ruby | def set_templates_dir_to_existing_dir(dir)
input = gets.chomp.strip.downcase
case
when input == "b"
jumpstart_menu
when input == "x"
exit_normal
when input == "y" || input == "yes"
JumpStart.templates_path = dir
JumpStart.dump_jumpstart_setup_yaml
puts "\n The directory ".green + dir.green_bold + " has been set as the JumpStart templates directory.".green
jumpstart_menu
when input == "n" || input == "no"
puts "\n The JumpStart templates directory has not been altered".yellow
jumpstart_menu
else
puts "\n The command has not been understood, try again!".red
set_templates_dir_to_existing_dir(dir)
end
end | [
"def",
"set_templates_dir_to_existing_dir",
"(",
"dir",
")",
"input",
"=",
"gets",
".",
"chomp",
".",
"strip",
".",
"downcase",
"case",
"when",
"input",
"==",
"\"b\"",
"jumpstart_menu",
"when",
"input",
"==",
"\"x\"",
"exit_normal",
"when",
"input",
"==",
"\"y\"",
"||",
"input",
"==",
"\"yes\"",
"JumpStart",
".",
"templates_path",
"=",
"dir",
"JumpStart",
".",
"dump_jumpstart_setup_yaml",
"puts",
"\"\\n The directory \"",
".",
"green",
"+",
"dir",
".",
"green_bold",
"+",
"\" has been set as the JumpStart templates directory.\"",
".",
"green",
"jumpstart_menu",
"when",
"input",
"==",
"\"n\"",
"||",
"input",
"==",
"\"no\"",
"puts",
"\"\\n The JumpStart templates directory has not been altered\"",
".",
"yellow",
"jumpstart_menu",
"else",
"puts",
"\"\\n The command has not been understood, try again!\"",
".",
"red",
"set_templates_dir_to_existing_dir",
"(",
"dir",
")",
"end",
"end"
] | TOOD set_templates_dir_to_existing_dir Needs tests | [
"TOOD",
"set_templates_dir_to_existing_dir",
"Needs",
"tests"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L419-L438 |
4,857 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.parse_template_dir | def parse_template_dir
@dir_list = []
file_list = []
@append_templates = []
@line_templates = []
@whole_templates = []
Find.find(@template_path) do |x|
case
when File.file?(x) && x !~ /\/jumpstart_config/ then
file_list << x.sub!(@template_path, '')
when File.directory?(x) && x !~ /\/jumpstart_config/ then
@dir_list << x.sub!(@template_path, '')
when File.file?(x) && x =~ /\/jumpstart_config\/nginx.local.conf/ then
@nginx_local_template = x
when File.file?(x) && x =~ /\/jumpstart_config\/nginx.remote.conf/ then
@nginx_remote_template = x
end
end
file_list.each do |file|
if file =~ /_([lL]?)\._{1}\w*/
@append_templates << file
elsif file =~ /_(\d+)\._{1}\w*/
@line_templates << file
else
@whole_templates << file
end
end
end | ruby | def parse_template_dir
@dir_list = []
file_list = []
@append_templates = []
@line_templates = []
@whole_templates = []
Find.find(@template_path) do |x|
case
when File.file?(x) && x !~ /\/jumpstart_config/ then
file_list << x.sub!(@template_path, '')
when File.directory?(x) && x !~ /\/jumpstart_config/ then
@dir_list << x.sub!(@template_path, '')
when File.file?(x) && x =~ /\/jumpstart_config\/nginx.local.conf/ then
@nginx_local_template = x
when File.file?(x) && x =~ /\/jumpstart_config\/nginx.remote.conf/ then
@nginx_remote_template = x
end
end
file_list.each do |file|
if file =~ /_([lL]?)\._{1}\w*/
@append_templates << file
elsif file =~ /_(\d+)\._{1}\w*/
@line_templates << file
else
@whole_templates << file
end
end
end | [
"def",
"parse_template_dir",
"@dir_list",
"=",
"[",
"]",
"file_list",
"=",
"[",
"]",
"@append_templates",
"=",
"[",
"]",
"@line_templates",
"=",
"[",
"]",
"@whole_templates",
"=",
"[",
"]",
"Find",
".",
"find",
"(",
"@template_path",
")",
"do",
"|",
"x",
"|",
"case",
"when",
"File",
".",
"file?",
"(",
"x",
")",
"&&",
"x",
"!~",
"/",
"\\/",
"/",
"then",
"file_list",
"<<",
"x",
".",
"sub!",
"(",
"@template_path",
",",
"''",
")",
"when",
"File",
".",
"directory?",
"(",
"x",
")",
"&&",
"x",
"!~",
"/",
"\\/",
"/",
"then",
"@dir_list",
"<<",
"x",
".",
"sub!",
"(",
"@template_path",
",",
"''",
")",
"when",
"File",
".",
"file?",
"(",
"x",
")",
"&&",
"x",
"=~",
"/",
"\\/",
"\\/",
"/",
"then",
"@nginx_local_template",
"=",
"x",
"when",
"File",
".",
"file?",
"(",
"x",
")",
"&&",
"x",
"=~",
"/",
"\\/",
"\\/",
"/",
"then",
"@nginx_remote_template",
"=",
"x",
"end",
"end",
"file_list",
".",
"each",
"do",
"|",
"file",
"|",
"if",
"file",
"=~",
"/",
"\\.",
"\\w",
"/",
"@append_templates",
"<<",
"file",
"elsif",
"file",
"=~",
"/",
"\\d",
"\\.",
"\\w",
"/",
"@line_templates",
"<<",
"file",
"else",
"@whole_templates",
"<<",
"file",
"end",
"end",
"end"
] | Parses the contents of the @template_path and sorts ready for template creation. | [
"Parses",
"the",
"contents",
"of",
"the"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L485-L512 |
4,858 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.populate_files_from_whole_templates | def populate_files_from_whole_templates
@whole_templates.each {|x| FileUtils.cp(FileUtils.join_paths(@template_path, x), FileUtils.join_paths(@install_path, @project_name, x)) } unless @whole_templates.nil?
end | ruby | def populate_files_from_whole_templates
@whole_templates.each {|x| FileUtils.cp(FileUtils.join_paths(@template_path, x), FileUtils.join_paths(@install_path, @project_name, x)) } unless @whole_templates.nil?
end | [
"def",
"populate_files_from_whole_templates",
"@whole_templates",
".",
"each",
"{",
"|",
"x",
"|",
"FileUtils",
".",
"cp",
"(",
"FileUtils",
".",
"join_paths",
"(",
"@template_path",
",",
"x",
")",
",",
"FileUtils",
".",
"join_paths",
"(",
"@install_path",
",",
"@project_name",
",",
"x",
")",
")",
"}",
"unless",
"@whole_templates",
".",
"nil?",
"end"
] | Create files from whole templates | [
"Create",
"files",
"from",
"whole",
"templates"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L520-L522 |
4,859 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.remove_unwanted_files | def remove_unwanted_files
file_array = []
root_path = FileUtils.join_paths(@install_path, @project_name)
unless @config_file[:remove_files].nil?
@config_file[:remove_files].each do |file|
file_array << FileUtils.join_paths(root_path, file)
end
FileUtils.remove_files(file_array)
end
end | ruby | def remove_unwanted_files
file_array = []
root_path = FileUtils.join_paths(@install_path, @project_name)
unless @config_file[:remove_files].nil?
@config_file[:remove_files].each do |file|
file_array << FileUtils.join_paths(root_path, file)
end
FileUtils.remove_files(file_array)
end
end | [
"def",
"remove_unwanted_files",
"file_array",
"=",
"[",
"]",
"root_path",
"=",
"FileUtils",
".",
"join_paths",
"(",
"@install_path",
",",
"@project_name",
")",
"unless",
"@config_file",
"[",
":remove_files",
"]",
".",
"nil?",
"@config_file",
"[",
":remove_files",
"]",
".",
"each",
"do",
"|",
"file",
"|",
"file_array",
"<<",
"FileUtils",
".",
"join_paths",
"(",
"root_path",
",",
"file",
")",
"end",
"FileUtils",
".",
"remove_files",
"(",
"file_array",
")",
"end",
"end"
] | Removes files specified in templates YAML | [
"Removes",
"files",
"specified",
"in",
"templates",
"YAML"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L553-L562 |
4,860 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.run_scripts_from_yaml | def run_scripts_from_yaml(script_name)
unless @config_file[script_name].nil? || @config_file[script_name].empty?
begin
Dir.chdir(FileUtils.join_paths(@install_path, @project_name))
@config_file[script_name].each do |x|
puts "\nExecuting command: #{x.green}"
system "#{x}"
end
rescue
puts "\nCould not access the directory #{FileUtils.join_paths(@install_path, @project_name).red}.\nIn the interest of safety JumpStart will NOT run any YAML scripts from #{script_name.to_s.red_bold} until it can change into the new projects home directory."
end
end
end | ruby | def run_scripts_from_yaml(script_name)
unless @config_file[script_name].nil? || @config_file[script_name].empty?
begin
Dir.chdir(FileUtils.join_paths(@install_path, @project_name))
@config_file[script_name].each do |x|
puts "\nExecuting command: #{x.green}"
system "#{x}"
end
rescue
puts "\nCould not access the directory #{FileUtils.join_paths(@install_path, @project_name).red}.\nIn the interest of safety JumpStart will NOT run any YAML scripts from #{script_name.to_s.red_bold} until it can change into the new projects home directory."
end
end
end | [
"def",
"run_scripts_from_yaml",
"(",
"script_name",
")",
"unless",
"@config_file",
"[",
"script_name",
"]",
".",
"nil?",
"||",
"@config_file",
"[",
"script_name",
"]",
".",
"empty?",
"begin",
"Dir",
".",
"chdir",
"(",
"FileUtils",
".",
"join_paths",
"(",
"@install_path",
",",
"@project_name",
")",
")",
"@config_file",
"[",
"script_name",
"]",
".",
"each",
"do",
"|",
"x",
"|",
"puts",
"\"\\nExecuting command: #{x.green}\"",
"system",
"\"#{x}\"",
"end",
"rescue",
"puts",
"\"\\nCould not access the directory #{FileUtils.join_paths(@install_path, @project_name).red}.\\nIn the interest of safety JumpStart will NOT run any YAML scripts from #{script_name.to_s.red_bold} until it can change into the new projects home directory.\"",
"end",
"end",
"end"
] | Runs additional scripts specified in YAML. Runs one set after the install command has executed, another after the templates have been generated, and a final time after string replacement | [
"Runs",
"additional",
"scripts",
"specified",
"in",
"YAML",
".",
"Runs",
"one",
"set",
"after",
"the",
"install",
"command",
"has",
"executed",
"another",
"after",
"the",
"templates",
"have",
"been",
"generated",
"and",
"a",
"final",
"time",
"after",
"string",
"replacement"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L565-L577 |
4,861 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.check_for_strings_to_replace | def check_for_strings_to_replace
if @replace_strings.nil? || @replace_strings.empty?
return false
else
puts "\nChecking for strings to replace inside files...\n\n"
@replace_strings.each do |file|
if file[:target_path].nil? || file[:symbols].nil?
return false
else
puts "Target file: #{file[:target_path].green}\n"
puts "Strings to replace:\n\n"
check_replace_string_pairs_for_project_name_sub(file[:symbols])
file[:symbols].each do |x,y|
puts "Key: #{x.to_s.green}"
puts "Value: #{y.to_s.green}\n\n"
end
puts "\n"
path = FileUtils.join_paths(@install_path, @project_name, file[:target_path])
FileUtils.replace_strings(path, file[:symbols])
end
end
end
end | ruby | def check_for_strings_to_replace
if @replace_strings.nil? || @replace_strings.empty?
return false
else
puts "\nChecking for strings to replace inside files...\n\n"
@replace_strings.each do |file|
if file[:target_path].nil? || file[:symbols].nil?
return false
else
puts "Target file: #{file[:target_path].green}\n"
puts "Strings to replace:\n\n"
check_replace_string_pairs_for_project_name_sub(file[:symbols])
file[:symbols].each do |x,y|
puts "Key: #{x.to_s.green}"
puts "Value: #{y.to_s.green}\n\n"
end
puts "\n"
path = FileUtils.join_paths(@install_path, @project_name, file[:target_path])
FileUtils.replace_strings(path, file[:symbols])
end
end
end
end | [
"def",
"check_for_strings_to_replace",
"if",
"@replace_strings",
".",
"nil?",
"||",
"@replace_strings",
".",
"empty?",
"return",
"false",
"else",
"puts",
"\"\\nChecking for strings to replace inside files...\\n\\n\"",
"@replace_strings",
".",
"each",
"do",
"|",
"file",
"|",
"if",
"file",
"[",
":target_path",
"]",
".",
"nil?",
"||",
"file",
"[",
":symbols",
"]",
".",
"nil?",
"return",
"false",
"else",
"puts",
"\"Target file: #{file[:target_path].green}\\n\"",
"puts",
"\"Strings to replace:\\n\\n\"",
"check_replace_string_pairs_for_project_name_sub",
"(",
"file",
"[",
":symbols",
"]",
")",
"file",
"[",
":symbols",
"]",
".",
"each",
"do",
"|",
"x",
",",
"y",
"|",
"puts",
"\"Key: #{x.to_s.green}\"",
"puts",
"\"Value: #{y.to_s.green}\\n\\n\"",
"end",
"puts",
"\"\\n\"",
"path",
"=",
"FileUtils",
".",
"join_paths",
"(",
"@install_path",
",",
"@project_name",
",",
"file",
"[",
":target_path",
"]",
")",
"FileUtils",
".",
"replace_strings",
"(",
"path",
",",
"file",
"[",
":symbols",
"]",
")",
"end",
"end",
"end",
"end"
] | Looks for strings IN_CAPS that are specified for replacement in the templates YAML | [
"Looks",
"for",
"strings",
"IN_CAPS",
"that",
"are",
"specified",
"for",
"replacement",
"in",
"the",
"templates",
"YAML"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L580-L602 |
4,862 | i0n/jumpstart | lib/jumpstart/base.rb | JumpStart.Base.exit_with_success | def exit_with_success
puts "\n\n Exiting JumpStart...".purple
puts "\n Success! ".green + @project_name.green_bold + " has been created at: ".green + FileUtils.join_paths(@install_path, @project_name).green_bold + "\n\n".green
puts "******************************************************************************************************************************************\n"
JumpStart.dump_jumpstart_setup_yaml
exit
end | ruby | def exit_with_success
puts "\n\n Exiting JumpStart...".purple
puts "\n Success! ".green + @project_name.green_bold + " has been created at: ".green + FileUtils.join_paths(@install_path, @project_name).green_bold + "\n\n".green
puts "******************************************************************************************************************************************\n"
JumpStart.dump_jumpstart_setup_yaml
exit
end | [
"def",
"exit_with_success",
"puts",
"\"\\n\\n Exiting JumpStart...\"",
".",
"purple",
"puts",
"\"\\n Success! \"",
".",
"green",
"+",
"@project_name",
".",
"green_bold",
"+",
"\" has been created at: \"",
".",
"green",
"+",
"FileUtils",
".",
"join_paths",
"(",
"@install_path",
",",
"@project_name",
")",
".",
"green_bold",
"+",
"\"\\n\\n\"",
".",
"green",
"puts",
"\"******************************************************************************************************************************************\\n\"",
"JumpStart",
".",
"dump_jumpstart_setup_yaml",
"exit",
"end"
] | Exit after creating a project, dumping current setup information to YAML | [
"Exit",
"after",
"creating",
"a",
"project",
"dumping",
"current",
"setup",
"information",
"to",
"YAML"
] | e61beee175ba5a69796e00c2fb88097227c5ce9b | https://github.com/i0n/jumpstart/blob/e61beee175ba5a69796e00c2fb88097227c5ce9b/lib/jumpstart/base.rb#L605-L611 |
4,863 | jage/elk | lib/elk/number.rb | Elk.Number.save | def save
attributes = {
sms_url: self.sms_url,
voice_start: self.voice_start_url
}
# If new URL, send country, otherwise not
unless self.number_id
attributes[:country] = self.country
end
response = @client.post("/Numbers/#{self.number_id}", attributes)
response.code == 200
end | ruby | def save
attributes = {
sms_url: self.sms_url,
voice_start: self.voice_start_url
}
# If new URL, send country, otherwise not
unless self.number_id
attributes[:country] = self.country
end
response = @client.post("/Numbers/#{self.number_id}", attributes)
response.code == 200
end | [
"def",
"save",
"attributes",
"=",
"{",
"sms_url",
":",
"self",
".",
"sms_url",
",",
"voice_start",
":",
"self",
".",
"voice_start_url",
"}",
"# If new URL, send country, otherwise not",
"unless",
"self",
".",
"number_id",
"attributes",
"[",
":country",
"]",
"=",
"self",
".",
"country",
"end",
"response",
"=",
"@client",
".",
"post",
"(",
"\"/Numbers/#{self.number_id}\"",
",",
"attributes",
")",
"response",
".",
"code",
"==",
"200",
"end"
] | Updates or allocates a number | [
"Updates",
"or",
"allocates",
"a",
"number"
] | 9e28155d1c270d7a21f5c009a4cdff9a0fff0808 | https://github.com/jage/elk/blob/9e28155d1c270d7a21f5c009a4cdff9a0fff0808/lib/elk/number.rb#L45-L57 |
4,864 | jage/elk | lib/elk/number.rb | Elk.Number.deallocate! | def deallocate!
response = @client.post("/Numbers/#{self.number_id}", { active: "no" })
self.set_paramaters(Elk::Util.parse_json(response.body))
response.code == 200
end | ruby | def deallocate!
response = @client.post("/Numbers/#{self.number_id}", { active: "no" })
self.set_paramaters(Elk::Util.parse_json(response.body))
response.code == 200
end | [
"def",
"deallocate!",
"response",
"=",
"@client",
".",
"post",
"(",
"\"/Numbers/#{self.number_id}\"",
",",
"{",
"active",
":",
"\"no\"",
"}",
")",
"self",
".",
"set_paramaters",
"(",
"Elk",
"::",
"Util",
".",
"parse_json",
"(",
"response",
".",
"body",
")",
")",
"response",
".",
"code",
"==",
"200",
"end"
] | Deallocates a number, once deallocated, a number cannot be used again, ever! | [
"Deallocates",
"a",
"number",
"once",
"deallocated",
"a",
"number",
"cannot",
"be",
"used",
"again",
"ever!"
] | 9e28155d1c270d7a21f5c009a4cdff9a0fff0808 | https://github.com/jage/elk/blob/9e28155d1c270d7a21f5c009a4cdff9a0fff0808/lib/elk/number.rb#L60-L64 |
4,865 | fuminori-ido/edgarj | app/helpers/edgarj/common_helper.rb | Edgarj.CommonHelper.datetime_fmt | def datetime_fmt(dt)
if dt.blank? then
''
else
I18n.l(dt, format: I18n.t('edgarj.time.format'))
end
end | ruby | def datetime_fmt(dt)
if dt.blank? then
''
else
I18n.l(dt, format: I18n.t('edgarj.time.format'))
end
end | [
"def",
"datetime_fmt",
"(",
"dt",
")",
"if",
"dt",
".",
"blank?",
"then",
"''",
"else",
"I18n",
".",
"l",
"(",
"dt",
",",
"format",
":",
"I18n",
".",
"t",
"(",
"'edgarj.time.format'",
")",
")",
"end",
"end"
] | Edgarj standard datetime format | [
"Edgarj",
"standard",
"datetime",
"format"
] | 1648ab180f1f4adaeea03d54b645f58f3702a2bf | https://github.com/fuminori-ido/edgarj/blob/1648ab180f1f4adaeea03d54b645f58f3702a2bf/app/helpers/edgarj/common_helper.rb#L6-L12 |
4,866 | fuminori-ido/edgarj | app/helpers/edgarj/common_helper.rb | Edgarj.CommonHelper.get_enum | def get_enum(model, col)
col_name = col.name
if model.const_defined?(col_name.camelize, false)
enum = model.const_get(col_name.camelize)
enum.is_a?(Module) ? enum : nil
else
nil
end
end | ruby | def get_enum(model, col)
col_name = col.name
if model.const_defined?(col_name.camelize, false)
enum = model.const_get(col_name.camelize)
enum.is_a?(Module) ? enum : nil
else
nil
end
end | [
"def",
"get_enum",
"(",
"model",
",",
"col",
")",
"col_name",
"=",
"col",
".",
"name",
"if",
"model",
".",
"const_defined?",
"(",
"col_name",
".",
"camelize",
",",
"false",
")",
"enum",
"=",
"model",
".",
"const_get",
"(",
"col_name",
".",
"camelize",
")",
"enum",
".",
"is_a?",
"(",
"Module",
")",
"?",
"enum",
":",
"nil",
"else",
"nil",
"end",
"end"
] | get enum Module.
When Col(camelized argument col name) module exists, the Col is
assumed enum definition. | [
"get",
"enum",
"Module",
"."
] | 1648ab180f1f4adaeea03d54b645f58f3702a2bf | https://github.com/fuminori-ido/edgarj/blob/1648ab180f1f4adaeea03d54b645f58f3702a2bf/app/helpers/edgarj/common_helper.rb#L27-L35 |
4,867 | darbylabs/magma | lib/magma/templater.rb | Magma.Templater.render | def render(template)
template.render(config.variables.deep_merge(options[:globals]), strict_variables: true).tap do
if template.errors&.length&.positive?
puts template.errors
raise template.errors.map(&:to_s).join('; ')
end
end
end | ruby | def render(template)
template.render(config.variables.deep_merge(options[:globals]), strict_variables: true).tap do
if template.errors&.length&.positive?
puts template.errors
raise template.errors.map(&:to_s).join('; ')
end
end
end | [
"def",
"render",
"(",
"template",
")",
"template",
".",
"render",
"(",
"config",
".",
"variables",
".",
"deep_merge",
"(",
"options",
"[",
":globals",
"]",
")",
",",
"strict_variables",
":",
"true",
")",
".",
"tap",
"do",
"if",
"template",
".",
"errors",
"&.",
"length",
"&.",
"positive?",
"puts",
"template",
".",
"errors",
"raise",
"template",
".",
"errors",
".",
"map",
"(",
":to_s",
")",
".",
"join",
"(",
"'; '",
")",
"end",
"end",
"end"
] | Pipeline
Renders a Liquid template | [
"Pipeline",
"Renders",
"a",
"Liquid",
"template"
] | 62da478396fb479786f109128b6f65dd85b7c04c | https://github.com/darbylabs/magma/blob/62da478396fb479786f109128b6f65dd85b7c04c/lib/magma/templater.rb#L49-L56 |
4,868 | artursbraucs/banklink | lib/banklink/banklink.rb | Banklink.Common.parse | def parse(post)
@raw = post.to_s
for line in @raw.split('&')
key, value = *line.scan( %r{^([A-Za-z0-9_.]+)\=(.*)$} ).flatten
params[key] = CGI.unescape(value)
end
end | ruby | def parse(post)
@raw = post.to_s
for line in @raw.split('&')
key, value = *line.scan( %r{^([A-Za-z0-9_.]+)\=(.*)$} ).flatten
params[key] = CGI.unescape(value)
end
end | [
"def",
"parse",
"(",
"post",
")",
"@raw",
"=",
"post",
".",
"to_s",
"for",
"line",
"in",
"@raw",
".",
"split",
"(",
"'&'",
")",
"key",
",",
"value",
"=",
"line",
".",
"scan",
"(",
"%r{",
"\\=",
"}",
")",
".",
"flatten",
"params",
"[",
"key",
"]",
"=",
"CGI",
".",
"unescape",
"(",
"value",
")",
"end",
"end"
] | Take the posted data and move the relevant data into a hash | [
"Take",
"the",
"posted",
"data",
"and",
"move",
"the",
"relevant",
"data",
"into",
"a",
"hash"
] | 0b86b16797df6eb88e2ec72f4aaf73c6bb2eed7e | https://github.com/artursbraucs/banklink/blob/0b86b16797df6eb88e2ec72f4aaf73c6bb2eed7e/lib/banklink/banklink.rb#L54-L60 |
4,869 | Kuniri/kuniri | lib/kuniri/language/container_data/structured_and_oo/manager_basic_structure_data.rb | Languages.ManagerBasicStructureData.add_conditional | def add_conditional(pConditional)
return nil unless pConditional.is_a?(Languages::ConditionalData)
pConditional.level = @currentLevel
@basicStructure.push(pConditional)
end | ruby | def add_conditional(pConditional)
return nil unless pConditional.is_a?(Languages::ConditionalData)
pConditional.level = @currentLevel
@basicStructure.push(pConditional)
end | [
"def",
"add_conditional",
"(",
"pConditional",
")",
"return",
"nil",
"unless",
"pConditional",
".",
"is_a?",
"(",
"Languages",
"::",
"ConditionalData",
")",
"pConditional",
".",
"level",
"=",
"@currentLevel",
"@basicStructure",
".",
"push",
"(",
"pConditional",
")",
"end"
] | Add conditional to basicStructure
@param pConditional ConditionalData to add inside basicStructure | [
"Add",
"conditional",
"to",
"basicStructure"
] | 8b840ab307dc6bec48edd272c732b28c98f93f45 | https://github.com/Kuniri/kuniri/blob/8b840ab307dc6bec48edd272c732b28c98f93f45/lib/kuniri/language/container_data/structured_and_oo/manager_basic_structure_data.rb#L27-L31 |
4,870 | Kuniri/kuniri | lib/kuniri/language/container_data/structured_and_oo/manager_basic_structure_data.rb | Languages.ManagerBasicStructureData.add_repetition | def add_repetition(pRepetition)
return nil unless pRepetition.is_a?(Languages::RepetitionData)
pRepetition.level = @currentLevel
@basicStructure.push(pRepetition)
end | ruby | def add_repetition(pRepetition)
return nil unless pRepetition.is_a?(Languages::RepetitionData)
pRepetition.level = @currentLevel
@basicStructure.push(pRepetition)
end | [
"def",
"add_repetition",
"(",
"pRepetition",
")",
"return",
"nil",
"unless",
"pRepetition",
".",
"is_a?",
"(",
"Languages",
"::",
"RepetitionData",
")",
"pRepetition",
".",
"level",
"=",
"@currentLevel",
"@basicStructure",
".",
"push",
"(",
"pRepetition",
")",
"end"
] | Add repetition to basicStructure
@param pRepetition RepetitionData to add inside basicStrure | [
"Add",
"repetition",
"to",
"basicStructure"
] | 8b840ab307dc6bec48edd272c732b28c98f93f45 | https://github.com/Kuniri/kuniri/blob/8b840ab307dc6bec48edd272c732b28c98f93f45/lib/kuniri/language/container_data/structured_and_oo/manager_basic_structure_data.rb#L35-L39 |
4,871 | Kuniri/kuniri | lib/kuniri/language/container_data/structured_and_oo/manager_basic_structure_data.rb | Languages.ManagerBasicStructureData.add_block | def add_block(pBlock)
return nil unless pBlock.is_a?(Languages::BlockData)
pBlock.level = @currentLevel
@basicStructure.push(pBlock)
end | ruby | def add_block(pBlock)
return nil unless pBlock.is_a?(Languages::BlockData)
pBlock.level = @currentLevel
@basicStructure.push(pBlock)
end | [
"def",
"add_block",
"(",
"pBlock",
")",
"return",
"nil",
"unless",
"pBlock",
".",
"is_a?",
"(",
"Languages",
"::",
"BlockData",
")",
"pBlock",
".",
"level",
"=",
"@currentLevel",
"@basicStructure",
".",
"push",
"(",
"pBlock",
")",
"end"
] | Add block to basicStructure
@param pBlock BlockData to add inside basicStructure | [
"Add",
"block",
"to",
"basicStructure"
] | 8b840ab307dc6bec48edd272c732b28c98f93f45 | https://github.com/Kuniri/kuniri/blob/8b840ab307dc6bec48edd272c732b28c98f93f45/lib/kuniri/language/container_data/structured_and_oo/manager_basic_structure_data.rb#L43-L47 |
4,872 | CITguy/xml-fu | lib/xml-fu/configuration.rb | XmlFu.Configuration.symbol_conversion_algorithm= | def symbol_conversion_algorithm=(algorithm)
raise(ArgumentError, "Missing symbol conversion algorithm") unless algorithm
if algorithm.respond_to?(:call)
@symbol_conversion_algorithm = algorithm
else
if algorithm == :default
@symbol_conversion_algorithm = ALGORITHMS[:lower_camelcase]
elsif ALGORITHMS.keys.include?(algorithm)
@symbol_conversion_algorithm = ALGORITHMS[algorithm]
else
raise(ArgumentError, "Invalid symbol conversion algorithm")
end
end
end | ruby | def symbol_conversion_algorithm=(algorithm)
raise(ArgumentError, "Missing symbol conversion algorithm") unless algorithm
if algorithm.respond_to?(:call)
@symbol_conversion_algorithm = algorithm
else
if algorithm == :default
@symbol_conversion_algorithm = ALGORITHMS[:lower_camelcase]
elsif ALGORITHMS.keys.include?(algorithm)
@symbol_conversion_algorithm = ALGORITHMS[algorithm]
else
raise(ArgumentError, "Invalid symbol conversion algorithm")
end
end
end | [
"def",
"symbol_conversion_algorithm",
"=",
"(",
"algorithm",
")",
"raise",
"(",
"ArgumentError",
",",
"\"Missing symbol conversion algorithm\"",
")",
"unless",
"algorithm",
"if",
"algorithm",
".",
"respond_to?",
"(",
":call",
")",
"@symbol_conversion_algorithm",
"=",
"algorithm",
"else",
"if",
"algorithm",
"==",
":default",
"@symbol_conversion_algorithm",
"=",
"ALGORITHMS",
"[",
":lower_camelcase",
"]",
"elsif",
"ALGORITHMS",
".",
"keys",
".",
"include?",
"(",
"algorithm",
")",
"@symbol_conversion_algorithm",
"=",
"ALGORITHMS",
"[",
"algorithm",
"]",
"else",
"raise",
"(",
"ArgumentError",
",",
"\"Invalid symbol conversion algorithm\"",
")",
"end",
"end",
"end"
] | Set default values
initialize
Method for setting global Symbol-to-string conversion algorithm
@param [symbol, lambda] algorithm
Can be symbol corresponding to predefined algorithm or a lambda that accepts a symbol
as an argument and returns a string | [
"Set",
"default",
"values",
"initialize",
"Method",
"for",
"setting",
"global",
"Symbol",
"-",
"to",
"-",
"string",
"conversion",
"algorithm"
] | 2499571130ba2cac2e62f6e9d27d953a2f1e6ad7 | https://github.com/CITguy/xml-fu/blob/2499571130ba2cac2e62f6e9d27d953a2f1e6ad7/lib/xml-fu/configuration.rb#L41-L55 |
4,873 | ruby-journal/cricos_scrape.rb | lib/cricos_scrape/importer/course_importer.rb | CricosScrape.CourseImporter.find_course_location | def find_course_location
location_ids = []
if location_results_paginated?
for page_number in 1..total_pages
jump_to_page(page_number)
location_ids += fetch_location_ids_from_current_page
end
else
location_ids += fetch_location_ids_from_current_page
end
location_ids
end | ruby | def find_course_location
location_ids = []
if location_results_paginated?
for page_number in 1..total_pages
jump_to_page(page_number)
location_ids += fetch_location_ids_from_current_page
end
else
location_ids += fetch_location_ids_from_current_page
end
location_ids
end | [
"def",
"find_course_location",
"location_ids",
"=",
"[",
"]",
"if",
"location_results_paginated?",
"for",
"page_number",
"in",
"1",
"..",
"total_pages",
"jump_to_page",
"(",
"page_number",
")",
"location_ids",
"+=",
"fetch_location_ids_from_current_page",
"end",
"else",
"location_ids",
"+=",
"fetch_location_ids_from_current_page",
"end",
"location_ids",
"end"
] | Get all locations of course | [
"Get",
"all",
"locations",
"of",
"course"
] | b0652e4b3f16e1cb813fa75644be5174ae73b559 | https://github.com/ruby-journal/cricos_scrape.rb/blob/b0652e4b3f16e1cb813fa75644be5174ae73b559/lib/cricos_scrape/importer/course_importer.rb#L214-L227 |
4,874 | wvanbergen/sql_tree | tasks/github-gem.rb | GithubGem.RakeTasks.define_rspec_tasks! | def define_rspec_tasks!
require 'rspec/core/rake_task'
namespace(:spec) do
desc "Verify all RSpec examples for #{gemspec.name}"
RSpec::Core::RakeTask.new(:basic) do |t|
t.pattern = spec_pattern
end
desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
RSpec::Core::RakeTask.new(:specdoc) do |t|
t.pattern = spec_pattern
t.rspec_opts = ['--format', 'documentation', '--color']
end
desc "Run RCov on specs for #{gemspec.name}"
RSpec::Core::RakeTask.new(:rcov) do |t|
t.pattern = spec_pattern
t.rcov = true
t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
end
end
desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
task(:spec => ['spec:specdoc'])
end | ruby | def define_rspec_tasks!
require 'rspec/core/rake_task'
namespace(:spec) do
desc "Verify all RSpec examples for #{gemspec.name}"
RSpec::Core::RakeTask.new(:basic) do |t|
t.pattern = spec_pattern
end
desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
RSpec::Core::RakeTask.new(:specdoc) do |t|
t.pattern = spec_pattern
t.rspec_opts = ['--format', 'documentation', '--color']
end
desc "Run RCov on specs for #{gemspec.name}"
RSpec::Core::RakeTask.new(:rcov) do |t|
t.pattern = spec_pattern
t.rcov = true
t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
end
end
desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
task(:spec => ['spec:specdoc'])
end | [
"def",
"define_rspec_tasks!",
"require",
"'rspec/core/rake_task'",
"namespace",
"(",
":spec",
")",
"do",
"desc",
"\"Verify all RSpec examples for #{gemspec.name}\"",
"RSpec",
"::",
"Core",
"::",
"RakeTask",
".",
"new",
"(",
":basic",
")",
"do",
"|",
"t",
"|",
"t",
".",
"pattern",
"=",
"spec_pattern",
"end",
"desc",
"\"Verify all RSpec examples for #{gemspec.name} and output specdoc\"",
"RSpec",
"::",
"Core",
"::",
"RakeTask",
".",
"new",
"(",
":specdoc",
")",
"do",
"|",
"t",
"|",
"t",
".",
"pattern",
"=",
"spec_pattern",
"t",
".",
"rspec_opts",
"=",
"[",
"'--format'",
",",
"'documentation'",
",",
"'--color'",
"]",
"end",
"desc",
"\"Run RCov on specs for #{gemspec.name}\"",
"RSpec",
"::",
"Core",
"::",
"RakeTask",
".",
"new",
"(",
":rcov",
")",
"do",
"|",
"t",
"|",
"t",
".",
"pattern",
"=",
"spec_pattern",
"t",
".",
"rcov",
"=",
"true",
"t",
".",
"rcov_opts",
"=",
"[",
"'--exclude'",
",",
"'\"spec/*,gems/*\"'",
",",
"'--rails'",
"]",
"end",
"end",
"desc",
"\"Verify all RSpec examples for #{gemspec.name} and output specdoc\"",
"task",
"(",
":spec",
"=>",
"[",
"'spec:specdoc'",
"]",
")",
"end"
] | Defines RSpec tasks | [
"Defines",
"RSpec",
"tasks"
] | b45566c4c52962def5bfd376622a19697dd49969 | https://github.com/wvanbergen/sql_tree/blob/b45566c4c52962def5bfd376622a19697dd49969/tasks/github-gem.rb#L75-L100 |
4,875 | wvanbergen/sql_tree | tasks/github-gem.rb | GithubGem.RakeTasks.define_tasks! | def define_tasks!
define_test_tasks! if has_tests?
define_rspec_tasks! if has_specs?
namespace(@task_namespace) do
desc "Updates the filelist in the gemspec file"
task(:manifest) { manifest_task }
desc "Builds the .gem package"
task(:build => :manifest) { build_task }
desc "Sets the version of the gem in the gemspec"
task(:set_version => [:check_version, :check_current_branch]) { version_task }
task(:check_version => :fetch_origin) { check_version_task }
task(:fetch_origin) { fetch_origin_task }
task(:check_current_branch) { check_current_branch_task }
task(:check_clean_status) { check_clean_status_task }
task(:check_not_diverged => :fetch_origin) { check_not_diverged_task }
checks = [:check_current_branch, :check_clean_status, :check_not_diverged, :check_version]
checks.unshift('spec:basic') if has_specs?
checks.unshift('test:basic') if has_tests?
# checks.push << [:check_rubyforge] if gemspec.rubyforge_project
desc "Perform all checks that would occur before a release"
task(:release_checks => checks)
release_tasks = [:release_checks, :set_version, :build, :github_release, :gemcutter_release]
# release_tasks << [:rubyforge_release] if gemspec.rubyforge_project
desc "Release a new version of the gem using the VERSION environment variable"
task(:release => release_tasks) { release_task }
namespace(:release) do
desc "Release the next version of the gem, by incrementing the last version segment by 1"
task(:next => [:next_version] + release_tasks) { release_task }
desc "Release the next version of the gem, using a patch increment (0.0.1)"
task(:patch => [:next_patch_version] + release_tasks) { release_task }
desc "Release the next version of the gem, using a minor increment (0.1.0)"
task(:minor => [:next_minor_version] + release_tasks) { release_task }
desc "Release the next version of the gem, using a major increment (1.0.0)"
task(:major => [:next_major_version] + release_tasks) { release_task }
end
# task(:check_rubyforge) { check_rubyforge_task }
# task(:rubyforge_release) { rubyforge_release_task }
task(:gemcutter_release) { gemcutter_release_task }
task(:github_release => [:commit_modified_files, :tag_version]) { github_release_task }
task(:tag_version) { tag_version_task }
task(:commit_modified_files) { commit_modified_files_task }
task(:next_version) { next_version_task }
task(:next_patch_version) { next_version_task(:patch) }
task(:next_minor_version) { next_version_task(:minor) }
task(:next_major_version) { next_version_task(:major) }
desc "Updates the gem release tasks with the latest version on Github"
task(:update_tasks) { update_tasks_task }
end
end | ruby | def define_tasks!
define_test_tasks! if has_tests?
define_rspec_tasks! if has_specs?
namespace(@task_namespace) do
desc "Updates the filelist in the gemspec file"
task(:manifest) { manifest_task }
desc "Builds the .gem package"
task(:build => :manifest) { build_task }
desc "Sets the version of the gem in the gemspec"
task(:set_version => [:check_version, :check_current_branch]) { version_task }
task(:check_version => :fetch_origin) { check_version_task }
task(:fetch_origin) { fetch_origin_task }
task(:check_current_branch) { check_current_branch_task }
task(:check_clean_status) { check_clean_status_task }
task(:check_not_diverged => :fetch_origin) { check_not_diverged_task }
checks = [:check_current_branch, :check_clean_status, :check_not_diverged, :check_version]
checks.unshift('spec:basic') if has_specs?
checks.unshift('test:basic') if has_tests?
# checks.push << [:check_rubyforge] if gemspec.rubyforge_project
desc "Perform all checks that would occur before a release"
task(:release_checks => checks)
release_tasks = [:release_checks, :set_version, :build, :github_release, :gemcutter_release]
# release_tasks << [:rubyforge_release] if gemspec.rubyforge_project
desc "Release a new version of the gem using the VERSION environment variable"
task(:release => release_tasks) { release_task }
namespace(:release) do
desc "Release the next version of the gem, by incrementing the last version segment by 1"
task(:next => [:next_version] + release_tasks) { release_task }
desc "Release the next version of the gem, using a patch increment (0.0.1)"
task(:patch => [:next_patch_version] + release_tasks) { release_task }
desc "Release the next version of the gem, using a minor increment (0.1.0)"
task(:minor => [:next_minor_version] + release_tasks) { release_task }
desc "Release the next version of the gem, using a major increment (1.0.0)"
task(:major => [:next_major_version] + release_tasks) { release_task }
end
# task(:check_rubyforge) { check_rubyforge_task }
# task(:rubyforge_release) { rubyforge_release_task }
task(:gemcutter_release) { gemcutter_release_task }
task(:github_release => [:commit_modified_files, :tag_version]) { github_release_task }
task(:tag_version) { tag_version_task }
task(:commit_modified_files) { commit_modified_files_task }
task(:next_version) { next_version_task }
task(:next_patch_version) { next_version_task(:patch) }
task(:next_minor_version) { next_version_task(:minor) }
task(:next_major_version) { next_version_task(:major) }
desc "Updates the gem release tasks with the latest version on Github"
task(:update_tasks) { update_tasks_task }
end
end | [
"def",
"define_tasks!",
"define_test_tasks!",
"if",
"has_tests?",
"define_rspec_tasks!",
"if",
"has_specs?",
"namespace",
"(",
"@task_namespace",
")",
"do",
"desc",
"\"Updates the filelist in the gemspec file\"",
"task",
"(",
":manifest",
")",
"{",
"manifest_task",
"}",
"desc",
"\"Builds the .gem package\"",
"task",
"(",
":build",
"=>",
":manifest",
")",
"{",
"build_task",
"}",
"desc",
"\"Sets the version of the gem in the gemspec\"",
"task",
"(",
":set_version",
"=>",
"[",
":check_version",
",",
":check_current_branch",
"]",
")",
"{",
"version_task",
"}",
"task",
"(",
":check_version",
"=>",
":fetch_origin",
")",
"{",
"check_version_task",
"}",
"task",
"(",
":fetch_origin",
")",
"{",
"fetch_origin_task",
"}",
"task",
"(",
":check_current_branch",
")",
"{",
"check_current_branch_task",
"}",
"task",
"(",
":check_clean_status",
")",
"{",
"check_clean_status_task",
"}",
"task",
"(",
":check_not_diverged",
"=>",
":fetch_origin",
")",
"{",
"check_not_diverged_task",
"}",
"checks",
"=",
"[",
":check_current_branch",
",",
":check_clean_status",
",",
":check_not_diverged",
",",
":check_version",
"]",
"checks",
".",
"unshift",
"(",
"'spec:basic'",
")",
"if",
"has_specs?",
"checks",
".",
"unshift",
"(",
"'test:basic'",
")",
"if",
"has_tests?",
"# checks.push << [:check_rubyforge] if gemspec.rubyforge_project",
"desc",
"\"Perform all checks that would occur before a release\"",
"task",
"(",
":release_checks",
"=>",
"checks",
")",
"release_tasks",
"=",
"[",
":release_checks",
",",
":set_version",
",",
":build",
",",
":github_release",
",",
":gemcutter_release",
"]",
"# release_tasks << [:rubyforge_release] if gemspec.rubyforge_project",
"desc",
"\"Release a new version of the gem using the VERSION environment variable\"",
"task",
"(",
":release",
"=>",
"release_tasks",
")",
"{",
"release_task",
"}",
"namespace",
"(",
":release",
")",
"do",
"desc",
"\"Release the next version of the gem, by incrementing the last version segment by 1\"",
"task",
"(",
":next",
"=>",
"[",
":next_version",
"]",
"+",
"release_tasks",
")",
"{",
"release_task",
"}",
"desc",
"\"Release the next version of the gem, using a patch increment (0.0.1)\"",
"task",
"(",
":patch",
"=>",
"[",
":next_patch_version",
"]",
"+",
"release_tasks",
")",
"{",
"release_task",
"}",
"desc",
"\"Release the next version of the gem, using a minor increment (0.1.0)\"",
"task",
"(",
":minor",
"=>",
"[",
":next_minor_version",
"]",
"+",
"release_tasks",
")",
"{",
"release_task",
"}",
"desc",
"\"Release the next version of the gem, using a major increment (1.0.0)\"",
"task",
"(",
":major",
"=>",
"[",
":next_major_version",
"]",
"+",
"release_tasks",
")",
"{",
"release_task",
"}",
"end",
"# task(:check_rubyforge) { check_rubyforge_task }",
"# task(:rubyforge_release) { rubyforge_release_task }",
"task",
"(",
":gemcutter_release",
")",
"{",
"gemcutter_release_task",
"}",
"task",
"(",
":github_release",
"=>",
"[",
":commit_modified_files",
",",
":tag_version",
"]",
")",
"{",
"github_release_task",
"}",
"task",
"(",
":tag_version",
")",
"{",
"tag_version_task",
"}",
"task",
"(",
":commit_modified_files",
")",
"{",
"commit_modified_files_task",
"}",
"task",
"(",
":next_version",
")",
"{",
"next_version_task",
"}",
"task",
"(",
":next_patch_version",
")",
"{",
"next_version_task",
"(",
":patch",
")",
"}",
"task",
"(",
":next_minor_version",
")",
"{",
"next_version_task",
"(",
":minor",
")",
"}",
"task",
"(",
":next_major_version",
")",
"{",
"next_version_task",
"(",
":major",
")",
"}",
"desc",
"\"Updates the gem release tasks with the latest version on Github\"",
"task",
"(",
":update_tasks",
")",
"{",
"update_tasks_task",
"}",
"end",
"end"
] | Defines the rake tasks | [
"Defines",
"the",
"rake",
"tasks"
] | b45566c4c52962def5bfd376622a19697dd49969 | https://github.com/wvanbergen/sql_tree/blob/b45566c4c52962def5bfd376622a19697dd49969/tasks/github-gem.rb#L103-L167 |
4,876 | wvanbergen/sql_tree | tasks/github-gem.rb | GithubGem.RakeTasks.version_task | def version_task
update_gemspec(:version, ENV['VERSION']) if ENV['VERSION']
update_gemspec(:date, Date.today)
update_version_file(gemspec.version)
update_version_constant(gemspec.version)
end | ruby | def version_task
update_gemspec(:version, ENV['VERSION']) if ENV['VERSION']
update_gemspec(:date, Date.today)
update_version_file(gemspec.version)
update_version_constant(gemspec.version)
end | [
"def",
"version_task",
"update_gemspec",
"(",
":version",
",",
"ENV",
"[",
"'VERSION'",
"]",
")",
"if",
"ENV",
"[",
"'VERSION'",
"]",
"update_gemspec",
"(",
":date",
",",
"Date",
".",
"today",
")",
"update_version_file",
"(",
"gemspec",
".",
"version",
")",
"update_version_constant",
"(",
"gemspec",
".",
"version",
")",
"end"
] | Updates the version number in the gemspec file, the VERSION constant in the main
include file and the contents of the VERSION file. | [
"Updates",
"the",
"version",
"number",
"in",
"the",
"gemspec",
"file",
"the",
"VERSION",
"constant",
"in",
"the",
"main",
"include",
"file",
"and",
"the",
"contents",
"of",
"the",
"VERSION",
"file",
"."
] | b45566c4c52962def5bfd376622a19697dd49969 | https://github.com/wvanbergen/sql_tree/blob/b45566c4c52962def5bfd376622a19697dd49969/tasks/github-gem.rb#L215-L221 |
4,877 | wvanbergen/sql_tree | tasks/github-gem.rb | GithubGem.RakeTasks.update_version_file | def update_version_file(version)
if File.exists?('VERSION')
File.open('VERSION', 'w') { |f| f << version.to_s }
modified_files << 'VERSION'
end
end | ruby | def update_version_file(version)
if File.exists?('VERSION')
File.open('VERSION', 'w') { |f| f << version.to_s }
modified_files << 'VERSION'
end
end | [
"def",
"update_version_file",
"(",
"version",
")",
"if",
"File",
".",
"exists?",
"(",
"'VERSION'",
")",
"File",
".",
"open",
"(",
"'VERSION'",
",",
"'w'",
")",
"{",
"|",
"f",
"|",
"f",
"<<",
"version",
".",
"to_s",
"}",
"modified_files",
"<<",
"'VERSION'",
"end",
"end"
] | Updates the VERSION file with the new version | [
"Updates",
"the",
"VERSION",
"file",
"with",
"the",
"new",
"version"
] | b45566c4c52962def5bfd376622a19697dd49969 | https://github.com/wvanbergen/sql_tree/blob/b45566c4c52962def5bfd376622a19697dd49969/tasks/github-gem.rb#L297-L302 |
4,878 | wvanbergen/sql_tree | tasks/github-gem.rb | GithubGem.RakeTasks.update_version_constant | def update_version_constant(version)
if main_include && File.exist?(main_include)
file_contents = File.read(main_include)
if file_contents.sub!(/^(\s+VERSION\s*=\s*)[^\s].*$/) { $1 + version.to_s.inspect }
File.open(main_include, 'w') { |f| f << file_contents }
modified_files << main_include
end
end
end | ruby | def update_version_constant(version)
if main_include && File.exist?(main_include)
file_contents = File.read(main_include)
if file_contents.sub!(/^(\s+VERSION\s*=\s*)[^\s].*$/) { $1 + version.to_s.inspect }
File.open(main_include, 'w') { |f| f << file_contents }
modified_files << main_include
end
end
end | [
"def",
"update_version_constant",
"(",
"version",
")",
"if",
"main_include",
"&&",
"File",
".",
"exist?",
"(",
"main_include",
")",
"file_contents",
"=",
"File",
".",
"read",
"(",
"main_include",
")",
"if",
"file_contents",
".",
"sub!",
"(",
"/",
"\\s",
"\\s",
"\\s",
"\\s",
"/",
")",
"{",
"$1",
"+",
"version",
".",
"to_s",
".",
"inspect",
"}",
"File",
".",
"open",
"(",
"main_include",
",",
"'w'",
")",
"{",
"|",
"f",
"|",
"f",
"<<",
"file_contents",
"}",
"modified_files",
"<<",
"main_include",
"end",
"end",
"end"
] | Updates the VERSION constant in the main include file if it exists | [
"Updates",
"the",
"VERSION",
"constant",
"in",
"the",
"main",
"include",
"file",
"if",
"it",
"exists"
] | b45566c4c52962def5bfd376622a19697dd49969 | https://github.com/wvanbergen/sql_tree/blob/b45566c4c52962def5bfd376622a19697dd49969/tasks/github-gem.rb#L305-L313 |
4,879 | bdurand/json_record | lib/json_record/embedded_document.rb | JsonRecord.EmbeddedDocument.attributes= | def attributes= (attrs)
attrs.each_pair do |name, value|
field = schema.fields[name.to_s] || FieldDefinition.new(name, :type => value.class)
setter = "#{name}=".to_sym
if respond_to?(setter)
send(setter, value)
else
write_attribute(field, value, self)
end
end
end | ruby | def attributes= (attrs)
attrs.each_pair do |name, value|
field = schema.fields[name.to_s] || FieldDefinition.new(name, :type => value.class)
setter = "#{name}=".to_sym
if respond_to?(setter)
send(setter, value)
else
write_attribute(field, value, self)
end
end
end | [
"def",
"attributes",
"=",
"(",
"attrs",
")",
"attrs",
".",
"each_pair",
"do",
"|",
"name",
",",
"value",
"|",
"field",
"=",
"schema",
".",
"fields",
"[",
"name",
".",
"to_s",
"]",
"||",
"FieldDefinition",
".",
"new",
"(",
"name",
",",
":type",
"=>",
"value",
".",
"class",
")",
"setter",
"=",
"\"#{name}=\"",
".",
"to_sym",
"if",
"respond_to?",
"(",
"setter",
")",
"send",
"(",
"setter",
",",
"value",
")",
"else",
"write_attribute",
"(",
"field",
",",
"value",
",",
"self",
")",
"end",
"end",
"end"
] | Set all the attributes at once. | [
"Set",
"all",
"the",
"attributes",
"at",
"once",
"."
] | 463f4719d9618f6d2406c0aab6028e0156f7c775 | https://github.com/bdurand/json_record/blob/463f4719d9618f6d2406c0aab6028e0156f7c775/lib/json_record/embedded_document.rb#L49-L59 |
4,880 | bdurand/json_record | lib/json_record/embedded_document.rb | JsonRecord.EmbeddedDocument.[]= | def []= (name, value)
field = schema.fields[name.to_s] || FieldDefinition.new(name, :type => value.class)
write_attribute(field, value, self)
end | ruby | def []= (name, value)
field = schema.fields[name.to_s] || FieldDefinition.new(name, :type => value.class)
write_attribute(field, value, self)
end | [
"def",
"[]=",
"(",
"name",
",",
"value",
")",
"field",
"=",
"schema",
".",
"fields",
"[",
"name",
".",
"to_s",
"]",
"||",
"FieldDefinition",
".",
"new",
"(",
"name",
",",
":type",
"=>",
"value",
".",
"class",
")",
"write_attribute",
"(",
"field",
",",
"value",
",",
"self",
")",
"end"
] | Set a field from the schema with the specified name. | [
"Set",
"a",
"field",
"from",
"the",
"schema",
"with",
"the",
"specified",
"name",
"."
] | 463f4719d9618f6d2406c0aab6028e0156f7c775 | https://github.com/bdurand/json_record/blob/463f4719d9618f6d2406c0aab6028e0156f7c775/lib/json_record/embedded_document.rb#L73-L76 |
4,881 | efreesen/active_repository | lib/active_repository/base.rb | ActiveRepository.Base.reload | def reload
object = self.id.present? ?
persistence_class.where(id: self.id).first_or_initialize :
self
serialize! object.attributes
end | ruby | def reload
object = self.id.present? ?
persistence_class.where(id: self.id).first_or_initialize :
self
serialize! object.attributes
end | [
"def",
"reload",
"object",
"=",
"self",
".",
"id",
".",
"present?",
"?",
"persistence_class",
".",
"where",
"(",
"id",
":",
"self",
".",
"id",
")",
".",
"first_or_initialize",
":",
"self",
"serialize!",
"object",
".",
"attributes",
"end"
] | Gathers the persisted object from database and updates self with it's attributes. | [
"Gathers",
"the",
"persisted",
"object",
"from",
"database",
"and",
"updates",
"self",
"with",
"it",
"s",
"attributes",
"."
] | e134b0e02959ac7e745319a2d74398101dfc5900 | https://github.com/efreesen/active_repository/blob/e134b0e02959ac7e745319a2d74398101dfc5900/lib/active_repository/base.rb#L201-L207 |
4,882 | efreesen/active_repository | lib/active_repository/base.rb | ActiveRepository.Base.serialize! | def serialize!(attributes)
unless attributes.nil?
attributes.each do |key, value|
key = "id" if key == "_id"
self.send("#{key}=", (value.dup rescue value))
end
end
self.dup
end | ruby | def serialize!(attributes)
unless attributes.nil?
attributes.each do |key, value|
key = "id" if key == "_id"
self.send("#{key}=", (value.dup rescue value))
end
end
self.dup
end | [
"def",
"serialize!",
"(",
"attributes",
")",
"unless",
"attributes",
".",
"nil?",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"key",
"=",
"\"id\"",
"if",
"key",
"==",
"\"_id\"",
"self",
".",
"send",
"(",
"\"#{key}=\"",
",",
"(",
"value",
".",
"dup",
"rescue",
"value",
")",
")",
"end",
"end",
"self",
".",
"dup",
"end"
] | Updates attributes from self with the attributes from the parameters | [
"Updates",
"attributes",
"from",
"self",
"with",
"the",
"attributes",
"from",
"the",
"parameters"
] | e134b0e02959ac7e745319a2d74398101dfc5900 | https://github.com/efreesen/active_repository/blob/e134b0e02959ac7e745319a2d74398101dfc5900/lib/active_repository/base.rb#L234-L243 |
4,883 | efreesen/active_repository | lib/active_repository/base.rb | ActiveRepository.Base.convert | def convert(attribute="id")
klass = persistence_class
object = klass.where(attribute.to_sym => self.send(attribute)).first
object ||= persistence_class.new
attributes = self.attributes.select{ |key, value| self.class.serialized_attributes.include?(key.to_s) }
attributes.delete(:id)
object.attributes = attributes
object.save
self.id = object.id
object
end | ruby | def convert(attribute="id")
klass = persistence_class
object = klass.where(attribute.to_sym => self.send(attribute)).first
object ||= persistence_class.new
attributes = self.attributes.select{ |key, value| self.class.serialized_attributes.include?(key.to_s) }
attributes.delete(:id)
object.attributes = attributes
object.save
self.id = object.id
object
end | [
"def",
"convert",
"(",
"attribute",
"=",
"\"id\"",
")",
"klass",
"=",
"persistence_class",
"object",
"=",
"klass",
".",
"where",
"(",
"attribute",
".",
"to_sym",
"=>",
"self",
".",
"send",
"(",
"attribute",
")",
")",
".",
"first",
"object",
"||=",
"persistence_class",
".",
"new",
"attributes",
"=",
"self",
".",
"attributes",
".",
"select",
"{",
"|",
"key",
",",
"value",
"|",
"self",
".",
"class",
".",
"serialized_attributes",
".",
"include?",
"(",
"key",
".",
"to_s",
")",
"}",
"attributes",
".",
"delete",
"(",
":id",
")",
"object",
".",
"attributes",
"=",
"attributes",
"object",
".",
"save",
"self",
".",
"id",
"=",
"object",
".",
"id",
"object",
"end"
] | Find related object on the database and updates it with attributes in self, if it didn't
find it on database it creates a new one. | [
"Find",
"related",
"object",
"on",
"the",
"database",
"and",
"updates",
"it",
"with",
"attributes",
"in",
"self",
"if",
"it",
"didn",
"t",
"find",
"it",
"on",
"database",
"it",
"creates",
"a",
"new",
"one",
"."
] | e134b0e02959ac7e745319a2d74398101dfc5900 | https://github.com/efreesen/active_repository/blob/e134b0e02959ac7e745319a2d74398101dfc5900/lib/active_repository/base.rb#L248-L265 |
4,884 | efreesen/active_repository | lib/active_repository/base.rb | ActiveRepository.Base.set_timestamps | def set_timestamps
if self.errors.empty?
self.created_at = DateTime.now.utc if self.respond_to?(:created_at=) && self.created_at.nil?
self.updated_at = DateTime.now.utc if self.respond_to?(:updated_at=)
end
end | ruby | def set_timestamps
if self.errors.empty?
self.created_at = DateTime.now.utc if self.respond_to?(:created_at=) && self.created_at.nil?
self.updated_at = DateTime.now.utc if self.respond_to?(:updated_at=)
end
end | [
"def",
"set_timestamps",
"if",
"self",
".",
"errors",
".",
"empty?",
"self",
".",
"created_at",
"=",
"DateTime",
".",
"now",
".",
"utc",
"if",
"self",
".",
"respond_to?",
"(",
":created_at=",
")",
"&&",
"self",
".",
"created_at",
".",
"nil?",
"self",
".",
"updated_at",
"=",
"DateTime",
".",
"now",
".",
"utc",
"if",
"self",
".",
"respond_to?",
"(",
":updated_at=",
")",
"end",
"end"
] | Updates created_at and updated_at | [
"Updates",
"created_at",
"and",
"updated_at"
] | e134b0e02959ac7e745319a2d74398101dfc5900 | https://github.com/efreesen/active_repository/blob/e134b0e02959ac7e745319a2d74398101dfc5900/lib/active_repository/base.rb#L290-L295 |
4,885 | lyokato/ruby-atomutil | lib/atomutil.rb | Atom.Element.set | def set(ns, element_name, value="", attributes=nil)
xpath = child_xpath(ns, element_name)
@elem.elements.delete_all(xpath)
add(ns, element_name, value, attributes)
end | ruby | def set(ns, element_name, value="", attributes=nil)
xpath = child_xpath(ns, element_name)
@elem.elements.delete_all(xpath)
add(ns, element_name, value, attributes)
end | [
"def",
"set",
"(",
"ns",
",",
"element_name",
",",
"value",
"=",
"\"\"",
",",
"attributes",
"=",
"nil",
")",
"xpath",
"=",
"child_xpath",
"(",
"ns",
",",
"element_name",
")",
"@elem",
".",
"elements",
".",
"delete_all",
"(",
"xpath",
")",
"add",
"(",
"ns",
",",
"element_name",
",",
"value",
",",
"attributes",
")",
"end"
] | This method allows you to handle extra-element such as you can't represent
with elements defined in Atom namespace.
entry = Atom::Entry.new
entry.set('http://example/2007/mynamespace', 'foo', 'bar')
Now your entry includes new element.
<foo xmlns="http://example/2007/mynamespace">bar</foo>
You also can add attributes
entry.set('http://example/2007/mynamespace', 'foo', 'bar', { :myattr => 'attr1', :myattr2 => 'attr2' })
And you can get following element from entry
<foo xmlns="http://example/2007/mynamespace" myattr="attr1" myattr2="attr2">bar</foo>
Or using prefix,
entry = Atom::Entry.new
ns = Atom::Namespace.new(:prefix => 'dc', :uri => 'http://purl.org/dc/elements/1.1/')
entry.set(ns, 'subject', 'buz')
Then your element contains
<dc:subject xmlns:dc="http://purl.org/dc/elements/1.1/">buz</dc:subject>
And in case you need to handle more complex element, pass the REXML::Element object
which you customized as third argument instead of text-value.
custom_element = REXML::Element.new
custom_child = REXML::Element.new('mychild')
custom_child.add_text = 'child!'
custom_element.add_element custom_child
entry.set(ns, 'mynamespace', costom_element) | [
"This",
"method",
"allows",
"you",
"to",
"handle",
"extra",
"-",
"element",
"such",
"as",
"you",
"can",
"t",
"represent",
"with",
"elements",
"defined",
"in",
"Atom",
"namespace",
"."
] | f4bb354bf56d1c0a85af38f6004eefacb44c336f | https://github.com/lyokato/ruby-atomutil/blob/f4bb354bf56d1c0a85af38f6004eefacb44c336f/lib/atomutil.rb#L498-L502 |
4,886 | lyokato/ruby-atomutil | lib/atomutil.rb | Atom.Element.add | def add(ns, element_name, value, attributes={})
element = REXML::Element.new(element_name)
if ns.is_a?(Namespace)
unless ns.prefix.nil? || ns.prefix.empty?
element.name = "#{ns.prefix}:#{element_name}"
element.add_namespace ns.prefix, ns.uri unless @ns == ns || @ns == ns.uri
else
element.add_namespace ns.uri unless @ns == ns || @ns == ns.uri
end
else
element.add_namespace ns unless @ns == ns || @ns.to_s == ns
end
if value.is_a?(Element)
value.elem.each_element do |e|
element.add e.deep_clone
end
value.elem.attributes.each_attribute do |a|
unless a.name =~ /^xmlns(?:\:)?/
element.add_attribute a
end
end
#element.text = value.elem.text unless value.elem.text.nil?
text = value.elem.get_text
unless text.nil?
element.text = REXML::Text.new(text.to_s, true, nil, true)
end
else
if value.is_a?(REXML::Element)
element.add_element value.deep_clone
else
element.add_text value.to_s
end
end
element.add_attributes attributes unless attributes.nil?
@elem.add_element element
end | ruby | def add(ns, element_name, value, attributes={})
element = REXML::Element.new(element_name)
if ns.is_a?(Namespace)
unless ns.prefix.nil? || ns.prefix.empty?
element.name = "#{ns.prefix}:#{element_name}"
element.add_namespace ns.prefix, ns.uri unless @ns == ns || @ns == ns.uri
else
element.add_namespace ns.uri unless @ns == ns || @ns == ns.uri
end
else
element.add_namespace ns unless @ns == ns || @ns.to_s == ns
end
if value.is_a?(Element)
value.elem.each_element do |e|
element.add e.deep_clone
end
value.elem.attributes.each_attribute do |a|
unless a.name =~ /^xmlns(?:\:)?/
element.add_attribute a
end
end
#element.text = value.elem.text unless value.elem.text.nil?
text = value.elem.get_text
unless text.nil?
element.text = REXML::Text.new(text.to_s, true, nil, true)
end
else
if value.is_a?(REXML::Element)
element.add_element value.deep_clone
else
element.add_text value.to_s
end
end
element.add_attributes attributes unless attributes.nil?
@elem.add_element element
end | [
"def",
"add",
"(",
"ns",
",",
"element_name",
",",
"value",
",",
"attributes",
"=",
"{",
"}",
")",
"element",
"=",
"REXML",
"::",
"Element",
".",
"new",
"(",
"element_name",
")",
"if",
"ns",
".",
"is_a?",
"(",
"Namespace",
")",
"unless",
"ns",
".",
"prefix",
".",
"nil?",
"||",
"ns",
".",
"prefix",
".",
"empty?",
"element",
".",
"name",
"=",
"\"#{ns.prefix}:#{element_name}\"",
"element",
".",
"add_namespace",
"ns",
".",
"prefix",
",",
"ns",
".",
"uri",
"unless",
"@ns",
"==",
"ns",
"||",
"@ns",
"==",
"ns",
".",
"uri",
"else",
"element",
".",
"add_namespace",
"ns",
".",
"uri",
"unless",
"@ns",
"==",
"ns",
"||",
"@ns",
"==",
"ns",
".",
"uri",
"end",
"else",
"element",
".",
"add_namespace",
"ns",
"unless",
"@ns",
"==",
"ns",
"||",
"@ns",
".",
"to_s",
"==",
"ns",
"end",
"if",
"value",
".",
"is_a?",
"(",
"Element",
")",
"value",
".",
"elem",
".",
"each_element",
"do",
"|",
"e",
"|",
"element",
".",
"add",
"e",
".",
"deep_clone",
"end",
"value",
".",
"elem",
".",
"attributes",
".",
"each_attribute",
"do",
"|",
"a",
"|",
"unless",
"a",
".",
"name",
"=~",
"/",
"\\:",
"/",
"element",
".",
"add_attribute",
"a",
"end",
"end",
"#element.text = value.elem.text unless value.elem.text.nil?",
"text",
"=",
"value",
".",
"elem",
".",
"get_text",
"unless",
"text",
".",
"nil?",
"element",
".",
"text",
"=",
"REXML",
"::",
"Text",
".",
"new",
"(",
"text",
".",
"to_s",
",",
"true",
",",
"nil",
",",
"true",
")",
"end",
"else",
"if",
"value",
".",
"is_a?",
"(",
"REXML",
"::",
"Element",
")",
"element",
".",
"add_element",
"value",
".",
"deep_clone",
"else",
"element",
".",
"add_text",
"value",
".",
"to_s",
"end",
"end",
"element",
".",
"add_attributes",
"attributes",
"unless",
"attributes",
".",
"nil?",
"@elem",
".",
"add_element",
"element",
"end"
] | Same as 'set', but when a element-name confliction occurs,
append new element without overriding. | [
"Same",
"as",
"set",
"but",
"when",
"a",
"element",
"-",
"name",
"confliction",
"occurs",
"append",
"new",
"element",
"without",
"overriding",
"."
] | f4bb354bf56d1c0a85af38f6004eefacb44c336f | https://github.com/lyokato/ruby-atomutil/blob/f4bb354bf56d1c0a85af38f6004eefacb44c336f/lib/atomutil.rb#L505-L540 |
4,887 | lyokato/ruby-atomutil | lib/atomutil.rb | Atom.Element.get_object | def get_object(ns, element_name, ext_class)
elements = getlist(ns, element_name)
return nil if elements.empty?
ext_class.new(:namespace => ns, :elem => elements.first)
end | ruby | def get_object(ns, element_name, ext_class)
elements = getlist(ns, element_name)
return nil if elements.empty?
ext_class.new(:namespace => ns, :elem => elements.first)
end | [
"def",
"get_object",
"(",
"ns",
",",
"element_name",
",",
"ext_class",
")",
"elements",
"=",
"getlist",
"(",
"ns",
",",
"element_name",
")",
"return",
"nil",
"if",
"elements",
".",
"empty?",
"ext_class",
".",
"new",
"(",
":namespace",
"=>",
"ns",
",",
":elem",
"=>",
"elements",
".",
"first",
")",
"end"
] | Get indicated elements as an object of the class you passed as thrid argument.
ns = Atom::Namespace.new(:uri => 'http://example.com/ns#')
obj = entry.get_object(ns, 'mytag', MyClass)
puts obj.class #MyClass
MyClass should inherit Atom::Element | [
"Get",
"indicated",
"elements",
"as",
"an",
"object",
"of",
"the",
"class",
"you",
"passed",
"as",
"thrid",
"argument",
"."
] | f4bb354bf56d1c0a85af38f6004eefacb44c336f | https://github.com/lyokato/ruby-atomutil/blob/f4bb354bf56d1c0a85af38f6004eefacb44c336f/lib/atomutil.rb#L568-L572 |
4,888 | lyokato/ruby-atomutil | lib/atomutil.rb | Atom.Element.get_objects | def get_objects(ns, element_name, ext_class)
elements = getlist(ns, element_name)
return [] if elements.empty?
elements.collect do |e|
ext_class.new(:namespace => ns, :elem => e)
end
end | ruby | def get_objects(ns, element_name, ext_class)
elements = getlist(ns, element_name)
return [] if elements.empty?
elements.collect do |e|
ext_class.new(:namespace => ns, :elem => e)
end
end | [
"def",
"get_objects",
"(",
"ns",
",",
"element_name",
",",
"ext_class",
")",
"elements",
"=",
"getlist",
"(",
"ns",
",",
"element_name",
")",
"return",
"[",
"]",
"if",
"elements",
".",
"empty?",
"elements",
".",
"collect",
"do",
"|",
"e",
"|",
"ext_class",
".",
"new",
"(",
":namespace",
"=>",
"ns",
",",
":elem",
"=>",
"e",
")",
"end",
"end"
] | Get all indicated elements as an object of the class you passed as thrid argument.
entry.get_objects(ns, 'mytag', MyClass).each{ |obj|
p obj.class #MyClass
} | [
"Get",
"all",
"indicated",
"elements",
"as",
"an",
"object",
"of",
"the",
"class",
"you",
"passed",
"as",
"thrid",
"argument",
"."
] | f4bb354bf56d1c0a85af38f6004eefacb44c336f | https://github.com/lyokato/ruby-atomutil/blob/f4bb354bf56d1c0a85af38f6004eefacb44c336f/lib/atomutil.rb#L579-L585 |
4,889 | lyokato/ruby-atomutil | lib/atomutil.rb | Atom.Element.to_s | def to_s(*)
doc = REXML::Document.new
decl = REXML::XMLDecl.new("1.0", "utf-8")
doc.add decl
doc.add_element @elem
doc.to_s
end | ruby | def to_s(*)
doc = REXML::Document.new
decl = REXML::XMLDecl.new("1.0", "utf-8")
doc.add decl
doc.add_element @elem
doc.to_s
end | [
"def",
"to_s",
"(",
"*",
")",
"doc",
"=",
"REXML",
"::",
"Document",
".",
"new",
"decl",
"=",
"REXML",
"::",
"XMLDecl",
".",
"new",
"(",
"\"1.0\"",
",",
"\"utf-8\"",
")",
"doc",
".",
"add",
"decl",
"doc",
".",
"add_element",
"@elem",
"doc",
".",
"to_s",
"end"
] | Convert to XML-Document and return it as string | [
"Convert",
"to",
"XML",
"-",
"Document",
"and",
"return",
"it",
"as",
"string"
] | f4bb354bf56d1c0a85af38f6004eefacb44c336f | https://github.com/lyokato/ruby-atomutil/blob/f4bb354bf56d1c0a85af38f6004eefacb44c336f/lib/atomutil.rb#L595-L601 |
4,890 | lyokato/ruby-atomutil | lib/atomutil.rb | Atom.Element.child_xpath | def child_xpath(ns, element_name, attributes=nil)
ns_uri = ns.is_a?(Namespace) ? ns.uri : ns
unless !attributes.nil? && attributes.is_a?(Hash)
"child::*[local-name()='#{element_name}' and namespace-uri()='#{ns_uri}']"
else
attr_str = attributes.collect{|key, val| "@#{key.to_s}='#{val}'"}.join(' and ')
"child::*[local-name()='#{element_name}' and namespace-uri()='#{ns_uri}' and #{attr_str}]"
end
end | ruby | def child_xpath(ns, element_name, attributes=nil)
ns_uri = ns.is_a?(Namespace) ? ns.uri : ns
unless !attributes.nil? && attributes.is_a?(Hash)
"child::*[local-name()='#{element_name}' and namespace-uri()='#{ns_uri}']"
else
attr_str = attributes.collect{|key, val| "@#{key.to_s}='#{val}'"}.join(' and ')
"child::*[local-name()='#{element_name}' and namespace-uri()='#{ns_uri}' and #{attr_str}]"
end
end | [
"def",
"child_xpath",
"(",
"ns",
",",
"element_name",
",",
"attributes",
"=",
"nil",
")",
"ns_uri",
"=",
"ns",
".",
"is_a?",
"(",
"Namespace",
")",
"?",
"ns",
".",
"uri",
":",
"ns",
"unless",
"!",
"attributes",
".",
"nil?",
"&&",
"attributes",
".",
"is_a?",
"(",
"Hash",
")",
"\"child::*[local-name()='#{element_name}' and namespace-uri()='#{ns_uri}']\"",
"else",
"attr_str",
"=",
"attributes",
".",
"collect",
"{",
"|",
"key",
",",
"val",
"|",
"\"@#{key.to_s}='#{val}'\"",
"}",
".",
"join",
"(",
"' and '",
")",
"\"child::*[local-name()='#{element_name}' and namespace-uri()='#{ns_uri}' and #{attr_str}]\"",
"end",
"end"
] | Get a xpath string to traverse child elements with namespace and name. | [
"Get",
"a",
"xpath",
"string",
"to",
"traverse",
"child",
"elements",
"with",
"namespace",
"and",
"name",
"."
] | f4bb354bf56d1c0a85af38f6004eefacb44c336f | https://github.com/lyokato/ruby-atomutil/blob/f4bb354bf56d1c0a85af38f6004eefacb44c336f/lib/atomutil.rb#L604-L612 |
4,891 | lyokato/ruby-atomutil | lib/atomutil.rb | Atompub.Client.get_media | def get_media(media_uri)
get_resource(media_uri)
if @rc.instance_of?(Atom::Entry)
raise ResponseError, "Response is not Media Resource"
end
return @rc, @res.content_type
end | ruby | def get_media(media_uri)
get_resource(media_uri)
if @rc.instance_of?(Atom::Entry)
raise ResponseError, "Response is not Media Resource"
end
return @rc, @res.content_type
end | [
"def",
"get_media",
"(",
"media_uri",
")",
"get_resource",
"(",
"media_uri",
")",
"if",
"@rc",
".",
"instance_of?",
"(",
"Atom",
"::",
"Entry",
")",
"raise",
"ResponseError",
",",
"\"Response is not Media Resource\"",
"end",
"return",
"@rc",
",",
"@res",
".",
"content_type",
"end"
] | Get media resource
Example:
resource, content_type = client.get_media(media_uri) | [
"Get",
"media",
"resource"
] | f4bb354bf56d1c0a85af38f6004eefacb44c336f | https://github.com/lyokato/ruby-atomutil/blob/f4bb354bf56d1c0a85af38f6004eefacb44c336f/lib/atomutil.rb#L1413-L1419 |
4,892 | lyokato/ruby-atomutil | lib/atomutil.rb | Atompub.Client.create_entry | def create_entry(post_uri, entry, slug=nil)
unless entry.kind_of?(Atom::Entry)
entry = Atom::Entry.new :stream => entry
end
service = @service_info.get(post_uri)
unless entry.categories.all?{ |c| service.allows_category?(c) }
raise RequestError, "Forbidden Category"
end
create_resource(post_uri, entry.to_s, Atom::MediaType::ENTRY.to_s, slug)
@res['Location']
end | ruby | def create_entry(post_uri, entry, slug=nil)
unless entry.kind_of?(Atom::Entry)
entry = Atom::Entry.new :stream => entry
end
service = @service_info.get(post_uri)
unless entry.categories.all?{ |c| service.allows_category?(c) }
raise RequestError, "Forbidden Category"
end
create_resource(post_uri, entry.to_s, Atom::MediaType::ENTRY.to_s, slug)
@res['Location']
end | [
"def",
"create_entry",
"(",
"post_uri",
",",
"entry",
",",
"slug",
"=",
"nil",
")",
"unless",
"entry",
".",
"kind_of?",
"(",
"Atom",
"::",
"Entry",
")",
"entry",
"=",
"Atom",
"::",
"Entry",
".",
"new",
":stream",
"=>",
"entry",
"end",
"service",
"=",
"@service_info",
".",
"get",
"(",
"post_uri",
")",
"unless",
"entry",
".",
"categories",
".",
"all?",
"{",
"|",
"c",
"|",
"service",
".",
"allows_category?",
"(",
"c",
")",
"}",
"raise",
"RequestError",
",",
"\"Forbidden Category\"",
"end",
"create_resource",
"(",
"post_uri",
",",
"entry",
".",
"to_s",
",",
"Atom",
"::",
"MediaType",
"::",
"ENTRY",
".",
"to_s",
",",
"slug",
")",
"@res",
"[",
"'Location'",
"]",
"end"
] | Create new entry
Example:
entry = Atom::Entry.new
entry.title = 'foo'
author = Atom::Author.new
author.name = 'Lyo Kato'
author.email = '[email protected]'
entry.author = author
entry_uri = client.create_entry(post_uri, entry) | [
"Create",
"new",
"entry"
] | f4bb354bf56d1c0a85af38f6004eefacb44c336f | https://github.com/lyokato/ruby-atomutil/blob/f4bb354bf56d1c0a85af38f6004eefacb44c336f/lib/atomutil.rb#L1432-L1442 |
4,893 | lyokato/ruby-atomutil | lib/atomutil.rb | Atompub.Client.create_media | def create_media(media_uri, file_path, content_type, slug=nil)
file_path = Pathname.new(file_path) unless file_path.is_a?(Pathname)
stream = file_path.open { |f| f.binmode; f.read }
service = @service_info.get(media_uri)
if service.nil?
raise RequestError, "Service information not found. Get service document before you do create_media."
end
unless service.accepts_media_type?(content_type)
raise RequestError, "Unsupported Media Type: #{content_type}"
end
create_resource(media_uri, stream, content_type, slug)
@res['Location']
end | ruby | def create_media(media_uri, file_path, content_type, slug=nil)
file_path = Pathname.new(file_path) unless file_path.is_a?(Pathname)
stream = file_path.open { |f| f.binmode; f.read }
service = @service_info.get(media_uri)
if service.nil?
raise RequestError, "Service information not found. Get service document before you do create_media."
end
unless service.accepts_media_type?(content_type)
raise RequestError, "Unsupported Media Type: #{content_type}"
end
create_resource(media_uri, stream, content_type, slug)
@res['Location']
end | [
"def",
"create_media",
"(",
"media_uri",
",",
"file_path",
",",
"content_type",
",",
"slug",
"=",
"nil",
")",
"file_path",
"=",
"Pathname",
".",
"new",
"(",
"file_path",
")",
"unless",
"file_path",
".",
"is_a?",
"(",
"Pathname",
")",
"stream",
"=",
"file_path",
".",
"open",
"{",
"|",
"f",
"|",
"f",
".",
"binmode",
";",
"f",
".",
"read",
"}",
"service",
"=",
"@service_info",
".",
"get",
"(",
"media_uri",
")",
"if",
"service",
".",
"nil?",
"raise",
"RequestError",
",",
"\"Service information not found. Get service document before you do create_media.\"",
"end",
"unless",
"service",
".",
"accepts_media_type?",
"(",
"content_type",
")",
"raise",
"RequestError",
",",
"\"Unsupported Media Type: #{content_type}\"",
"end",
"create_resource",
"(",
"media_uri",
",",
"stream",
",",
"content_type",
",",
"slug",
")",
"@res",
"[",
"'Location'",
"]",
"end"
] | Create new media resource
Example:
media_uri = client.create_media(post_media_uri, 'myimage.jpg', 'image/jpeg') | [
"Create",
"new",
"media",
"resource"
] | f4bb354bf56d1c0a85af38f6004eefacb44c336f | https://github.com/lyokato/ruby-atomutil/blob/f4bb354bf56d1c0a85af38f6004eefacb44c336f/lib/atomutil.rb#L1449-L1461 |
4,894 | lyokato/ruby-atomutil | lib/atomutil.rb | Atompub.Client.update_media | def update_media(media_uri, file_path, content_type)
file_path = Pathname.new(file_path) unless file_path.is_a?(Pathname)
stream = file_path.open { |f| f.binmode; f.read }
update_resource(media_uri, stream, content_type)
end | ruby | def update_media(media_uri, file_path, content_type)
file_path = Pathname.new(file_path) unless file_path.is_a?(Pathname)
stream = file_path.open { |f| f.binmode; f.read }
update_resource(media_uri, stream, content_type)
end | [
"def",
"update_media",
"(",
"media_uri",
",",
"file_path",
",",
"content_type",
")",
"file_path",
"=",
"Pathname",
".",
"new",
"(",
"file_path",
")",
"unless",
"file_path",
".",
"is_a?",
"(",
"Pathname",
")",
"stream",
"=",
"file_path",
".",
"open",
"{",
"|",
"f",
"|",
"f",
".",
"binmode",
";",
"f",
".",
"read",
"}",
"update_resource",
"(",
"media_uri",
",",
"stream",
",",
"content_type",
")",
"end"
] | Update media resource
Example:
entry = client.get_entry(media_link_uri)
client.update_media(entry.edit_media_link, 'newimage.jpg', 'image/jpeg') | [
"Update",
"media",
"resource"
] | f4bb354bf56d1c0a85af38f6004eefacb44c336f | https://github.com/lyokato/ruby-atomutil/blob/f4bb354bf56d1c0a85af38f6004eefacb44c336f/lib/atomutil.rb#L1483-L1487 |
4,895 | lyokato/ruby-atomutil | lib/atomutil.rb | Atompub.Client.get_contents_except_resources | def get_contents_except_resources(uri, &block)
clear
uri = URI.parse(uri)
@req = Net::HTTP::Get.new uri.request_uri
set_common_info(@req)
@http_class.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
@res = http.request(@req)
case @res
when Net::HTTPOK
block.call(@res) if block_given?
else
raise RequestError, "Failed to get contents. #{@res.code}"
end
end
end | ruby | def get_contents_except_resources(uri, &block)
clear
uri = URI.parse(uri)
@req = Net::HTTP::Get.new uri.request_uri
set_common_info(@req)
@http_class.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
@res = http.request(@req)
case @res
when Net::HTTPOK
block.call(@res) if block_given?
else
raise RequestError, "Failed to get contents. #{@res.code}"
end
end
end | [
"def",
"get_contents_except_resources",
"(",
"uri",
",",
"&",
"block",
")",
"clear",
"uri",
"=",
"URI",
".",
"parse",
"(",
"uri",
")",
"@req",
"=",
"Net",
"::",
"HTTP",
"::",
"Get",
".",
"new",
"uri",
".",
"request_uri",
"set_common_info",
"(",
"@req",
")",
"@http_class",
".",
"start",
"(",
"uri",
".",
"host",
",",
"uri",
".",
"port",
",",
":use_ssl",
"=>",
"uri",
".",
"scheme",
"==",
"'https'",
")",
"do",
"|",
"http",
"|",
"@res",
"=",
"http",
".",
"request",
"(",
"@req",
")",
"case",
"@res",
"when",
"Net",
"::",
"HTTPOK",
"block",
".",
"call",
"(",
"@res",
")",
"if",
"block_given?",
"else",
"raise",
"RequestError",
",",
"\"Failed to get contents. #{@res.code}\"",
"end",
"end",
"end"
] | Get contents, for example, service-document, categories, and feed. | [
"Get",
"contents",
"for",
"example",
"service",
"-",
"document",
"categories",
"and",
"feed",
"."
] | f4bb354bf56d1c0a85af38f6004eefacb44c336f | https://github.com/lyokato/ruby-atomutil/blob/f4bb354bf56d1c0a85af38f6004eefacb44c336f/lib/atomutil.rb#L1515-L1529 |
4,896 | ndlib/rof | lib/rof/translators/osf_to_rof.rb | ROF::Translators.OsfToRof.fetch_from_ttl | def fetch_from_ttl(ttl_file)
graph = RDF::Turtle::Reader.open(ttl_file, prefixes: ROF::OsfPrefixList.dup)
JSON::LD::API.fromRdf(graph)
end | ruby | def fetch_from_ttl(ttl_file)
graph = RDF::Turtle::Reader.open(ttl_file, prefixes: ROF::OsfPrefixList.dup)
JSON::LD::API.fromRdf(graph)
end | [
"def",
"fetch_from_ttl",
"(",
"ttl_file",
")",
"graph",
"=",
"RDF",
"::",
"Turtle",
"::",
"Reader",
".",
"open",
"(",
"ttl_file",
",",
"prefixes",
":",
"ROF",
"::",
"OsfPrefixList",
".",
"dup",
")",
"JSON",
"::",
"LD",
"::",
"API",
".",
"fromRdf",
"(",
"graph",
")",
"end"
] | reads a ttl file and makes it a JSON-LD file that we can parse | [
"reads",
"a",
"ttl",
"file",
"and",
"makes",
"it",
"a",
"JSON",
"-",
"LD",
"file",
"that",
"we",
"can",
"parse"
] | 18a8cc009540a868447952eed82de035451025e8 | https://github.com/ndlib/rof/blob/18a8cc009540a868447952eed82de035451025e8/lib/rof/translators/osf_to_rof.rb#L80-L83 |
4,897 | ndlib/rof | lib/rof/translators/osf_to_rof.rb | ROF::Translators.OsfToRof.apply_previous_archived_version_if_applicable | def apply_previous_archived_version_if_applicable(rels_ext)
# If a previously archived pid was passed in, use it to set pav:previousVersion
# If not, check SOLR for one.
pid = previously_archived_pid_finder.call(archive_type, osf_project_identifier)
pid = ROF::Utility.check_solr_for_previous(config, osf_project_identifier) if pid.nil?
rels_ext['pav:previousVersion'] = pid if pid
rels_ext
end | ruby | def apply_previous_archived_version_if_applicable(rels_ext)
# If a previously archived pid was passed in, use it to set pav:previousVersion
# If not, check SOLR for one.
pid = previously_archived_pid_finder.call(archive_type, osf_project_identifier)
pid = ROF::Utility.check_solr_for_previous(config, osf_project_identifier) if pid.nil?
rels_ext['pav:previousVersion'] = pid if pid
rels_ext
end | [
"def",
"apply_previous_archived_version_if_applicable",
"(",
"rels_ext",
")",
"# If a previously archived pid was passed in, use it to set pav:previousVersion",
"# If not, check SOLR for one.",
"pid",
"=",
"previously_archived_pid_finder",
".",
"call",
"(",
"archive_type",
",",
"osf_project_identifier",
")",
"pid",
"=",
"ROF",
"::",
"Utility",
".",
"check_solr_for_previous",
"(",
"config",
",",
"osf_project_identifier",
")",
"if",
"pid",
".",
"nil?",
"rels_ext",
"[",
"'pav:previousVersion'",
"]",
"=",
"pid",
"if",
"pid",
"rels_ext",
"end"
] | For reference to the assumed RELS-EXT see the following spec in CurateND
@see https://github.com/ndlib/curate_nd/blob/115efec2e046257282a86fe2cd98c7d229d04cf9/spec/repository_models/osf_archive_spec.rb#L97 | [
"For",
"reference",
"to",
"the",
"assumed",
"RELS",
"-",
"EXT",
"see",
"the",
"following",
"spec",
"in",
"CurateND"
] | 18a8cc009540a868447952eed82de035451025e8 | https://github.com/ndlib/rof/blob/18a8cc009540a868447952eed82de035451025e8/lib/rof/translators/osf_to_rof.rb#L124-L131 |
4,898 | ndlib/rof | lib/rof/translators/osf_to_rof.rb | ROF::Translators.OsfToRof.build_archive_record | def build_archive_record
this_rof = {}
this_rof['owner'] = project['owner']
this_rof['type'] = 'OsfArchive'
this_rof['rights'] = map_rights
this_rof['rels-ext'] = map_rels_ext
this_rof['metadata'] = map_metadata
this_rof['files'] = [source_slug + '.tar.gz']
this_rof
end | ruby | def build_archive_record
this_rof = {}
this_rof['owner'] = project['owner']
this_rof['type'] = 'OsfArchive'
this_rof['rights'] = map_rights
this_rof['rels-ext'] = map_rels_ext
this_rof['metadata'] = map_metadata
this_rof['files'] = [source_slug + '.tar.gz']
this_rof
end | [
"def",
"build_archive_record",
"this_rof",
"=",
"{",
"}",
"this_rof",
"[",
"'owner'",
"]",
"=",
"project",
"[",
"'owner'",
"]",
"this_rof",
"[",
"'type'",
"]",
"=",
"'OsfArchive'",
"this_rof",
"[",
"'rights'",
"]",
"=",
"map_rights",
"this_rof",
"[",
"'rels-ext'",
"]",
"=",
"map_rels_ext",
"this_rof",
"[",
"'metadata'",
"]",
"=",
"map_metadata",
"this_rof",
"[",
"'files'",
"]",
"=",
"[",
"source_slug",
"+",
"'.tar.gz'",
"]",
"this_rof",
"end"
] | Constructs OsfArchive Record from ttl_data, data from the UI form,
and task config data | [
"Constructs",
"OsfArchive",
"Record",
"from",
"ttl_data",
"data",
"from",
"the",
"UI",
"form",
"and",
"task",
"config",
"data"
] | 18a8cc009540a868447952eed82de035451025e8 | https://github.com/ndlib/rof/blob/18a8cc009540a868447952eed82de035451025e8/lib/rof/translators/osf_to_rof.rb#L135-L144 |
4,899 | ndlib/rof | lib/rof/translators/osf_to_rof.rb | ROF::Translators.OsfToRof.map_creator | def map_creator
creator = []
ttl_data[0][@osf_map['hasContributor']].each do |contributor|
# Looping through the primary document and the contributors
ttl_data.each do |item|
next unless item['@id'] == contributor['@id']
if item[@osf_map['isBibliographic']][0]['@value'] == 'true'
creator.push map_user_from_ttl(item[@osf_map['hasUser']][0]['@id'])
end
end
end
creator
end | ruby | def map_creator
creator = []
ttl_data[0][@osf_map['hasContributor']].each do |contributor|
# Looping through the primary document and the contributors
ttl_data.each do |item|
next unless item['@id'] == contributor['@id']
if item[@osf_map['isBibliographic']][0]['@value'] == 'true'
creator.push map_user_from_ttl(item[@osf_map['hasUser']][0]['@id'])
end
end
end
creator
end | [
"def",
"map_creator",
"creator",
"=",
"[",
"]",
"ttl_data",
"[",
"0",
"]",
"[",
"@osf_map",
"[",
"'hasContributor'",
"]",
"]",
".",
"each",
"do",
"|",
"contributor",
"|",
"# Looping through the primary document and the contributors",
"ttl_data",
".",
"each",
"do",
"|",
"item",
"|",
"next",
"unless",
"item",
"[",
"'@id'",
"]",
"==",
"contributor",
"[",
"'@id'",
"]",
"if",
"item",
"[",
"@osf_map",
"[",
"'isBibliographic'",
"]",
"]",
"[",
"0",
"]",
"[",
"'@value'",
"]",
"==",
"'true'",
"creator",
".",
"push",
"map_user_from_ttl",
"(",
"item",
"[",
"@osf_map",
"[",
"'hasUser'",
"]",
"]",
"[",
"0",
"]",
"[",
"'@id'",
"]",
")",
"end",
"end",
"end",
"creator",
"end"
] | sets the creator- needs to read another ttl for the User data
only contrubutors with isBibliographic true are considered | [
"sets",
"the",
"creator",
"-",
"needs",
"to",
"read",
"another",
"ttl",
"for",
"the",
"User",
"data",
"only",
"contrubutors",
"with",
"isBibliographic",
"true",
"are",
"considered"
] | 18a8cc009540a868447952eed82de035451025e8 | https://github.com/ndlib/rof/blob/18a8cc009540a868447952eed82de035451025e8/lib/rof/translators/osf_to_rof.rb#L171-L183 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.