id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
sequence
docstring
stringlengths
8
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
94
266
4,600
dryade/georuby-ext
lib/georuby-ext/geokit.rb
GeoKit.LatLng.wgs84_to_google
def wgs84_to_google ActiveSupport::Deprecation.warn "use Point geometry which supports srid" self.class.from_pro4j Proj4::Projection.wgs84.transform Proj4::Projection.google, self.proj4_point(Math::PI / 180).x, self.proj4_point(Math::PI / 180).y end
ruby
def wgs84_to_google ActiveSupport::Deprecation.warn "use Point geometry which supports srid" self.class.from_pro4j Proj4::Projection.wgs84.transform Proj4::Projection.google, self.proj4_point(Math::PI / 180).x, self.proj4_point(Math::PI / 180).y end
[ "def", "wgs84_to_google", "ActiveSupport", "::", "Deprecation", ".", "warn", "\"use Point geometry which supports srid\"", "self", ".", "class", ".", "from_pro4j", "Proj4", "::", "Projection", ".", "wgs84", ".", "transform", "Proj4", "::", "Projection", ".", "google", ",", "self", ".", "proj4_point", "(", "Math", "::", "PI", "/", "180", ")", ".", "x", ",", "self", ".", "proj4_point", "(", "Math", "::", "PI", "/", "180", ")", ".", "y", "end" ]
DEPRECATED Use Point geometry which supports srid
[ "DEPRECATED", "Use", "Point", "geometry", "which", "supports", "srid" ]
8c5aa1436868f970ea07c169ad9761b495e3a798
https://github.com/dryade/georuby-ext/blob/8c5aa1436868f970ea07c169ad9761b495e3a798/lib/georuby-ext/geokit.rb#L13-L16
4,601
unipept/unipept-cli
lib/server_message.rb
Unipept.ServerMessage.print
def print return unless $stdout.tty? return if recently_fetched? resp = fetch_server_message update_fetched puts resp unless resp.empty? end
ruby
def print return unless $stdout.tty? return if recently_fetched? resp = fetch_server_message update_fetched puts resp unless resp.empty? end
[ "def", "print", "return", "unless", "$stdout", ".", "tty?", "return", "if", "recently_fetched?", "resp", "=", "fetch_server_message", "update_fetched", "puts", "resp", "unless", "resp", ".", "empty?", "end" ]
Checks if the server has a message and prints it if not empty. We will only check this once a day and won't print anything if the quiet option is set or if we output to a file.
[ "Checks", "if", "the", "server", "has", "a", "message", "and", "prints", "it", "if", "not", "empty", ".", "We", "will", "only", "check", "this", "once", "a", "day", "and", "won", "t", "print", "anything", "if", "the", "quiet", "option", "is", "set", "or", "if", "we", "output", "to", "a", "file", "." ]
183779bd1dffcd01ed623685c789160153b78681
https://github.com/unipept/unipept-cli/blob/183779bd1dffcd01ed623685c789160153b78681/lib/server_message.rb#L19-L26
4,602
phatworx/rails_paginate
lib/rails_paginate/renderers/html_default.rb
RailsPaginate::Renderers.HtmlDefault.render
def render content_tag(:ul) do html = "\n" if show_first_page? html += content_tag(:li, :class => "first_page") do link_to_page collection.first_page, 'paginate.first_page_label' end html += "\n" end if show_previous_page? html += content_tag(:li, :class => "previous_page") do link_to_page collection.previous_page, 'paginate.previous_page_label' end html += "\n" end html += render_pager if show_next_page? html += content_tag(:li, :class => "next_page") do link_to_page collection.next_page, 'paginate.next_page_label' end html += "\n" end if show_last_page? html += content_tag(:li, :class => "last_page") do link_to_page collection.last_page, 'paginate.last_page_label' end html += "\n" end html.html_safe end end
ruby
def render content_tag(:ul) do html = "\n" if show_first_page? html += content_tag(:li, :class => "first_page") do link_to_page collection.first_page, 'paginate.first_page_label' end html += "\n" end if show_previous_page? html += content_tag(:li, :class => "previous_page") do link_to_page collection.previous_page, 'paginate.previous_page_label' end html += "\n" end html += render_pager if show_next_page? html += content_tag(:li, :class => "next_page") do link_to_page collection.next_page, 'paginate.next_page_label' end html += "\n" end if show_last_page? html += content_tag(:li, :class => "last_page") do link_to_page collection.last_page, 'paginate.last_page_label' end html += "\n" end html.html_safe end end
[ "def", "render", "content_tag", "(", ":ul", ")", "do", "html", "=", "\"\\n\"", "if", "show_first_page?", "html", "+=", "content_tag", "(", ":li", ",", ":class", "=>", "\"first_page\"", ")", "do", "link_to_page", "collection", ".", "first_page", ",", "'paginate.first_page_label'", "end", "html", "+=", "\"\\n\"", "end", "if", "show_previous_page?", "html", "+=", "content_tag", "(", ":li", ",", ":class", "=>", "\"previous_page\"", ")", "do", "link_to_page", "collection", ".", "previous_page", ",", "'paginate.previous_page_label'", "end", "html", "+=", "\"\\n\"", "end", "html", "+=", "render_pager", "if", "show_next_page?", "html", "+=", "content_tag", "(", ":li", ",", ":class", "=>", "\"next_page\"", ")", "do", "link_to_page", "collection", ".", "next_page", ",", "'paginate.next_page_label'", "end", "html", "+=", "\"\\n\"", "end", "if", "show_last_page?", "html", "+=", "content_tag", "(", ":li", ",", ":class", "=>", "\"last_page\"", ")", "do", "link_to_page", "collection", ".", "last_page", ",", "'paginate.last_page_label'", "end", "html", "+=", "\"\\n\"", "end", "html", ".", "html_safe", "end", "end" ]
render html for pagination
[ "render", "html", "for", "pagination" ]
ae8cbc12030853b236dc2cbf6ede8700fb835771
https://github.com/phatworx/rails_paginate/blob/ae8cbc12030853b236dc2cbf6ede8700fb835771/lib/rails_paginate/renderers/html_default.rb#L22-L57
4,603
smolnar/squire
lib/squire/configuration.rb
Squire.Configuration.namespace
def namespace(namespace = nil, options = {}) return @namespace unless namespace @namespace = namespace.to_sym if namespace @base_namespace = options[:base].to_sym if options[:base] end
ruby
def namespace(namespace = nil, options = {}) return @namespace unless namespace @namespace = namespace.to_sym if namespace @base_namespace = options[:base].to_sym if options[:base] end
[ "def", "namespace", "(", "namespace", "=", "nil", ",", "options", "=", "{", "}", ")", "return", "@namespace", "unless", "namespace", "@namespace", "=", "namespace", ".", "to_sym", "if", "namespace", "@base_namespace", "=", "options", "[", ":base", "]", ".", "to_sym", "if", "options", "[", ":base", "]", "end" ]
Sets and returns +namespace+. If called without parameters, returns +namespace+. Possible options: * <tt>:base</tt> - base namespace used for deep merging of values of other namespaces
[ "Sets", "and", "returns", "+", "namespace", "+", ".", "If", "called", "without", "parameters", "returns", "+", "namespace", "+", "." ]
f9175cf007ccadefe4cd77f34271f76e311c2d60
https://github.com/smolnar/squire/blob/f9175cf007ccadefe4cd77f34271f76e311c2d60/lib/squire/configuration.rb#L11-L16
4,604
smolnar/squire
lib/squire/configuration.rb
Squire.Configuration.source
def source(source = nil, options = {}) return @source unless source @source = source @parser = options[:parser] @type = options[:type] @type ||= source.is_a?(Hash) ? :hash : File.extname(@source)[1..-1].to_sym end
ruby
def source(source = nil, options = {}) return @source unless source @source = source @parser = options[:parser] @type = options[:type] @type ||= source.is_a?(Hash) ? :hash : File.extname(@source)[1..-1].to_sym end
[ "def", "source", "(", "source", "=", "nil", ",", "options", "=", "{", "}", ")", "return", "@source", "unless", "source", "@source", "=", "source", "@parser", "=", "options", "[", ":parser", "]", "@type", "=", "options", "[", ":type", "]", "@type", "||=", "source", ".", "is_a?", "(", "Hash", ")", "?", ":hash", ":", "File", ".", "extname", "(", "@source", ")", "[", "1", "..", "-", "1", "]", ".", "to_sym", "end" ]
Sets +source+ for the configuration If called without parameters, returns +source+. Possible options: * <tt>:type</tt> - type of +source+ (optional, based on file extension) * <tt>:parser</tt> - parse of input +source+ (optional, based on +:type+)
[ "Sets", "+", "source", "+", "for", "the", "configuration", "If", "called", "without", "parameters", "returns", "+", "source", "+", "." ]
f9175cf007ccadefe4cd77f34271f76e311c2d60
https://github.com/smolnar/squire/blob/f9175cf007ccadefe4cd77f34271f76e311c2d60/lib/squire/configuration.rb#L25-L33
4,605
smolnar/squire
lib/squire/configuration.rb
Squire.Configuration.settings
def settings(&block) @settings ||= setup settings = instance_variable_defined?(:@namespace) ? @settings.get_value(@namespace) : @settings if block_given? block.arity == 0 ? settings.instance_eval(&block) : block.call(settings) end settings end
ruby
def settings(&block) @settings ||= setup settings = instance_variable_defined?(:@namespace) ? @settings.get_value(@namespace) : @settings if block_given? block.arity == 0 ? settings.instance_eval(&block) : block.call(settings) end settings end
[ "def", "settings", "(", "&", "block", ")", "@settings", "||=", "setup", "settings", "=", "instance_variable_defined?", "(", ":@namespace", ")", "?", "@settings", ".", "get_value", "(", "@namespace", ")", ":", "@settings", "if", "block_given?", "block", ".", "arity", "==", "0", "?", "settings", ".", "instance_eval", "(", "block", ")", ":", "block", ".", "call", "(", "settings", ")", "end", "settings", "end" ]
Loaded configuration stored in Settings class. Accepts +block+ as parameter. == Examples settings do |settings| settings.a = 1 end settings do a 1 end settings.a = 1
[ "Loaded", "configuration", "stored", "in", "Settings", "class", ".", "Accepts", "+", "block", "+", "as", "parameter", "." ]
f9175cf007ccadefe4cd77f34271f76e311c2d60
https://github.com/smolnar/squire/blob/f9175cf007ccadefe4cd77f34271f76e311c2d60/lib/squire/configuration.rb#L49-L59
4,606
smolnar/squire
lib/squire/configuration.rb
Squire.Configuration.setup
def setup return Squire::Settings.new unless @source parser = Squire::Parser.of(@type) hash = parser.parse(source).with_indifferent_access if base_namespace hash.except(base_namespace).each do |key, values| # favours value from namespace over value from defaults hash[key] = hash[base_namespace].deep_merge(values) { |_, default, value| value.nil? ? default : value } end end Squire::Settings.from_hash(hash) end
ruby
def setup return Squire::Settings.new unless @source parser = Squire::Parser.of(@type) hash = parser.parse(source).with_indifferent_access if base_namespace hash.except(base_namespace).each do |key, values| # favours value from namespace over value from defaults hash[key] = hash[base_namespace].deep_merge(values) { |_, default, value| value.nil? ? default : value } end end Squire::Settings.from_hash(hash) end
[ "def", "setup", "return", "Squire", "::", "Settings", ".", "new", "unless", "@source", "parser", "=", "Squire", "::", "Parser", ".", "of", "(", "@type", ")", "hash", "=", "parser", ".", "parse", "(", "source", ")", ".", "with_indifferent_access", "if", "base_namespace", "hash", ".", "except", "(", "base_namespace", ")", ".", "each", "do", "|", "key", ",", "values", "|", "# favours value from namespace over value from defaults", "hash", "[", "key", "]", "=", "hash", "[", "base_namespace", "]", ".", "deep_merge", "(", "values", ")", "{", "|", "_", ",", "default", ",", "value", "|", "value", ".", "nil?", "?", "default", ":", "value", "}", "end", "end", "Squire", "::", "Settings", ".", "from_hash", "(", "hash", ")", "end" ]
Sets up the configuration based on +namespace+ and +source+. If +base_namespace+ provided, merges it's values with other namespaces for handling nested overriding of values. Favours values from +namespace+ over values from +base_namespace+.
[ "Sets", "up", "the", "configuration", "based", "on", "+", "namespace", "+", "and", "+", "source", "+", ".", "If", "+", "base_namespace", "+", "provided", "merges", "it", "s", "values", "with", "other", "namespaces", "for", "handling", "nested", "overriding", "of", "values", "." ]
f9175cf007ccadefe4cd77f34271f76e311c2d60
https://github.com/smolnar/squire/blob/f9175cf007ccadefe4cd77f34271f76e311c2d60/lib/squire/configuration.rb#L69-L84
4,607
isabanin/mercurial-ruby
lib/mercurial-ruby/factories/commit_factory.rb
Mercurial.CommitFactory.count_range
def count_range(hash_a, hash_b, cmd_options={}) hg_to_array([%Q[log -r ?:? --template "{node}\n"], hash_a, hash_b], {}, cmd_options) do |line| line end.size end
ruby
def count_range(hash_a, hash_b, cmd_options={}) hg_to_array([%Q[log -r ?:? --template "{node}\n"], hash_a, hash_b], {}, cmd_options) do |line| line end.size end
[ "def", "count_range", "(", "hash_a", ",", "hash_b", ",", "cmd_options", "=", "{", "}", ")", "hg_to_array", "(", "[", "%Q[log -r ?:? --template \"{node}\\n\"]", ",", "hash_a", ",", "hash_b", "]", ",", "{", "}", ",", "cmd_options", ")", "do", "|", "line", "|", "line", "end", ".", "size", "end" ]
Count changesets in the range from hash_a to hash_b in the repository. === Example: repository.commits.count_range(hash_a, hash_b)
[ "Count", "changesets", "in", "the", "range", "from", "hash_a", "to", "hash_b", "in", "the", "repository", "." ]
d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a
https://github.com/isabanin/mercurial-ruby/blob/d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a/lib/mercurial-ruby/factories/commit_factory.rb#L69-L73
4,608
pacop/adfly
lib/adfly/adfly.rb
Adfly.API.create_link
def create_link data body = http_get URL_API, {key: @key, uid: @uid}.merge(data) raise ArgumentError if body.nil? || body.empty? body end
ruby
def create_link data body = http_get URL_API, {key: @key, uid: @uid}.merge(data) raise ArgumentError if body.nil? || body.empty? body end
[ "def", "create_link", "data", "body", "=", "http_get", "URL_API", ",", "{", "key", ":", "@key", ",", "uid", ":", "@uid", "}", ".", "merge", "(", "data", ")", "raise", "ArgumentError", "if", "body", ".", "nil?", "||", "body", ".", "empty?", "body", "end" ]
Create instance to use API adfly If you want to get API key from https://adf.ly/publisher/tools#tools-api @param uid [String] Uid @param key [String] Key Create single link Maybe you want to see https://adf.ly/publisher/tools#tools-api @param data [Hash] data to send api @option data [String] :url Link to be converted @option data [Symbol] :advert_type Type of advertisement(:int or :banner) @option data [String] :domain Alias domain to be used for ther generated link @example Simple use adfly.create_link(url: 'http://www.google.es') @return [String] Short link @raise [ArgumentError] Invalid parameters, link cannot be created
[ "Create", "instance", "to", "use", "API", "adfly" ]
e27bdaf22fafc83657ebbd696b2591306362d2b0
https://github.com/pacop/adfly/blob/e27bdaf22fafc83657ebbd696b2591306362d2b0/lib/adfly/adfly.rb#L37-L42
4,609
Mik-die/mongoid_globalize
lib/mongoid_globalize/fields_builder.rb
Mongoid::Globalize.FieldsBuilder.field
def field(name, *params) @model.translated_attribute_names.push name.to_sym @model.translated_attr_accessor(name) @model.translation_class.field name, *params end
ruby
def field(name, *params) @model.translated_attribute_names.push name.to_sym @model.translated_attr_accessor(name) @model.translation_class.field name, *params end
[ "def", "field", "(", "name", ",", "*", "params", ")", "@model", ".", "translated_attribute_names", ".", "push", "name", ".", "to_sym", "@model", ".", "translated_attr_accessor", "(", "name", ")", "@model", ".", "translation_class", ".", "field", "name", ",", "params", "end" ]
Initializes new istance of FieldsBuilder. Param Class Creates new field in translation document. Param String or Symbol Other params are the same as for Mongoid's +field+
[ "Initializes", "new", "istance", "of", "FieldsBuilder", ".", "Param", "Class", "Creates", "new", "field", "in", "translation", "document", ".", "Param", "String", "or", "Symbol", "Other", "params", "are", "the", "same", "as", "for", "Mongoid", "s", "+", "field", "+" ]
458105154574950aed98119fd54ffaae4e1a55ee
https://github.com/Mik-die/mongoid_globalize/blob/458105154574950aed98119fd54ffaae4e1a55ee/lib/mongoid_globalize/fields_builder.rb#L12-L16
4,610
marcelofabri/danger-simplecov_json
lib/simplecov_json/plugin.rb
Danger.DangerSimpleCovJson.report
def report(coverage_path, sticky: true) if File.exist? coverage_path coverage_json = JSON.parse(File.read(coverage_path), symbolize_names: true) metrics = coverage_json[:metrics] percentage = metrics[:covered_percent] lines = metrics[:covered_lines] total_lines = metrics[:total_lines] formatted_percentage = format('%.02f', percentage) message("Code coverage is now at #{formatted_percentage}% (#{lines}/#{total_lines} lines)", sticky: sticky) else fail('Code coverage data not found') end end
ruby
def report(coverage_path, sticky: true) if File.exist? coverage_path coverage_json = JSON.parse(File.read(coverage_path), symbolize_names: true) metrics = coverage_json[:metrics] percentage = metrics[:covered_percent] lines = metrics[:covered_lines] total_lines = metrics[:total_lines] formatted_percentage = format('%.02f', percentage) message("Code coverage is now at #{formatted_percentage}% (#{lines}/#{total_lines} lines)", sticky: sticky) else fail('Code coverage data not found') end end
[ "def", "report", "(", "coverage_path", ",", "sticky", ":", "true", ")", "if", "File", ".", "exist?", "coverage_path", "coverage_json", "=", "JSON", ".", "parse", "(", "File", ".", "read", "(", "coverage_path", ")", ",", "symbolize_names", ":", "true", ")", "metrics", "=", "coverage_json", "[", ":metrics", "]", "percentage", "=", "metrics", "[", ":covered_percent", "]", "lines", "=", "metrics", "[", ":covered_lines", "]", "total_lines", "=", "metrics", "[", ":total_lines", "]", "formatted_percentage", "=", "format", "(", "'%.02f'", ",", "percentage", ")", "message", "(", "\"Code coverage is now at #{formatted_percentage}% (#{lines}/#{total_lines} lines)\"", ",", "sticky", ":", "sticky", ")", "else", "fail", "(", "'Code coverage data not found'", ")", "end", "end" ]
Parse a JSON code coverage file and report that information as a message in Danger. @return [void]
[ "Parse", "a", "JSON", "code", "coverage", "file", "and", "report", "that", "information", "as", "a", "message", "in", "Danger", "." ]
95a0649a3f542741203a3dfed67755ac8dcbfcb1
https://github.com/marcelofabri/danger-simplecov_json/blob/95a0649a3f542741203a3dfed67755ac8dcbfcb1/lib/simplecov_json/plugin.rb#L22-L35
4,611
marcelofabri/danger-simplecov_json
lib/simplecov_json/plugin.rb
Danger.DangerSimpleCovJson.individual_coverage_message
def individual_coverage_message(covered_files) require 'terminal-table' message = "### Code Coverage\n\n" table = Terminal::Table.new( headings: %w(File Coverage), style: { border_i: '|' }, rows: covered_files.map do |file| [file[:filename], "#{format('%.02f', file[:covered_percent])}%"] end ).to_s message + table.split("\n")[1..-2].join("\n") end
ruby
def individual_coverage_message(covered_files) require 'terminal-table' message = "### Code Coverage\n\n" table = Terminal::Table.new( headings: %w(File Coverage), style: { border_i: '|' }, rows: covered_files.map do |file| [file[:filename], "#{format('%.02f', file[:covered_percent])}%"] end ).to_s message + table.split("\n")[1..-2].join("\n") end
[ "def", "individual_coverage_message", "(", "covered_files", ")", "require", "'terminal-table'", "message", "=", "\"### Code Coverage\\n\\n\"", "table", "=", "Terminal", "::", "Table", ".", "new", "(", "headings", ":", "%w(", "File", "Coverage", ")", ",", "style", ":", "{", "border_i", ":", "'|'", "}", ",", "rows", ":", "covered_files", ".", "map", "do", "|", "file", "|", "[", "file", "[", ":filename", "]", ",", "\"#{format('%.02f', file[:covered_percent])}%\"", "]", "end", ")", ".", "to_s", "message", "+", "table", ".", "split", "(", "\"\\n\"", ")", "[", "1", "..", "-", "2", "]", ".", "join", "(", "\"\\n\"", ")", "end" ]
Builds the markdown table displaying coverage on individual files @param [Array] covered_files @return [String] Markdown table
[ "Builds", "the", "markdown", "table", "displaying", "coverage", "on", "individual", "files" ]
95a0649a3f542741203a3dfed67755ac8dcbfcb1
https://github.com/marcelofabri/danger-simplecov_json/blob/95a0649a3f542741203a3dfed67755ac8dcbfcb1/lib/simplecov_json/plugin.rb#L69-L81
4,612
miketheman/knife-community
lib/chef/knife/community_release.rb
KnifeCommunity.CommunityRelease.validate_args
def validate_args if name_args.size < 1 ui.error('No cookbook has been specified') show_usage exit 1 end if name_args.size > 2 ui.error('Too many arguments are being passed. Please verify.') show_usage exit 1 end end
ruby
def validate_args if name_args.size < 1 ui.error('No cookbook has been specified') show_usage exit 1 end if name_args.size > 2 ui.error('Too many arguments are being passed. Please verify.') show_usage exit 1 end end
[ "def", "validate_args", "if", "name_args", ".", "size", "<", "1", "ui", ".", "error", "(", "'No cookbook has been specified'", ")", "show_usage", "exit", "1", "end", "if", "name_args", ".", "size", ">", "2", "ui", ".", "error", "(", "'Too many arguments are being passed. Please verify.'", ")", "show_usage", "exit", "1", "end", "end" ]
Ensure argumanets are valid, assign values of arguments @param [Array] the global `name_args` object
[ "Ensure", "argumanets", "are", "valid", "assign", "values", "of", "arguments" ]
fc7b4f7482d0ff9b8ac32636ad369227eb909be7
https://github.com/miketheman/knife-community/blob/fc7b4f7482d0ff9b8ac32636ad369227eb909be7/lib/chef/knife/community_release.rb#L119-L130
4,613
miketheman/knife-community
lib/chef/knife/community_release.rb
KnifeCommunity.CommunityRelease.validate_repo_clean
def validate_repo_clean @gitrepo = Grit::Repo.new(@repo_root) status = @gitrepo.status if !status.changed.nil? || status.changed.size != 0 # This has to be a convoluted way to determine a non-empty... # Test each for the magic sha_index. Ref: https://github.com/mojombo/grit/issues/142 status.changed.each do |file| case file[1].sha_index when '0' * 40 ui.error 'There seem to be unstaged changes in your repo. Either stash or add them.' exit 4 else ui.msg 'There are modified files that have been staged, and will be included in the push.' end end elsif status.untracked.size > 0 ui.warn 'There are untracked files in your repo. You might want to look into that.' end end
ruby
def validate_repo_clean @gitrepo = Grit::Repo.new(@repo_root) status = @gitrepo.status if !status.changed.nil? || status.changed.size != 0 # This has to be a convoluted way to determine a non-empty... # Test each for the magic sha_index. Ref: https://github.com/mojombo/grit/issues/142 status.changed.each do |file| case file[1].sha_index when '0' * 40 ui.error 'There seem to be unstaged changes in your repo. Either stash or add them.' exit 4 else ui.msg 'There are modified files that have been staged, and will be included in the push.' end end elsif status.untracked.size > 0 ui.warn 'There are untracked files in your repo. You might want to look into that.' end end
[ "def", "validate_repo_clean", "@gitrepo", "=", "Grit", "::", "Repo", ".", "new", "(", "@repo_root", ")", "status", "=", "@gitrepo", ".", "status", "if", "!", "status", ".", "changed", ".", "nil?", "||", "status", ".", "changed", ".", "size", "!=", "0", "# This has to be a convoluted way to determine a non-empty...", "# Test each for the magic sha_index. Ref: https://github.com/mojombo/grit/issues/142", "status", ".", "changed", ".", "each", "do", "|", "file", "|", "case", "file", "[", "1", "]", ".", "sha_index", "when", "'0'", "*", "40", "ui", ".", "error", "'There seem to be unstaged changes in your repo. Either stash or add them.'", "exit", "4", "else", "ui", ".", "msg", "'There are modified files that have been staged, and will be included in the push.'", "end", "end", "elsif", "status", ".", "untracked", ".", "size", ">", "0", "ui", ".", "warn", "'There are untracked files in your repo. You might want to look into that.'", "end", "end" ]
Inspect the cookbook directory's git status is good to push. Any existing tracked files should be staged, otherwise error & exit. Untracked files are warned about, but will allow continue. This needs more testing.
[ "Inspect", "the", "cookbook", "directory", "s", "git", "status", "is", "good", "to", "push", ".", "Any", "existing", "tracked", "files", "should", "be", "staged", "otherwise", "error", "&", "exit", ".", "Untracked", "files", "are", "warned", "about", "but", "will", "allow", "continue", ".", "This", "needs", "more", "testing", "." ]
fc7b4f7482d0ff9b8ac32636ad369227eb909be7
https://github.com/miketheman/knife-community/blob/fc7b4f7482d0ff9b8ac32636ad369227eb909be7/lib/chef/knife/community_release.rb#L150-L167
4,614
miketheman/knife-community
lib/chef/knife/community_release.rb
KnifeCommunity.CommunityRelease.validate_no_existing_tag
def validate_no_existing_tag(tag_string) existing_tags = [] @gitrepo.tags.each { |tag| existing_tags << tag.name } if existing_tags.include?(tag_string) ui.error 'This version tag has already been committed to the repo.' ui.error "Are you sure you haven't released this already?" exit 6 end end
ruby
def validate_no_existing_tag(tag_string) existing_tags = [] @gitrepo.tags.each { |tag| existing_tags << tag.name } if existing_tags.include?(tag_string) ui.error 'This version tag has already been committed to the repo.' ui.error "Are you sure you haven't released this already?" exit 6 end end
[ "def", "validate_no_existing_tag", "(", "tag_string", ")", "existing_tags", "=", "[", "]", "@gitrepo", ".", "tags", ".", "each", "{", "|", "tag", "|", "existing_tags", "<<", "tag", ".", "name", "}", "if", "existing_tags", ".", "include?", "(", "tag_string", ")", "ui", ".", "error", "'This version tag has already been committed to the repo.'", "ui", ".", "error", "\"Are you sure you haven't released this already?\"", "exit", "6", "end", "end" ]
Ensure that there isn't already a git tag for this version.
[ "Ensure", "that", "there", "isn", "t", "already", "a", "git", "tag", "for", "this", "version", "." ]
fc7b4f7482d0ff9b8ac32636ad369227eb909be7
https://github.com/miketheman/knife-community/blob/fc7b4f7482d0ff9b8ac32636ad369227eb909be7/lib/chef/knife/community_release.rb#L170-L178
4,615
miketheman/knife-community
lib/chef/knife/community_release.rb
KnifeCommunity.CommunityRelease.validate_target_remote_branch
def validate_target_remote_branch remote_path = File.join(config[:remote], config[:branch]) remotes = [] @gitrepo.remotes.each { |remote| remotes << remote.name } unless remotes.include?(remote_path) ui.error 'The remote/branch specified does not seem to exist.' exit 7 end end
ruby
def validate_target_remote_branch remote_path = File.join(config[:remote], config[:branch]) remotes = [] @gitrepo.remotes.each { |remote| remotes << remote.name } unless remotes.include?(remote_path) ui.error 'The remote/branch specified does not seem to exist.' exit 7 end end
[ "def", "validate_target_remote_branch", "remote_path", "=", "File", ".", "join", "(", "config", "[", ":remote", "]", ",", "config", "[", ":branch", "]", ")", "remotes", "=", "[", "]", "@gitrepo", ".", "remotes", ".", "each", "{", "|", "remote", "|", "remotes", "<<", "remote", ".", "name", "}", "unless", "remotes", ".", "include?", "(", "remote_path", ")", "ui", ".", "error", "'The remote/branch specified does not seem to exist.'", "exit", "7", "end", "end" ]
Ensure that the remote and branch are indeed valid. We provide defaults in options.
[ "Ensure", "that", "the", "remote", "and", "branch", "are", "indeed", "valid", ".", "We", "provide", "defaults", "in", "options", "." ]
fc7b4f7482d0ff9b8ac32636ad369227eb909be7
https://github.com/miketheman/knife-community/blob/fc7b4f7482d0ff9b8ac32636ad369227eb909be7/lib/chef/knife/community_release.rb#L181-L190
4,616
sosedoff/munin-ruby
lib/munin-ruby/node.rb
Munin.Node.nodes
def nodes nodes = [] cache 'nodes' do connection.send_data("nodes") while ( ( line = connection.read_line ) != "." ) nodes << line end nodes end end
ruby
def nodes nodes = [] cache 'nodes' do connection.send_data("nodes") while ( ( line = connection.read_line ) != "." ) nodes << line end nodes end end
[ "def", "nodes", "nodes", "=", "[", "]", "cache", "'nodes'", "do", "connection", ".", "send_data", "(", "\"nodes\"", ")", "while", "(", "(", "line", "=", "connection", ".", "read_line", ")", "!=", "\".\"", ")", "nodes", "<<", "line", "end", "nodes", "end", "end" ]
Get a list of all available nodes
[ "Get", "a", "list", "of", "all", "available", "nodes" ]
28f65b0abb88fc40e234b6af327094992504be6a
https://github.com/sosedoff/munin-ruby/blob/28f65b0abb88fc40e234b6af327094992504be6a/lib/munin-ruby/node.rb#L47-L56
4,617
sosedoff/munin-ruby
lib/munin-ruby/node.rb
Munin.Node.list
def list(node = "") cache "list_#{node.empty? ? 'default' : node}" do connection.send_data("list #{node}") if ( line = connection.read_line ) != "." line.split else connection.read_line.split end end end
ruby
def list(node = "") cache "list_#{node.empty? ? 'default' : node}" do connection.send_data("list #{node}") if ( line = connection.read_line ) != "." line.split else connection.read_line.split end end end
[ "def", "list", "(", "node", "=", "\"\"", ")", "cache", "\"list_#{node.empty? ? 'default' : node}\"", "do", "connection", ".", "send_data", "(", "\"list #{node}\"", ")", "if", "(", "line", "=", "connection", ".", "read_line", ")", "!=", "\".\"", "line", ".", "split", "else", "connection", ".", "read_line", ".", "split", "end", "end", "end" ]
Get a list of all available metrics
[ "Get", "a", "list", "of", "all", "available", "metrics" ]
28f65b0abb88fc40e234b6af327094992504be6a
https://github.com/sosedoff/munin-ruby/blob/28f65b0abb88fc40e234b6af327094992504be6a/lib/munin-ruby/node.rb#L60-L69
4,618
sosedoff/munin-ruby
lib/munin-ruby/node.rb
Munin.Node.config
def config(services, raw=false) unless [String, Array].include?(services.class) raise ArgumentError, "Service(s) argument required" end results = {} names = [services].flatten.uniq if names.empty? raise ArgumentError, "Service(s) argument required" end key = 'config_' + Digest::MD5.hexdigest(names.to_s) + "_#{raw}" cache(key) do names.each do |service| begin connection.send_data("config #{service}") lines = connection.read_packet results[service] = raw ? lines.join("\n") : parse_config(lines) rescue UnknownService, BadExit # TODO end end results end end
ruby
def config(services, raw=false) unless [String, Array].include?(services.class) raise ArgumentError, "Service(s) argument required" end results = {} names = [services].flatten.uniq if names.empty? raise ArgumentError, "Service(s) argument required" end key = 'config_' + Digest::MD5.hexdigest(names.to_s) + "_#{raw}" cache(key) do names.each do |service| begin connection.send_data("config #{service}") lines = connection.read_packet results[service] = raw ? lines.join("\n") : parse_config(lines) rescue UnknownService, BadExit # TODO end end results end end
[ "def", "config", "(", "services", ",", "raw", "=", "false", ")", "unless", "[", "String", ",", "Array", "]", ".", "include?", "(", "services", ".", "class", ")", "raise", "ArgumentError", ",", "\"Service(s) argument required\"", "end", "results", "=", "{", "}", "names", "=", "[", "services", "]", ".", "flatten", ".", "uniq", "if", "names", ".", "empty?", "raise", "ArgumentError", ",", "\"Service(s) argument required\"", "end", "key", "=", "'config_'", "+", "Digest", "::", "MD5", ".", "hexdigest", "(", "names", ".", "to_s", ")", "+", "\"_#{raw}\"", "cache", "(", "key", ")", "do", "names", ".", "each", "do", "|", "service", "|", "begin", "connection", ".", "send_data", "(", "\"config #{service}\"", ")", "lines", "=", "connection", ".", "read_packet", "results", "[", "service", "]", "=", "raw", "?", "lines", ".", "join", "(", "\"\\n\"", ")", ":", "parse_config", "(", "lines", ")", "rescue", "UnknownService", ",", "BadExit", "# TODO", "end", "end", "results", "end", "end" ]
Get a configuration information for service services - Name of the service, or list of service names
[ "Get", "a", "configuration", "information", "for", "service" ]
28f65b0abb88fc40e234b6af327094992504be6a
https://github.com/sosedoff/munin-ruby/blob/28f65b0abb88fc40e234b6af327094992504be6a/lib/munin-ruby/node.rb#L75-L101
4,619
sosedoff/munin-ruby
lib/munin-ruby/node.rb
Munin.Node.fetch
def fetch(services) unless [String, Array].include?(services.class) raise ArgumentError, "Service(s) argument required" end results = {} names = [services].flatten if names.empty? raise ArgumentError, "Service(s) argument required" end names.each do |service| begin connection.send_data("fetch #{service}") lines = connection.read_packet results[service] = parse_fetch(lines) rescue UnknownService, BadExit # TODO end end results end
ruby
def fetch(services) unless [String, Array].include?(services.class) raise ArgumentError, "Service(s) argument required" end results = {} names = [services].flatten if names.empty? raise ArgumentError, "Service(s) argument required" end names.each do |service| begin connection.send_data("fetch #{service}") lines = connection.read_packet results[service] = parse_fetch(lines) rescue UnknownService, BadExit # TODO end end results end
[ "def", "fetch", "(", "services", ")", "unless", "[", "String", ",", "Array", "]", ".", "include?", "(", "services", ".", "class", ")", "raise", "ArgumentError", ",", "\"Service(s) argument required\"", "end", "results", "=", "{", "}", "names", "=", "[", "services", "]", ".", "flatten", "if", "names", ".", "empty?", "raise", "ArgumentError", ",", "\"Service(s) argument required\"", "end", "names", ".", "each", "do", "|", "service", "|", "begin", "connection", ".", "send_data", "(", "\"fetch #{service}\"", ")", "lines", "=", "connection", ".", "read_packet", "results", "[", "service", "]", "=", "parse_fetch", "(", "lines", ")", "rescue", "UnknownService", ",", "BadExit", "# TODO", "end", "end", "results", "end" ]
Get all service metrics values services - Name of the service, or list of service names
[ "Get", "all", "service", "metrics", "values" ]
28f65b0abb88fc40e234b6af327094992504be6a
https://github.com/sosedoff/munin-ruby/blob/28f65b0abb88fc40e234b6af327094992504be6a/lib/munin-ruby/node.rb#L107-L129
4,620
smolnar/squire
lib/squire/settings.rb
Squire.Settings.get_value
def get_value(key, &block) key = key.to_sym value = @table[key] if block_given? block.arity == 0 ? value.instance_eval(&block) : block.call(value) end value end
ruby
def get_value(key, &block) key = key.to_sym value = @table[key] if block_given? block.arity == 0 ? value.instance_eval(&block) : block.call(value) end value end
[ "def", "get_value", "(", "key", ",", "&", "block", ")", "key", "=", "key", ".", "to_sym", "value", "=", "@table", "[", "key", "]", "if", "block_given?", "block", ".", "arity", "==", "0", "?", "value", ".", "instance_eval", "(", "block", ")", ":", "block", ".", "call", "(", "value", ")", "end", "value", "end" ]
Returns a value for +key+ from settings table. Yields +value+ of +key+ if +block+ provided. == Examples: .key do |key| ... end # or .key do ... end
[ "Returns", "a", "value", "for", "+", "key", "+", "from", "settings", "table", ".", "Yields", "+", "value", "+", "of", "+", "key", "+", "if", "+", "block", "+", "provided", "." ]
f9175cf007ccadefe4cd77f34271f76e311c2d60
https://github.com/smolnar/squire/blob/f9175cf007ccadefe4cd77f34271f76e311c2d60/lib/squire/settings.rb#L85-L94
4,621
smolnar/squire
lib/squire/settings.rb
Squire.Settings.to_hash
def to_hash result = ::Hash.new @table.each do |key, value| if value.is_a? Settings value = value.to_hash end result[key] = value end result end
ruby
def to_hash result = ::Hash.new @table.each do |key, value| if value.is_a? Settings value = value.to_hash end result[key] = value end result end
[ "def", "to_hash", "result", "=", "::", "Hash", ".", "new", "@table", ".", "each", "do", "|", "key", ",", "value", "|", "if", "value", ".", "is_a?", "Settings", "value", "=", "value", ".", "to_hash", "end", "result", "[", "key", "]", "=", "value", "end", "result", "end" ]
Dumps settings as hash.
[ "Dumps", "settings", "as", "hash", "." ]
f9175cf007ccadefe4cd77f34271f76e311c2d60
https://github.com/smolnar/squire/blob/f9175cf007ccadefe4cd77f34271f76e311c2d60/lib/squire/settings.rb#L106-L118
4,622
AssemDeghady/questionpro_rails
lib/questionpro_rails/question.rb
QuestionproRails.Question.choices
def choices extracted_choices = [] unless self.qp_answers.nil? self.qp_answers.each do |choice| extracted_choices.push(Choice.new(choice)) end end return extracted_choices end
ruby
def choices extracted_choices = [] unless self.qp_answers.nil? self.qp_answers.each do |choice| extracted_choices.push(Choice.new(choice)) end end return extracted_choices end
[ "def", "choices", "extracted_choices", "=", "[", "]", "unless", "self", ".", "qp_answers", ".", "nil?", "self", ".", "qp_answers", ".", "each", "do", "|", "choice", "|", "extracted_choices", ".", "push", "(", "Choice", ".", "new", "(", "choice", ")", ")", "end", "end", "return", "extracted_choices", "end" ]
Extract the choices from the hashes stored inside qp_answers attribute. @return [Array<QuestionproRails::Choice>] Choices.
[ "Extract", "the", "choices", "from", "the", "hashes", "stored", "inside", "qp_answers", "attribute", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/question.rb#L22-L32
4,623
dropofwill/rtasklib
lib/rtasklib/helpers.rb
Rtasklib.Helpers.filter
def filter ids: nil, tags: nil, dom: nil id_s = tag_s = dom_s = "" id_s = process_ids(ids) unless ids.nil? tag_s = process_tags(tags) unless tags.nil? dom_s = process_dom(dom) unless dom.nil? return "#{id_s} #{tag_s} #{dom_s}".strip end
ruby
def filter ids: nil, tags: nil, dom: nil id_s = tag_s = dom_s = "" id_s = process_ids(ids) unless ids.nil? tag_s = process_tags(tags) unless tags.nil? dom_s = process_dom(dom) unless dom.nil? return "#{id_s} #{tag_s} #{dom_s}".strip end
[ "def", "filter", "ids", ":", "nil", ",", "tags", ":", "nil", ",", "dom", ":", "nil", "id_s", "=", "tag_s", "=", "dom_s", "=", "\"\"", "id_s", "=", "process_ids", "(", "ids", ")", "unless", "ids", ".", "nil?", "tag_s", "=", "process_tags", "(", "tags", ")", "unless", "tags", ".", "nil?", "dom_s", "=", "process_dom", "(", "dom", ")", "unless", "dom", ".", "nil?", "return", "\"#{id_s} #{tag_s} #{dom_s}\"", ".", "strip", "end" ]
Converts ids, tags, and dom queries to a single string ready to pass directly to task. @param ids[Range, Array<String, Range, Fixnum>, String, Fixnum] @param tags[String, Array<String>] @param dom[String, Array<String>] @return [String] a string with ids tags and dom joined by a space @api public
[ "Converts", "ids", "tags", "and", "dom", "queries", "to", "a", "single", "string", "ready", "to", "pass", "directly", "to", "task", "." ]
c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c
https://github.com/dropofwill/rtasklib/blob/c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c/lib/rtasklib/helpers.rb#L49-L55
4,624
dropofwill/rtasklib
lib/rtasklib/helpers.rb
Rtasklib.Helpers.process_ids
def process_ids ids case ids when Range return id_range_to_s(ids) when Array return id_a_to_s(ids) when String return ids.delete(" ") when Fixnum return ids end end
ruby
def process_ids ids case ids when Range return id_range_to_s(ids) when Array return id_a_to_s(ids) when String return ids.delete(" ") when Fixnum return ids end end
[ "def", "process_ids", "ids", "case", "ids", "when", "Range", "return", "id_range_to_s", "(", "ids", ")", "when", "Array", "return", "id_a_to_s", "(", "ids", ")", "when", "String", "return", "ids", ".", "delete", "(", "\" \"", ")", "when", "Fixnum", "return", "ids", "end", "end" ]
Converts arbitrary id input to a task safe string @param ids[Range, Array<String, Range, Fixnum>, String, Fixnum] @api public
[ "Converts", "arbitrary", "id", "input", "to", "a", "task", "safe", "string" ]
c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c
https://github.com/dropofwill/rtasklib/blob/c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c/lib/rtasklib/helpers.rb#L79-L90
4,625
dropofwill/rtasklib
lib/rtasklib/helpers.rb
Rtasklib.Helpers.process_tags
def process_tags tags case tags when String tags.split(" ").map { |t| process_tag t }.join(" ") when Array tags.map { |t| process_tags t }.join(" ") end end
ruby
def process_tags tags case tags when String tags.split(" ").map { |t| process_tag t }.join(" ") when Array tags.map { |t| process_tags t }.join(" ") end end
[ "def", "process_tags", "tags", "case", "tags", "when", "String", "tags", ".", "split", "(", "\" \"", ")", ".", "map", "{", "|", "t", "|", "process_tag", "t", "}", ".", "join", "(", "\" \"", ")", "when", "Array", "tags", ".", "map", "{", "|", "t", "|", "process_tags", "t", "}", ".", "join", "(", "\" \"", ")", "end", "end" ]
Convert a tag string or an array of strings to a space separated string @param tags [String, Array<String>] @api private
[ "Convert", "a", "tag", "string", "or", "an", "array", "of", "strings", "to", "a", "space", "separated", "string" ]
c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c
https://github.com/dropofwill/rtasklib/blob/c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c/lib/rtasklib/helpers.rb#L105-L112
4,626
dropofwill/rtasklib
lib/rtasklib/helpers.rb
Rtasklib.Helpers.json?
def json? value begin return false unless value.is_a? String MultiJson.load(value) true rescue MultiJson::ParseError false end end
ruby
def json? value begin return false unless value.is_a? String MultiJson.load(value) true rescue MultiJson::ParseError false end end
[ "def", "json?", "value", "begin", "return", "false", "unless", "value", ".", "is_a?", "String", "MultiJson", ".", "load", "(", "value", ")", "true", "rescue", "MultiJson", "::", "ParseError", "false", "end", "end" ]
Can the input be coerced to a JSON object without losing information? @return [Boolean] true if coercible, false if not @api private
[ "Can", "the", "input", "be", "coerced", "to", "a", "JSON", "object", "without", "losing", "information?" ]
c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c
https://github.com/dropofwill/rtasklib/blob/c3a69a7188765e5d662d9d0d1fd5d4f87dc74d8c/lib/rtasklib/helpers.rb#L243-L251
4,627
couchrest/couchrest_extended_document
lib/couchrest/property.rb
CouchRest.Property.cast_value
def cast_value(parent, value) raise "An array inside an array cannot be casted, use CastedModel" if value.is_a?(Array) value = typecast_value(value, self) associate_casted_value_to_parent(parent, value) end
ruby
def cast_value(parent, value) raise "An array inside an array cannot be casted, use CastedModel" if value.is_a?(Array) value = typecast_value(value, self) associate_casted_value_to_parent(parent, value) end
[ "def", "cast_value", "(", "parent", ",", "value", ")", "raise", "\"An array inside an array cannot be casted, use CastedModel\"", "if", "value", ".", "is_a?", "(", "Array", ")", "value", "=", "typecast_value", "(", "value", ",", "self", ")", "associate_casted_value_to_parent", "(", "parent", ",", "value", ")", "end" ]
Cast an individual value, not an array
[ "Cast", "an", "individual", "value", "not", "an", "array" ]
71511202ae10d3010dcf7b98fcba017cb37c76da
https://github.com/couchrest/couchrest_extended_document/blob/71511202ae10d3010dcf7b98fcba017cb37c76da/lib/couchrest/property.rb#L44-L48
4,628
couchrest/couchrest_extended_document
lib/couchrest/property.rb
CouchRest.Property.type_class
def type_class return String unless casted # This is rubbish, to handle validations return @type_class unless @type_class.nil? base = @type.is_a?(Array) ? @type.first : @type base = String if base.nil? base = TrueClass if base.is_a?(String) && base.downcase == 'boolean' @type_class = base.is_a?(Class) ? base : base.constantize end
ruby
def type_class return String unless casted # This is rubbish, to handle validations return @type_class unless @type_class.nil? base = @type.is_a?(Array) ? @type.first : @type base = String if base.nil? base = TrueClass if base.is_a?(String) && base.downcase == 'boolean' @type_class = base.is_a?(Class) ? base : base.constantize end
[ "def", "type_class", "return", "String", "unless", "casted", "# This is rubbish, to handle validations", "return", "@type_class", "unless", "@type_class", ".", "nil?", "base", "=", "@type", ".", "is_a?", "(", "Array", ")", "?", "@type", ".", "first", ":", "@type", "base", "=", "String", "if", "base", ".", "nil?", "base", "=", "TrueClass", "if", "base", ".", "is_a?", "(", "String", ")", "&&", "base", ".", "downcase", "==", "'boolean'", "@type_class", "=", "base", ".", "is_a?", "(", "Class", ")", "?", "base", ":", "base", ".", "constantize", "end" ]
Always provide the basic type as a class. If the type is an array, the class will be extracted.
[ "Always", "provide", "the", "basic", "type", "as", "a", "class", ".", "If", "the", "type", "is", "an", "array", "the", "class", "will", "be", "extracted", "." ]
71511202ae10d3010dcf7b98fcba017cb37c76da
https://github.com/couchrest/couchrest_extended_document/blob/71511202ae10d3010dcf7b98fcba017cb37c76da/lib/couchrest/property.rb#L61-L68
4,629
unipept/unipept-cli
lib/batch_iterator.rb
Unipept.BatchIterator.fasta_iterator
def fasta_iterator(first_line, next_lines) current_fasta_header = first_line.chomp next_lines.each_slice(batch_size).with_index do |slice, i| fasta_mapper = [] input_set = Set.new slice.each do |line| line.chomp! if fasta? line current_fasta_header = line else fasta_mapper << [current_fasta_header, line] input_set << line end end yield(input_set.to_a, i, fasta_mapper) end end
ruby
def fasta_iterator(first_line, next_lines) current_fasta_header = first_line.chomp next_lines.each_slice(batch_size).with_index do |slice, i| fasta_mapper = [] input_set = Set.new slice.each do |line| line.chomp! if fasta? line current_fasta_header = line else fasta_mapper << [current_fasta_header, line] input_set << line end end yield(input_set.to_a, i, fasta_mapper) end end
[ "def", "fasta_iterator", "(", "first_line", ",", "next_lines", ")", "current_fasta_header", "=", "first_line", ".", "chomp", "next_lines", ".", "each_slice", "(", "batch_size", ")", ".", "with_index", "do", "|", "slice", ",", "i", "|", "fasta_mapper", "=", "[", "]", "input_set", "=", "Set", ".", "new", "slice", ".", "each", "do", "|", "line", "|", "line", ".", "chomp!", "if", "fasta?", "line", "current_fasta_header", "=", "line", "else", "fasta_mapper", "<<", "[", "current_fasta_header", ",", "line", "]", "input_set", "<<", "line", "end", "end", "yield", "(", "input_set", ".", "to_a", ",", "i", ",", "fasta_mapper", ")", "end", "end" ]
Splits the input lines in fasta format into slices, based on the batch_size of the current command. Executes the given block for each of the batches.
[ "Splits", "the", "input", "lines", "in", "fasta", "format", "into", "slices", "based", "on", "the", "batch_size", "of", "the", "current", "command", ".", "Executes", "the", "given", "block", "for", "each", "of", "the", "batches", "." ]
183779bd1dffcd01ed623685c789160153b78681
https://github.com/unipept/unipept-cli/blob/183779bd1dffcd01ed623685c789160153b78681/lib/batch_iterator.rb#L42-L60
4,630
yoyo0906/ruby-adb-sdklib
lib/adb_sdklib/device.rb
AdbSdkLib.Device.properties
def properties convert_map_to_hash(@device.getProperties) do |hash, key, value| hash[key.toString] = value.toString end end
ruby
def properties convert_map_to_hash(@device.getProperties) do |hash, key, value| hash[key.toString] = value.toString end end
[ "def", "properties", "convert_map_to_hash", "(", "@device", ".", "getProperties", ")", "do", "|", "hash", ",", "key", ",", "value", "|", "hash", "[", "key", ".", "toString", "]", "=", "value", ".", "toString", "end", "end" ]
Returns the device properties. It contains the whole output of 'getprop' @return [Hash<String, String>] the device properties
[ "Returns", "the", "device", "properties", ".", "It", "contains", "the", "whole", "output", "of", "getprop" ]
9f8a5c88ee8e7b572600ca7919b506bfc0e8d105
https://github.com/yoyo0906/ruby-adb-sdklib/blob/9f8a5c88ee8e7b572600ca7919b506bfc0e8d105/lib/adb_sdklib/device.rb#L81-L85
4,631
yoyo0906/ruby-adb-sdklib
lib/adb_sdklib/device.rb
AdbSdkLib.Device.shell
def shell(command, &block) capture = CommandCapture.new(block_given? ? block : nil) receiver = Rjb::bind(capture, 'com.android.ddmlib.IShellOutputReceiver') @device.executeShellCommand(command.to_s, receiver) block_given? ? self : capture.to_s end
ruby
def shell(command, &block) capture = CommandCapture.new(block_given? ? block : nil) receiver = Rjb::bind(capture, 'com.android.ddmlib.IShellOutputReceiver') @device.executeShellCommand(command.to_s, receiver) block_given? ? self : capture.to_s end
[ "def", "shell", "(", "command", ",", "&", "block", ")", "capture", "=", "CommandCapture", ".", "new", "(", "block_given?", "?", "block", ":", "nil", ")", "receiver", "=", "Rjb", "::", "bind", "(", "capture", ",", "'com.android.ddmlib.IShellOutputReceiver'", ")", "@device", ".", "executeShellCommand", "(", "command", ".", "to_s", ",", "receiver", ")", "block_given?", "?", "self", ":", "capture", ".", "to_s", "end" ]
Executes a shell command on the device, and receives the result. @!method shell(command) @return [String, self] @overload shell(command) @param [String] command the command to execute @return [String] all results of the command. @overload shell(command) @param [String] command the command to execute @return [self] self @yield [line] @yieldparam [String] line each line of results of the command.
[ "Executes", "a", "shell", "command", "on", "the", "device", "and", "receives", "the", "result", "." ]
9f8a5c88ee8e7b572600ca7919b506bfc0e8d105
https://github.com/yoyo0906/ruby-adb-sdklib/blob/9f8a5c88ee8e7b572600ca7919b506bfc0e8d105/lib/adb_sdklib/device.rb#L145-L150
4,632
yoyo0906/ruby-adb-sdklib
lib/adb_sdklib/device.rb
AdbSdkLib.Device.push
def push(localfile, remotefile) raise ArgumentError, "Not found #{localfile}" unless File.exist?(localfile) if remotefile.end_with?('/') remotefile = "#{remotefile}#{File.basename(localfile)}" end @device.pushFile(localfile, remotefile) self end
ruby
def push(localfile, remotefile) raise ArgumentError, "Not found #{localfile}" unless File.exist?(localfile) if remotefile.end_with?('/') remotefile = "#{remotefile}#{File.basename(localfile)}" end @device.pushFile(localfile, remotefile) self end
[ "def", "push", "(", "localfile", ",", "remotefile", ")", "raise", "ArgumentError", ",", "\"Not found #{localfile}\"", "unless", "File", ".", "exist?", "(", "localfile", ")", "if", "remotefile", ".", "end_with?", "(", "'/'", ")", "remotefile", "=", "\"#{remotefile}#{File.basename(localfile)}\"", "end", "@device", ".", "pushFile", "(", "localfile", ",", "remotefile", ")", "self", "end" ]
Pushes a file to the device. If *remotefile* path ends with '/', complements by the basename of *localfile*. @example device = AdbSdkLib::Adb.new.devices.first device.push('path/to/local.txt', '/data/local/tmp/remote.txt') device.push('path/to/file.txt', '/data/local/tmp/') # uses file.txt @param [String] localfile the name of the local file to send @param [String] remotefile the name of the remote file or directory on the device @return [self] self @raise [ArgumentError] If *localfile* is not found
[ "Pushes", "a", "file", "to", "the", "device", "." ]
9f8a5c88ee8e7b572600ca7919b506bfc0e8d105
https://github.com/yoyo0906/ruby-adb-sdklib/blob/9f8a5c88ee8e7b572600ca7919b506bfc0e8d105/lib/adb_sdklib/device.rb#L165-L172
4,633
yoyo0906/ruby-adb-sdklib
lib/adb_sdklib/device.rb
AdbSdkLib.Device.pull
def pull(remotefile, localfile) if localfile.end_with?('/') || File.directory?(localfile) localdir = localfile.chomp('/') localfilename = nil else localdir = File.dirname(localfile) localfilename = File.basename(localfile) end unless File.exist?(localdir) FileUtils.mkdir_p(localdir) end localfilename = File.basename(remotefile) if localfilename.nil? @device.pullFile(remotefile, "#{localdir}/#{localfilename}") self end
ruby
def pull(remotefile, localfile) if localfile.end_with?('/') || File.directory?(localfile) localdir = localfile.chomp('/') localfilename = nil else localdir = File.dirname(localfile) localfilename = File.basename(localfile) end unless File.exist?(localdir) FileUtils.mkdir_p(localdir) end localfilename = File.basename(remotefile) if localfilename.nil? @device.pullFile(remotefile, "#{localdir}/#{localfilename}") self end
[ "def", "pull", "(", "remotefile", ",", "localfile", ")", "if", "localfile", ".", "end_with?", "(", "'/'", ")", "||", "File", ".", "directory?", "(", "localfile", ")", "localdir", "=", "localfile", ".", "chomp", "(", "'/'", ")", "localfilename", "=", "nil", "else", "localdir", "=", "File", ".", "dirname", "(", "localfile", ")", "localfilename", "=", "File", ".", "basename", "(", "localfile", ")", "end", "unless", "File", ".", "exist?", "(", "localdir", ")", "FileUtils", ".", "mkdir_p", "(", "localdir", ")", "end", "localfilename", "=", "File", ".", "basename", "(", "remotefile", ")", "if", "localfilename", ".", "nil?", "@device", ".", "pullFile", "(", "remotefile", ",", "\"#{localdir}/#{localfilename}\"", ")", "self", "end" ]
Pulls a file from the device. If *localfile* path ends with '/', complements by the basename of *remotefile*. @example device = AdbSdkLib::Adb.new.devices.first device.pull('/data/local/tmp/remote.txt', 'path/to/local.txt') device.pull('/data/local/tmp/file.txt', 'path/to/dir/') # uses file.txt @param [String] remotefile the name of the remote file on the device to get @param [String] localfile the name of the local file or directory @return [self] self
[ "Pulls", "a", "file", "from", "the", "device", "." ]
9f8a5c88ee8e7b572600ca7919b506bfc0e8d105
https://github.com/yoyo0906/ruby-adb-sdklib/blob/9f8a5c88ee8e7b572600ca7919b506bfc0e8d105/lib/adb_sdklib/device.rb#L185-L200
4,634
samvera-labs/geo_works
app/models/concerns/geo_works/raster_file_behavior.rb
GeoWorks.RasterFileBehavior.raster_work
def raster_work parents.select do |parent| parent.class.included_modules.include?(::GeoWorks::RasterWorkBehavior) end.to_a end
ruby
def raster_work parents.select do |parent| parent.class.included_modules.include?(::GeoWorks::RasterWorkBehavior) end.to_a end
[ "def", "raster_work", "parents", ".", "select", "do", "|", "parent", "|", "parent", ".", "class", ".", "included_modules", ".", "include?", "(", "::", "GeoWorks", "::", "RasterWorkBehavior", ")", "end", ".", "to_a", "end" ]
Retrieve the Raster Work of which this Object is a member @return [GeoWorks::Raster]
[ "Retrieve", "the", "Raster", "Work", "of", "which", "this", "Object", "is", "a", "member" ]
df1eff35fd01469a623fafeb9d71b44fd6160ca8
https://github.com/samvera-labs/geo_works/blob/df1eff35fd01469a623fafeb9d71b44fd6160ca8/app/models/concerns/geo_works/raster_file_behavior.rb#L8-L12
4,635
yoyo0906/ruby-adb-sdklib
lib/adb_sdklib/raw_image.rb
AdbSdkLib.RawImage.pixel
def pixel(x,y) Pixel.new(x,y,@image.getARGB(point_to_index(x,y))) end
ruby
def pixel(x,y) Pixel.new(x,y,@image.getARGB(point_to_index(x,y))) end
[ "def", "pixel", "(", "x", ",", "y", ")", "Pixel", ".", "new", "(", "x", ",", "y", ",", "@image", ".", "getARGB", "(", "point_to_index", "(", "x", ",", "y", ")", ")", ")", "end" ]
Returns pixel content @param [Integer, Integer] pixel position x,y @return [AdbSdkLib::Pixel] pixel content
[ "Returns", "pixel", "content" ]
9f8a5c88ee8e7b572600ca7919b506bfc0e8d105
https://github.com/yoyo0906/ruby-adb-sdklib/blob/9f8a5c88ee8e7b572600ca7919b506bfc0e8d105/lib/adb_sdklib/raw_image.rb#L67-L69
4,636
yoyo0906/ruby-adb-sdklib
lib/adb_sdklib/raw_image.rb
AdbSdkLib.RawImage.each_pixel
def each_pixel() return to_enum :each_pixel unless block_given? @image.height.times do |y| @image.width.times do |x| yield pixel(x,y) end end self end
ruby
def each_pixel() return to_enum :each_pixel unless block_given? @image.height.times do |y| @image.width.times do |x| yield pixel(x,y) end end self end
[ "def", "each_pixel", "(", ")", "return", "to_enum", ":each_pixel", "unless", "block_given?", "@image", ".", "height", ".", "times", "do", "|", "y", "|", "@image", ".", "width", ".", "times", "do", "|", "x", "|", "yield", "pixel", "(", "x", ",", "y", ")", "end", "end", "self", "end" ]
Calls block once for each pixel in data, passing that device as a parameter. If no block is given, an enumerator is returned instead. @return [Enumerator] if not block given @return [self] if block given @yield [pixel] called with each pixel @yieldparam [Pixel] pixel a pixel instance
[ "Calls", "block", "once", "for", "each", "pixel", "in", "data", "passing", "that", "device", "as", "a", "parameter", ".", "If", "no", "block", "is", "given", "an", "enumerator", "is", "returned", "instead", "." ]
9f8a5c88ee8e7b572600ca7919b506bfc0e8d105
https://github.com/yoyo0906/ruby-adb-sdklib/blob/9f8a5c88ee8e7b572600ca7919b506bfc0e8d105/lib/adb_sdklib/raw_image.rb#L77-L85
4,637
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.options
def options {id: self.survey_id, surveyID: self.survey_id, responseID: self.response_id, resultMode: self.result_mode, startDate: self.start_date, userID: self.user_id, endDate: self.end_date, startingResponseCounter: self.starting_response_counter, emailGroupID: self.email_group_id, templateID: self.template_id}.compact.to_json end
ruby
def options {id: self.survey_id, surveyID: self.survey_id, responseID: self.response_id, resultMode: self.result_mode, startDate: self.start_date, userID: self.user_id, endDate: self.end_date, startingResponseCounter: self.starting_response_counter, emailGroupID: self.email_group_id, templateID: self.template_id}.compact.to_json end
[ "def", "options", "{", "id", ":", "self", ".", "survey_id", ",", "surveyID", ":", "self", ".", "survey_id", ",", "responseID", ":", "self", ".", "response_id", ",", "resultMode", ":", "self", ".", "result_mode", ",", "startDate", ":", "self", ".", "start_date", ",", "userID", ":", "self", ".", "user_id", ",", "endDate", ":", "self", ".", "end_date", ",", "startingResponseCounter", ":", "self", ".", "starting_response_counter", ",", "emailGroupID", ":", "self", ".", "email_group_id", ",", "templateID", ":", "self", ".", "template_id", "}", ".", "compact", ".", "to_json", "end" ]
Transform the object to the acceptable json format by questionpro. @return [Json] options in the call request.
[ "Transform", "the", "object", "to", "the", "acceptable", "json", "format", "by", "questionpro", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L56-L61
4,638
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.list_surveys
def list_surveys url = ApiRequest.base_path("questionpro.survey.getAllSurveys") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] surveys = [] result_surveys = result['response']['surveys'] result_surveys.each do |survey| surveys.push(Survey.new(survey)) end return surveys end
ruby
def list_surveys url = ApiRequest.base_path("questionpro.survey.getAllSurveys") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] surveys = [] result_surveys = result['response']['surveys'] result_surveys.each do |survey| surveys.push(Survey.new(survey)) end return surveys end
[ "def", "list_surveys", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.getAllSurveys\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "surveys", "=", "[", "]", "result_surveys", "=", "result", "[", "'response'", "]", "[", "'surveys'", "]", "result_surveys", ".", "each", "do", "|", "survey", "|", "surveys", ".", "push", "(", "Survey", ".", "new", "(", "survey", ")", ")", "end", "return", "surveys", "end" ]
Get all the surveys that belongs to the api key's owner. @return [Array<QuestionproRails::Survey>] Surveys.
[ "Get", "all", "the", "surveys", "that", "belongs", "to", "the", "api", "key", "s", "owner", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L66-L80
4,639
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_survey
def get_survey url = ApiRequest.base_path("questionpro.survey.getSurvey") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] survey = Survey.new(result['response']) return survey end
ruby
def get_survey url = ApiRequest.base_path("questionpro.survey.getSurvey") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] survey = Survey.new(result['response']) return survey end
[ "def", "get_survey", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.getSurvey\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "survey", "=", "Survey", ".", "new", "(", "result", "[", "'response'", "]", ")", "return", "survey", "end" ]
Get a specific survey. Survey ID must be set inside the api request object. @return [QuestionproRails::Survey] Survey.
[ "Get", "a", "specific", "survey", ".", "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L86-L96
4,640
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_survey_responses
def get_survey_responses url = ApiRequest.base_path("questionpro.survey.surveyResponses") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] survey_responses = [] result_responses = result['response']['responses'] result_responses.each do |response| survey_responses.push(SurveyResponse.new(response)) end return survey_responses end
ruby
def get_survey_responses url = ApiRequest.base_path("questionpro.survey.surveyResponses") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] survey_responses = [] result_responses = result['response']['responses'] result_responses.each do |response| survey_responses.push(SurveyResponse.new(response)) end return survey_responses end
[ "def", "get_survey_responses", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.surveyResponses\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "survey_responses", "=", "[", "]", "result_responses", "=", "result", "[", "'response'", "]", "[", "'responses'", "]", "result_responses", ".", "each", "do", "|", "response", "|", "survey_responses", ".", "push", "(", "SurveyResponse", ".", "new", "(", "response", ")", ")", "end", "return", "survey_responses", "end" ]
Get list of survey Responses. Survey ID must be set inside the api request object. @return [Array<QuestionproRails::SurveyResponse>] Survey Responses.
[ "Get", "list", "of", "survey", "Responses", ".", "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L117-L131
4,641
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_survey_reponse
def get_survey_reponse url = ApiRequest.base_path("questionpro.survey.surveyResponse") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] response = SurveyResponse.new(result['response']['surveyResponse']) return response end
ruby
def get_survey_reponse url = ApiRequest.base_path("questionpro.survey.surveyResponse") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] response = SurveyResponse.new(result['response']['surveyResponse']) return response end
[ "def", "get_survey_reponse", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.surveyResponse\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "response", "=", "SurveyResponse", ".", "new", "(", "result", "[", "'response'", "]", "[", "'surveyResponse'", "]", ")", "return", "response", "end" ]
Get a specific survey Response. Survey ID must be set inside the api request object. Response ID must be set inside the api request object. @return [QuestionproRails::SurveyResponse] Survey Response.
[ "Get", "a", "specific", "survey", "Response", ".", "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", ".", "Response", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L138-L148
4,642
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_survey_response_count
def get_survey_response_count url = ApiRequest.base_path("questionpro.survey.responseCount") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] response_count = SurveyResponseCount.new(result['response']) return response_count end
ruby
def get_survey_response_count url = ApiRequest.base_path("questionpro.survey.responseCount") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] response_count = SurveyResponseCount.new(result['response']) return response_count end
[ "def", "get_survey_response_count", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.responseCount\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "response_count", "=", "SurveyResponseCount", ".", "new", "(", "result", "[", "'response'", "]", ")", "return", "response_count", "end" ]
Get a specific survey Response Statistics. Survey ID must be set inside the api request object. @return [QuestionproRails::SurveyResponseCount] Survey Response Statistics.
[ "Get", "a", "specific", "survey", "Response", "Statistics", ".", "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L154-L164
4,643
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.delete_response
def delete_response url = ApiRequest.base_path("questionpro.survey.deleteResponse") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] self.success = result['response']['success'] return self end
ruby
def delete_response url = ApiRequest.base_path("questionpro.survey.deleteResponse") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] self.success = result['response']['success'] return self end
[ "def", "delete_response", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.deleteResponse\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "self", ".", "success", "=", "result", "[", "'response'", "]", "[", "'success'", "]", "return", "self", "end" ]
Delete a specific survey response. Survey ID must be set inside the api request object. Response ID must be set inside the api request object. @return sets ApiRequest success attribute to 1.
[ "Delete", "a", "specific", "survey", "response", ".", "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", ".", "Response", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L171-L180
4,644
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_email_lists
def get_email_lists url = ApiRequest.base_path("questionpro.survey.getEmailLists") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] email_lists = [] result_email_lists = result['response']['emailLists'] result_email_lists.each do |email_list| email_lists.push(EmailList.new(email_list)) end return email_lists end
ruby
def get_email_lists url = ApiRequest.base_path("questionpro.survey.getEmailLists") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] email_lists = [] result_email_lists = result['response']['emailLists'] result_email_lists.each do |email_list| email_lists.push(EmailList.new(email_list)) end return email_lists end
[ "def", "get_email_lists", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.getEmailLists\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "email_lists", "=", "[", "]", "result_email_lists", "=", "result", "[", "'response'", "]", "[", "'emailLists'", "]", "result_email_lists", ".", "each", "do", "|", "email_list", "|", "email_lists", ".", "push", "(", "EmailList", ".", "new", "(", "email_list", ")", ")", "end", "return", "email_lists", "end" ]
Get Email Lists related to a specific survey. Survey ID must be set inside the api request object. @return [Array<QuestionproRails::EmailList>] Email Lists.
[ "Get", "Email", "Lists", "related", "to", "a", "specific", "survey", ".", "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L186-L200
4,645
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_email_list
def get_email_list url = ApiRequest.base_path("questionpro.survey.getEmailList") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] email_list = EmailList.new(result['response']['emailList']) return email_list end
ruby
def get_email_list url = ApiRequest.base_path("questionpro.survey.getEmailList") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] email_list = EmailList.new(result['response']['emailList']) return email_list end
[ "def", "get_email_list", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.getEmailList\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "email_list", "=", "EmailList", ".", "new", "(", "result", "[", "'response'", "]", "[", "'emailList'", "]", ")", "return", "email_list", "end" ]
Get Specific Email List. Email Group ID must be set inside the api request object. @return [QuestionproRails::EmailList] Email List.
[ "Get", "Specific", "Email", "List", ".", "Email", "Group", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L206-L216
4,646
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_email_templates
def get_email_templates url = ApiRequest.base_path("questionpro.survey.getEmailTemplates") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] email_templates = [] result_email_templates = result['response']['emailTemplates'] result_email_templates.each do |email_template| email_templates.push(EmailTemplate.new(email_template)) end return email_templates end
ruby
def get_email_templates url = ApiRequest.base_path("questionpro.survey.getEmailTemplates") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] email_templates = [] result_email_templates = result['response']['emailTemplates'] result_email_templates.each do |email_template| email_templates.push(EmailTemplate.new(email_template)) end return email_templates end
[ "def", "get_email_templates", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.getEmailTemplates\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "email_templates", "=", "[", "]", "result_email_templates", "=", "result", "[", "'response'", "]", "[", "'emailTemplates'", "]", "result_email_templates", ".", "each", "do", "|", "email_template", "|", "email_templates", ".", "push", "(", "EmailTemplate", ".", "new", "(", "email_template", ")", ")", "end", "return", "email_templates", "end" ]
Get Templates related to a specific survey. Survey ID must be set inside the api request object. @return [Array<QuestionproRails::Template>] Templates.
[ "Get", "Templates", "related", "to", "a", "specific", "survey", ".", "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L237-L251
4,647
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_email_template
def get_email_template url = ApiRequest.base_path("questionpro.survey.getEmailTemplate") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] email_template = EmailTemplate.new(result['response']['emailTemplate']) return email_template end
ruby
def get_email_template url = ApiRequest.base_path("questionpro.survey.getEmailTemplate") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] email_template = EmailTemplate.new(result['response']['emailTemplate']) return email_template end
[ "def", "get_email_template", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.getEmailTemplate\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "email_template", "=", "EmailTemplate", ".", "new", "(", "result", "[", "'response'", "]", "[", "'emailTemplate'", "]", ")", "return", "email_template", "end" ]
Get Specific Template. Template ID must be set inside the api request object. @return [QuestionproRails::Template] Template.
[ "Get", "Specific", "Template", ".", "Template", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L257-L267
4,648
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_all_accounts
def get_all_accounts url = ApiRequest.base_path("questionpro.survey.getAllAccounts") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] accounts = [] result_accounts = result['response']['accounts'] result_accounts.each do |account| accounts.push(Account.new(account)) end return accounts end
ruby
def get_all_accounts url = ApiRequest.base_path("questionpro.survey.getAllAccounts") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] accounts = [] result_accounts = result['response']['accounts'] result_accounts.each do |account| accounts.push(Account.new(account)) end return accounts end
[ "def", "get_all_accounts", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.getAllAccounts\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "accounts", "=", "[", "]", "result_accounts", "=", "result", "[", "'response'", "]", "[", "'accounts'", "]", "result_accounts", ".", "each", "do", "|", "account", "|", "accounts", ".", "push", "(", "Account", ".", "new", "(", "account", ")", ")", "end", "return", "accounts", "end" ]
Get all the accounts that belongs to the api key's owner. @return [Array<QuestionproRails::Account>] Accounts.
[ "Get", "all", "the", "accounts", "that", "belongs", "to", "the", "api", "key", "s", "owner", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L287-L301
4,649
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_account
def get_account url = ApiRequest.base_path("questionpro.survey.getAccount") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] account = Account.new(result['response']['account']) return account end
ruby
def get_account url = ApiRequest.base_path("questionpro.survey.getAccount") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] account = Account.new(result['response']['account']) return account end
[ "def", "get_account", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.getAccount\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "account", "=", "Account", ".", "new", "(", "result", "[", "'response'", "]", "[", "'account'", "]", ")", "return", "account", "end" ]
Get Specific Account. User ID must be set inside the api request object. @return [QuestionproRails::Account] Account.
[ "Get", "Specific", "Account", ".", "User", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L307-L317
4,650
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_unsubscribers
def get_unsubscribers url = ApiRequest.base_path("questionpro.survey.getUnsubscribedEmailAddresses") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] unsubscribers = [] result_unsubscribers = result['response']['response'] result_unsubscribers.each do |unsubscriber| unsubscribers.push(UnsubscribedEmail.new(unsubscriber)) end return unsubscribers end
ruby
def get_unsubscribers url = ApiRequest.base_path("questionpro.survey.getUnsubscribedEmailAddresses") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] unsubscribers = [] result_unsubscribers = result['response']['response'] result_unsubscribers.each do |unsubscriber| unsubscribers.push(UnsubscribedEmail.new(unsubscriber)) end return unsubscribers end
[ "def", "get_unsubscribers", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.getUnsubscribedEmailAddresses\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "unsubscribers", "=", "[", "]", "result_unsubscribers", "=", "result", "[", "'response'", "]", "[", "'response'", "]", "result_unsubscribers", ".", "each", "do", "|", "unsubscriber", "|", "unsubscribers", ".", "push", "(", "UnsubscribedEmail", ".", "new", "(", "unsubscriber", ")", ")", "end", "return", "unsubscribers", "end" ]
Get Unsubscribed Emails related to the api key. @return [Array<QuestionproRails::UnsubscribedEmail>] Unsubscribed Emails.
[ "Get", "Unsubscribed", "Emails", "related", "to", "the", "api", "key", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L322-L336
4,651
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_survey_meta
def get_survey_meta url = ApiRequest.base_path("questionpro.survey.sendSurveyMetaData") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] survey_meta = SurveyMeta.new(result['response']) return survey_meta end
ruby
def get_survey_meta url = ApiRequest.base_path("questionpro.survey.sendSurveyMetaData") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] survey_meta = SurveyMeta.new(result['response']) return survey_meta end
[ "def", "get_survey_meta", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.sendSurveyMetaData\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "survey_meta", "=", "SurveyMeta", ".", "new", "(", "result", "[", "'response'", "]", ")", "return", "survey_meta", "end" ]
Survey ID must be set inside the api request object. @return [QuestionproRails::SurveyMeta] Survey meta.
[ "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L341-L351
4,652
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.send_survey
def send_survey(mode = 1, emails = nil, template_id = nil) url = ApiRequest.base_path("questionpro.survey.sendSurvey") result = self.class.get(url, body: {surveyID: self.survey_id, mode: mode, emailGroupID: self.email_group_id, emails: emails, templateID: self.template_id, template: template_id}.compact.to_json) self.full_response = result self.status = result['status'] self.message = result['response']['result'] end
ruby
def send_survey(mode = 1, emails = nil, template_id = nil) url = ApiRequest.base_path("questionpro.survey.sendSurvey") result = self.class.get(url, body: {surveyID: self.survey_id, mode: mode, emailGroupID: self.email_group_id, emails: emails, templateID: self.template_id, template: template_id}.compact.to_json) self.full_response = result self.status = result['status'] self.message = result['response']['result'] end
[ "def", "send_survey", "(", "mode", "=", "1", ",", "emails", "=", "nil", ",", "template_id", "=", "nil", ")", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.sendSurvey\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "{", "surveyID", ":", "self", ".", "survey_id", ",", "mode", ":", "mode", ",", "emailGroupID", ":", "self", ".", "email_group_id", ",", "emails", ":", "emails", ",", "templateID", ":", "self", ".", "template_id", ",", "template", ":", "template_id", "}", ".", "compact", ".", "to_json", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "self", ".", "message", "=", "result", "[", "'response'", "]", "[", "'result'", "]", "end" ]
Send Specific Survey. Survey ID must be set inside the api request object. @param [Integer] mode (1). @param [Array<String>] emails to send to (nil). @param [Integer] template_id of email (nil). @return sets ApiRequest message attribute to "Message successful.".
[ "Send", "Specific", "Survey", ".", "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L360-L369
4,653
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.get_send_history
def get_send_history url = ApiRequest.base_path("questionpro.survey.emailBatchStatistics") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] email_batches = [] result_email_batches = result['response']['emailBatches'] result_email_batches.each do |email_batch| email_batches.push(EmailBatch.new(email_batch)) end return email_batches end
ruby
def get_send_history url = ApiRequest.base_path("questionpro.survey.emailBatchStatistics") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] email_batches = [] result_email_batches = result['response']['emailBatches'] result_email_batches.each do |email_batch| email_batches.push(EmailBatch.new(email_batch)) end return email_batches end
[ "def", "get_send_history", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.emailBatchStatistics\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "email_batches", "=", "[", "]", "result_email_batches", "=", "result", "[", "'response'", "]", "[", "'emailBatches'", "]", "result_email_batches", ".", "each", "do", "|", "email_batch", "|", "email_batches", ".", "push", "(", "EmailBatch", ".", "new", "(", "email_batch", ")", ")", "end", "return", "email_batches", "end" ]
Get Send History related to a specific survey. Survey ID must be set inside the api request object. @return [Array<QuestionproRails::EmailBatch>] Email Batches.
[ "Get", "Send", "History", "related", "to", "a", "specific", "survey", ".", "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L375-L389
4,654
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.send_reminders
def send_reminders url = ApiRequest.base_path("questionpro.survey.sendReminder") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] self.message = result['response']['result'] end
ruby
def send_reminders url = ApiRequest.base_path("questionpro.survey.sendReminder") result = self.class.get(url, body: self.options) self.full_response = result self.status = result['status'] self.message = result['response']['result'] end
[ "def", "send_reminders", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.sendReminder\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "self", ".", "options", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "self", ".", "message", "=", "result", "[", "'response'", "]", "[", "'result'", "]", "end" ]
Send Reminders. Survey ID must be set inside the api request object. Email Group ID must be set inside the api request object. Template ID must be set inside the api request object. @return sets ApiRequest message attribute to "Message successful.".
[ "Send", "Reminders", ".", "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", ".", "Email", "Group", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", ".", "Template", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L397-L404
4,655
AssemDeghady/questionpro_rails
lib/questionpro_rails/api_request.rb
QuestionproRails.ApiRequest.create_email_list
def create_email_list (emails = [], email_group_name = nil) url = ApiRequest.base_path("questionpro.survey.createEmailGroup") result = self.class.get(url, body: {id: self.survey_id, emails: emails, emailGroupName: email_group_name}.compact.to_json) self.full_response = result self.status = result['status'] unless result['response']['result']['emailGroupID'].nil? self.email_group_id = result['response']['result']['emailGroupID'] end end
ruby
def create_email_list (emails = [], email_group_name = nil) url = ApiRequest.base_path("questionpro.survey.createEmailGroup") result = self.class.get(url, body: {id: self.survey_id, emails: emails, emailGroupName: email_group_name}.compact.to_json) self.full_response = result self.status = result['status'] unless result['response']['result']['emailGroupID'].nil? self.email_group_id = result['response']['result']['emailGroupID'] end end
[ "def", "create_email_list", "(", "emails", "=", "[", "]", ",", "email_group_name", "=", "nil", ")", "url", "=", "ApiRequest", ".", "base_path", "(", "\"questionpro.survey.createEmailGroup\"", ")", "result", "=", "self", ".", "class", ".", "get", "(", "url", ",", "body", ":", "{", "id", ":", "self", ".", "survey_id", ",", "emails", ":", "emails", ",", "emailGroupName", ":", "email_group_name", "}", ".", "compact", ".", "to_json", ")", "self", ".", "full_response", "=", "result", "self", ".", "status", "=", "result", "[", "'status'", "]", "unless", "result", "[", "'response'", "]", "[", "'result'", "]", "[", "'emailGroupID'", "]", ".", "nil?", "self", ".", "email_group_id", "=", "result", "[", "'response'", "]", "[", "'result'", "]", "[", "'emailGroupID'", "]", "end", "end" ]
Create Email List. Survey ID must be set inside the api request object. @param [Array<String>] emails ([]). @param [String] email_group_name (nil). @return sets ApiRequest email_group_id to the created email list id.
[ "Create", "Email", "List", ".", "Survey", "ID", "must", "be", "set", "inside", "the", "api", "request", "object", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/api_request.rb#L412-L423
4,656
AssemDeghady/questionpro_rails
lib/questionpro_rails/section.rb
QuestionproRails.Section.questions
def questions extracted_questions = [] unless self.qp_questions.nil? self.qp_questions.each do |question| extracted_questions.push(Question.new(question)) end end return extracted_questions end
ruby
def questions extracted_questions = [] unless self.qp_questions.nil? self.qp_questions.each do |question| extracted_questions.push(Question.new(question)) end end return extracted_questions end
[ "def", "questions", "extracted_questions", "=", "[", "]", "unless", "self", ".", "qp_questions", ".", "nil?", "self", ".", "qp_questions", ".", "each", "do", "|", "question", "|", "extracted_questions", ".", "push", "(", "Question", ".", "new", "(", "question", ")", ")", "end", "end", "return", "extracted_questions", "end" ]
Extract the Questions from the hashes stored inside qp_questions attribute. @return [Array<QuestionproRails::Question>] Questions.
[ "Extract", "the", "Questions", "from", "the", "hashes", "stored", "inside", "qp_questions", "attribute", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/section.rb#L43-L53
4,657
yegor256/xcop
lib/xcop.rb
Xcop.Document.ldiff
def ldiff(license) xml = Nokogiri::XML(File.open(@path), &:noblanks) comment = xml.xpath('/comment()')[0] now = comment.nil? ? '' : comment.text.to_s.strip ideal = license.strip differ(ideal, now) end
ruby
def ldiff(license) xml = Nokogiri::XML(File.open(@path), &:noblanks) comment = xml.xpath('/comment()')[0] now = comment.nil? ? '' : comment.text.to_s.strip ideal = license.strip differ(ideal, now) end
[ "def", "ldiff", "(", "license", ")", "xml", "=", "Nokogiri", "::", "XML", "(", "File", ".", "open", "(", "@path", ")", ",", ":noblanks", ")", "comment", "=", "xml", ".", "xpath", "(", "'/comment()'", ")", "[", "0", "]", "now", "=", "comment", ".", "nil?", "?", "''", ":", "comment", ".", "text", ".", "to_s", ".", "strip", "ideal", "=", "license", ".", "strip", "differ", "(", "ideal", ",", "now", ")", "end" ]
Return the difference for the license.
[ "Return", "the", "difference", "for", "the", "license", "." ]
281a053cb9b96ed9dbcf931271daf716ba10e4b5
https://github.com/yegor256/xcop/blob/281a053cb9b96ed9dbcf931271daf716ba10e4b5/lib/xcop.rb#L84-L90
4,658
yegor256/xcop
lib/xcop.rb
Xcop.Document.fix
def fix(license = '') xml = Nokogiri::XML(File.open(@path), &:noblanks) unless license.empty? xml.xpath('/comment()').remove xml.children.before( Nokogiri::XML::Comment.new(xml, "\n#{license.strip}\n") ) end ideal = xml.to_xml(indent: 2) File.write(@path, ideal) end
ruby
def fix(license = '') xml = Nokogiri::XML(File.open(@path), &:noblanks) unless license.empty? xml.xpath('/comment()').remove xml.children.before( Nokogiri::XML::Comment.new(xml, "\n#{license.strip}\n") ) end ideal = xml.to_xml(indent: 2) File.write(@path, ideal) end
[ "def", "fix", "(", "license", "=", "''", ")", "xml", "=", "Nokogiri", "::", "XML", "(", "File", ".", "open", "(", "@path", ")", ",", ":noblanks", ")", "unless", "license", ".", "empty?", "xml", ".", "xpath", "(", "'/comment()'", ")", ".", "remove", "xml", ".", "children", ".", "before", "(", "Nokogiri", "::", "XML", "::", "Comment", ".", "new", "(", "xml", ",", "\"\\n#{license.strip}\\n\"", ")", ")", "end", "ideal", "=", "xml", ".", "to_xml", "(", "indent", ":", "2", ")", "File", ".", "write", "(", "@path", ",", "ideal", ")", "end" ]
Fixes the document.
[ "Fixes", "the", "document", "." ]
281a053cb9b96ed9dbcf931271daf716ba10e4b5
https://github.com/yegor256/xcop/blob/281a053cb9b96ed9dbcf931271daf716ba10e4b5/lib/xcop.rb#L93-L103
4,659
dwayne/xo
lib/xo/engine/init.rb
XO.Init.start
def start(turn) game_context.check_turn(turn) game_context.set_turn_and_clear_grid(turn) engine.transition_to_state_and_send_event(Playing, :game_started) end
ruby
def start(turn) game_context.check_turn(turn) game_context.set_turn_and_clear_grid(turn) engine.transition_to_state_and_send_event(Playing, :game_started) end
[ "def", "start", "(", "turn", ")", "game_context", ".", "check_turn", "(", "turn", ")", "game_context", ".", "set_turn_and_clear_grid", "(", "turn", ")", "engine", ".", "transition_to_state_and_send_event", "(", "Playing", ",", ":game_started", ")", "end" ]
Starts a new game. The engine is transitioned into the {Playing} state and the event { name: :game_started } is triggered. @param turn [Grid::X, Grid::O] specifies which token has first play @raise [ArgumentError] unless turn is either {Grid::X} or {Grid::O}
[ "Starts", "a", "new", "game", "." ]
bd6524cf8882585fd5cca940f1daa5fb5f75d2bb
https://github.com/dwayne/xo/blob/bd6524cf8882585fd5cca940f1daa5fb5f75d2bb/lib/xo/engine/init.rb#L18-L22
4,660
AssemDeghady/questionpro_rails
lib/questionpro_rails/survey.rb
QuestionproRails.Survey.sections
def sections extracted_sections = [] unless self.qp_sections.nil? self.qp_sections.each do |section| extracted_sections.push(Section.new(section)) end end return extracted_sections end
ruby
def sections extracted_sections = [] unless self.qp_sections.nil? self.qp_sections.each do |section| extracted_sections.push(Section.new(section)) end end return extracted_sections end
[ "def", "sections", "extracted_sections", "=", "[", "]", "unless", "self", ".", "qp_sections", ".", "nil?", "self", ".", "qp_sections", ".", "each", "do", "|", "section", "|", "extracted_sections", ".", "push", "(", "Section", ".", "new", "(", "section", ")", ")", "end", "end", "return", "extracted_sections", "end" ]
Extract the Sections from the hashes stored inside qp_sections attribute. @return [Array<QuestionproRails::Section>] Sections.
[ "Extract", "the", "Sections", "from", "the", "hashes", "stored", "inside", "qp_sections", "attribute", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/survey.rb#L28-L38
4,661
isabanin/mercurial-ruby
lib/mercurial-ruby/commit.rb
Mercurial.Commit.stats
def stats(cmd_options={}) raw = hg(["log -r ? --stat --template '{node}\n'", hash_id], cmd_options) result = raw.scan(/(\d+) files changed, (\d+) insertions\(\+\), (\d+) deletions\(\-\)$/).flatten.map{|r| r.to_i} return {} if result.empty? # that commit has no stats { 'files' => result[0], 'additions' => result[1], 'deletions' => result[2], 'total' => result[1] + result[2] } end
ruby
def stats(cmd_options={}) raw = hg(["log -r ? --stat --template '{node}\n'", hash_id], cmd_options) result = raw.scan(/(\d+) files changed, (\d+) insertions\(\+\), (\d+) deletions\(\-\)$/).flatten.map{|r| r.to_i} return {} if result.empty? # that commit has no stats { 'files' => result[0], 'additions' => result[1], 'deletions' => result[2], 'total' => result[1] + result[2] } end
[ "def", "stats", "(", "cmd_options", "=", "{", "}", ")", "raw", "=", "hg", "(", "[", "\"log -r ? --stat --template '{node}\\n'\"", ",", "hash_id", "]", ",", "cmd_options", ")", "result", "=", "raw", ".", "scan", "(", "/", "\\d", "\\d", "\\(", "\\+", "\\)", "\\d", "\\(", "\\-", "\\)", "/", ")", ".", "flatten", ".", "map", "{", "|", "r", "|", "r", ".", "to_i", "}", "return", "{", "}", "if", "result", ".", "empty?", "# that commit has no stats", "{", "'files'", "=>", "result", "[", "0", "]", ",", "'additions'", "=>", "result", "[", "1", "]", ",", "'deletions'", "=>", "result", "[", "2", "]", ",", "'total'", "=>", "result", "[", "1", "]", "+", "result", "[", "2", "]", "}", "end" ]
Returns a Hash of diffstat-style summary of changes for the commit.
[ "Returns", "a", "Hash", "of", "diffstat", "-", "style", "summary", "of", "changes", "for", "the", "commit", "." ]
d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a
https://github.com/isabanin/mercurial-ruby/blob/d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a/lib/mercurial-ruby/commit.rb#L102-L112
4,662
buren/honey_format
lib/honey_format/matrix/row_builder.rb
HoneyFormat.RowBuilder.build
def build(row) build_row!(row) rescue ArgumentError => e raise unless e.message == 'struct size differs' raise_invalid_row_length!(e, row) end
ruby
def build(row) build_row!(row) rescue ArgumentError => e raise unless e.message == 'struct size differs' raise_invalid_row_length!(e, row) end
[ "def", "build", "(", "row", ")", "build_row!", "(", "row", ")", "rescue", "ArgumentError", "=>", "e", "raise", "unless", "e", ".", "message", "==", "'struct size differs'", "raise_invalid_row_length!", "(", "e", ",", "row", ")", "end" ]
Returns a new instance of RowBuilder. @return [RowBuilder] a new instance of RowBuilder. @param [Array<Symbol>] columns an array of symbols. @param builder [#call, #to_csv] optional row builder. @param type_map [Hash] map of column_name => type conversion to perform. @raise [RowError] super class of errors raised when there is a row error. @raise [EmptyRowColumnsError] raised when there are no columns. @raise [InvalidRowLengthError] raised when row has more columns than header columns. @example Create new row RowBuilder.new!([:id]) Returns an object representing the row. @return [Row, Object] a new instance of built row. @param row [Array] the row array. @raise [InvalidRowLengthError] raised when there are more row elements longer than columns @example Build new row r = RowBuilder.new([:id]) r.build(['1']).id #=> '1'
[ "Returns", "a", "new", "instance", "of", "RowBuilder", "." ]
5c54fba5f5ba044721afeef460a069af2018452c
https://github.com/buren/honey_format/blob/5c54fba5f5ba044721afeef460a069af2018452c/lib/honey_format/matrix/row_builder.rb#L38-L44
4,663
isabanin/mercurial-ruby
lib/mercurial-ruby/config_file.rb
Mercurial.ConfigFile.find_header
def find_header(header) {}.tap do |returning| contents.scan(header_with_content_regexp(header)).flatten.first.split("\n").each do |setting| name, value = *setting.split('=').map(&:strip) returning[name] = value end end end
ruby
def find_header(header) {}.tap do |returning| contents.scan(header_with_content_regexp(header)).flatten.first.split("\n").each do |setting| name, value = *setting.split('=').map(&:strip) returning[name] = value end end end
[ "def", "find_header", "(", "header", ")", "{", "}", ".", "tap", "do", "|", "returning", "|", "contents", ".", "scan", "(", "header_with_content_regexp", "(", "header", ")", ")", ".", "flatten", ".", "first", ".", "split", "(", "\"\\n\"", ")", ".", "each", "do", "|", "setting", "|", "name", ",", "value", "=", "setting", ".", "split", "(", "'='", ")", ".", "map", "(", ":strip", ")", "returning", "[", "name", "]", "=", "value", "end", "end", "end" ]
Returns content of the specified section of hgrc.
[ "Returns", "content", "of", "the", "specified", "section", "of", "hgrc", "." ]
d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a
https://github.com/isabanin/mercurial-ruby/blob/d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a/lib/mercurial-ruby/config_file.rb#L93-L100
4,664
isabanin/mercurial-ruby
lib/mercurial-ruby/config_file.rb
Mercurial.ConfigFile.find_setting
def find_setting(header, setting) #:nodoc: return nil if contents.nil? contents.scan(setting_regexp(header, setting)).flatten.first end
ruby
def find_setting(header, setting) #:nodoc: return nil if contents.nil? contents.scan(setting_regexp(header, setting)).flatten.first end
[ "def", "find_setting", "(", "header", ",", "setting", ")", "#:nodoc:", "return", "nil", "if", "contents", ".", "nil?", "contents", ".", "scan", "(", "setting_regexp", "(", "header", ",", "setting", ")", ")", ".", "flatten", ".", "first", "end" ]
Returns content of the specified setting from a section.
[ "Returns", "content", "of", "the", "specified", "setting", "from", "a", "section", "." ]
d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a
https://github.com/isabanin/mercurial-ruby/blob/d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a/lib/mercurial-ruby/config_file.rb#L105-L108
4,665
isabanin/mercurial-ruby
lib/mercurial-ruby/factories/hook_factory.rb
Mercurial.HookFactory.add
def add(name, value) build(name, value).tap do |hook| hook.save end end
ruby
def add(name, value) build(name, value).tap do |hook| hook.save end end
[ "def", "add", "(", "name", ",", "value", ")", "build", "(", "name", ",", "value", ")", ".", "tap", "do", "|", "hook", "|", "hook", ".", "save", "end", "end" ]
Adds a new hook to the repository. === Example: repository.hooks.add('changegroup', 'do_something')
[ "Adds", "a", "new", "hook", "to", "the", "repository", "." ]
d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a
https://github.com/isabanin/mercurial-ruby/blob/d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a/lib/mercurial-ruby/factories/hook_factory.rb#L47-L51
4,666
couchrest/couchrest_extended_document
lib/couchrest/extended_document.rb
CouchRest.ExtendedDocument.create_without_callbacks
def create_without_callbacks(bulk =false) raise ArgumentError, "a document requires a database to be created to (The document or the #{self.class} default database were not set)" unless database set_unique_id if new? && self.respond_to?(:set_unique_id) result = database.save_doc(self, bulk) (result["ok"] == true) ? self : false end
ruby
def create_without_callbacks(bulk =false) raise ArgumentError, "a document requires a database to be created to (The document or the #{self.class} default database were not set)" unless database set_unique_id if new? && self.respond_to?(:set_unique_id) result = database.save_doc(self, bulk) (result["ok"] == true) ? self : false end
[ "def", "create_without_callbacks", "(", "bulk", "=", "false", ")", "raise", "ArgumentError", ",", "\"a document requires a database to be created to (The document or the #{self.class} default database were not set)\"", "unless", "database", "set_unique_id", "if", "new?", "&&", "self", ".", "respond_to?", "(", ":set_unique_id", ")", "result", "=", "database", ".", "save_doc", "(", "self", ",", "bulk", ")", "(", "result", "[", "\"ok\"", "]", "==", "true", ")", "?", "self", ":", "false", "end" ]
unlike save, create returns the newly created document
[ "unlike", "save", "create", "returns", "the", "newly", "created", "document" ]
71511202ae10d3010dcf7b98fcba017cb37c76da
https://github.com/couchrest/couchrest_extended_document/blob/71511202ae10d3010dcf7b98fcba017cb37c76da/lib/couchrest/extended_document.rb#L185-L190
4,667
acaprojects/doorkeeper-couchbase
lib/support/orm/couchbase/access_token.rb
Doorkeeper.AccessToken.save
def save(**options) if use_refresh_token? options[:ttl] = self.created_at + 6.months else options[:ttl] = self.created_at + self.expires_in + 30 end super(**options) end
ruby
def save(**options) if use_refresh_token? options[:ttl] = self.created_at + 6.months else options[:ttl] = self.created_at + self.expires_in + 30 end super(**options) end
[ "def", "save", "(", "**", "options", ")", "if", "use_refresh_token?", "options", "[", ":ttl", "]", "=", "self", ".", "created_at", "+", "6", ".", "months", "else", "options", "[", ":ttl", "]", "=", "self", ".", "created_at", "+", "self", ".", "expires_in", "+", "30", "end", "super", "(", "**", "options", ")", "end" ]
Lets make sure these keys are not clogging up the database forever
[ "Lets", "make", "sure", "these", "keys", "are", "not", "clogging", "up", "the", "database", "forever" ]
534747e4e58c44805c99a6f2e746de6ffc5c4e59
https://github.com/acaprojects/doorkeeper-couchbase/blob/534747e4e58c44805c99a6f2e746de6ffc5c4e59/lib/support/orm/couchbase/access_token.rb#L212-L219
4,668
buren/honey_format
lib/honey_format/matrix/row.rb
HoneyFormat.Row.to_csv
def to_csv(columns: nil) attributes = members attributes = columns & attributes if columns row = attributes.map! { |column| to_csv_value(column) } ::CSV.generate_line(row) end
ruby
def to_csv(columns: nil) attributes = members attributes = columns & attributes if columns row = attributes.map! { |column| to_csv_value(column) } ::CSV.generate_line(row) end
[ "def", "to_csv", "(", "columns", ":", "nil", ")", "attributes", "=", "members", "attributes", "=", "columns", "&", "attributes", "if", "columns", "row", "=", "attributes", ".", "map!", "{", "|", "column", "|", "to_csv_value", "(", "column", ")", "}", "::", "CSV", ".", "generate_line", "(", "row", ")", "end" ]
Represent row as CSV @param columns [Array<Symbol>, Set<Symbol>, NilClass] the columns to output, nil means all columns (default: nil) @return [String] CSV-string representation.
[ "Represent", "row", "as", "CSV" ]
5c54fba5f5ba044721afeef460a069af2018452c
https://github.com/buren/honey_format/blob/5c54fba5f5ba044721afeef460a069af2018452c/lib/honey_format/matrix/row.rb#L20-L27
4,669
buren/honey_format
lib/honey_format/matrix/row.rb
HoneyFormat.Row.inspect
def inspect attributes = members.map do |field| value = self[field] value = "\"#{value}\"" if value.is_a?(String) [field, value].join('=') end.join(', ') "#<Row #{attributes}>" end
ruby
def inspect attributes = members.map do |field| value = self[field] value = "\"#{value}\"" if value.is_a?(String) [field, value].join('=') end.join(', ') "#<Row #{attributes}>" end
[ "def", "inspect", "attributes", "=", "members", ".", "map", "do", "|", "field", "|", "value", "=", "self", "[", "field", "]", "value", "=", "\"\\\"#{value}\\\"\"", "if", "value", ".", "is_a?", "(", "String", ")", "[", "field", ",", "value", "]", ".", "join", "(", "'='", ")", "end", ".", "join", "(", "', '", ")", "\"#<Row #{attributes}>\"", "end" ]
Describe the contents of this row in a string. @return [String] content of this row
[ "Describe", "the", "contents", "of", "this", "row", "in", "a", "string", "." ]
5c54fba5f5ba044721afeef460a069af2018452c
https://github.com/buren/honey_format/blob/5c54fba5f5ba044721afeef460a069af2018452c/lib/honey_format/matrix/row.rb#L31-L40
4,670
buren/honey_format
lib/honey_format/matrix/row.rb
HoneyFormat.Row.to_csv_value
def to_csv_value(column) value = public_send(column) return if value.nil? return value.to_csv if value.respond_to?(:to_csv) value.to_s end
ruby
def to_csv_value(column) value = public_send(column) return if value.nil? return value.to_csv if value.respond_to?(:to_csv) value.to_s end
[ "def", "to_csv_value", "(", "column", ")", "value", "=", "public_send", "(", "column", ")", "return", "if", "value", ".", "nil?", "return", "value", ".", "to_csv", "if", "value", ".", "respond_to?", "(", ":to_csv", ")", "value", ".", "to_s", "end" ]
Returns the column in CSV format @param [Symbol] column name @return [String] column value as CSV string
[ "Returns", "the", "column", "in", "CSV", "format" ]
5c54fba5f5ba044721afeef460a069af2018452c
https://github.com/buren/honey_format/blob/5c54fba5f5ba044721afeef460a069af2018452c/lib/honey_format/matrix/row.rb#L48-L54
4,671
isabanin/mercurial-ruby
lib/mercurial-ruby/file_index.rb
Mercurial.FileIndex.update
def update(oldrev=nil, newrev=nil) if index_file_exists? && oldrev != "0"*40 hg([ "log --debug -r ?:? --style ? >> ?", oldrev, newrev, Style.file_index, path ]) else hg(["log --debug -r : --style ? > ?", Style.file_index, path]) end end
ruby
def update(oldrev=nil, newrev=nil) if index_file_exists? && oldrev != "0"*40 hg([ "log --debug -r ?:? --style ? >> ?", oldrev, newrev, Style.file_index, path ]) else hg(["log --debug -r : --style ? > ?", Style.file_index, path]) end end
[ "def", "update", "(", "oldrev", "=", "nil", ",", "newrev", "=", "nil", ")", "if", "index_file_exists?", "&&", "oldrev", "!=", "\"0\"", "*", "40", "hg", "(", "[", "\"log --debug -r ?:? --style ? >> ?\"", ",", "oldrev", ",", "newrev", ",", "Style", ".", "file_index", ",", "path", "]", ")", "else", "hg", "(", "[", "\"log --debug -r : --style ? > ?\"", ",", "Style", ".", "file_index", ",", "path", "]", ")", "end", "end" ]
updates file index
[ "updates", "file", "index" ]
d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a
https://github.com/isabanin/mercurial-ruby/blob/d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a/lib/mercurial-ruby/file_index.rb#L37-L46
4,672
isabanin/mercurial-ruby
lib/mercurial-ruby/file_index.rb
Mercurial.FileIndex.commits_from
def commits_from(commit_sha) raise UnsupportedRef if commit_sha.is_a? Array read_if_needed already = {} final = [] left_to_do = [commit_sha] while commit_sha = left_to_do.shift next if already[commit_sha] final << commit_sha already[commit_sha] = true commit = @commit_index[commit_sha] commit[:parents].each do |sha| left_to_do << sha end if commit end sort_commits(final) end
ruby
def commits_from(commit_sha) raise UnsupportedRef if commit_sha.is_a? Array read_if_needed already = {} final = [] left_to_do = [commit_sha] while commit_sha = left_to_do.shift next if already[commit_sha] final << commit_sha already[commit_sha] = true commit = @commit_index[commit_sha] commit[:parents].each do |sha| left_to_do << sha end if commit end sort_commits(final) end
[ "def", "commits_from", "(", "commit_sha", ")", "raise", "UnsupportedRef", "if", "commit_sha", ".", "is_a?", "Array", "read_if_needed", "already", "=", "{", "}", "final", "=", "[", "]", "left_to_do", "=", "[", "commit_sha", "]", "while", "commit_sha", "=", "left_to_do", ".", "shift", "next", "if", "already", "[", "commit_sha", "]", "final", "<<", "commit_sha", "already", "[", "commit_sha", "]", "=", "true", "commit", "=", "@commit_index", "[", "commit_sha", "]", "commit", "[", ":parents", "]", ".", "each", "do", "|", "sha", "|", "left_to_do", "<<", "sha", "end", "if", "commit", "end", "sort_commits", "(", "final", ")", "end" ]
builds a list of all commits reachable from a single commit
[ "builds", "a", "list", "of", "all", "commits", "reachable", "from", "a", "single", "commit" ]
d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a
https://github.com/isabanin/mercurial-ruby/blob/d7cc2d3bfeaa7564f6ea8d622fbddd92ca5a3d0a/lib/mercurial-ruby/file_index.rb#L63-L84
4,673
couchrest/couchrest_extended_document
lib/couchrest/casted_model.rb
CouchRest.CastedModel.update_attributes_without_saving
def update_attributes_without_saving(hash) hash.each do |k, v| raise NoMethodError, "#{k}= method not available, use property :#{k}" unless self.respond_to?("#{k}=") end hash.each do |k, v| self.send("#{k}=",v) end end
ruby
def update_attributes_without_saving(hash) hash.each do |k, v| raise NoMethodError, "#{k}= method not available, use property :#{k}" unless self.respond_to?("#{k}=") end hash.each do |k, v| self.send("#{k}=",v) end end
[ "def", "update_attributes_without_saving", "(", "hash", ")", "hash", ".", "each", "do", "|", "k", ",", "v", "|", "raise", "NoMethodError", ",", "\"#{k}= method not available, use property :#{k}\"", "unless", "self", ".", "respond_to?", "(", "\"#{k}=\"", ")", "end", "hash", ".", "each", "do", "|", "k", ",", "v", "|", "self", ".", "send", "(", "\"#{k}=\"", ",", "v", ")", "end", "end" ]
Sets the attributes from a hash
[ "Sets", "the", "attributes", "from", "a", "hash" ]
71511202ae10d3010dcf7b98fcba017cb37c76da
https://github.com/couchrest/couchrest_extended_document/blob/71511202ae10d3010dcf7b98fcba017cb37c76da/lib/couchrest/casted_model.rb#L42-L49
4,674
mjy/obo_parser
lib/obo_parser.rb
OboParser.OboParser.term_hash
def term_hash @terms.inject({}) {|sum, t| sum.update(t.name.value => t.id.value)} end
ruby
def term_hash @terms.inject({}) {|sum, t| sum.update(t.name.value => t.id.value)} end
[ "def", "term_hash", "@terms", ".", "inject", "(", "{", "}", ")", "{", "|", "sum", ",", "t", "|", "sum", ".", "update", "(", "t", ".", "name", ".", "value", "=>", "t", ".", "id", ".", "value", ")", "}", "end" ]
Warning! This assumes terms are unique, they are NOT required to be so in an OBO file. Ignores hash colisions!! @return [Hash] (String => String) (name => id)
[ "Warning!", "This", "assumes", "terms", "are", "unique", "they", "are", "NOT", "required", "to", "be", "so", "in", "an", "OBO", "file", ".", "Ignores", "hash", "colisions!!" ]
f81757b512f3557277909c46372ab89a42704722
https://github.com/mjy/obo_parser/blob/f81757b512f3557277909c46372ab89a42704722/lib/obo_parser.rb#L32-L34
4,675
AssemDeghady/questionpro_rails
lib/questionpro_rails/response_set.rb
QuestionproRails.ResponseSet.answers
def answers extracted_answers = [] unless self.qp_values.nil? self.qp_values.each do |answer| extracted_answers.push(ResponseAnswer.new(answer)) end end return extracted_answers end
ruby
def answers extracted_answers = [] unless self.qp_values.nil? self.qp_values.each do |answer| extracted_answers.push(ResponseAnswer.new(answer)) end end return extracted_answers end
[ "def", "answers", "extracted_answers", "=", "[", "]", "unless", "self", ".", "qp_values", ".", "nil?", "self", ".", "qp_values", ".", "each", "do", "|", "answer", "|", "extracted_answers", ".", "push", "(", "ResponseAnswer", ".", "new", "(", "answer", ")", ")", "end", "end", "return", "extracted_answers", "end" ]
Extract the Answers from the hashes stored inside qp_values attribute. @return [Array<QuestionproRails::ResponseAnswer>] Response Answers.
[ "Extract", "the", "Answers", "from", "the", "hashes", "stored", "inside", "qp_values", "attribute", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/response_set.rb#L23-L33
4,676
Tapjoy/acts_as_approvable
lib/acts_as_approvable/model.rb
ActsAsApprovable.Model.acts_as_approvable
def acts_as_approvable(options = {}) extend ClassMethods include InstanceMethods cattr_accessor :approvable_on self.approvable_on = Array.wrap(options.delete(:on) { [:create, :update, :destroy] }) cattr_accessor :approvable_field self.approvable_field = options.delete(:state_field) cattr_accessor :approvable_ignore ignores = Array.wrap(options.delete(:ignore) { [] }) ignores.push('created_at', 'updated_at', primary_key, self.approvable_field) self.approvable_ignore = ignores.compact.uniq.map(&:to_s) cattr_accessor :approvable_only self.approvable_only = Array.wrap(options.delete(:only) { [] }).uniq.map(&:to_s) cattr_accessor :approvals_disabled self.approvals_disabled = false has_many :approvals, :as => :item, :dependent => :destroy if approvable_on?(:update) include UpdateInstanceMethods before_update :approvable_update, :if => :approvable_update? end if approvable_on?(:create) include CreateInstanceMethods before_create :approvable_create, :if => :approvable_create? end if approvable_on?(:destroy) include DestroyInstanceMethods end after_save :approvable_save, :if => :approvals_enabled? end
ruby
def acts_as_approvable(options = {}) extend ClassMethods include InstanceMethods cattr_accessor :approvable_on self.approvable_on = Array.wrap(options.delete(:on) { [:create, :update, :destroy] }) cattr_accessor :approvable_field self.approvable_field = options.delete(:state_field) cattr_accessor :approvable_ignore ignores = Array.wrap(options.delete(:ignore) { [] }) ignores.push('created_at', 'updated_at', primary_key, self.approvable_field) self.approvable_ignore = ignores.compact.uniq.map(&:to_s) cattr_accessor :approvable_only self.approvable_only = Array.wrap(options.delete(:only) { [] }).uniq.map(&:to_s) cattr_accessor :approvals_disabled self.approvals_disabled = false has_many :approvals, :as => :item, :dependent => :destroy if approvable_on?(:update) include UpdateInstanceMethods before_update :approvable_update, :if => :approvable_update? end if approvable_on?(:create) include CreateInstanceMethods before_create :approvable_create, :if => :approvable_create? end if approvable_on?(:destroy) include DestroyInstanceMethods end after_save :approvable_save, :if => :approvals_enabled? end
[ "def", "acts_as_approvable", "(", "options", "=", "{", "}", ")", "extend", "ClassMethods", "include", "InstanceMethods", "cattr_accessor", ":approvable_on", "self", ".", "approvable_on", "=", "Array", ".", "wrap", "(", "options", ".", "delete", "(", ":on", ")", "{", "[", ":create", ",", ":update", ",", ":destroy", "]", "}", ")", "cattr_accessor", ":approvable_field", "self", ".", "approvable_field", "=", "options", ".", "delete", "(", ":state_field", ")", "cattr_accessor", ":approvable_ignore", "ignores", "=", "Array", ".", "wrap", "(", "options", ".", "delete", "(", ":ignore", ")", "{", "[", "]", "}", ")", "ignores", ".", "push", "(", "'created_at'", ",", "'updated_at'", ",", "primary_key", ",", "self", ".", "approvable_field", ")", "self", ".", "approvable_ignore", "=", "ignores", ".", "compact", ".", "uniq", ".", "map", "(", ":to_s", ")", "cattr_accessor", ":approvable_only", "self", ".", "approvable_only", "=", "Array", ".", "wrap", "(", "options", ".", "delete", "(", ":only", ")", "{", "[", "]", "}", ")", ".", "uniq", ".", "map", "(", ":to_s", ")", "cattr_accessor", ":approvals_disabled", "self", ".", "approvals_disabled", "=", "false", "has_many", ":approvals", ",", ":as", "=>", ":item", ",", ":dependent", "=>", ":destroy", "if", "approvable_on?", "(", ":update", ")", "include", "UpdateInstanceMethods", "before_update", ":approvable_update", ",", ":if", "=>", ":approvable_update?", "end", "if", "approvable_on?", "(", ":create", ")", "include", "CreateInstanceMethods", "before_create", ":approvable_create", ",", ":if", "=>", ":approvable_create?", "end", "if", "approvable_on?", "(", ":destroy", ")", "include", "DestroyInstanceMethods", "end", "after_save", ":approvable_save", ",", ":if", "=>", ":approvals_enabled?", "end" ]
Declare this in your model to require approval on new records or changes to fields. @param [Hash] options the options for this models approval workflow. @option options [Symbol,Array] :on The events to require approval on (`:create`, `:update` or `:destroy`). @option options [String] :state_field The local field to store `:create` approval state. @option options [Array] :ignore A list of fields to ignore. By default we ignore `:created_at`, `:updated_at` and the field specified in `:state_field`. @option options [Array] :only A list of fields to explicitly require approval on. This list supercedes `:ignore`.
[ "Declare", "this", "in", "your", "model", "to", "require", "approval", "on", "new", "records", "or", "changes", "to", "fields", "." ]
5113ba6fd2a05a1cc95bd657519f3334c596eed5
https://github.com/Tapjoy/acts_as_approvable/blob/5113ba6fd2a05a1cc95bd657519f3334c596eed5/lib/acts_as_approvable/model.rb#L20-L58
4,677
jrochkind/traject_horizon
lib/traject/horizon_reader.rb
Traject.HorizonReader.require_jars!
def require_jars! require 'jruby' # ask marc-marc4j gem to load the marc4j jars MARC::MARC4J.new(:jardir => settings['marc4j_reader.jar_dir']) # For some reason we seem to need to java_import it, and use # a string like this. can't just refer to it by full # qualified name, not sure why, but this seems to work. java_import "org.marc4j.converter.impl.AnselToUnicode" unless defined? Java::net.sourceforge.jtds.jdbc.Driver jtds_jar_dir = settings["jtds.jar_path"] || File.expand_path("../../vendor/jtds", File.dirname(__FILE__)) Dir.glob("#{jtds_jar_dir}/*.jar") do |x| require x end # For confusing reasons, in normal Java need to # Class.forName("net.sourceforge.jtds.jdbc.Driver") # to get the jtds driver to actually be recognized by JDBC. # # In Jruby, Class.forName doesn't work, but this seems # to do the same thing: Java::net.sourceforge.jtds.jdbc.Driver end # So we can refer to these classes as just ResultSet, etc. java_import java.sql.ResultSet, java.sql.PreparedStatement, java.sql.Driver end
ruby
def require_jars! require 'jruby' # ask marc-marc4j gem to load the marc4j jars MARC::MARC4J.new(:jardir => settings['marc4j_reader.jar_dir']) # For some reason we seem to need to java_import it, and use # a string like this. can't just refer to it by full # qualified name, not sure why, but this seems to work. java_import "org.marc4j.converter.impl.AnselToUnicode" unless defined? Java::net.sourceforge.jtds.jdbc.Driver jtds_jar_dir = settings["jtds.jar_path"] || File.expand_path("../../vendor/jtds", File.dirname(__FILE__)) Dir.glob("#{jtds_jar_dir}/*.jar") do |x| require x end # For confusing reasons, in normal Java need to # Class.forName("net.sourceforge.jtds.jdbc.Driver") # to get the jtds driver to actually be recognized by JDBC. # # In Jruby, Class.forName doesn't work, but this seems # to do the same thing: Java::net.sourceforge.jtds.jdbc.Driver end # So we can refer to these classes as just ResultSet, etc. java_import java.sql.ResultSet, java.sql.PreparedStatement, java.sql.Driver end
[ "def", "require_jars!", "require", "'jruby'", "# ask marc-marc4j gem to load the marc4j jars", "MARC", "::", "MARC4J", ".", "new", "(", ":jardir", "=>", "settings", "[", "'marc4j_reader.jar_dir'", "]", ")", "# For some reason we seem to need to java_import it, and use", "# a string like this. can't just refer to it by full", "# qualified name, not sure why, but this seems to work.", "java_import", "\"org.marc4j.converter.impl.AnselToUnicode\"", "unless", "defined?", "Java", "::", "net", ".", "sourceforge", ".", "jtds", ".", "jdbc", ".", "Driver", "jtds_jar_dir", "=", "settings", "[", "\"jtds.jar_path\"", "]", "||", "File", ".", "expand_path", "(", "\"../../vendor/jtds\"", ",", "File", ".", "dirname", "(", "__FILE__", ")", ")", "Dir", ".", "glob", "(", "\"#{jtds_jar_dir}/*.jar\"", ")", "do", "|", "x", "|", "require", "x", "end", "# For confusing reasons, in normal Java need to", "# Class.forName(\"net.sourceforge.jtds.jdbc.Driver\")", "# to get the jtds driver to actually be recognized by JDBC.", "#", "# In Jruby, Class.forName doesn't work, but this seems", "# to do the same thing:", "Java", "::", "net", ".", "sourceforge", ".", "jtds", ".", "jdbc", ".", "Driver", "end", "# So we can refer to these classes as just ResultSet, etc.", "java_import", "java", ".", "sql", ".", "ResultSet", ",", "java", ".", "sql", ".", "PreparedStatement", ",", "java", ".", "sql", ".", "Driver", "end" ]
We ignore the iostream even though we get one, we're gonna read from a Horizon DB! Requires marc4j and jtds, and java_import's some classes.
[ "We", "ignore", "the", "iostream", "even", "though", "we", "get", "one", "we", "re", "gonna", "read", "from", "a", "Horizon", "DB!", "Requires", "marc4j", "and", "jtds", "and", "java_import", "s", "some", "classes", "." ]
f56f1785fccfb2cb123ce3100a3051fca4db39ac
https://github.com/jrochkind/traject_horizon/blob/f56f1785fccfb2cb123ce3100a3051fca4db39ac/lib/traject/horizon_reader.rb#L161-L190
4,678
jrochkind/traject_horizon
lib/traject/horizon_reader.rb
Traject.HorizonReader.convert_text!
def convert_text!(text, error_handler) text = AnselToUnicode.new(error_handler, true).convert(text) if convert_marc8_to_utf8? # Turn Horizon's weird escaping into UTF8: <U+nnnn> where nnnn is a hex unicode # codepoint, turn it UTF8 for that codepoint if settings["horizon.destination_encoding"] == "UTF8" && (settings["horizon.codepoint_translate"].to_s == "true" || settings["horizon.character_reference_translate"].to_s == "true") regexp = if settings["horizon.codepoint_translate"].to_s == "true" && settings["horizon.character_reference_translate"].to_s == "true" # unicode codepoint in either HTML char reference form OR # weird horizon form. /(?:\<U\+|&#x)([0-9A-Fa-f]{4})(?:\>|;)/ elsif settings["horizon.codepoint_translate"].to_s == "true" # just weird horizon form /\<U\+([0-9A-Fa-f]{4})\>/ else # just character references /&#x([0-9A-Fa-f]{4});/ end text.gsub!(regexp) do [$1.hex].pack("U") end end # eliminate illegal control chars. All ASCII less than 0x20 # _except_ for four legal ones (including MARC delimiters). # http://www.loc.gov/marc/specifications/specchargeneral.html#controlfunction # this is all bytes from 0x00 to 0x19 except for the allowed 1B, 1D, 1E, 1F. text.gsub!(/[\x00-\x1A\x1C]/, '') return text end
ruby
def convert_text!(text, error_handler) text = AnselToUnicode.new(error_handler, true).convert(text) if convert_marc8_to_utf8? # Turn Horizon's weird escaping into UTF8: <U+nnnn> where nnnn is a hex unicode # codepoint, turn it UTF8 for that codepoint if settings["horizon.destination_encoding"] == "UTF8" && (settings["horizon.codepoint_translate"].to_s == "true" || settings["horizon.character_reference_translate"].to_s == "true") regexp = if settings["horizon.codepoint_translate"].to_s == "true" && settings["horizon.character_reference_translate"].to_s == "true" # unicode codepoint in either HTML char reference form OR # weird horizon form. /(?:\<U\+|&#x)([0-9A-Fa-f]{4})(?:\>|;)/ elsif settings["horizon.codepoint_translate"].to_s == "true" # just weird horizon form /\<U\+([0-9A-Fa-f]{4})\>/ else # just character references /&#x([0-9A-Fa-f]{4});/ end text.gsub!(regexp) do [$1.hex].pack("U") end end # eliminate illegal control chars. All ASCII less than 0x20 # _except_ for four legal ones (including MARC delimiters). # http://www.loc.gov/marc/specifications/specchargeneral.html#controlfunction # this is all bytes from 0x00 to 0x19 except for the allowed 1B, 1D, 1E, 1F. text.gsub!(/[\x00-\x1A\x1C]/, '') return text end
[ "def", "convert_text!", "(", "text", ",", "error_handler", ")", "text", "=", "AnselToUnicode", ".", "new", "(", "error_handler", ",", "true", ")", ".", "convert", "(", "text", ")", "if", "convert_marc8_to_utf8?", "# Turn Horizon's weird escaping into UTF8: <U+nnnn> where nnnn is a hex unicode", "# codepoint, turn it UTF8 for that codepoint", "if", "settings", "[", "\"horizon.destination_encoding\"", "]", "==", "\"UTF8\"", "&&", "(", "settings", "[", "\"horizon.codepoint_translate\"", "]", ".", "to_s", "==", "\"true\"", "||", "settings", "[", "\"horizon.character_reference_translate\"", "]", ".", "to_s", "==", "\"true\"", ")", "regexp", "=", "if", "settings", "[", "\"horizon.codepoint_translate\"", "]", ".", "to_s", "==", "\"true\"", "&&", "settings", "[", "\"horizon.character_reference_translate\"", "]", ".", "to_s", "==", "\"true\"", "# unicode codepoint in either HTML char reference form OR", "# weird horizon form. ", "/", "\\<", "\\+", "\\>", "/", "elsif", "settings", "[", "\"horizon.codepoint_translate\"", "]", ".", "to_s", "==", "\"true\"", "# just weird horizon form", "/", "\\<", "\\+", "\\>", "/", "else", "# just character references", "/", "/", "end", "text", ".", "gsub!", "(", "regexp", ")", "do", "[", "$1", ".", "hex", "]", ".", "pack", "(", "\"U\"", ")", "end", "end", "# eliminate illegal control chars. All ASCII less than 0x20", "# _except_ for four legal ones (including MARC delimiters). ", "# http://www.loc.gov/marc/specifications/specchargeneral.html#controlfunction", "# this is all bytes from 0x00 to 0x19 except for the allowed 1B, 1D, 1E, 1F. ", "text", ".", "gsub!", "(", "/", "\\x00", "\\x1A", "\\x1C", "/", ",", "''", ")", "return", "text", "end" ]
Converts from Marc8 to UTF8 if neccesary. Also replaces escaped unicode codepoints using custom Horizon "<U+nnnn>" format Or standard MARC 'lossless encoding' "&#xHHHH;" format.
[ "Converts", "from", "Marc8", "to", "UTF8", "if", "neccesary", "." ]
f56f1785fccfb2cb123ce3100a3051fca4db39ac
https://github.com/jrochkind/traject_horizon/blob/f56f1785fccfb2cb123ce3100a3051fca4db39ac/lib/traject/horizon_reader.rb#L275-L307
4,679
jrochkind/traject_horizon
lib/traject/horizon_reader.rb
Traject.HorizonReader.fix_leader!
def fix_leader!(leader) if leader.length < 24 # pad it to 24 bytes, leader is supposed to be 24 bytes leader.replace( leader.ljust(24, ' ') ) elsif leader.length > 24 # Also a problem, slice it leader.replace( leader.byteslice(0, 24)) end # http://www.loc.gov/marc/bibliographic/ecbdldrd.html leader[10..11] = '22' leader[20..23] = '4500' if settings['horizon.destination_encoding'] == "UTF8" leader[9] = 'a' end # leader should only have ascii chars in it; invalid non-ascii # chars can cause ruby encoding problems down the line. # additionally, a force_encoding may be neccesary to # deal with apparent weird hard to isolate jruby bug prob same one # as at https://github.com/jruby/jruby/issues/886 leader.force_encoding('ascii') unless leader.valid_encoding? # replace any non-ascii chars with a space. # Can't access leader.chars when it's not a valid encoding # without a weird index out of bounds exception, think it's # https://github.com/jruby/jruby/issues/886 # Grr. #leader.replace( leader.chars.collect { |c| c.valid_encoding? ? c : ' ' }.join('') ) leader.replace(leader.split('').collect { |c| c.valid_encoding? ? c : ' ' }.join('')) end end
ruby
def fix_leader!(leader) if leader.length < 24 # pad it to 24 bytes, leader is supposed to be 24 bytes leader.replace( leader.ljust(24, ' ') ) elsif leader.length > 24 # Also a problem, slice it leader.replace( leader.byteslice(0, 24)) end # http://www.loc.gov/marc/bibliographic/ecbdldrd.html leader[10..11] = '22' leader[20..23] = '4500' if settings['horizon.destination_encoding'] == "UTF8" leader[9] = 'a' end # leader should only have ascii chars in it; invalid non-ascii # chars can cause ruby encoding problems down the line. # additionally, a force_encoding may be neccesary to # deal with apparent weird hard to isolate jruby bug prob same one # as at https://github.com/jruby/jruby/issues/886 leader.force_encoding('ascii') unless leader.valid_encoding? # replace any non-ascii chars with a space. # Can't access leader.chars when it's not a valid encoding # without a weird index out of bounds exception, think it's # https://github.com/jruby/jruby/issues/886 # Grr. #leader.replace( leader.chars.collect { |c| c.valid_encoding? ? c : ' ' }.join('') ) leader.replace(leader.split('').collect { |c| c.valid_encoding? ? c : ' ' }.join('')) end end
[ "def", "fix_leader!", "(", "leader", ")", "if", "leader", ".", "length", "<", "24", "# pad it to 24 bytes, leader is supposed to be 24 bytes", "leader", ".", "replace", "(", "leader", ".", "ljust", "(", "24", ",", "' '", ")", ")", "elsif", "leader", ".", "length", ">", "24", "# Also a problem, slice it", "leader", ".", "replace", "(", "leader", ".", "byteslice", "(", "0", ",", "24", ")", ")", "end", "# http://www.loc.gov/marc/bibliographic/ecbdldrd.html", "leader", "[", "10", "..", "11", "]", "=", "'22'", "leader", "[", "20", "..", "23", "]", "=", "'4500'", "if", "settings", "[", "'horizon.destination_encoding'", "]", "==", "\"UTF8\"", "leader", "[", "9", "]", "=", "'a'", "end", "# leader should only have ascii chars in it; invalid non-ascii", "# chars can cause ruby encoding problems down the line.", "# additionally, a force_encoding may be neccesary to", "# deal with apparent weird hard to isolate jruby bug prob same one", "# as at https://github.com/jruby/jruby/issues/886", "leader", ".", "force_encoding", "(", "'ascii'", ")", "unless", "leader", ".", "valid_encoding?", "# replace any non-ascii chars with a space.", "# Can't access leader.chars when it's not a valid encoding", "# without a weird index out of bounds exception, think it's", "# https://github.com/jruby/jruby/issues/886", "# Grr.", "#leader.replace( leader.chars.collect { |c| c.valid_encoding? ? c : ' ' }.join('') )", "leader", ".", "replace", "(", "leader", ".", "split", "(", "''", ")", ".", "collect", "{", "|", "c", "|", "c", ".", "valid_encoding?", "?", "c", ":", "' '", "}", ".", "join", "(", "''", ")", ")", "end", "end" ]
Mutate string passed in to fix leader bytes for marc21
[ "Mutate", "string", "passed", "in", "to", "fix", "leader", "bytes", "for", "marc21" ]
f56f1785fccfb2cb123ce3100a3051fca4db39ac
https://github.com/jrochkind/traject_horizon/blob/f56f1785fccfb2cb123ce3100a3051fca4db39ac/lib/traject/horizon_reader.rb#L633-L671
4,680
arjunmenon/smalltext
lib/smalltext.rb
Smalltext.Classifier.softmax
def softmax(w) e = Numo::NMath.exp(w - (w.max)) dist = e / (e.sum) return dist end
ruby
def softmax(w) e = Numo::NMath.exp(w - (w.max)) dist = e / (e.sum) return dist end
[ "def", "softmax", "(", "w", ")", "e", "=", "Numo", "::", "NMath", ".", "exp", "(", "w", "-", "(", "w", ".", "max", ")", ")", "dist", "=", "e", "/", "(", "e", ".", "sum", ")", "return", "dist", "end" ]
using softmax as output layer is recommended for classification where outputs are mutually exclusive
[ "using", "softmax", "as", "output", "layer", "is", "recommended", "for", "classification", "where", "outputs", "are", "mutually", "exclusive" ]
0d208f70d0300ac7a5a375568a7457fb2a6bbd9a
https://github.com/arjunmenon/smalltext/blob/0d208f70d0300ac7a5a375568a7457fb2a6bbd9a/lib/smalltext.rb#L329-L333
4,681
wingrunr21/gitolite
lib/gitolite/config.rb
Gitolite.Config.normalize_name
def normalize_name(context, constant = nil) case context when constant context.name when Symbol context.to_s else context end end
ruby
def normalize_name(context, constant = nil) case context when constant context.name when Symbol context.to_s else context end end
[ "def", "normalize_name", "(", "context", ",", "constant", "=", "nil", ")", "case", "context", "when", "constant", "context", ".", "name", "when", "Symbol", "context", ".", "to_s", "else", "context", "end", "end" ]
Normalizes the various different input objects to Strings
[ "Normalizes", "the", "various", "different", "input", "objects", "to", "Strings" ]
f86ec83e0885734000432b9502ccaa2dc26f4376
https://github.com/wingrunr21/gitolite/blob/f86ec83e0885734000432b9502ccaa2dc26f4376/lib/gitolite/config.rb#L192-L201
4,682
murakmii/cborb
lib/cborb/decoding/state.rb
Cborb::Decoding.State.<<
def <<(cbor) @buffer.write(cbor) @decoding_fiber.resume rescue FiberError => e msg = e.message # umm... if msg.include?("dead") raise Cborb::InvalidByteSequenceError elsif msg.include?("threads") raise Cborb::DecodingError, "Can't decode across threads" else raise end end
ruby
def <<(cbor) @buffer.write(cbor) @decoding_fiber.resume rescue FiberError => e msg = e.message # umm... if msg.include?("dead") raise Cborb::InvalidByteSequenceError elsif msg.include?("threads") raise Cborb::DecodingError, "Can't decode across threads" else raise end end
[ "def", "<<", "(", "cbor", ")", "@buffer", ".", "write", "(", "cbor", ")", "@decoding_fiber", ".", "resume", "rescue", "FiberError", "=>", "e", "msg", "=", "e", ".", "message", "# umm...", "if", "msg", ".", "include?", "(", "\"dead\"", ")", "raise", "Cborb", "::", "InvalidByteSequenceError", "elsif", "msg", ".", "include?", "(", "\"threads\"", ")", "raise", "Cborb", "::", "DecodingError", ",", "\"Can't decode across threads\"", "else", "raise", "end", "end" ]
Buffering new CBOR data @param [String] cbor
[ "Buffering", "new", "CBOR", "data" ]
ea4763ff815889f31e19375db8284d9337d409eb
https://github.com/murakmii/cborb/blob/ea4763ff815889f31e19375db8284d9337d409eb/lib/cborb/decoding/state.rb#L21-L36
4,683
murakmii/cborb
lib/cborb/decoding/state.rb
Cborb::Decoding.State.consume
def consume(size) data = @buffer.read(size).to_s # If buffered data is not enought, yield fiber until new data will be buffered. if data.size < size @buffer.reset! while data.size != size Fiber.yield data += @buffer.read(size - data.size) end end data end
ruby
def consume(size) data = @buffer.read(size).to_s # If buffered data is not enought, yield fiber until new data will be buffered. if data.size < size @buffer.reset! while data.size != size Fiber.yield data += @buffer.read(size - data.size) end end data end
[ "def", "consume", "(", "size", ")", "data", "=", "@buffer", ".", "read", "(", "size", ")", ".", "to_s", "# If buffered data is not enought, yield fiber until new data will be buffered.", "if", "data", ".", "size", "<", "size", "@buffer", ".", "reset!", "while", "data", ".", "size", "!=", "size", "Fiber", ".", "yield", "data", "+=", "@buffer", ".", "read", "(", "size", "-", "data", ".", "size", ")", "end", "end", "data", "end" ]
Consume CBOR data. This method will be called only in fiber. @param [Integer] size Size to consume @return [String]
[ "Consume", "CBOR", "data", ".", "This", "method", "will", "be", "called", "only", "in", "fiber", "." ]
ea4763ff815889f31e19375db8284d9337d409eb
https://github.com/murakmii/cborb/blob/ea4763ff815889f31e19375db8284d9337d409eb/lib/cborb/decoding/state.rb#L43-L57
4,684
AssemDeghady/questionpro_rails
lib/questionpro_rails/survey_meta.rb
QuestionproRails.SurveyMeta.email_groups
def email_groups extracted_groups = [] unless self.email_groups_list.nil? self.email_groups_list.each do |email_group| extracted_groups.push(EmailGroup.new(email_group)) end end return extracted_groups end
ruby
def email_groups extracted_groups = [] unless self.email_groups_list.nil? self.email_groups_list.each do |email_group| extracted_groups.push(EmailGroup.new(email_group)) end end return extracted_groups end
[ "def", "email_groups", "extracted_groups", "=", "[", "]", "unless", "self", ".", "email_groups_list", ".", "nil?", "self", ".", "email_groups_list", ".", "each", "do", "|", "email_group", "|", "extracted_groups", ".", "push", "(", "EmailGroup", ".", "new", "(", "email_group", ")", ")", "end", "end", "return", "extracted_groups", "end" ]
Extract the Email Groups from the hashes stored inside email_groups_list attribute. @return [Array<QuestionproRails::EmailGroup>] Email Groups.
[ "Extract", "the", "Email", "Groups", "from", "the", "hashes", "stored", "inside", "email_groups_list", "attribute", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/survey_meta.rb#L22-L32
4,685
AssemDeghady/questionpro_rails
lib/questionpro_rails/survey_meta.rb
QuestionproRails.SurveyMeta.templates
def templates extracted_templates = [] unless self.templates_list.nil? self.templates_list.each do |template| extracted_templates.push(Template.new(template)) end end return extracted_templates end
ruby
def templates extracted_templates = [] unless self.templates_list.nil? self.templates_list.each do |template| extracted_templates.push(Template.new(template)) end end return extracted_templates end
[ "def", "templates", "extracted_templates", "=", "[", "]", "unless", "self", ".", "templates_list", ".", "nil?", "self", ".", "templates_list", ".", "each", "do", "|", "template", "|", "extracted_templates", ".", "push", "(", "Template", ".", "new", "(", "template", ")", ")", "end", "end", "return", "extracted_templates", "end" ]
Extract the Templates from the hashes stored inside templates_list attribute. @return [Array<QuestionproRails::Template>] Templates.
[ "Extract", "the", "Templates", "from", "the", "hashes", "stored", "inside", "templates_list", "attribute", "." ]
79f295f193b6ad593f4d56d8edfa3076a23d8e4f
https://github.com/AssemDeghady/questionpro_rails/blob/79f295f193b6ad593f4d56d8edfa3076a23d8e4f/lib/questionpro_rails/survey_meta.rb#L38-L48
4,686
culturecode/stagehand
lib/stagehand/production.rb
Stagehand.Production.matching
def matching(staging_record, table_name = nil) table_name, id = Stagehand::Key.generate(staging_record, :table_name => table_name) prepare_to_modify(table_name) return Record.where(:id => id) end
ruby
def matching(staging_record, table_name = nil) table_name, id = Stagehand::Key.generate(staging_record, :table_name => table_name) prepare_to_modify(table_name) return Record.where(:id => id) end
[ "def", "matching", "(", "staging_record", ",", "table_name", "=", "nil", ")", "table_name", ",", "id", "=", "Stagehand", "::", "Key", ".", "generate", "(", "staging_record", ",", ":table_name", "=>", "table_name", ")", "prepare_to_modify", "(", "table_name", ")", "return", "Record", ".", "where", "(", ":id", "=>", "id", ")", "end" ]
Returns a scope that limits results any occurrences of the specified record. Record can be specified by passing a staging record, or an id and table_name.
[ "Returns", "a", "scope", "that", "limits", "results", "any", "occurrences", "of", "the", "specified", "record", ".", "Record", "can", "be", "specified", "by", "passing", "a", "staging", "record", "or", "an", "id", "and", "table_name", "." ]
af627f1948b9dfc39ec13aefe77a47c21b4456a5
https://github.com/culturecode/stagehand/blob/af627f1948b9dfc39ec13aefe77a47c21b4456a5/lib/stagehand/production.rb#L62-L66
4,687
alexdovzhanyn/rydux
lib/rydux/store.rb
Rydux.Store.subscribe
def subscribe(caller = nil, &block) if block_given? notify_when = block.call(state) @listeners << { obj: block.binding.receiver, notify_when: notify_when } else @listeners << { obj: caller } end end
ruby
def subscribe(caller = nil, &block) if block_given? notify_when = block.call(state) @listeners << { obj: block.binding.receiver, notify_when: notify_when } else @listeners << { obj: caller } end end
[ "def", "subscribe", "(", "caller", "=", "nil", ",", "&", "block", ")", "if", "block_given?", "notify_when", "=", "block", ".", "call", "(", "state", ")", "@listeners", "<<", "{", "obj", ":", "block", ".", "binding", ".", "receiver", ",", "notify_when", ":", "notify_when", "}", "else", "@listeners", "<<", "{", "obj", ":", "caller", "}", "end", "end" ]
Allow subscribing either by passing a reference to self or by passing a block which defines the state keys that this listener cares about
[ "Allow", "subscribing", "either", "by", "passing", "a", "reference", "to", "self", "or", "by", "passing", "a", "block", "which", "defines", "the", "state", "keys", "that", "this", "listener", "cares", "about" ]
04983f5fd5cff8c2e9a0eb230ca72e9eb954170f
https://github.com/alexdovzhanyn/rydux/blob/04983f5fd5cff8c2e9a0eb230ca72e9eb954170f/lib/rydux/store.rb#L13-L20
4,688
alexdovzhanyn/rydux
lib/rydux/store.rb
Rydux.Store.strap_reducers
def strap_reducers(reducers) reducers.each {|k, reducer| set_state *[k, reducer.map_state(type: nil)]} reducers end
ruby
def strap_reducers(reducers) reducers.each {|k, reducer| set_state *[k, reducer.map_state(type: nil)]} reducers end
[ "def", "strap_reducers", "(", "reducers", ")", "reducers", ".", "each", "{", "|", "k", ",", "reducer", "|", "set_state", "[", "k", ",", "reducer", ".", "map_state", "(", "type", ":", "nil", ")", "]", "}", "reducers", "end" ]
Initialize state with the key-value pair associated with each reducer
[ "Initialize", "state", "with", "the", "key", "-", "value", "pair", "associated", "with", "each", "reducer" ]
04983f5fd5cff8c2e9a0eb230ca72e9eb954170f
https://github.com/alexdovzhanyn/rydux/blob/04983f5fd5cff8c2e9a0eb230ca72e9eb954170f/lib/rydux/store.rb#L60-L63
4,689
koraktor/silo
lib/silo/repository.rb
Silo.Repository.add
def add(path, prefix = nil) path = File.expand_path path prefix ||= '/' in_work_tree File.dirname(path) do index = @git.index index.read_tree 'HEAD' add = lambda do |f, p| file = File.basename f pre = (p == '/') ? file : File.join(p, file) dir = File.stat(f).directory? if dir (Dir.entries(f) - %w{. ..}).each do |child| add.call File.join(f, child), pre end else index.add pre, IO.read(f) end dir end dir = add.call path, prefix type = dir ? 'directory' : 'file' commit_msg = "Added #{type} #{path} into '#{prefix}'" index.commit commit_msg, [@git.head.commit.sha] end end
ruby
def add(path, prefix = nil) path = File.expand_path path prefix ||= '/' in_work_tree File.dirname(path) do index = @git.index index.read_tree 'HEAD' add = lambda do |f, p| file = File.basename f pre = (p == '/') ? file : File.join(p, file) dir = File.stat(f).directory? if dir (Dir.entries(f) - %w{. ..}).each do |child| add.call File.join(f, child), pre end else index.add pre, IO.read(f) end dir end dir = add.call path, prefix type = dir ? 'directory' : 'file' commit_msg = "Added #{type} #{path} into '#{prefix}'" index.commit commit_msg, [@git.head.commit.sha] end end
[ "def", "add", "(", "path", ",", "prefix", "=", "nil", ")", "path", "=", "File", ".", "expand_path", "path", "prefix", "||=", "'/'", "in_work_tree", "File", ".", "dirname", "(", "path", ")", "do", "index", "=", "@git", ".", "index", "index", ".", "read_tree", "'HEAD'", "add", "=", "lambda", "do", "|", "f", ",", "p", "|", "file", "=", "File", ".", "basename", "f", "pre", "=", "(", "p", "==", "'/'", ")", "?", "file", ":", "File", ".", "join", "(", "p", ",", "file", ")", "dir", "=", "File", ".", "stat", "(", "f", ")", ".", "directory?", "if", "dir", "(", "Dir", ".", "entries", "(", "f", ")", "-", "%w{", ".", "..", "}", ")", ".", "each", "do", "|", "child", "|", "add", ".", "call", "File", ".", "join", "(", "f", ",", "child", ")", ",", "pre", "end", "else", "index", ".", "add", "pre", ",", "IO", ".", "read", "(", "f", ")", "end", "dir", "end", "dir", "=", "add", ".", "call", "path", ",", "prefix", "type", "=", "dir", "?", "'directory'", ":", "'file'", "commit_msg", "=", "\"Added #{type} #{path} into '#{prefix}'\"", "index", ".", "commit", "commit_msg", ",", "[", "@git", ".", "head", ".", "commit", ".", "sha", "]", "end", "end" ]
Creates a new repository instance on the given path @param [Hash] options A hash of options @option options [Boolean] :create (true) Creates the backing Git repository if it does not already exist @option options [Boolean] :prepare (true) Prepares the backing Git repository for use with Silo if not already done @raise [Grit::InvalidGitRepositoryError] if the path exists, but is not a valid Git repository @raise [Grit::NoSuchPathError] if the path does not exist and option :create is +false+ @raise [InvalidRepositoryError] if the path contains another Git repository that does not contain data managed by Silo. Stores a file or full directory structure into the repository inside an optional prefix path This adds one commit to the history of the repository including the file or directory structure. If the file or directory already existed inside the prefix, Git will only save the changes. @param [String] path The path of the file or directory to store into the repository @param [String] prefix An optional prefix where the file is stored inside the repository
[ "Creates", "a", "new", "repository", "instance", "on", "the", "given", "path" ]
19a5fcc162dc24dd4846d154756a7c3bdeab400d
https://github.com/koraktor/silo/blob/19a5fcc162dc24dd4846d154756a7c3bdeab400d/lib/silo/repository.rb#L91-L115
4,690
koraktor/silo
lib/silo/repository.rb
Silo.Repository.add_remote
def add_remote(name, url) @remotes[name] = Remote::Git.new(self, name, url) @remotes[name].add end
ruby
def add_remote(name, url) @remotes[name] = Remote::Git.new(self, name, url) @remotes[name].add end
[ "def", "add_remote", "(", "name", ",", "url", ")", "@remotes", "[", "name", "]", "=", "Remote", "::", "Git", ".", "new", "(", "self", ",", "name", ",", "url", ")", "@remotes", "[", "name", "]", ".", "add", "end" ]
Adds a new remote to this Repository @param [String] name The name of the remote to add @param [String] url The URL of the remote repository @see Remote
[ "Adds", "a", "new", "remote", "to", "this", "Repository" ]
19a5fcc162dc24dd4846d154756a7c3bdeab400d
https://github.com/koraktor/silo/blob/19a5fcc162dc24dd4846d154756a7c3bdeab400d/lib/silo/repository.rb#L122-L125
4,691
koraktor/silo
lib/silo/repository.rb
Silo.Repository.contents
def contents(path = nil) contents = [] object = find_object(path || '/') contents << path unless path.nil? || object.nil? if object.is_a? Grit::Tree (object.blobs + object.trees).each do |obj| contents += contents(path.nil? ? obj.basename : File.join(path, obj.basename)) end end contents end
ruby
def contents(path = nil) contents = [] object = find_object(path || '/') contents << path unless path.nil? || object.nil? if object.is_a? Grit::Tree (object.blobs + object.trees).each do |obj| contents += contents(path.nil? ? obj.basename : File.join(path, obj.basename)) end end contents end
[ "def", "contents", "(", "path", "=", "nil", ")", "contents", "=", "[", "]", "object", "=", "find_object", "(", "path", "||", "'/'", ")", "contents", "<<", "path", "unless", "path", ".", "nil?", "||", "object", ".", "nil?", "if", "object", ".", "is_a?", "Grit", "::", "Tree", "(", "object", ".", "blobs", "+", "object", ".", "trees", ")", ".", "each", "do", "|", "obj", "|", "contents", "+=", "contents", "(", "path", ".", "nil?", "?", "obj", ".", "basename", ":", "File", ".", "join", "(", "path", ",", "obj", ".", "basename", ")", ")", "end", "end", "contents", "end" ]
Gets a list of files and directories in the specified path inside the repository @param [String] path The path to search for inside the repository @return [Array<String>] All files and directories found in the specidied path
[ "Gets", "a", "list", "of", "files", "and", "directories", "in", "the", "specified", "path", "inside", "the", "repository" ]
19a5fcc162dc24dd4846d154756a7c3bdeab400d
https://github.com/koraktor/silo/blob/19a5fcc162dc24dd4846d154756a7c3bdeab400d/lib/silo/repository.rb#L133-L145
4,692
koraktor/silo
lib/silo/repository.rb
Silo.Repository.git_remotes
def git_remotes remotes = {} @git.git.remote.split.each do |remote| url = @git.git.config({}, '--get', "remote.#{remote}.url").strip remotes[remote] = Remote::Git.new(self, remote, url) end remotes end
ruby
def git_remotes remotes = {} @git.git.remote.split.each do |remote| url = @git.git.config({}, '--get', "remote.#{remote}.url").strip remotes[remote] = Remote::Git.new(self, remote, url) end remotes end
[ "def", "git_remotes", "remotes", "=", "{", "}", "@git", ".", "git", ".", "remote", ".", "split", ".", "each", "do", "|", "remote", "|", "url", "=", "@git", ".", "git", ".", "config", "(", "{", "}", ",", "'--get'", ",", "\"remote.#{remote}.url\"", ")", ".", "strip", "remotes", "[", "remote", "]", "=", "Remote", "::", "Git", ".", "new", "(", "self", ",", "remote", ",", "url", ")", "end", "remotes", "end" ]
Loads remotes from the backing Git repository's configuration @see Remote::Git
[ "Loads", "remotes", "from", "the", "backing", "Git", "repository", "s", "configuration" ]
19a5fcc162dc24dd4846d154756a7c3bdeab400d
https://github.com/koraktor/silo/blob/19a5fcc162dc24dd4846d154756a7c3bdeab400d/lib/silo/repository.rb#L167-L174
4,693
koraktor/silo
lib/silo/repository.rb
Silo.Repository.history
def history(path = nil) params = ['--format=raw'] params += ['--', path] unless path.nil? output = @git.git.log({}, *params) Grit::Commit.list_from_string @git, output end
ruby
def history(path = nil) params = ['--format=raw'] params += ['--', path] unless path.nil? output = @git.git.log({}, *params) Grit::Commit.list_from_string @git, output end
[ "def", "history", "(", "path", "=", "nil", ")", "params", "=", "[", "'--format=raw'", "]", "params", "+=", "[", "'--'", ",", "path", "]", "unless", "path", ".", "nil?", "output", "=", "@git", ".", "git", ".", "log", "(", "{", "}", ",", "params", ")", "Grit", "::", "Commit", ".", "list_from_string", "@git", ",", "output", "end" ]
Generate a history of Git commits for either the complete repository or a specified file or directory @param [String] path The path of the file or directory to generate the history for. If +nil+, the history of the entire repository will be returned. @return [Array<Grit::Commit>] The commit history for the repository or given path
[ "Generate", "a", "history", "of", "Git", "commits", "for", "either", "the", "complete", "repository", "or", "a", "specified", "file", "or", "directory" ]
19a5fcc162dc24dd4846d154756a7c3bdeab400d
https://github.com/koraktor/silo/blob/19a5fcc162dc24dd4846d154756a7c3bdeab400d/lib/silo/repository.rb#L184-L189
4,694
koraktor/silo
lib/silo/repository.rb
Silo.Repository.info
def info(path) info = {} object = object! path info[:history] = history path info[:mode] = object.mode info[:name] = object.name info[:path] = path info[:sha] = object.id info[:created] = info[:history].last.committed_date info[:modified] = info[:history].first.committed_date if object.is_a? Grit::Blob info[:mime] = object.mime_type info[:size] = object.size info[:type] = :blob else info[:path] += '/' info[:type] = :tree end info end
ruby
def info(path) info = {} object = object! path info[:history] = history path info[:mode] = object.mode info[:name] = object.name info[:path] = path info[:sha] = object.id info[:created] = info[:history].last.committed_date info[:modified] = info[:history].first.committed_date if object.is_a? Grit::Blob info[:mime] = object.mime_type info[:size] = object.size info[:type] = :blob else info[:path] += '/' info[:type] = :tree end info end
[ "def", "info", "(", "path", ")", "info", "=", "{", "}", "object", "=", "object!", "path", "info", "[", ":history", "]", "=", "history", "path", "info", "[", ":mode", "]", "=", "object", ".", "mode", "info", "[", ":name", "]", "=", "object", ".", "name", "info", "[", ":path", "]", "=", "path", "info", "[", ":sha", "]", "=", "object", ".", "id", "info", "[", ":created", "]", "=", "info", "[", ":history", "]", ".", "last", ".", "committed_date", "info", "[", ":modified", "]", "=", "info", "[", ":history", "]", ".", "first", ".", "committed_date", "if", "object", ".", "is_a?", "Grit", "::", "Blob", "info", "[", ":mime", "]", "=", "object", ".", "mime_type", "info", "[", ":size", "]", "=", "object", ".", "size", "info", "[", ":type", "]", "=", ":blob", "else", "info", "[", ":path", "]", "+=", "'/'", "info", "[", ":type", "]", "=", ":tree", "end", "info", "end" ]
Get information about a file or directory in the repository @param [String] path The path of the file or directory to get information about @return [Hash<Symbol, Object>] Information about the requested file or directory.
[ "Get", "information", "about", "a", "file", "or", "directory", "in", "the", "repository" ]
19a5fcc162dc24dd4846d154756a7c3bdeab400d
https://github.com/koraktor/silo/blob/19a5fcc162dc24dd4846d154756a7c3bdeab400d/lib/silo/repository.rb#L218-L241
4,695
koraktor/silo
lib/silo/repository.rb
Silo.Repository.prepare
def prepare raise AlreadyPreparedError.new(@path) if prepared? in_work_tree :tmp do FileUtils.touch '.silo' @git.add '.silo' @git.commit_index 'Enabled Silo for this repository' end end
ruby
def prepare raise AlreadyPreparedError.new(@path) if prepared? in_work_tree :tmp do FileUtils.touch '.silo' @git.add '.silo' @git.commit_index 'Enabled Silo for this repository' end end
[ "def", "prepare", "raise", "AlreadyPreparedError", ".", "new", "(", "@path", ")", "if", "prepared?", "in_work_tree", ":tmp", "do", "FileUtils", ".", "touch", "'.silo'", "@git", ".", "add", "'.silo'", "@git", ".", "commit_index", "'Enabled Silo for this repository'", "end", "end" ]
Prepares the Git repository backing this Silo repository for use with Silo @raise [AlreadyPreparedError] if the repository has been already prepared
[ "Prepares", "the", "Git", "repository", "backing", "this", "Silo", "repository", "for", "use", "with", "Silo" ]
19a5fcc162dc24dd4846d154756a7c3bdeab400d
https://github.com/koraktor/silo/blob/19a5fcc162dc24dd4846d154756a7c3bdeab400d/lib/silo/repository.rb#L259-L266
4,696
koraktor/silo
lib/silo/repository.rb
Silo.Repository.purge
def purge(path, prune = true) object = object! path if object.is_a? Grit::Tree (object.blobs + object.trees).each do |blob| purge File.join(path, blob.basename), prune end else params = ['-f', '--index-filter', "git rm --cached --ignore-unmatch #{path}"] params << '--prune-empty' if prune params << 'HEAD' @git.git.filter_branch({}, *params) end end
ruby
def purge(path, prune = true) object = object! path if object.is_a? Grit::Tree (object.blobs + object.trees).each do |blob| purge File.join(path, blob.basename), prune end else params = ['-f', '--index-filter', "git rm --cached --ignore-unmatch #{path}"] params << '--prune-empty' if prune params << 'HEAD' @git.git.filter_branch({}, *params) end end
[ "def", "purge", "(", "path", ",", "prune", "=", "true", ")", "object", "=", "object!", "path", "if", "object", ".", "is_a?", "Grit", "::", "Tree", "(", "object", ".", "blobs", "+", "object", ".", "trees", ")", ".", "each", "do", "|", "blob", "|", "purge", "File", ".", "join", "(", "path", ",", "blob", ".", "basename", ")", ",", "prune", "end", "else", "params", "=", "[", "'-f'", ",", "'--index-filter'", ",", "\"git rm --cached --ignore-unmatch #{path}\"", "]", "params", "<<", "'--prune-empty'", "if", "prune", "params", "<<", "'HEAD'", "@git", ".", "git", ".", "filter_branch", "(", "{", "}", ",", "params", ")", "end", "end" ]
Purges a single file or the complete structure of a directory with the given path from the repository *WARNING*: This will cause a complete rewrite of the repository history and therefore deletes the data completely. @param [String] path The path of the file or directory to purge from the repository @param [Boolean] prune Remove empty commits in the Git history
[ "Purges", "a", "single", "file", "or", "the", "complete", "structure", "of", "a", "directory", "with", "the", "given", "path", "from", "the", "repository" ]
19a5fcc162dc24dd4846d154756a7c3bdeab400d
https://github.com/koraktor/silo/blob/19a5fcc162dc24dd4846d154756a7c3bdeab400d/lib/silo/repository.rb#L285-L298
4,697
koraktor/silo
lib/silo/repository.rb
Silo.Repository.remove
def remove(path) object = object! path path += '/' if object.is_a?(Grit::Tree) && path[-1].chr != '/' index = @git.index index.read_tree 'HEAD' index.delete path type = object.is_a?(Grit::Tree) ? 'directory' : 'file' commit_msg = "Removed #{type} #{path}" index.commit commit_msg, [@git.head.commit.sha] end
ruby
def remove(path) object = object! path path += '/' if object.is_a?(Grit::Tree) && path[-1].chr != '/' index = @git.index index.read_tree 'HEAD' index.delete path type = object.is_a?(Grit::Tree) ? 'directory' : 'file' commit_msg = "Removed #{type} #{path}" index.commit commit_msg, [@git.head.commit.sha] end
[ "def", "remove", "(", "path", ")", "object", "=", "object!", "path", "path", "+=", "'/'", "if", "object", ".", "is_a?", "(", "Grit", "::", "Tree", ")", "&&", "path", "[", "-", "1", "]", ".", "chr", "!=", "'/'", "index", "=", "@git", ".", "index", "index", ".", "read_tree", "'HEAD'", "index", ".", "delete", "path", "type", "=", "object", ".", "is_a?", "(", "Grit", "::", "Tree", ")", "?", "'directory'", ":", "'file'", "commit_msg", "=", "\"Removed #{type} #{path}\"", "index", ".", "commit", "commit_msg", ",", "[", "@git", ".", "head", ".", "commit", ".", "sha", "]", "end" ]
Removes a single file or the complete structure of a directory with the given path from the HEAD revision of the repository *NOTE*: The data won't be lost as it will be preserved in the history of the Git repository. @param [String] path The path of the file or directory to remove from the repository
[ "Removes", "a", "single", "file", "or", "the", "complete", "structure", "of", "a", "directory", "with", "the", "given", "path", "from", "the", "HEAD", "revision", "of", "the", "repository" ]
19a5fcc162dc24dd4846d154756a7c3bdeab400d
https://github.com/koraktor/silo/blob/19a5fcc162dc24dd4846d154756a7c3bdeab400d/lib/silo/repository.rb#L308-L317
4,698
koraktor/silo
lib/silo/repository.rb
Silo.Repository.remove_remote
def remove_remote(name) remote = @remotes[name] raise UndefinedRemoteError.new(name) if remote.nil? remote.remove @remotes[name] = nil end
ruby
def remove_remote(name) remote = @remotes[name] raise UndefinedRemoteError.new(name) if remote.nil? remote.remove @remotes[name] = nil end
[ "def", "remove_remote", "(", "name", ")", "remote", "=", "@remotes", "[", "name", "]", "raise", "UndefinedRemoteError", ".", "new", "(", "name", ")", "if", "remote", ".", "nil?", "remote", ".", "remove", "@remotes", "[", "name", "]", "=", "nil", "end" ]
Removes the remote with the given name from this repository @param [String] name The name of the remote to remove @see Remote
[ "Removes", "the", "remote", "with", "the", "given", "name", "from", "this", "repository" ]
19a5fcc162dc24dd4846d154756a7c3bdeab400d
https://github.com/koraktor/silo/blob/19a5fcc162dc24dd4846d154756a7c3bdeab400d/lib/silo/repository.rb#L324-L329
4,699
koraktor/silo
lib/silo/repository.rb
Silo.Repository.restore
def restore(path, prefix = '.') object = object! path prefix = File.expand_path prefix FileUtils.mkdir_p prefix unless File.exists? prefix file_path = File.join prefix, File.basename(path) if object.is_a? Grit::Tree FileUtils.mkdir file_path unless File.directory? file_path (object.blobs + object.trees).each do |obj| restore File.join(path, obj.basename), file_path end else file = File.new file_path, 'w' file.write object.data file.close end end
ruby
def restore(path, prefix = '.') object = object! path prefix = File.expand_path prefix FileUtils.mkdir_p prefix unless File.exists? prefix file_path = File.join prefix, File.basename(path) if object.is_a? Grit::Tree FileUtils.mkdir file_path unless File.directory? file_path (object.blobs + object.trees).each do |obj| restore File.join(path, obj.basename), file_path end else file = File.new file_path, 'w' file.write object.data file.close end end
[ "def", "restore", "(", "path", ",", "prefix", "=", "'.'", ")", "object", "=", "object!", "path", "prefix", "=", "File", ".", "expand_path", "prefix", "FileUtils", ".", "mkdir_p", "prefix", "unless", "File", ".", "exists?", "prefix", "file_path", "=", "File", ".", "join", "prefix", ",", "File", ".", "basename", "(", "path", ")", "if", "object", ".", "is_a?", "Grit", "::", "Tree", "FileUtils", ".", "mkdir", "file_path", "unless", "File", ".", "directory?", "file_path", "(", "object", ".", "blobs", "+", "object", ".", "trees", ")", ".", "each", "do", "|", "obj", "|", "restore", "File", ".", "join", "(", "path", ",", "obj", ".", "basename", ")", ",", "file_path", "end", "else", "file", "=", "File", ".", "new", "file_path", ",", "'w'", "file", ".", "write", "object", ".", "data", "file", ".", "close", "end", "end" ]
Restores a single file or the complete structure of a directory with the given path from the repository @param [String] path The path of the file or directory to restore from the repository @param [String] prefix An optional prefix where the file is restored
[ "Restores", "a", "single", "file", "or", "the", "complete", "structure", "of", "a", "directory", "with", "the", "given", "path", "from", "the", "repository" ]
19a5fcc162dc24dd4846d154756a7c3bdeab400d
https://github.com/koraktor/silo/blob/19a5fcc162dc24dd4846d154756a7c3bdeab400d/lib/silo/repository.rb#L337-L354