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
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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",
"}",
"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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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?",
"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",
"]",
"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",
"(",
":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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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",
"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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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",
")",
"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 | train |
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 | train |
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",
"|",
"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 | train |
donaldpiret/github-pivotal-flow | lib/github_pivotal_flow/configuration.rb | GithubPivotalFlow.Configuration.api_token | def api_token
api_token = @options[:api_token] || Git.get_config(KEY_API_TOKEN, :inherited)
if api_token.blank?
api_token = ask('Pivotal API Token (found at https://www.pivotaltracker.com/profile): ').strip
Git.set_config(KEY_API_TOKEN, api_token, :local) unless api_token.blank?
puts
end
api_token
end | ruby | def api_token
api_token = @options[:api_token] || Git.get_config(KEY_API_TOKEN, :inherited)
if api_token.blank?
api_token = ask('Pivotal API Token (found at https://www.pivotaltracker.com/profile): ').strip
Git.set_config(KEY_API_TOKEN, api_token, :local) unless api_token.blank?
puts
end
api_token
end | [
"def",
"api_token",
"api_token",
"=",
"@options",
"[",
":api_token",
"]",
"||",
"Git",
".",
"get_config",
"(",
"KEY_API_TOKEN",
",",
":inherited",
")",
"if",
"api_token",
".",
"blank?",
"api_token",
"=",
"ask",
"(",
"'Pivotal API Token (found at https://www.pivotaltracker.com/profile): '",
")",
".",
"strip",
"Git",
".",
"set_config",
"(",
"KEY_API_TOKEN",
",",
"api_token",
",",
":local",
")",
"unless",
"api_token",
".",
"blank?",
"puts",
"end",
"api_token",
"end"
] | Returns the user's Pivotal Tracker API token. If this token has not been
configured, prompts the user for the value. The value is checked for in
the _inherited_ Git configuration, but is stored in the _global_ Git
configuration so that it can be used across multiple repositories.
@return [String] The user's Pivotal Tracker API token | [
"Returns",
"the",
"user",
"s",
"Pivotal",
"Tracker",
"API",
"token",
".",
"If",
"this",
"token",
"has",
"not",
"been",
"configured",
"prompts",
"the",
"user",
"for",
"the",
"value",
".",
"The",
"value",
"is",
"checked",
"for",
"in",
"the",
"_inherited_",
"Git",
"configuration",
"but",
"is",
"stored",
"in",
"the",
"_global_",
"Git",
"configuration",
"so",
"that",
"it",
"can",
"be",
"used",
"across",
"multiple",
"repositories",
"."
] | 676436950b691f57ad793a9023a4765ab9420dd0 | https://github.com/donaldpiret/github-pivotal-flow/blob/676436950b691f57ad793a9023a4765ab9420dd0/lib/github_pivotal_flow/configuration.rb#L43-L53 | train |
donaldpiret/github-pivotal-flow | lib/github_pivotal_flow/configuration.rb | GithubPivotalFlow.Configuration.project_id | def project_id
project_id = @options[:project_id] || Git.get_config(KEY_PROJECT_ID, :inherited)
if project_id.empty?
project_id = choose do |menu|
menu.prompt = 'Choose project associated with this repository: '
PivotalTracker::Project.all.sort_by { |project| project.name }.each do |project|
menu.choice(project.name) { project.id }
end
end
Git.set_config(KEY_PROJECT_ID, project_id, :local)
puts
end
project_id
end | ruby | def project_id
project_id = @options[:project_id] || Git.get_config(KEY_PROJECT_ID, :inherited)
if project_id.empty?
project_id = choose do |menu|
menu.prompt = 'Choose project associated with this repository: '
PivotalTracker::Project.all.sort_by { |project| project.name }.each do |project|
menu.choice(project.name) { project.id }
end
end
Git.set_config(KEY_PROJECT_ID, project_id, :local)
puts
end
project_id
end | [
"def",
"project_id",
"project_id",
"=",
"@options",
"[",
":project_id",
"]",
"||",
"Git",
".",
"get_config",
"(",
"KEY_PROJECT_ID",
",",
":inherited",
")",
"if",
"project_id",
".",
"empty?",
"project_id",
"=",
"choose",
"do",
"|",
"menu",
"|",
"menu",
".",
"prompt",
"=",
"'Choose project associated with this repository: '",
"PivotalTracker",
"::",
"Project",
".",
"all",
".",
"sort_by",
"{",
"|",
"project",
"|",
"project",
".",
"name",
"}",
".",
"each",
"do",
"|",
"project",
"|",
"menu",
".",
"choice",
"(",
"project",
".",
"name",
")",
"{",
"project",
".",
"id",
"}",
"end",
"end",
"Git",
".",
"set_config",
"(",
"KEY_PROJECT_ID",
",",
"project_id",
",",
":local",
")",
"puts",
"end",
"project_id",
"end"
] | Returns the Pivotal Tracker project id for this repository. If this id
has not been configuration, prompts the user for the value. The value is
checked for in the _inherited_ Git configuration, but is stored in the
_local_ Git configuration so that it is specific to this repository.
@return [String] The repository's Pivotal Tracker project id | [
"Returns",
"the",
"Pivotal",
"Tracker",
"project",
"id",
"for",
"this",
"repository",
".",
"If",
"this",
"id",
"has",
"not",
"been",
"configuration",
"prompts",
"the",
"user",
"for",
"the",
"value",
".",
"The",
"value",
"is",
"checked",
"for",
"in",
"the",
"_inherited_",
"Git",
"configuration",
"but",
"is",
"stored",
"in",
"the",
"_local_",
"Git",
"configuration",
"so",
"that",
"it",
"is",
"specific",
"to",
"this",
"repository",
"."
] | 676436950b691f57ad793a9023a4765ab9420dd0 | https://github.com/donaldpiret/github-pivotal-flow/blob/676436950b691f57ad793a9023a4765ab9420dd0/lib/github_pivotal_flow/configuration.rb#L79-L96 | train |
donaldpiret/github-pivotal-flow | lib/github_pivotal_flow/configuration.rb | GithubPivotalFlow.Configuration.story | def story
return @story if @story
story_id = Git.get_config(KEY_STORY_ID, :branch)
if story_id.blank? && (matchdata = /^[a-z0-9_\-]+\/(\d+)(-[a-z0-9_\-]+)?$/i.match(Git.current_branch))
story_id = matchdata[1]
Git.set_config(KEY_STORY_ID, story_id, :branch) unless story_id.blank?
end
if story_id.blank?
story_id = ask('What Pivotal story ID is this branch associated with?').strip
Git.set_config(KEY_STORY_ID, story_id, :branch) unless story_id.blank?
end
return nil if story_id.blank?
return (@story = Story.new(project, project.stories.find(story_id.to_i), branch_name: Git.current_branch))
end | ruby | def story
return @story if @story
story_id = Git.get_config(KEY_STORY_ID, :branch)
if story_id.blank? && (matchdata = /^[a-z0-9_\-]+\/(\d+)(-[a-z0-9_\-]+)?$/i.match(Git.current_branch))
story_id = matchdata[1]
Git.set_config(KEY_STORY_ID, story_id, :branch) unless story_id.blank?
end
if story_id.blank?
story_id = ask('What Pivotal story ID is this branch associated with?').strip
Git.set_config(KEY_STORY_ID, story_id, :branch) unless story_id.blank?
end
return nil if story_id.blank?
return (@story = Story.new(project, project.stories.find(story_id.to_i), branch_name: Git.current_branch))
end | [
"def",
"story",
"return",
"@story",
"if",
"@story",
"story_id",
"=",
"Git",
".",
"get_config",
"(",
"KEY_STORY_ID",
",",
":branch",
")",
"if",
"story_id",
".",
"blank?",
"&&",
"(",
"matchdata",
"=",
"/",
"\\-",
"\\/",
"\\d",
"\\-",
"/i",
".",
"match",
"(",
"Git",
".",
"current_branch",
")",
")",
"story_id",
"=",
"matchdata",
"[",
"1",
"]",
"Git",
".",
"set_config",
"(",
"KEY_STORY_ID",
",",
"story_id",
",",
":branch",
")",
"unless",
"story_id",
".",
"blank?",
"end",
"if",
"story_id",
".",
"blank?",
"story_id",
"=",
"ask",
"(",
"'What Pivotal story ID is this branch associated with?'",
")",
".",
"strip",
"Git",
".",
"set_config",
"(",
"KEY_STORY_ID",
",",
"story_id",
",",
":branch",
")",
"unless",
"story_id",
".",
"blank?",
"end",
"return",
"nil",
"if",
"story_id",
".",
"blank?",
"return",
"(",
"@story",
"=",
"Story",
".",
"new",
"(",
"project",
",",
"project",
".",
"stories",
".",
"find",
"(",
"story_id",
".",
"to_i",
")",
",",
"branch_name",
":",
"Git",
".",
"current_branch",
")",
")",
"end"
] | Returns the story associated with the branch
@return [Story] the story associated with the current development branch | [
"Returns",
"the",
"story",
"associated",
"with",
"the",
"branch"
] | 676436950b691f57ad793a9023a4765ab9420dd0 | https://github.com/donaldpiret/github-pivotal-flow/blob/676436950b691f57ad793a9023a4765ab9420dd0/lib/github_pivotal_flow/configuration.rb#L105-L118 | train |
donaldpiret/github-pivotal-flow | lib/github_pivotal_flow/configuration.rb | GithubPivotalFlow.Configuration.ask_github_password | def ask_github_password(username = nil)
username ||= github_username
print "Github password for #{username} (never stored): "
if $stdin.tty?
password = askpass
puts ''
password
else
# in testing
$stdin.gets.chomp
end
rescue Interrupt
abort
end | ruby | def ask_github_password(username = nil)
username ||= github_username
print "Github password for #{username} (never stored): "
if $stdin.tty?
password = askpass
puts ''
password
else
# in testing
$stdin.gets.chomp
end
rescue Interrupt
abort
end | [
"def",
"ask_github_password",
"(",
"username",
"=",
"nil",
")",
"username",
"||=",
"github_username",
"print",
"\"Github password for #{username} (never stored): \"",
"if",
"$stdin",
".",
"tty?",
"password",
"=",
"askpass",
"puts",
"''",
"password",
"else",
"$stdin",
".",
"gets",
".",
"chomp",
"end",
"rescue",
"Interrupt",
"abort",
"end"
] | special prompt that has hidden input | [
"special",
"prompt",
"that",
"has",
"hidden",
"input"
] | 676436950b691f57ad793a9023a4765ab9420dd0 | https://github.com/donaldpiret/github-pivotal-flow/blob/676436950b691f57ad793a9023a4765ab9420dd0/lib/github_pivotal_flow/configuration.rb#L260-L273 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/payment_processor.rb | PaynetEasy::PaynetEasyApi.PaymentProcessor.execute_query | def execute_query(query_name, payment_transaction)
query = query(query_name)
begin
request = query.create_request payment_transaction
response = make_request request
query.process_response payment_transaction, response
rescue Exception => error
handle_exception error, payment_transaction, response
return
end
handle_query_result payment_transaction, response
response
end | ruby | def execute_query(query_name, payment_transaction)
query = query(query_name)
begin
request = query.create_request payment_transaction
response = make_request request
query.process_response payment_transaction, response
rescue Exception => error
handle_exception error, payment_transaction, response
return
end
handle_query_result payment_transaction, response
response
end | [
"def",
"execute_query",
"(",
"query_name",
",",
"payment_transaction",
")",
"query",
"=",
"query",
"(",
"query_name",
")",
"begin",
"request",
"=",
"query",
".",
"create_request",
"payment_transaction",
"response",
"=",
"make_request",
"request",
"query",
".",
"process_response",
"payment_transaction",
",",
"response",
"rescue",
"Exception",
"=>",
"error",
"handle_exception",
"error",
",",
"payment_transaction",
",",
"response",
"return",
"end",
"handle_query_result",
"payment_transaction",
",",
"response",
"response",
"end"
] | Executes payment API query
@param query_name [String] Payment API query name
@param payment_transaction [PaymentTransaction] Payment transaction for processing
@return [Response] Query response | [
"Executes",
"payment",
"API",
"query"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/payment_processor.rb#L62-L77 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/payment_processor.rb | PaynetEasy::PaynetEasyApi.PaymentProcessor.process_paynet_easy_callback | def process_paynet_easy_callback(callback_response, payment_transaction)
begin
callback(callback_response.type).process_callback(payment_transaction, callback_response)
rescue Exception => error
handle_exception error, payment_transaction, callback_response
return
end
handle_query_result payment_transaction, callback_response
callback_response
end | ruby | def process_paynet_easy_callback(callback_response, payment_transaction)
begin
callback(callback_response.type).process_callback(payment_transaction, callback_response)
rescue Exception => error
handle_exception error, payment_transaction, callback_response
return
end
handle_query_result payment_transaction, callback_response
callback_response
end | [
"def",
"process_paynet_easy_callback",
"(",
"callback_response",
",",
"payment_transaction",
")",
"begin",
"callback",
"(",
"callback_response",
".",
"type",
")",
".",
"process_callback",
"(",
"payment_transaction",
",",
"callback_response",
")",
"rescue",
"Exception",
"=>",
"error",
"handle_exception",
"error",
",",
"payment_transaction",
",",
"callback_response",
"return",
"end",
"handle_query_result",
"payment_transaction",
",",
"callback_response",
"callback_response",
"end"
] | Executes payment gateway processor for PaynetEasy payment callback
@param callback_response [CallbackResponse] Callback object with data from payment gateway
@param payment_transaction [PaymentTransaction] Payment transaction for processing
@return [CallbackResponse] Validated payment gateway callback | [
"Executes",
"payment",
"gateway",
"processor",
"for",
"PaynetEasy",
"payment",
"callback"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/payment_processor.rb#L96-L107 | train |
kyohei8/inoreader-api | lib/inoreader/api/app.rb | InoreaderApi.Api.login | def login(un, pw)
response_body = Helper.auth_request un, pw
auth_token = Hash[*response_body.split.collect { |i| i.split('=') }.flatten]['Auth']
raise InoreaderApi::InoreaderApiError.new 'Bad Authentication' if auth_token.nil?
auth_token
rescue => e
raise InoreaderApi::InoreaderApiError.new e.message if auth_token.nil?
end | ruby | def login(un, pw)
response_body = Helper.auth_request un, pw
auth_token = Hash[*response_body.split.collect { |i| i.split('=') }.flatten]['Auth']
raise InoreaderApi::InoreaderApiError.new 'Bad Authentication' if auth_token.nil?
auth_token
rescue => e
raise InoreaderApi::InoreaderApiError.new e.message if auth_token.nil?
end | [
"def",
"login",
"(",
"un",
",",
"pw",
")",
"response_body",
"=",
"Helper",
".",
"auth_request",
"un",
",",
"pw",
"auth_token",
"=",
"Hash",
"[",
"*",
"response_body",
".",
"split",
".",
"collect",
"{",
"|",
"i",
"|",
"i",
".",
"split",
"(",
"'='",
")",
"}",
".",
"flatten",
"]",
"[",
"'Auth'",
"]",
"raise",
"InoreaderApi",
"::",
"InoreaderApiError",
".",
"new",
"'Bad Authentication'",
"if",
"auth_token",
".",
"nil?",
"auth_token",
"rescue",
"=>",
"e",
"raise",
"InoreaderApi",
"::",
"InoreaderApiError",
".",
"new",
"e",
".",
"message",
"if",
"auth_token",
".",
"nil?",
"end"
] | Authenticate, to return authToken
@param un username or Email
@param pw Password
@return Hash
if success
{
:auth_token => xxxxxxxx
} | [
"Authenticate",
"to",
"return",
"authToken"
] | 4b894dc0fe3a663df5cf1bab0081aee616ac0305 | https://github.com/kyohei8/inoreader-api/blob/4b894dc0fe3a663df5cf1bab0081aee616ac0305/lib/inoreader/api/app.rb#L219-L226 | train |
imanel/libwebsocket | lib/libwebsocket/frame.rb | LibWebSocket.Frame.to_s | def to_s
ary = ["\x00", @buffer.dup, "\xff"]
ary.collect{ |s| s.force_encoding('UTF-8') if s.respond_to?(:force_encoding) }
return ary.join
end | ruby | def to_s
ary = ["\x00", @buffer.dup, "\xff"]
ary.collect{ |s| s.force_encoding('UTF-8') if s.respond_to?(:force_encoding) }
return ary.join
end | [
"def",
"to_s",
"ary",
"=",
"[",
"\"\\x00\"",
",",
"@buffer",
".",
"dup",
",",
"\"\\xff\"",
"]",
"ary",
".",
"collect",
"{",
"|",
"s",
"|",
"s",
".",
"force_encoding",
"(",
"'UTF-8'",
")",
"if",
"s",
".",
"respond_to?",
"(",
":force_encoding",
")",
"}",
"return",
"ary",
".",
"join",
"end"
] | Construct a WebSocket frame.
@example
frame = LibWebSocket::Frame.new('foo')
frame.to_s # => \x00foo\xff | [
"Construct",
"a",
"WebSocket",
"frame",
"."
] | 3e071439246f5a2c306e16fefc772d2f6f716f6b | https://github.com/imanel/libwebsocket/blob/3e071439246f5a2c306e16fefc772d2f6f716f6b/lib/libwebsocket/frame.rb#L59-L65 | train |
tpope/ldaptic | lib/ldaptic/methods.rb | Ldaptic.Methods.add | def add(dn, attributes)
attributes = normalize_attributes(attributes)
log_dispatch(:add, dn, attributes)
adapter.add(dn, attributes)
end | ruby | def add(dn, attributes)
attributes = normalize_attributes(attributes)
log_dispatch(:add, dn, attributes)
adapter.add(dn, attributes)
end | [
"def",
"add",
"(",
"dn",
",",
"attributes",
")",
"attributes",
"=",
"normalize_attributes",
"(",
"attributes",
")",
"log_dispatch",
"(",
":add",
",",
"dn",
",",
"attributes",
")",
"adapter",
".",
"add",
"(",
"dn",
",",
"attributes",
")",
"end"
] | Performs an LDAP add. | [
"Performs",
"an",
"LDAP",
"add",
"."
] | 159a39464e9f5a05c0145db2b21cb256ef859612 | https://github.com/tpope/ldaptic/blob/159a39464e9f5a05c0145db2b21cb256ef859612/lib/ldaptic/methods.rb#L251-L255 | train |
tpope/ldaptic | lib/ldaptic/methods.rb | Ldaptic.Methods.modify | def modify(dn, attributes)
if attributes.kind_of?(Hash)
attributes = normalize_attributes(attributes)
else
attributes = attributes.map do |(action, key, values)|
[action, Ldaptic.encode(key), values.respond_to?(:before_type_cast) ? values.before_type_cast : [values].flatten.compact]
end
end
log_dispatch(:modify, dn, attributes)
adapter.modify(dn, attributes) unless attributes.empty?
end | ruby | def modify(dn, attributes)
if attributes.kind_of?(Hash)
attributes = normalize_attributes(attributes)
else
attributes = attributes.map do |(action, key, values)|
[action, Ldaptic.encode(key), values.respond_to?(:before_type_cast) ? values.before_type_cast : [values].flatten.compact]
end
end
log_dispatch(:modify, dn, attributes)
adapter.modify(dn, attributes) unless attributes.empty?
end | [
"def",
"modify",
"(",
"dn",
",",
"attributes",
")",
"if",
"attributes",
".",
"kind_of?",
"(",
"Hash",
")",
"attributes",
"=",
"normalize_attributes",
"(",
"attributes",
")",
"else",
"attributes",
"=",
"attributes",
".",
"map",
"do",
"|",
"(",
"action",
",",
"key",
",",
"values",
")",
"|",
"[",
"action",
",",
"Ldaptic",
".",
"encode",
"(",
"key",
")",
",",
"values",
".",
"respond_to?",
"(",
":before_type_cast",
")",
"?",
"values",
".",
"before_type_cast",
":",
"[",
"values",
"]",
".",
"flatten",
".",
"compact",
"]",
"end",
"end",
"log_dispatch",
"(",
":modify",
",",
"dn",
",",
"attributes",
")",
"adapter",
".",
"modify",
"(",
"dn",
",",
"attributes",
")",
"unless",
"attributes",
".",
"empty?",
"end"
] | Performs an LDAP modify. | [
"Performs",
"an",
"LDAP",
"modify",
"."
] | 159a39464e9f5a05c0145db2b21cb256ef859612 | https://github.com/tpope/ldaptic/blob/159a39464e9f5a05c0145db2b21cb256ef859612/lib/ldaptic/methods.rb#L258-L268 | train |
tpope/ldaptic | lib/ldaptic/methods.rb | Ldaptic.Methods.rename | def rename(dn, new_rdn, delete_old, *args)
log_dispatch(:rename, dn, new_rdn, delete_old, *args)
adapter.rename(dn, new_rdn.to_str, delete_old, *args)
end | ruby | def rename(dn, new_rdn, delete_old, *args)
log_dispatch(:rename, dn, new_rdn, delete_old, *args)
adapter.rename(dn, new_rdn.to_str, delete_old, *args)
end | [
"def",
"rename",
"(",
"dn",
",",
"new_rdn",
",",
"delete_old",
",",
"*",
"args",
")",
"log_dispatch",
"(",
":rename",
",",
"dn",
",",
"new_rdn",
",",
"delete_old",
",",
"*",
"args",
")",
"adapter",
".",
"rename",
"(",
"dn",
",",
"new_rdn",
".",
"to_str",
",",
"delete_old",
",",
"*",
"args",
")",
"end"
] | Performs an LDAP modrdn. | [
"Performs",
"an",
"LDAP",
"modrdn",
"."
] | 159a39464e9f5a05c0145db2b21cb256ef859612 | https://github.com/tpope/ldaptic/blob/159a39464e9f5a05c0145db2b21cb256ef859612/lib/ldaptic/methods.rb#L277-L280 | train |
tpope/ldaptic | lib/ldaptic/methods.rb | Ldaptic.Methods.compare | def compare(dn, key, value)
log_dispatch(:compare, dn, key, value)
adapter.compare(dn, Ldaptic.encode(key), Ldaptic.encode(value))
end | ruby | def compare(dn, key, value)
log_dispatch(:compare, dn, key, value)
adapter.compare(dn, Ldaptic.encode(key), Ldaptic.encode(value))
end | [
"def",
"compare",
"(",
"dn",
",",
"key",
",",
"value",
")",
"log_dispatch",
"(",
":compare",
",",
"dn",
",",
"key",
",",
"value",
")",
"adapter",
".",
"compare",
"(",
"dn",
",",
"Ldaptic",
".",
"encode",
"(",
"key",
")",
",",
"Ldaptic",
".",
"encode",
"(",
"value",
")",
")",
"end"
] | Performs an LDAP compare. | [
"Performs",
"an",
"LDAP",
"compare",
"."
] | 159a39464e9f5a05c0145db2b21cb256ef859612 | https://github.com/tpope/ldaptic/blob/159a39464e9f5a05c0145db2b21cb256ef859612/lib/ldaptic/methods.rb#L283-L286 | train |
ronyv89/skydrive | lib/skydrive/operations.rb | Skydrive.Operations.upload | def upload folder_path, filename, file, options={}
response = put("/#{folder_path}/files/#{filename}", file.read, options)
end | ruby | def upload folder_path, filename, file, options={}
response = put("/#{folder_path}/files/#{filename}", file.read, options)
end | [
"def",
"upload",
"folder_path",
",",
"filename",
",",
"file",
",",
"options",
"=",
"{",
"}",
"response",
"=",
"put",
"(",
"\"/#{folder_path}/files/#{filename}\"",
",",
"file",
".",
"read",
",",
"options",
")",
"end"
] | Upload a file
@param [String] folder_path Either 'me/skydrive' or FOLDER_ID(id of the parent folder)
@param [String] filename Name of the new file
@param [File] The actual file to be uploaded
@param [Hash] options Any additional options to be passed
@option options [Boolean] :overwrite whether to overwrite the file
@return [Skydrive::File] the created file with minimum details | [
"Upload",
"a",
"file"
] | 6cf7b692f64c6f00a81bc7ca6fffca3020244072 | https://github.com/ronyv89/skydrive/blob/6cf7b692f64c6f00a81bc7ca6fffca3020244072/lib/skydrive/operations.rb#L189-L191 | train |
mamantoha/freshdesk_api_client_rb | lib/freshdesk_api/configuration.rb | FreshdeskAPI.Configuration.options | def options
{
headers: {
accept: :json,
content_type: :json,
accept_encoding: 'gzip ,deflate',
user_agent: "FreshdeskAPI API #{FreshdeskAPI::VERSION}"
},
read_timeout: nil,
open_timeout: nil,
base_url: @base_url
}.merge(client_options)
end | ruby | def options
{
headers: {
accept: :json,
content_type: :json,
accept_encoding: 'gzip ,deflate',
user_agent: "FreshdeskAPI API #{FreshdeskAPI::VERSION}"
},
read_timeout: nil,
open_timeout: nil,
base_url: @base_url
}.merge(client_options)
end | [
"def",
"options",
"{",
"headers",
":",
"{",
"accept",
":",
":json",
",",
"content_type",
":",
":json",
",",
"accept_encoding",
":",
"'gzip ,deflate'",
",",
"user_agent",
":",
"\"FreshdeskAPI API #{FreshdeskAPI::VERSION}\"",
"}",
",",
"read_timeout",
":",
"nil",
",",
"open_timeout",
":",
"nil",
",",
"base_url",
":",
"@base_url",
"}",
".",
"merge",
"(",
"client_options",
")",
"end"
] | Sets accept and user_agent headers, and url
@return [Hash] RestClient-formatted hash of options. | [
"Sets",
"accept",
"and",
"user_agent",
"headers",
"and",
"url"
] | 74367fe0dd31bd269197b3f419412ef600031e62 | https://github.com/mamantoha/freshdesk_api_client_rb/blob/74367fe0dd31bd269197b3f419412ef600031e62/lib/freshdesk_api/configuration.rb#L39-L51 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/prototype/query.rb | PaynetEasy::PaynetEasyApi::Query::Prototype.Query.create_request | def create_request(payment_transaction)
validate_payment_transaction payment_transaction
request = payment_transaction_to_request payment_transaction
request.api_method = @api_method
request.end_point = payment_transaction.query_config.end_point
request.gateway_url = payment_transaction.query_config.gateway_url
request.signature = create_signature payment_transaction
request
rescue Exception => error
payment_transaction.add_error error
payment_transaction.status = PaymentTransaction::STATUS_ERROR
raise error
end | ruby | def create_request(payment_transaction)
validate_payment_transaction payment_transaction
request = payment_transaction_to_request payment_transaction
request.api_method = @api_method
request.end_point = payment_transaction.query_config.end_point
request.gateway_url = payment_transaction.query_config.gateway_url
request.signature = create_signature payment_transaction
request
rescue Exception => error
payment_transaction.add_error error
payment_transaction.status = PaymentTransaction::STATUS_ERROR
raise error
end | [
"def",
"create_request",
"(",
"payment_transaction",
")",
"validate_payment_transaction",
"payment_transaction",
"request",
"=",
"payment_transaction_to_request",
"payment_transaction",
"request",
".",
"api_method",
"=",
"@api_method",
"request",
".",
"end_point",
"=",
"payment_transaction",
".",
"query_config",
".",
"end_point",
"request",
".",
"gateway_url",
"=",
"payment_transaction",
".",
"query_config",
".",
"gateway_url",
"request",
".",
"signature",
"=",
"create_signature",
"payment_transaction",
"request",
"rescue",
"Exception",
"=>",
"error",
"payment_transaction",
".",
"add_error",
"error",
"payment_transaction",
".",
"status",
"=",
"PaymentTransaction",
"::",
"STATUS_ERROR",
"raise",
"error",
"end"
] | Create API gateway request from payment transaction data
@param payment_transaction [PaymentTransaction] Payment transaction for query
@return [Request] Request object | [
"Create",
"API",
"gateway",
"request",
"from",
"payment",
"transaction",
"data"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb#L45-L61 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/prototype/query.rb | PaynetEasy::PaynetEasyApi::Query::Prototype.Query.process_response | def process_response(payment_transaction, response)
if response.processing? || response.approved?
validate = :validate_response_on_success
update = :update_payment_transaction_on_success
else
validate = :validate_response_on_error
update = :update_payment_transaction_on_error
end
begin
send validate, payment_transaction, response
rescue Exception => error
payment_transaction.add_error error
payment_transaction.status = PaymentTransaction::STATUS_ERROR
raise error
end
send update, payment_transaction, response
if response.error?
raise response.error
end
response
end | ruby | def process_response(payment_transaction, response)
if response.processing? || response.approved?
validate = :validate_response_on_success
update = :update_payment_transaction_on_success
else
validate = :validate_response_on_error
update = :update_payment_transaction_on_error
end
begin
send validate, payment_transaction, response
rescue Exception => error
payment_transaction.add_error error
payment_transaction.status = PaymentTransaction::STATUS_ERROR
raise error
end
send update, payment_transaction, response
if response.error?
raise response.error
end
response
end | [
"def",
"process_response",
"(",
"payment_transaction",
",",
"response",
")",
"if",
"response",
".",
"processing?",
"||",
"response",
".",
"approved?",
"validate",
"=",
":validate_response_on_success",
"update",
"=",
":update_payment_transaction_on_success",
"else",
"validate",
"=",
":validate_response_on_error",
"update",
"=",
":update_payment_transaction_on_error",
"end",
"begin",
"send",
"validate",
",",
"payment_transaction",
",",
"response",
"rescue",
"Exception",
"=>",
"error",
"payment_transaction",
".",
"add_error",
"error",
"payment_transaction",
".",
"status",
"=",
"PaymentTransaction",
"::",
"STATUS_ERROR",
"raise",
"error",
"end",
"send",
"update",
",",
"payment_transaction",
",",
"response",
"if",
"response",
".",
"error?",
"raise",
"response",
".",
"error",
"end",
"response",
"end"
] | Process API gateway response and update payment transaction
@param payment_transaction [PaymentTransaction] Payment transaction for update
@param response [Response] API gateway response
@return [Response] API gateway response | [
"Process",
"API",
"gateway",
"response",
"and",
"update",
"payment",
"transaction"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb#L69-L94 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/prototype/query.rb | PaynetEasy::PaynetEasyApi::Query::Prototype.Query.validate_payment_transaction | def validate_payment_transaction(payment_transaction)
validate_query_config payment_transaction
error_message = ''
missed_fields = []
invalid_fields = []
request_fields_definition.each do |field_name, property_path, is_field_required, validation_rule|
field_value = PropertyAccessor.get_value payment_transaction, property_path, false
if field_value
begin
Validator.validate_by_rule field_value, validation_rule
rescue ValidationError => error
invalid_fields << "Field '#{field_name}' from property path '#{property_path}', #{error.message}."
end
elsif is_field_required
missed_fields << "Field '#{field_name}' from property path '#{property_path}' missed or empty."
end
end
unless missed_fields.empty?
error_message << "Some required fields missed or empty in PaymentTransaction: \n#{missed_fields.join "\n"}\n"
end
unless invalid_fields.empty?
error_message << "Some fields invalid in PaymentTransaction: \n#{invalid_fields.join "\n"}\n"
end
unless error_message.empty?
raise ValidationError, error_message
end
end | ruby | def validate_payment_transaction(payment_transaction)
validate_query_config payment_transaction
error_message = ''
missed_fields = []
invalid_fields = []
request_fields_definition.each do |field_name, property_path, is_field_required, validation_rule|
field_value = PropertyAccessor.get_value payment_transaction, property_path, false
if field_value
begin
Validator.validate_by_rule field_value, validation_rule
rescue ValidationError => error
invalid_fields << "Field '#{field_name}' from property path '#{property_path}', #{error.message}."
end
elsif is_field_required
missed_fields << "Field '#{field_name}' from property path '#{property_path}' missed or empty."
end
end
unless missed_fields.empty?
error_message << "Some required fields missed or empty in PaymentTransaction: \n#{missed_fields.join "\n"}\n"
end
unless invalid_fields.empty?
error_message << "Some fields invalid in PaymentTransaction: \n#{invalid_fields.join "\n"}\n"
end
unless error_message.empty?
raise ValidationError, error_message
end
end | [
"def",
"validate_payment_transaction",
"(",
"payment_transaction",
")",
"validate_query_config",
"payment_transaction",
"error_message",
"=",
"''",
"missed_fields",
"=",
"[",
"]",
"invalid_fields",
"=",
"[",
"]",
"request_fields_definition",
".",
"each",
"do",
"|",
"field_name",
",",
"property_path",
",",
"is_field_required",
",",
"validation_rule",
"|",
"field_value",
"=",
"PropertyAccessor",
".",
"get_value",
"payment_transaction",
",",
"property_path",
",",
"false",
"if",
"field_value",
"begin",
"Validator",
".",
"validate_by_rule",
"field_value",
",",
"validation_rule",
"rescue",
"ValidationError",
"=>",
"error",
"invalid_fields",
"<<",
"\"Field '#{field_name}' from property path '#{property_path}', #{error.message}.\"",
"end",
"elsif",
"is_field_required",
"missed_fields",
"<<",
"\"Field '#{field_name}' from property path '#{property_path}' missed or empty.\"",
"end",
"end",
"unless",
"missed_fields",
".",
"empty?",
"error_message",
"<<",
"\"Some required fields missed or empty in PaymentTransaction: \\n#{missed_fields.join \"\\n\"}\\n\"",
"end",
"unless",
"invalid_fields",
".",
"empty?",
"error_message",
"<<",
"\"Some fields invalid in PaymentTransaction: \\n#{invalid_fields.join \"\\n\"}\\n\"",
"end",
"unless",
"error_message",
".",
"empty?",
"raise",
"ValidationError",
",",
"error_message",
"end",
"end"
] | Validates payment transaction before request constructing
@param payment_transaction [PaymentTransaction] Payment transaction for validation | [
"Validates",
"payment",
"transaction",
"before",
"request",
"constructing"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb#L101-L133 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/prototype/query.rb | PaynetEasy::PaynetEasyApi::Query::Prototype.Query.payment_transaction_to_request | def payment_transaction_to_request(payment_transaction)
request_fields = {}
request_fields_definition.each do |field_name, property_path, _|
field_value = PropertyAccessor.get_value payment_transaction, property_path
if field_value
request_fields[field_name] = field_value
end
end
Request.new request_fields
end | ruby | def payment_transaction_to_request(payment_transaction)
request_fields = {}
request_fields_definition.each do |field_name, property_path, _|
field_value = PropertyAccessor.get_value payment_transaction, property_path
if field_value
request_fields[field_name] = field_value
end
end
Request.new request_fields
end | [
"def",
"payment_transaction_to_request",
"(",
"payment_transaction",
")",
"request_fields",
"=",
"{",
"}",
"request_fields_definition",
".",
"each",
"do",
"|",
"field_name",
",",
"property_path",
",",
"_",
"|",
"field_value",
"=",
"PropertyAccessor",
".",
"get_value",
"payment_transaction",
",",
"property_path",
"if",
"field_value",
"request_fields",
"[",
"field_name",
"]",
"=",
"field_value",
"end",
"end",
"Request",
".",
"new",
"request_fields",
"end"
] | Creates request from payment transaction
@param payment_transaction [PaymentTransaction] Payment transaction for request constructing
@return [Request] Request object | [
"Creates",
"request",
"from",
"payment",
"transaction"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb#L140-L152 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/prototype/query.rb | PaynetEasy::PaynetEasyApi::Query::Prototype.Query.validate_response_on_success | def validate_response_on_success(payment_transaction, response)
if response.type != success_response_type
raise ValidationError, "Response type '#{response.type}' does " +
"not match success response type '#{success_response_type}'"
end
missed_fields = []
response_fields_definition.each do |field_name|
missed_fields << field_name unless response.key? field_name
end
unless missed_fields.empty?
raise ValidationError, "Some required fields missed or empty in Response: #{missed_fields.join ', '}"
end
validate_client_id payment_transaction, response
end | ruby | def validate_response_on_success(payment_transaction, response)
if response.type != success_response_type
raise ValidationError, "Response type '#{response.type}' does " +
"not match success response type '#{success_response_type}'"
end
missed_fields = []
response_fields_definition.each do |field_name|
missed_fields << field_name unless response.key? field_name
end
unless missed_fields.empty?
raise ValidationError, "Some required fields missed or empty in Response: #{missed_fields.join ', '}"
end
validate_client_id payment_transaction, response
end | [
"def",
"validate_response_on_success",
"(",
"payment_transaction",
",",
"response",
")",
"if",
"response",
".",
"type",
"!=",
"success_response_type",
"raise",
"ValidationError",
",",
"\"Response type '#{response.type}' does \"",
"+",
"\"not match success response type '#{success_response_type}'\"",
"end",
"missed_fields",
"=",
"[",
"]",
"response_fields_definition",
".",
"each",
"do",
"|",
"field_name",
"|",
"missed_fields",
"<<",
"field_name",
"unless",
"response",
".",
"key?",
"field_name",
"end",
"unless",
"missed_fields",
".",
"empty?",
"raise",
"ValidationError",
",",
"\"Some required fields missed or empty in Response: #{missed_fields.join ', '}\"",
"end",
"validate_client_id",
"payment_transaction",
",",
"response",
"end"
] | Validates response before payment transaction updating
if payment transaction is processing or approved
@param payment_transaction [PaymentTransaction] Payment transaction
@param response [Response] Response for validating | [
"Validates",
"response",
"before",
"payment",
"transaction",
"updating",
"if",
"payment",
"transaction",
"is",
"processing",
"or",
"approved"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb#L175-L192 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/prototype/query.rb | PaynetEasy::PaynetEasyApi::Query::Prototype.Query.validate_response_on_error | def validate_response_on_error(payment_transaction, response)
unless [success_response_type, 'error', 'validation-error'].include? response.type
raise ValidationError, "Unknown response type '#{response.type}'"
end
validate_client_id payment_transaction, response
end | ruby | def validate_response_on_error(payment_transaction, response)
unless [success_response_type, 'error', 'validation-error'].include? response.type
raise ValidationError, "Unknown response type '#{response.type}'"
end
validate_client_id payment_transaction, response
end | [
"def",
"validate_response_on_error",
"(",
"payment_transaction",
",",
"response",
")",
"unless",
"[",
"success_response_type",
",",
"'error'",
",",
"'validation-error'",
"]",
".",
"include?",
"response",
".",
"type",
"raise",
"ValidationError",
",",
"\"Unknown response type '#{response.type}'\"",
"end",
"validate_client_id",
"payment_transaction",
",",
"response",
"end"
] | Validates response before payment transaction updating
if payment transaction is not processing or approved
@param payment_transaction [PaymentTransaction] Payment transaction
@param response [Response] Response for validating | [
"Validates",
"response",
"before",
"payment",
"transaction",
"updating",
"if",
"payment",
"transaction",
"is",
"not",
"processing",
"or",
"approved"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb#L199-L205 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/prototype/query.rb | PaynetEasy::PaynetEasyApi::Query::Prototype.Query.update_payment_transaction_on_success | def update_payment_transaction_on_success(payment_transaction, response)
payment_transaction.status = response.status
set_paynet_id payment_transaction, response
end | ruby | def update_payment_transaction_on_success(payment_transaction, response)
payment_transaction.status = response.status
set_paynet_id payment_transaction, response
end | [
"def",
"update_payment_transaction_on_success",
"(",
"payment_transaction",
",",
"response",
")",
"payment_transaction",
".",
"status",
"=",
"response",
".",
"status",
"set_paynet_id",
"payment_transaction",
",",
"response",
"end"
] | Updates payment transaction by query response data
if payment transaction is processing or approved
@param payment_transaction [PaymentTransaction] Payment transaction
@param response [Response] Response for payment transaction updating | [
"Updates",
"payment",
"transaction",
"by",
"query",
"response",
"data",
"if",
"payment",
"transaction",
"is",
"processing",
"or",
"approved"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb#L212-L215 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/prototype/query.rb | PaynetEasy::PaynetEasyApi::Query::Prototype.Query.update_payment_transaction_on_error | def update_payment_transaction_on_error(payment_transaction, response)
if response.declined?
payment_transaction.status = response.status
else
payment_transaction.status = PaymentTransaction::STATUS_ERROR
end
payment_transaction.add_error response.error
set_paynet_id payment_transaction, response
end | ruby | def update_payment_transaction_on_error(payment_transaction, response)
if response.declined?
payment_transaction.status = response.status
else
payment_transaction.status = PaymentTransaction::STATUS_ERROR
end
payment_transaction.add_error response.error
set_paynet_id payment_transaction, response
end | [
"def",
"update_payment_transaction_on_error",
"(",
"payment_transaction",
",",
"response",
")",
"if",
"response",
".",
"declined?",
"payment_transaction",
".",
"status",
"=",
"response",
".",
"status",
"else",
"payment_transaction",
".",
"status",
"=",
"PaymentTransaction",
"::",
"STATUS_ERROR",
"end",
"payment_transaction",
".",
"add_error",
"response",
".",
"error",
"set_paynet_id",
"payment_transaction",
",",
"response",
"end"
] | Updates payment transaction by query response data
if payment transaction is not processing or approved
@param payment_transaction [PaymentTransaction] Payment transaction
@param response [Response] Response for payment transaction updating | [
"Updates",
"payment",
"transaction",
"by",
"query",
"response",
"data",
"if",
"payment",
"transaction",
"is",
"not",
"processing",
"or",
"approved"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb#L222-L231 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/prototype/query.rb | PaynetEasy::PaynetEasyApi::Query::Prototype.Query.validate_query_definition | def validate_query_definition
raise RuntimeError, 'You must configure @request_fields_definition' if request_fields_definition.empty?
raise RuntimeError, 'You must configure @signature_definition' if signature_definition.empty?
raise RuntimeError, 'You must configure @response_fields_definition' if response_fields_definition.empty?
raise RuntimeError, 'You must configure @success_response_type' if success_response_type.nil?
end | ruby | def validate_query_definition
raise RuntimeError, 'You must configure @request_fields_definition' if request_fields_definition.empty?
raise RuntimeError, 'You must configure @signature_definition' if signature_definition.empty?
raise RuntimeError, 'You must configure @response_fields_definition' if response_fields_definition.empty?
raise RuntimeError, 'You must configure @success_response_type' if success_response_type.nil?
end | [
"def",
"validate_query_definition",
"raise",
"RuntimeError",
",",
"'You must configure @request_fields_definition'",
"if",
"request_fields_definition",
".",
"empty?",
"raise",
"RuntimeError",
",",
"'You must configure @signature_definition'",
"if",
"signature_definition",
".",
"empty?",
"raise",
"RuntimeError",
",",
"'You must configure @response_fields_definition'",
"if",
"response_fields_definition",
".",
"empty?",
"raise",
"RuntimeError",
",",
"'You must configure @success_response_type'",
"if",
"success_response_type",
".",
"nil?",
"end"
] | Validates query object definition | [
"Validates",
"query",
"object",
"definition"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb#L243-L248 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/prototype/query.rb | PaynetEasy::PaynetEasyApi::Query::Prototype.Query.validate_client_id | def validate_client_id(payment_transaction, response)
payment_id = payment_transaction.payment.client_id
response_id = response.payment_client_id
if response_id && payment_id.to_s != response_id.to_s # Different types with equal values must pass validation
raise ValidationError, "Response client_id '#{response_id}' does not match Payment client_id '#{payment_id}'"
end
end | ruby | def validate_client_id(payment_transaction, response)
payment_id = payment_transaction.payment.client_id
response_id = response.payment_client_id
if response_id && payment_id.to_s != response_id.to_s # Different types with equal values must pass validation
raise ValidationError, "Response client_id '#{response_id}' does not match Payment client_id '#{payment_id}'"
end
end | [
"def",
"validate_client_id",
"(",
"payment_transaction",
",",
"response",
")",
"payment_id",
"=",
"payment_transaction",
".",
"payment",
".",
"client_id",
"response_id",
"=",
"response",
".",
"payment_client_id",
"if",
"response_id",
"&&",
"payment_id",
".",
"to_s",
"!=",
"response_id",
".",
"to_s",
"raise",
"ValidationError",
",",
"\"Response client_id '#{response_id}' does not match Payment client_id '#{payment_id}'\"",
"end",
"end"
] | Check, is payment transaction client order id and query response client order id equal or not.
@param payment_transaction [PaymentTransaction] Payment transaction for update
@param response [Response] API gateway response | [
"Check",
"is",
"payment",
"transaction",
"client",
"order",
"id",
"and",
"query",
"response",
"client",
"order",
"id",
"equal",
"or",
"not",
"."
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb#L254-L261 | train |
payneteasy/ruby-library-payneteasy-api | lib/paynet_easy/paynet_easy_api/query/prototype/query.rb | PaynetEasy::PaynetEasyApi::Query::Prototype.Query.set_paynet_id | def set_paynet_id(payment_transaction, response)
if response.payment_paynet_id
payment_transaction.payment.paynet_id = response.payment_paynet_id
end
end | ruby | def set_paynet_id(payment_transaction, response)
if response.payment_paynet_id
payment_transaction.payment.paynet_id = response.payment_paynet_id
end
end | [
"def",
"set_paynet_id",
"(",
"payment_transaction",
",",
"response",
")",
"if",
"response",
".",
"payment_paynet_id",
"payment_transaction",
".",
"payment",
".",
"paynet_id",
"=",
"response",
".",
"payment_paynet_id",
"end",
"end"
] | Set PaynetEasy payment id to payment transaction Payment
@param payment_transaction [PaymentTransaction] Payment transaction for update
@param response [Response] API gateway response | [
"Set",
"PaynetEasy",
"payment",
"id",
"to",
"payment",
"transaction",
"Payment"
] | 3200a447829b62e241fdc329f80fddb5f8d68cc0 | https://github.com/payneteasy/ruby-library-payneteasy-api/blob/3200a447829b62e241fdc329f80fddb5f8d68cc0/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb#L267-L271 | train |
grempe/opensecrets | lib/opensecrets.rb | OpenSecrets.Candidate.summary | def summary(options = {})
raise ArgumentError, 'You must provide a :cid option' if options[:cid].nil? || options[:cid].empty?
options.merge!({:method => 'candSummary'})
self.class.get("/", :query => options)
end | ruby | def summary(options = {})
raise ArgumentError, 'You must provide a :cid option' if options[:cid].nil? || options[:cid].empty?
options.merge!({:method => 'candSummary'})
self.class.get("/", :query => options)
end | [
"def",
"summary",
"(",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'You must provide a :cid option'",
"if",
"options",
"[",
":cid",
"]",
".",
"nil?",
"||",
"options",
"[",
":cid",
"]",
".",
"empty?",
"options",
".",
"merge!",
"(",
"{",
":method",
"=>",
"'candSummary'",
"}",
")",
"self",
".",
"class",
".",
"get",
"(",
"\"/\"",
",",
":query",
"=>",
"options",
")",
"end"
] | Provides summary fundraising information for specified politician.
See : http://www.opensecrets.org/api/?method=candSummary&output=doc
@option options [String] :cid ("") a CRP CandidateID
@option options [optional, String] :cycle ("") blank values returns current cycle. | [
"Provides",
"summary",
"fundraising",
"information",
"for",
"specified",
"politician",
"."
] | 2f507e214de716ce7b23831e056160b1384bff78 | https://github.com/grempe/opensecrets/blob/2f507e214de716ce7b23831e056160b1384bff78/lib/opensecrets.rb#L66-L70 | train |
grempe/opensecrets | lib/opensecrets.rb | OpenSecrets.Candidate.contributors | def contributors(options = {})
raise ArgumentError, 'You must provide a :cid option' if options[:cid].nil? || options[:cid].empty?
options.merge!({:method => 'candContrib'})
self.class.get("/", :query => options)
end | ruby | def contributors(options = {})
raise ArgumentError, 'You must provide a :cid option' if options[:cid].nil? || options[:cid].empty?
options.merge!({:method => 'candContrib'})
self.class.get("/", :query => options)
end | [
"def",
"contributors",
"(",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'You must provide a :cid option'",
"if",
"options",
"[",
":cid",
"]",
".",
"nil?",
"||",
"options",
"[",
":cid",
"]",
".",
"empty?",
"options",
".",
"merge!",
"(",
"{",
":method",
"=>",
"'candContrib'",
"}",
")",
"self",
".",
"class",
".",
"get",
"(",
"\"/\"",
",",
":query",
"=>",
"options",
")",
"end"
] | Provides the top organizations contributing to specified politician.
See : http://www.opensecrets.org/api/?method=candContrib&output=doc
@option options [String] :cid ("") a CRP CandidateID
@option options [optional, String] :cycle ("") 2008 or 2010. | [
"Provides",
"the",
"top",
"organizations",
"contributing",
"to",
"specified",
"politician",
"."
] | 2f507e214de716ce7b23831e056160b1384bff78 | https://github.com/grempe/opensecrets/blob/2f507e214de716ce7b23831e056160b1384bff78/lib/opensecrets.rb#L79-L83 | train |
grempe/opensecrets | lib/opensecrets.rb | OpenSecrets.Candidate.industries | def industries(options = {})
raise ArgumentError, 'You must provide a :cid option' if options[:cid].nil? || options[:cid].empty?
options.merge!({:method => 'candIndustry'})
self.class.get("/", :query => options)
end | ruby | def industries(options = {})
raise ArgumentError, 'You must provide a :cid option' if options[:cid].nil? || options[:cid].empty?
options.merge!({:method => 'candIndustry'})
self.class.get("/", :query => options)
end | [
"def",
"industries",
"(",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'You must provide a :cid option'",
"if",
"options",
"[",
":cid",
"]",
".",
"nil?",
"||",
"options",
"[",
":cid",
"]",
".",
"empty?",
"options",
".",
"merge!",
"(",
"{",
":method",
"=>",
"'candIndustry'",
"}",
")",
"self",
".",
"class",
".",
"get",
"(",
"\"/\"",
",",
":query",
"=>",
"options",
")",
"end"
] | Provides the top industries contributing to a specified politician.
See : http://www.opensecrets.org/api/?method=candIndustry&output=doc
@option options [String] :cid ("") a CRP CandidateID
@option options [optional, String] :cycle ("") blank values returns current cycle. | [
"Provides",
"the",
"top",
"industries",
"contributing",
"to",
"a",
"specified",
"politician",
"."
] | 2f507e214de716ce7b23831e056160b1384bff78 | https://github.com/grempe/opensecrets/blob/2f507e214de716ce7b23831e056160b1384bff78/lib/opensecrets.rb#L92-L96 | train |
grempe/opensecrets | lib/opensecrets.rb | OpenSecrets.Candidate.contributions_by_industry | def contributions_by_industry(options = {})
raise ArgumentError, 'You must provide a :cid option' if options[:cid].nil? || options[:cid].empty?
raise ArgumentError, 'You must provide a :ind option' if options[:ind].nil? || options[:ind].empty?
options.merge!({:method => 'CandIndByInd'})
self.class.get("/", :query => options)
end | ruby | def contributions_by_industry(options = {})
raise ArgumentError, 'You must provide a :cid option' if options[:cid].nil? || options[:cid].empty?
raise ArgumentError, 'You must provide a :ind option' if options[:ind].nil? || options[:ind].empty?
options.merge!({:method => 'CandIndByInd'})
self.class.get("/", :query => options)
end | [
"def",
"contributions_by_industry",
"(",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'You must provide a :cid option'",
"if",
"options",
"[",
":cid",
"]",
".",
"nil?",
"||",
"options",
"[",
":cid",
"]",
".",
"empty?",
"raise",
"ArgumentError",
",",
"'You must provide a :ind option'",
"if",
"options",
"[",
":ind",
"]",
".",
"nil?",
"||",
"options",
"[",
":ind",
"]",
".",
"empty?",
"options",
".",
"merge!",
"(",
"{",
":method",
"=>",
"'CandIndByInd'",
"}",
")",
"self",
".",
"class",
".",
"get",
"(",
"\"/\"",
",",
":query",
"=>",
"options",
")",
"end"
] | Provides total contributed to specified candidate from specified industry for specified cycle.
See : http://www.opensecrets.org/api/?method=candIndByInd&output=doc
@option options [String] :cid ("") a CRP CandidateID
@option options [String] :ind ("") a a 3-character industry code
@option options [optional, String] :cycle ("") 2012, 2014 available. leave blank for latest cycle | [
"Provides",
"total",
"contributed",
"to",
"specified",
"candidate",
"from",
"specified",
"industry",
"for",
"specified",
"cycle",
"."
] | 2f507e214de716ce7b23831e056160b1384bff78 | https://github.com/grempe/opensecrets/blob/2f507e214de716ce7b23831e056160b1384bff78/lib/opensecrets.rb#L106-L111 | train |
grempe/opensecrets | lib/opensecrets.rb | OpenSecrets.Candidate.sector | def sector(options = {})
raise ArgumentError, 'You must provide a :cid option' if options[:cid].nil? || options[:cid].empty?
options.merge!({:method => 'candSector'})
self.class.get("/", :query => options)
end | ruby | def sector(options = {})
raise ArgumentError, 'You must provide a :cid option' if options[:cid].nil? || options[:cid].empty?
options.merge!({:method => 'candSector'})
self.class.get("/", :query => options)
end | [
"def",
"sector",
"(",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'You must provide a :cid option'",
"if",
"options",
"[",
":cid",
"]",
".",
"nil?",
"||",
"options",
"[",
":cid",
"]",
".",
"empty?",
"options",
".",
"merge!",
"(",
"{",
":method",
"=>",
"'candSector'",
"}",
")",
"self",
".",
"class",
".",
"get",
"(",
"\"/\"",
",",
":query",
"=>",
"options",
")",
"end"
] | Provides sector total of specified politician's receipts.
See : http://www.opensecrets.org/api/?method=candSector&output=doc
@option options [String] :cid ("") a CRP CandidateID
@option options [optional, String] :cycle ("") blank values returns current cycle. | [
"Provides",
"sector",
"total",
"of",
"specified",
"politician",
"s",
"receipts",
"."
] | 2f507e214de716ce7b23831e056160b1384bff78 | https://github.com/grempe/opensecrets/blob/2f507e214de716ce7b23831e056160b1384bff78/lib/opensecrets.rb#L120-L124 | train |
grempe/opensecrets | lib/opensecrets.rb | OpenSecrets.Committee.by_industry | def by_industry(options = {})
raise ArgumentError, 'You must provide a :cmte option' if options[:cmte].nil? || options[:cmte].empty?
raise ArgumentError, 'You must provide a :congno option' if options[:congno].nil? || options[:congno].empty?
raise ArgumentError, 'You must provide a :indus option' if options[:indus].nil? || options[:indus].empty?
options.merge!({:method => 'congCmteIndus'})
self.class.get("/", :query => options)
end | ruby | def by_industry(options = {})
raise ArgumentError, 'You must provide a :cmte option' if options[:cmte].nil? || options[:cmte].empty?
raise ArgumentError, 'You must provide a :congno option' if options[:congno].nil? || options[:congno].empty?
raise ArgumentError, 'You must provide a :indus option' if options[:indus].nil? || options[:indus].empty?
options.merge!({:method => 'congCmteIndus'})
self.class.get("/", :query => options)
end | [
"def",
"by_industry",
"(",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'You must provide a :cmte option'",
"if",
"options",
"[",
":cmte",
"]",
".",
"nil?",
"||",
"options",
"[",
":cmte",
"]",
".",
"empty?",
"raise",
"ArgumentError",
",",
"'You must provide a :congno option'",
"if",
"options",
"[",
":congno",
"]",
".",
"nil?",
"||",
"options",
"[",
":congno",
"]",
".",
"empty?",
"raise",
"ArgumentError",
",",
"'You must provide a :indus option'",
"if",
"options",
"[",
":indus",
"]",
".",
"nil?",
"||",
"options",
"[",
":indus",
"]",
".",
"empty?",
"options",
".",
"merge!",
"(",
"{",
":method",
"=>",
"'congCmteIndus'",
"}",
")",
"self",
".",
"class",
".",
"get",
"(",
"\"/\"",
",",
":query",
"=>",
"options",
")",
"end"
] | Provides summary fundraising information for a specific committee, industry and Congress number.
See : http://www.opensecrets.org/api/?method=congCmteIndus&output=doc
@option options [String] :cmte ("") Committee ID in CQ format
@option options [String] :congno ("") Congress Number (like 110)
@option options [String] :indus ("") Industry code | [
"Provides",
"summary",
"fundraising",
"information",
"for",
"a",
"specific",
"committee",
"industry",
"and",
"Congress",
"number",
"."
] | 2f507e214de716ce7b23831e056160b1384bff78 | https://github.com/grempe/opensecrets/blob/2f507e214de716ce7b23831e056160b1384bff78/lib/opensecrets.rb#L138-L144 | train |
grempe/opensecrets | lib/opensecrets.rb | OpenSecrets.Organization.get_orgs | def get_orgs(options = {})
raise ArgumentError, 'You must provide a :org option' if options[:org].nil? || options[:org].empty?
options.merge!({:method => 'getOrgs'})
self.class.get("/", :query => options)
end | ruby | def get_orgs(options = {})
raise ArgumentError, 'You must provide a :org option' if options[:org].nil? || options[:org].empty?
options.merge!({:method => 'getOrgs'})
self.class.get("/", :query => options)
end | [
"def",
"get_orgs",
"(",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'You must provide a :org option'",
"if",
"options",
"[",
":org",
"]",
".",
"nil?",
"||",
"options",
"[",
":org",
"]",
".",
"empty?",
"options",
".",
"merge!",
"(",
"{",
":method",
"=>",
"'getOrgs'",
"}",
")",
"self",
".",
"class",
".",
"get",
"(",
"\"/\"",
",",
":query",
"=>",
"options",
")",
"end"
] | Look up an organization by name.
See : https://www.opensecrets.org/api/?method=getOrgs&output=doc
@option options [String] :org ("") name or partial name of organization requested | [
"Look",
"up",
"an",
"organization",
"by",
"name",
"."
] | 2f507e214de716ce7b23831e056160b1384bff78 | https://github.com/grempe/opensecrets/blob/2f507e214de716ce7b23831e056160b1384bff78/lib/opensecrets.rb#L156-L160 | train |
grempe/opensecrets | lib/opensecrets.rb | OpenSecrets.Organization.org_summary | def org_summary(options = {})
raise ArgumentError, 'You must provide a :id option' if options[:id].nil? || options[:id].empty?
options.merge!({:method => 'orgSummary'})
self.class.get("/", :query => options)
end | ruby | def org_summary(options = {})
raise ArgumentError, 'You must provide a :id option' if options[:id].nil? || options[:id].empty?
options.merge!({:method => 'orgSummary'})
self.class.get("/", :query => options)
end | [
"def",
"org_summary",
"(",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'You must provide a :id option'",
"if",
"options",
"[",
":id",
"]",
".",
"nil?",
"||",
"options",
"[",
":id",
"]",
".",
"empty?",
"options",
".",
"merge!",
"(",
"{",
":method",
"=>",
"'orgSummary'",
"}",
")",
"self",
".",
"class",
".",
"get",
"(",
"\"/\"",
",",
":query",
"=>",
"options",
")",
"end"
] | Provides summary fundraising information for the specified organization id.
See : https://www.opensecrets.org/api/?method=orgSummary&output=doc
@option options [String] :org ("") CRP orgid (available via 'get_orgs' method) | [
"Provides",
"summary",
"fundraising",
"information",
"for",
"the",
"specified",
"organization",
"id",
"."
] | 2f507e214de716ce7b23831e056160b1384bff78 | https://github.com/grempe/opensecrets/blob/2f507e214de716ce7b23831e056160b1384bff78/lib/opensecrets.rb#L168-L172 | train |
petebrowne/massimo | lib/massimo/config.rb | Massimo.Config.path_for | def path_for(resource_name)
if resource_path = send("#{resource_name}_path")
File.expand_path resource_path
else
File.join source_path, resource_name.to_s
end
end | ruby | def path_for(resource_name)
if resource_path = send("#{resource_name}_path")
File.expand_path resource_path
else
File.join source_path, resource_name.to_s
end
end | [
"def",
"path_for",
"(",
"resource_name",
")",
"if",
"resource_path",
"=",
"send",
"(",
"\"#{resource_name}_path\"",
")",
"File",
".",
"expand_path",
"resource_path",
"else",
"File",
".",
"join",
"source_path",
",",
"resource_name",
".",
"to_s",
"end",
"end"
] | Get a full, expanded path for the given resource name. This is either set
in the configuration or determined dynamically based on the name. | [
"Get",
"a",
"full",
"expanded",
"path",
"for",
"the",
"given",
"resource",
"name",
".",
"This",
"is",
"either",
"set",
"in",
"the",
"configuration",
"or",
"determined",
"dynamically",
"based",
"on",
"the",
"name",
"."
] | c450edc531ad358f011da0a47e5d0bc9a038d911 | https://github.com/petebrowne/massimo/blob/c450edc531ad358f011da0a47e5d0bc9a038d911/lib/massimo/config.rb#L131-L137 | train |
mooreryan/parse_fasta | lib/parse_fasta/seq_file.rb | ParseFasta.SeqFile.get_first_char | def get_first_char fname
if File.exists? fname
begin
f = Zlib::GzipReader.open fname
rescue Zlib::GzipFile::Error
f = File.open fname
end
begin
first_char = f.each.peek[0]
return first_char
ensure
f.close
end
else
raise ParseFasta::Error::FileNotFoundError,
"No such file or directory -- #{fname}"
end
end | ruby | def get_first_char fname
if File.exists? fname
begin
f = Zlib::GzipReader.open fname
rescue Zlib::GzipFile::Error
f = File.open fname
end
begin
first_char = f.each.peek[0]
return first_char
ensure
f.close
end
else
raise ParseFasta::Error::FileNotFoundError,
"No such file or directory -- #{fname}"
end
end | [
"def",
"get_first_char",
"fname",
"if",
"File",
".",
"exists?",
"fname",
"begin",
"f",
"=",
"Zlib",
"::",
"GzipReader",
".",
"open",
"fname",
"rescue",
"Zlib",
"::",
"GzipFile",
"::",
"Error",
"f",
"=",
"File",
".",
"open",
"fname",
"end",
"begin",
"first_char",
"=",
"f",
".",
"each",
".",
"peek",
"[",
"0",
"]",
"return",
"first_char",
"ensure",
"f",
".",
"close",
"end",
"else",
"raise",
"ParseFasta",
"::",
"Error",
"::",
"FileNotFoundError",
",",
"\"No such file or directory -- #{fname}\"",
"end",
"end"
] | Get the first char of the file whether it is gzip'd or not. No
need to rewind the stream afterwards. | [
"Get",
"the",
"first",
"char",
"of",
"the",
"file",
"whether",
"it",
"is",
"gzip",
"d",
"or",
"not",
".",
"No",
"need",
"to",
"rewind",
"the",
"stream",
"afterwards",
"."
] | 016272371be668addb29d3c92ec6a5d2e07332ad | https://github.com/mooreryan/parse_fasta/blob/016272371be668addb29d3c92ec6a5d2e07332ad/lib/parse_fasta/seq_file.rb#L214-L234 | train |
donaldpiret/github-pivotal-flow | lib/github_pivotal_flow/github_api.rb | GithubPivotalFlow.GitHubAPI.create_pullrequest | def create_pullrequest options
project = options.fetch(:project)
params = {
:base => options.fetch(:base),
:head => options.fetch(:head)
}
if options[:issue]
params[:issue] = options[:issue]
else
params[:title] = options[:title] if options[:title]
params[:body] = options[:body] if options[:body]
end
res = post "https://%s/repos/%s/%s/pulls" %
[api_host(project.host), project.owner, project.name], params
res.error! unless res.success?
res.data
end | ruby | def create_pullrequest options
project = options.fetch(:project)
params = {
:base => options.fetch(:base),
:head => options.fetch(:head)
}
if options[:issue]
params[:issue] = options[:issue]
else
params[:title] = options[:title] if options[:title]
params[:body] = options[:body] if options[:body]
end
res = post "https://%s/repos/%s/%s/pulls" %
[api_host(project.host), project.owner, project.name], params
res.error! unless res.success?
res.data
end | [
"def",
"create_pullrequest",
"options",
"project",
"=",
"options",
".",
"fetch",
"(",
":project",
")",
"params",
"=",
"{",
":base",
"=>",
"options",
".",
"fetch",
"(",
":base",
")",
",",
":head",
"=>",
"options",
".",
"fetch",
"(",
":head",
")",
"}",
"if",
"options",
"[",
":issue",
"]",
"params",
"[",
":issue",
"]",
"=",
"options",
"[",
":issue",
"]",
"else",
"params",
"[",
":title",
"]",
"=",
"options",
"[",
":title",
"]",
"if",
"options",
"[",
":title",
"]",
"params",
"[",
":body",
"]",
"=",
"options",
"[",
":body",
"]",
"if",
"options",
"[",
":body",
"]",
"end",
"res",
"=",
"post",
"\"https://%s/repos/%s/%s/pulls\"",
"%",
"[",
"api_host",
"(",
"project",
".",
"host",
")",
",",
"project",
".",
"owner",
",",
"project",
".",
"name",
"]",
",",
"params",
"res",
".",
"error!",
"unless",
"res",
".",
"success?",
"res",
".",
"data",
"end"
] | Returns parsed data from the new pull request. | [
"Returns",
"parsed",
"data",
"from",
"the",
"new",
"pull",
"request",
"."
] | 676436950b691f57ad793a9023a4765ab9420dd0 | https://github.com/donaldpiret/github-pivotal-flow/blob/676436950b691f57ad793a9023a4765ab9420dd0/lib/github_pivotal_flow/github_api.rb#L47-L66 | train |
petebrowne/massimo | lib/massimo/watcher.rb | Massimo.Watcher.process | def process
if config_changed?
Massimo::UI.say 'massimo is reloading your site'
@site.reload
@site.process
Massimo::UI.say 'massimo has built your site', :growl => true
elsif changed?
Massimo::UI.say 'massimo has noticed a change'
@site.process
Massimo::UI.say 'massimo has built your site', :growl => true
end
end | ruby | def process
if config_changed?
Massimo::UI.say 'massimo is reloading your site'
@site.reload
@site.process
Massimo::UI.say 'massimo has built your site', :growl => true
elsif changed?
Massimo::UI.say 'massimo has noticed a change'
@site.process
Massimo::UI.say 'massimo has built your site', :growl => true
end
end | [
"def",
"process",
"if",
"config_changed?",
"Massimo",
"::",
"UI",
".",
"say",
"'massimo is reloading your site'",
"@site",
".",
"reload",
"@site",
".",
"process",
"Massimo",
"::",
"UI",
".",
"say",
"'massimo has built your site'",
",",
":growl",
"=>",
"true",
"elsif",
"changed?",
"Massimo",
"::",
"UI",
".",
"say",
"'massimo has noticed a change'",
"@site",
".",
"process",
"Massimo",
"::",
"UI",
".",
"say",
"'massimo has built your site'",
",",
":growl",
"=>",
"true",
"end",
"end"
] | Processes the Site if any of the files have changed. | [
"Processes",
"the",
"Site",
"if",
"any",
"of",
"the",
"files",
"have",
"changed",
"."
] | c450edc531ad358f011da0a47e5d0bc9a038d911 | https://github.com/petebrowne/massimo/blob/c450edc531ad358f011da0a47e5d0bc9a038d911/lib/massimo/watcher.rb#L29-L40 | train |
fuminori-ido/edgarj | app/helpers/edgarj/field_helper.rb | Edgarj.FieldHelper.draw_form_buttons | def draw_form_buttons(options = {})
content_tag(:table) do
content_tag(:tr) do
# save button
content_tag(:td) do
#cp_bitset = Edgarj::ModelPermission::FlagsBitset
#create_or_update = cp_bitset::CREATE + cp_bitset::UPDATE
tag(:input, {
type: 'button',
name: 'save',
onClick: '$("#_edgarj_form").submit()',
value: t('edgarj.default.save'),
class: '_edgarj_form_save',})
#disabled: !permitted?(create_or_update)}.merge(options[:save]||{}))
end +
# search button
content_tag(:td) do
button_for_js(t('edgarj.default.search_form'), <<-JS,
$('#edgarj_form').hide();
$('#edgarj_search_form').show();
JS
{class: '_edgarj_form_search'}.merge(options[:search_form] ||{}))
end +
# clear button
content_tag(:td) do
button_to(t('edgarj.default.clear'),
{action: 'clear'},
{
method: :get,
remote: true,
})
end +
# delete button
content_tag(:td) do
button_to(t('edgarj.default.delete'),
if @record.new_record?
url_for('/')
else
url_for({
controller: params[:controller],
action: 'destroy',
id: @record.id})
end,
{
method: :delete,
remote: true,
data: {confirm: t('edgarj.form.delete_confirm')},
disabled: @record.new_record? # || !permitted?(cp_bitset::DELETE),
})
end
end
end
end | ruby | def draw_form_buttons(options = {})
content_tag(:table) do
content_tag(:tr) do
# save button
content_tag(:td) do
#cp_bitset = Edgarj::ModelPermission::FlagsBitset
#create_or_update = cp_bitset::CREATE + cp_bitset::UPDATE
tag(:input, {
type: 'button',
name: 'save',
onClick: '$("#_edgarj_form").submit()',
value: t('edgarj.default.save'),
class: '_edgarj_form_save',})
#disabled: !permitted?(create_or_update)}.merge(options[:save]||{}))
end +
# search button
content_tag(:td) do
button_for_js(t('edgarj.default.search_form'), <<-JS,
$('#edgarj_form').hide();
$('#edgarj_search_form').show();
JS
{class: '_edgarj_form_search'}.merge(options[:search_form] ||{}))
end +
# clear button
content_tag(:td) do
button_to(t('edgarj.default.clear'),
{action: 'clear'},
{
method: :get,
remote: true,
})
end +
# delete button
content_tag(:td) do
button_to(t('edgarj.default.delete'),
if @record.new_record?
url_for('/')
else
url_for({
controller: params[:controller],
action: 'destroy',
id: @record.id})
end,
{
method: :delete,
remote: true,
data: {confirm: t('edgarj.form.delete_confirm')},
disabled: @record.new_record? # || !permitted?(cp_bitset::DELETE),
})
end
end
end
end | [
"def",
"draw_form_buttons",
"(",
"options",
"=",
"{",
"}",
")",
"content_tag",
"(",
":table",
")",
"do",
"content_tag",
"(",
":tr",
")",
"do",
"content_tag",
"(",
":td",
")",
"do",
"tag",
"(",
":input",
",",
"{",
"type",
":",
"'button'",
",",
"name",
":",
"'save'",
",",
"onClick",
":",
"'$(\"#_edgarj_form\").submit()'",
",",
"value",
":",
"t",
"(",
"'edgarj.default.save'",
")",
",",
"class",
":",
"'_edgarj_form_save'",
",",
"}",
")",
"end",
"+",
"content_tag",
"(",
":td",
")",
"do",
"button_for_js",
"(",
"t",
"(",
"'edgarj.default.search_form'",
")",
",",
"<<-JS",
",",
"JS",
"{",
"class",
":",
"'_edgarj_form_search'",
"}",
".",
"merge",
"(",
"options",
"[",
":search_form",
"]",
"||",
"{",
"}",
")",
")",
"end",
"+",
"content_tag",
"(",
":td",
")",
"do",
"button_to",
"(",
"t",
"(",
"'edgarj.default.clear'",
")",
",",
"{",
"action",
":",
"'clear'",
"}",
",",
"{",
"method",
":",
":get",
",",
"remote",
":",
"true",
",",
"}",
")",
"end",
"+",
"content_tag",
"(",
":td",
")",
"do",
"button_to",
"(",
"t",
"(",
"'edgarj.default.delete'",
")",
",",
"if",
"@record",
".",
"new_record?",
"url_for",
"(",
"'/'",
")",
"else",
"url_for",
"(",
"{",
"controller",
":",
"params",
"[",
":controller",
"]",
",",
"action",
":",
"'destroy'",
",",
"id",
":",
"@record",
".",
"id",
"}",
")",
"end",
",",
"{",
"method",
":",
":delete",
",",
"remote",
":",
"true",
",",
"data",
":",
"{",
"confirm",
":",
"t",
"(",
"'edgarj.form.delete_confirm'",
")",
"}",
",",
"disabled",
":",
"@record",
".",
"new_record?",
"}",
")",
"end",
"end",
"end",
"end"
] | Draw buttons for form.
When no CREATE/UPDATE permission, save button is disabled.
It can be overwritten by options[:save].
When no DELETE permission, delete button is disabled.
It can be overwritten by options[:delete].
options may have:
:save:: html options for 'save' button.
:search_form:: html options for 'search_form' button.
:delete:: html options for 'delete' button. | [
"Draw",
"buttons",
"for",
"form",
"."
] | 1648ab180f1f4adaeea03d54b645f58f3702a2bf | https://github.com/fuminori-ido/edgarj/blob/1648ab180f1f4adaeea03d54b645f58f3702a2bf/app/helpers/edgarj/field_helper.rb#L18-L73 | train |
fuminori-ido/edgarj | app/helpers/edgarj/field_helper.rb | Edgarj.FieldHelper.draw_field | def draw_field(f, col, options={})
case col.type
when :date
draw_date(f, col, options[:date] || {})
when :datetime
draw_datetime(f, col, options[:datetime] || {})
when :integer
f.text_field(col.name, options[:integer])
else
f.text_field(col.name, options[:text])
end
end | ruby | def draw_field(f, col, options={})
case col.type
when :date
draw_date(f, col, options[:date] || {})
when :datetime
draw_datetime(f, col, options[:datetime] || {})
when :integer
f.text_field(col.name, options[:integer])
else
f.text_field(col.name, options[:text])
end
end | [
"def",
"draw_field",
"(",
"f",
",",
"col",
",",
"options",
"=",
"{",
"}",
")",
"case",
"col",
".",
"type",
"when",
":date",
"draw_date",
"(",
"f",
",",
"col",
",",
"options",
"[",
":date",
"]",
"||",
"{",
"}",
")",
"when",
":datetime",
"draw_datetime",
"(",
"f",
",",
"col",
",",
"options",
"[",
":datetime",
"]",
"||",
"{",
"}",
")",
"when",
":integer",
"f",
".",
"text_field",
"(",
"col",
".",
"name",
",",
"options",
"[",
":integer",
"]",
")",
"else",
"f",
".",
"text_field",
"(",
"col",
".",
"name",
",",
"options",
"[",
":text",
"]",
")",
"end",
"end"
] | draw default field for col.type
options[type] is passed to each rails helper. Following types are
supported:
* :date
* :datetime
* :integer
* :boolean
* :text
=== INPUTS
f:: FormBuilder object
col:: column info returned by AR.columns, or symbol
options:: options hash passed to each helper. | [
"draw",
"default",
"field",
"for",
"col",
".",
"type"
] | 1648ab180f1f4adaeea03d54b645f58f3702a2bf | https://github.com/fuminori-ido/edgarj/blob/1648ab180f1f4adaeea03d54b645f58f3702a2bf/app/helpers/edgarj/field_helper.rb#L122-L133 | train |
fuminori-ido/edgarj | app/helpers/edgarj/field_helper.rb | Edgarj.FieldHelper.draw_datetime | def draw_datetime(f, col_or_sym, options={})
col_name = get_column_name(col_or_sym)
f.text_field(col_name,
value: datetime_fmt(f.object.send(col_name)))
end | ruby | def draw_datetime(f, col_or_sym, options={})
col_name = get_column_name(col_or_sym)
f.text_field(col_name,
value: datetime_fmt(f.object.send(col_name)))
end | [
"def",
"draw_datetime",
"(",
"f",
",",
"col_or_sym",
",",
"options",
"=",
"{",
"}",
")",
"col_name",
"=",
"get_column_name",
"(",
"col_or_sym",
")",
"f",
".",
"text_field",
"(",
"col_name",
",",
"value",
":",
"datetime_fmt",
"(",
"f",
".",
"object",
".",
"send",
"(",
"col_name",
")",
")",
")",
"end"
] | draw calendar datetime select
=== INPUTS
f:: Form builder object.
col_or_sym:: column object returned by rec.class.columns, or symbol
options:: passed to calendar_date_select | [
"draw",
"calendar",
"datetime",
"select"
] | 1648ab180f1f4adaeea03d54b645f58f3702a2bf | https://github.com/fuminori-ido/edgarj/blob/1648ab180f1f4adaeea03d54b645f58f3702a2bf/app/helpers/edgarj/field_helper.rb#L165-L169 | train |
fuminori-ido/edgarj | app/helpers/edgarj/field_helper.rb | Edgarj.FieldHelper.draw_address | def draw_address(f, col_or_sym)
address_name = f.object.class.get_belongs_to_name(col_or_sym)
render('edgarj/address',
f: f,
rec: f.object,
address_name: address_name
)
end | ruby | def draw_address(f, col_or_sym)
address_name = f.object.class.get_belongs_to_name(col_or_sym)
render('edgarj/address',
f: f,
rec: f.object,
address_name: address_name
)
end | [
"def",
"draw_address",
"(",
"f",
",",
"col_or_sym",
")",
"address_name",
"=",
"f",
".",
"object",
".",
"class",
".",
"get_belongs_to_name",
"(",
"col_or_sym",
")",
"render",
"(",
"'edgarj/address'",
",",
"f",
":",
"f",
",",
"rec",
":",
"f",
".",
"object",
",",
"address_name",
":",
"address_name",
")",
"end"
] | draw 'edgarj_address' field
The column, which is declared as 'edgarj_address', can be
drawn by this helper.
=== INPUTS
f:: FormBuilder
col_or_sym:: column object returned by rec.class.columns, or symbol | [
"draw",
"edgarj_address",
"field"
] | 1648ab180f1f4adaeea03d54b645f58f3702a2bf | https://github.com/fuminori-ido/edgarj/blob/1648ab180f1f4adaeea03d54b645f58f3702a2bf/app/helpers/edgarj/field_helper.rb#L179-L186 | train |
fuminori-ido/edgarj | app/helpers/edgarj/field_helper.rb | Edgarj.FieldHelper.draw_bitset | def draw_bitset(f, col, bitset=nil, options={})
html = ''
bitset = model.const_get(col_name.to_s.camelize + 'Bitset') if !bitset
i = 0
id_array_var = sprintf('%s_%s_var', f.object_name, col.name)
ids = []
for flag in bitset.constants do
checkbox_id = sprintf('%s_%s_%d', f.object_name, col.name, i)
html += draw_checkbox(f, checkbox_id, flag, bitset, id_array_var) +
label_tag(
checkbox_id,
f.object.class.human_const_name(bitset, flag)) +
' '.html_safe
ids << checkbox_id
i += 1
end
# draw hidden field to send sum-up value
html += f.hidden_field(col.name)
# add hidden-field name to ids' last
ids << sprintf("%s_%s", f.object_name, col.name)
# define arrays to calculate flags
html += "<script> var #{id_array_var}=[" +
ids.map{|id| "'" + id + "'"}.join(',') +
"];</script>"
html.html_safe
end | ruby | def draw_bitset(f, col, bitset=nil, options={})
html = ''
bitset = model.const_get(col_name.to_s.camelize + 'Bitset') if !bitset
i = 0
id_array_var = sprintf('%s_%s_var', f.object_name, col.name)
ids = []
for flag in bitset.constants do
checkbox_id = sprintf('%s_%s_%d', f.object_name, col.name, i)
html += draw_checkbox(f, checkbox_id, flag, bitset, id_array_var) +
label_tag(
checkbox_id,
f.object.class.human_const_name(bitset, flag)) +
' '.html_safe
ids << checkbox_id
i += 1
end
# draw hidden field to send sum-up value
html += f.hidden_field(col.name)
# add hidden-field name to ids' last
ids << sprintf("%s_%s", f.object_name, col.name)
# define arrays to calculate flags
html += "<script> var #{id_array_var}=[" +
ids.map{|id| "'" + id + "'"}.join(',') +
"];</script>"
html.html_safe
end | [
"def",
"draw_bitset",
"(",
"f",
",",
"col",
",",
"bitset",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"html",
"=",
"''",
"bitset",
"=",
"model",
".",
"const_get",
"(",
"col_name",
".",
"to_s",
".",
"camelize",
"+",
"'Bitset'",
")",
"if",
"!",
"bitset",
"i",
"=",
"0",
"id_array_var",
"=",
"sprintf",
"(",
"'%s_%s_var'",
",",
"f",
".",
"object_name",
",",
"col",
".",
"name",
")",
"ids",
"=",
"[",
"]",
"for",
"flag",
"in",
"bitset",
".",
"constants",
"do",
"checkbox_id",
"=",
"sprintf",
"(",
"'%s_%s_%d'",
",",
"f",
".",
"object_name",
",",
"col",
".",
"name",
",",
"i",
")",
"html",
"+=",
"draw_checkbox",
"(",
"f",
",",
"checkbox_id",
",",
"flag",
",",
"bitset",
",",
"id_array_var",
")",
"+",
"label_tag",
"(",
"checkbox_id",
",",
"f",
".",
"object",
".",
"class",
".",
"human_const_name",
"(",
"bitset",
",",
"flag",
")",
")",
"+",
"' '",
".",
"html_safe",
"ids",
"<<",
"checkbox_id",
"i",
"+=",
"1",
"end",
"html",
"+=",
"f",
".",
"hidden_field",
"(",
"col",
".",
"name",
")",
"ids",
"<<",
"sprintf",
"(",
"\"%s_%s\"",
",",
"f",
".",
"object_name",
",",
"col",
".",
"name",
")",
"html",
"+=",
"\"<script> var #{id_array_var}=[\"",
"+",
"ids",
".",
"map",
"{",
"|",
"id",
"|",
"\"'\"",
"+",
"id",
"+",
"\"'\"",
"}",
".",
"join",
"(",
"','",
")",
"+",
"\"];</script>\"",
"html",
".",
"html_safe",
"end"
] | draw bitset checkboxes.
When model class has integer field (e.g. 'flags') and
Flags module which defines 'bitflag' constant,
model.flags integer column is drawn as bitset checkboxes.
Constant name will be translated by config/locales/*.yml
See ModelPermission for example.
'flags' column value is calculated at client side by JavaScript.
options is not used now.
=== INPUTS
f:: Form builder object.
col:: column object returned by rec.class.columns, or symbol
bitset:: ruby module contains 'bitflag' integer constants
options:: (not used) | [
"draw",
"bitset",
"checkboxes",
"."
] | 1648ab180f1f4adaeea03d54b645f58f3702a2bf | https://github.com/fuminori-ido/edgarj/blob/1648ab180f1f4adaeea03d54b645f58f3702a2bf/app/helpers/edgarj/field_helper.rb#L205-L232 | train |
fuminori-ido/edgarj | app/helpers/edgarj/field_helper.rb | Edgarj.FieldHelper.draw_enum | def draw_enum(f, col_or_sym, enum=nil, options={})
col_name = get_column_name(col_or_sym)
enum = model.const_get(col_name.to_s.camelize) if !enum
sorted_elements = enum.constants.sort{|a,b|
enum.const_get(a) <=> enum.const_get(b)}
options_for_select = options.dup
choice_1st = options_for_select.delete(:choice_1st)
class_4_human_const = options_for_select.delete(:class) || f.object.class
f.select(col_name,
(choice_1st ? [choice_1st] : []) +
sorted_elements.map{|member|
[class_4_human_const.human_const_name(enum, member),
enum.const_get(member)]},
options_for_select)
end | ruby | def draw_enum(f, col_or_sym, enum=nil, options={})
col_name = get_column_name(col_or_sym)
enum = model.const_get(col_name.to_s.camelize) if !enum
sorted_elements = enum.constants.sort{|a,b|
enum.const_get(a) <=> enum.const_get(b)}
options_for_select = options.dup
choice_1st = options_for_select.delete(:choice_1st)
class_4_human_const = options_for_select.delete(:class) || f.object.class
f.select(col_name,
(choice_1st ? [choice_1st] : []) +
sorted_elements.map{|member|
[class_4_human_const.human_const_name(enum, member),
enum.const_get(member)]},
options_for_select)
end | [
"def",
"draw_enum",
"(",
"f",
",",
"col_or_sym",
",",
"enum",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"col_name",
"=",
"get_column_name",
"(",
"col_or_sym",
")",
"enum",
"=",
"model",
".",
"const_get",
"(",
"col_name",
".",
"to_s",
".",
"camelize",
")",
"if",
"!",
"enum",
"sorted_elements",
"=",
"enum",
".",
"constants",
".",
"sort",
"{",
"|",
"a",
",",
"b",
"|",
"enum",
".",
"const_get",
"(",
"a",
")",
"<=>",
"enum",
".",
"const_get",
"(",
"b",
")",
"}",
"options_for_select",
"=",
"options",
".",
"dup",
"choice_1st",
"=",
"options_for_select",
".",
"delete",
"(",
":choice_1st",
")",
"class_4_human_const",
"=",
"options_for_select",
".",
"delete",
"(",
":class",
")",
"||",
"f",
".",
"object",
".",
"class",
"f",
".",
"select",
"(",
"col_name",
",",
"(",
"choice_1st",
"?",
"[",
"choice_1st",
"]",
":",
"[",
"]",
")",
"+",
"sorted_elements",
".",
"map",
"{",
"|",
"member",
"|",
"[",
"class_4_human_const",
".",
"human_const_name",
"(",
"enum",
",",
"member",
")",
",",
"enum",
".",
"const_get",
"(",
"member",
")",
"]",
"}",
",",
"options_for_select",
")",
"end"
] | draw enum selection.
'Enum' in Edgarj is a module which integer constants are defined.
draw_enum() draws selection rather than simple integer text field.
Selection-option label is I18 supported by AR human_const_name API.
See lib/edgarj/model.rb rdoc.
=== EXAMPLE
Followings draws Question module's Priority selection
on @question.priority integer column:
<%= edgarj_form do |f| %>
:
<%= draw_enum(f, :priority) %>
:
<% end %>
=== INPUTS
f:: Form builder object.
col_or_sym:: column object returned by rec.class.columns, or symbol
enum:: enum module. When nil, guess by column name.
options:: draw_enum options and/or passed to select helper.
==== Supported options
:choice_1st:: additional 1st choice (mainly used SearchForm enum selection)
:class AR class which will be used for human_const_name()
=== SEE ALSO
get_enum():: get enum definition
draw_column_enum():: draw enum column in list
FIXME: choices for selection should be cached. | [
"draw",
"enum",
"selection",
"."
] | 1648ab180f1f4adaeea03d54b645f58f3702a2bf | https://github.com/fuminori-ido/edgarj/blob/1648ab180f1f4adaeea03d54b645f58f3702a2bf/app/helpers/edgarj/field_helper.rb#L267-L281 | train |
fuminori-ido/edgarj | app/helpers/edgarj/field_helper.rb | Edgarj.FieldHelper.draw_checkbox | def draw_checkbox(f, id, flag, bitset, id_array_var)
val = f.object.send(:flags) || 0
flag_val = bitset.const_get(flag)
tag(:input,
type: 'checkbox',
id: id,
name: id,
value: flag_val,
onChange: "Edgarj.sum_bitset(#{id_array_var})",
checked: (val & flag_val) != 0 )
end | ruby | def draw_checkbox(f, id, flag, bitset, id_array_var)
val = f.object.send(:flags) || 0
flag_val = bitset.const_get(flag)
tag(:input,
type: 'checkbox',
id: id,
name: id,
value: flag_val,
onChange: "Edgarj.sum_bitset(#{id_array_var})",
checked: (val & flag_val) != 0 )
end | [
"def",
"draw_checkbox",
"(",
"f",
",",
"id",
",",
"flag",
",",
"bitset",
",",
"id_array_var",
")",
"val",
"=",
"f",
".",
"object",
".",
"send",
"(",
":flags",
")",
"||",
"0",
"flag_val",
"=",
"bitset",
".",
"const_get",
"(",
"flag",
")",
"tag",
"(",
":input",
",",
"type",
":",
"'checkbox'",
",",
"id",
":",
"id",
",",
"name",
":",
"id",
",",
"value",
":",
"flag_val",
",",
"onChange",
":",
"\"Edgarj.sum_bitset(#{id_array_var})\"",
",",
"checked",
":",
"(",
"val",
"&",
"flag_val",
")",
"!=",
"0",
")",
"end"
] | draw Edgarj flags specific checkbox | [
"draw",
"Edgarj",
"flags",
"specific",
"checkbox"
] | 1648ab180f1f4adaeea03d54b645f58f3702a2bf | https://github.com/fuminori-ido/edgarj/blob/1648ab180f1f4adaeea03d54b645f58f3702a2bf/app/helpers/edgarj/field_helper.rb#L359-L369 | train |
fuminori-ido/edgarj | app/helpers/edgarj/field_helper.rb | Edgarj.FieldHelper.find_col | def find_col(rec, sym)
rec.class.columns.detect{|c| c.name == sym.to_s}
end | ruby | def find_col(rec, sym)
rec.class.columns.detect{|c| c.name == sym.to_s}
end | [
"def",
"find_col",
"(",
"rec",
",",
"sym",
")",
"rec",
".",
"class",
".",
"columns",
".",
"detect",
"{",
"|",
"c",
"|",
"c",
".",
"name",
"==",
"sym",
".",
"to_s",
"}",
"end"
] | find column info from name | [
"find",
"column",
"info",
"from",
"name"
] | 1648ab180f1f4adaeea03d54b645f58f3702a2bf | https://github.com/fuminori-ido/edgarj/blob/1648ab180f1f4adaeea03d54b645f58f3702a2bf/app/helpers/edgarj/field_helper.rb#L372-L374 | train |
fuminori-ido/edgarj | app/helpers/edgarj/field_helper.rb | Edgarj.FieldHelper.button_for_js | def button_for_js(label, js, html_options={})
tag(:input, {type: 'button', value: label, onClick: js}.merge(
html_options))
end | ruby | def button_for_js(label, js, html_options={})
tag(:input, {type: 'button', value: label, onClick: js}.merge(
html_options))
end | [
"def",
"button_for_js",
"(",
"label",
",",
"js",
",",
"html_options",
"=",
"{",
"}",
")",
"tag",
"(",
":input",
",",
"{",
"type",
":",
"'button'",
",",
"value",
":",
"label",
",",
"onClick",
":",
"js",
"}",
".",
"merge",
"(",
"html_options",
")",
")",
"end"
] | replacement of button_to_function to avoid DEPRECATION WARNING.
When the js is called just once, onClick is simpler than
unobtrusive-javascript approach. | [
"replacement",
"of",
"button_to_function",
"to",
"avoid",
"DEPRECATION",
"WARNING",
"."
] | 1648ab180f1f4adaeea03d54b645f58f3702a2bf | https://github.com/fuminori-ido/edgarj/blob/1648ab180f1f4adaeea03d54b645f58f3702a2bf/app/helpers/edgarj/field_helper.rb#L398-L401 | train |
jwoertink/tourets | lib/tourets/utilities.rb | TouRETS.Utilities.map_search_params | def map_search_params(search_params)
Hash[search_params.map {|k, v| [key_map[k], v] }]
end | ruby | def map_search_params(search_params)
Hash[search_params.map {|k, v| [key_map[k], v] }]
end | [
"def",
"map_search_params",
"(",
"search_params",
")",
"Hash",
"[",
"search_params",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"[",
"key_map",
"[",
"k",
"]",
",",
"v",
"]",
"}",
"]",
"end"
] | This takes a hash of search parameters, and modifies
the hash to have the correct key types for the current RETS server | [
"This",
"takes",
"a",
"hash",
"of",
"search",
"parameters",
"and",
"modifies",
"the",
"hash",
"to",
"have",
"the",
"correct",
"key",
"types",
"for",
"the",
"current",
"RETS",
"server"
] | 1cf5b5b061702846d38a261ad256f1641d2553c1 | https://github.com/jwoertink/tourets/blob/1cf5b5b061702846d38a261ad256f1641d2553c1/lib/tourets/utilities.rb#L17-L19 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.