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
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
17,500
mdp/gibberish
lib/gibberish/rsa.rb
Gibberish.RSA.decrypt
def decrypt(data, opts={}) data = data.to_s raise "No private key set!" unless @key.private? unless opts[:binary] data = Base64.decode64(data) end @key.private_decrypt(data) end
ruby
def decrypt(data, opts={}) data = data.to_s raise "No private key set!" unless @key.private? unless opts[:binary] data = Base64.decode64(data) end @key.private_decrypt(data) end
[ "def", "decrypt", "(", "data", ",", "opts", "=", "{", "}", ")", "data", "=", "data", ".", "to_s", "raise", "\"No private key set!\"", "unless", "@key", ".", "private?", "unless", "opts", "[", ":binary", "]", "data", "=", "Base64", ".", "decode64", "(", ...
Decrypt data using the key @param [#to_s] data @param [Hash] opts @option opts [Boolean] :binary (false) don't decode the data as Base64
[ "Decrypt", "data", "using", "the", "key" ]
707bfc1f6c4ab17df8a980a9e2b80970768a41c6
https://github.com/mdp/gibberish/blob/707bfc1f6c4ab17df8a980a9e2b80970768a41c6/lib/gibberish/rsa.rb#L102-L109
17,501
fabrik42/acts_as_api
lib/acts_as_api/base.rb
ActsAsApi.Base.acts_as_api
def acts_as_api class_eval do include ActsAsApi::Base::InstanceMethods extend ActsAsApi::Base::ClassMethods end if block_given? yield ActsAsApi::Config end end
ruby
def acts_as_api class_eval do include ActsAsApi::Base::InstanceMethods extend ActsAsApi::Base::ClassMethods end if block_given? yield ActsAsApi::Config end end
[ "def", "acts_as_api", "class_eval", "do", "include", "ActsAsApi", "::", "Base", "::", "InstanceMethods", "extend", "ActsAsApi", "::", "Base", "::", "ClassMethods", "end", "if", "block_given?", "yield", "ActsAsApi", "::", "Config", "end", "end" ]
When invoked, it enriches the current model with the class and instance methods to act as api.
[ "When", "invoked", "it", "enriches", "the", "current", "model", "with", "the", "class", "and", "instance", "methods", "to", "act", "as", "api", "." ]
874ccfbcd5efcd90b6b56ec126b07c053675901e
https://github.com/fabrik42/acts_as_api/blob/874ccfbcd5efcd90b6b56ec126b07c053675901e/lib/acts_as_api/base.rb#L12-L21
17,502
fabrik42/acts_as_api
lib/acts_as_api/api_template.rb
ActsAsApi.ApiTemplate.add
def add(val, options = {}) item_key = (options[:as] || val).to_sym self[item_key] = val @options[item_key] = options end
ruby
def add(val, options = {}) item_key = (options[:as] || val).to_sym self[item_key] = val @options[item_key] = options end
[ "def", "add", "(", "val", ",", "options", "=", "{", "}", ")", "item_key", "=", "(", "options", "[", ":as", "]", "||", "val", ")", ".", "to_sym", "self", "[", "item_key", "]", "=", "val", "@options", "[", "item_key", "]", "=", "options", "end" ]
Adds a field to the api template The value passed can be one of the following: * Symbol - the method with the same name will be called on the model when rendering. * String - must be in the form "method1.method2.method3", will call this method chain. * Hash - will be added as a sub hash and all its items will b...
[ "Adds", "a", "field", "to", "the", "api", "template" ]
874ccfbcd5efcd90b6b56ec126b07c053675901e
https://github.com/fabrik42/acts_as_api/blob/874ccfbcd5efcd90b6b56ec126b07c053675901e/lib/acts_as_api/api_template.rb#L36-L42
17,503
fabrik42/acts_as_api
lib/acts_as_api/api_template.rb
ActsAsApi.ApiTemplate.allowed_to_render?
def allowed_to_render?(fieldset, field, model, options) return true unless fieldset.is_a? ActsAsApi::ApiTemplate fieldset_options = fieldset.options_for(field) if fieldset_options[:unless] !(condition_fulfilled?(model, fieldset_options[:unless], options)) elsif fieldset_options[:if] ...
ruby
def allowed_to_render?(fieldset, field, model, options) return true unless fieldset.is_a? ActsAsApi::ApiTemplate fieldset_options = fieldset.options_for(field) if fieldset_options[:unless] !(condition_fulfilled?(model, fieldset_options[:unless], options)) elsif fieldset_options[:if] ...
[ "def", "allowed_to_render?", "(", "fieldset", ",", "field", ",", "model", ",", "options", ")", "return", "true", "unless", "fieldset", ".", "is_a?", "ActsAsApi", "::", "ApiTemplate", "fieldset_options", "=", "fieldset", ".", "options_for", "(", "field", ")", "...
Decides if the passed item should be added to the response based on the conditional options passed.
[ "Decides", "if", "the", "passed", "item", "should", "be", "added", "to", "the", "response", "based", "on", "the", "conditional", "options", "passed", "." ]
874ccfbcd5efcd90b6b56ec126b07c053675901e
https://github.com/fabrik42/acts_as_api/blob/874ccfbcd5efcd90b6b56ec126b07c053675901e/lib/acts_as_api/api_template.rb#L67-L79
17,504
fabrik42/acts_as_api
lib/acts_as_api/api_template.rb
ActsAsApi.ApiTemplate.to_response_hash
def to_response_hash(model, fieldset = self, options = {}) api_output = {} fieldset.each do |field, value| next unless allowed_to_render?(fieldset, field, model, options) out = process_value(model, value, options) if out.respond_to?(:as_api_response) sub_template = api_t...
ruby
def to_response_hash(model, fieldset = self, options = {}) api_output = {} fieldset.each do |field, value| next unless allowed_to_render?(fieldset, field, model, options) out = process_value(model, value, options) if out.respond_to?(:as_api_response) sub_template = api_t...
[ "def", "to_response_hash", "(", "model", ",", "fieldset", "=", "self", ",", "options", "=", "{", "}", ")", "api_output", "=", "{", "}", "fieldset", ".", "each", "do", "|", "field", ",", "value", "|", "next", "unless", "allowed_to_render?", "(", "fieldset...
Generates a hash that represents the api response based on this template for the passed model instance.
[ "Generates", "a", "hash", "that", "represents", "the", "api", "response", "based", "on", "this", "template", "for", "the", "passed", "model", "instance", "." ]
874ccfbcd5efcd90b6b56ec126b07c053675901e
https://github.com/fabrik42/acts_as_api/blob/874ccfbcd5efcd90b6b56ec126b07c053675901e/lib/acts_as_api/api_template.rb#L95-L112
17,505
fabrik42/acts_as_api
lib/acts_as_api/rendering.rb
ActsAsApi.Rendering.render_for_api
def render_for_api(api_template_or_options, render_options) if api_template_or_options.is_a?(Hash) api_template = [] api_template << api_template_or_options.delete(:prefix) api_template << api_template_or_options.delete(:template) api_template << api_template_or_options.delete(:pos...
ruby
def render_for_api(api_template_or_options, render_options) if api_template_or_options.is_a?(Hash) api_template = [] api_template << api_template_or_options.delete(:prefix) api_template << api_template_or_options.delete(:template) api_template << api_template_or_options.delete(:pos...
[ "def", "render_for_api", "(", "api_template_or_options", ",", "render_options", ")", "if", "api_template_or_options", ".", "is_a?", "(", "Hash", ")", "api_template", "=", "[", "]", "api_template", "<<", "api_template_or_options", ".", "delete", "(", ":prefix", ")", ...
Provides an alternative to the +render+ method used within the controller to simply generate API outputs. The default Rails serializers are used to serialize the data.
[ "Provides", "an", "alternative", "to", "the", "+", "render", "+", "method", "used", "within", "the", "controller", "to", "simply", "generate", "API", "outputs", "." ]
874ccfbcd5efcd90b6b56ec126b07c053675901e
https://github.com/fabrik42/acts_as_api/blob/874ccfbcd5efcd90b6b56ec126b07c053675901e/lib/acts_as_api/rendering.rb#L9-L86
17,506
fabrik42/acts_as_api
lib/acts_as_api/collection.rb
ActsAsApi.Collection.as_api_response
def as_api_response(api_template, options = {}) collect do |item| if item.respond_to?(:as_api_response) item.as_api_response(api_template, options) else item end end end
ruby
def as_api_response(api_template, options = {}) collect do |item| if item.respond_to?(:as_api_response) item.as_api_response(api_template, options) else item end end end
[ "def", "as_api_response", "(", "api_template", ",", "options", "=", "{", "}", ")", "collect", "do", "|", "item", "|", "if", "item", ".", "respond_to?", "(", ":as_api_response", ")", "item", ".", "as_api_response", "(", "api_template", ",", "options", ")", ...
The collection checks all its items if they respond to the +as_api_response+ method. If they do, the result of this method will be collected. If they don't, the item itself will be collected.
[ "The", "collection", "checks", "all", "its", "items", "if", "they", "respond", "to", "the", "+", "as_api_response", "+", "method", ".", "If", "they", "do", "the", "result", "of", "this", "method", "will", "be", "collected", ".", "If", "they", "don", "t",...
874ccfbcd5efcd90b6b56ec126b07c053675901e
https://github.com/fabrik42/acts_as_api/blob/874ccfbcd5efcd90b6b56ec126b07c053675901e/lib/acts_as_api/collection.rb#L6-L14
17,507
ccocchi/rabl-rails
lib/rabl-rails/compiler.rb
RablRails.Compiler.condition
def condition(proc) return unless block_given? @template.add_node Nodes::Condition.new(proc, sub_compile(nil, true) { yield }) end
ruby
def condition(proc) return unless block_given? @template.add_node Nodes::Condition.new(proc, sub_compile(nil, true) { yield }) end
[ "def", "condition", "(", "proc", ")", "return", "unless", "block_given?", "@template", ".", "add_node", "Nodes", "::", "Condition", ".", "new", "(", "proc", ",", "sub_compile", "(", "nil", ",", "true", ")", "{", "yield", "}", ")", "end" ]
Provide a conditionnal block condition(->(u) { u.is_a?(Admin) }) do attributes :secret end
[ "Provide", "a", "conditionnal", "block" ]
8d4c7eef42b9721e0aa68fece24457368614334f
https://github.com/ccocchi/rabl-rails/blob/8d4c7eef42b9721e0aa68fece24457368614334f/lib/rabl-rails/compiler.rb#L160-L163
17,508
documentcloud/jammit
lib/jammit/command_line.rb
Jammit.CommandLine.ensure_configuration_file
def ensure_configuration_file config = @options[:config_paths] return true if File.exists?(config) && File.readable?(config) puts "Could not find the asset configuration file \"#{config}\"" exit(1) end
ruby
def ensure_configuration_file config = @options[:config_paths] return true if File.exists?(config) && File.readable?(config) puts "Could not find the asset configuration file \"#{config}\"" exit(1) end
[ "def", "ensure_configuration_file", "config", "=", "@options", "[", ":config_paths", "]", "return", "true", "if", "File", ".", "exists?", "(", "config", ")", "&&", "File", ".", "readable?", "(", "config", ")", "puts", "\"Could not find the asset configuration file \...
Make sure that we have a readable configuration file. The @jammit@ command can't run without one.
[ "Make", "sure", "that", "we", "have", "a", "readable", "configuration", "file", ".", "The" ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/command_line.rb#L37-L42
17,509
documentcloud/jammit
lib/jammit/packager.rb
Jammit.Packager.precache_all
def precache_all(output_dir=nil, base_url=nil) output_dir ||= File.join(Jammit.public_root, Jammit.package_path) cacheable(:js, output_dir).each {|p| cache(p, 'js', pack_javascripts(p), output_dir) } cacheable(:css, output_dir).each do |p| cache(p, 'css', pack_stylesheets(p), output_dir) ...
ruby
def precache_all(output_dir=nil, base_url=nil) output_dir ||= File.join(Jammit.public_root, Jammit.package_path) cacheable(:js, output_dir).each {|p| cache(p, 'js', pack_javascripts(p), output_dir) } cacheable(:css, output_dir).each do |p| cache(p, 'css', pack_stylesheets(p), output_dir) ...
[ "def", "precache_all", "(", "output_dir", "=", "nil", ",", "base_url", "=", "nil", ")", "output_dir", "||=", "File", ".", "join", "(", "Jammit", ".", "public_root", ",", "Jammit", ".", "package_path", ")", "cacheable", "(", ":js", ",", "output_dir", ")", ...
Creating a new Packager will rebuild the list of assets from the Jammit.configuration. When assets.yml is being changed on the fly, create a new Packager. Ask the packager to precache all defined assets, along with their gzip'd versions. In order to prebuild the MHTML stylesheets, we need to know the base_url, bec...
[ "Creating", "a", "new", "Packager", "will", "rebuild", "the", "list", "of", "assets", "from", "the", "Jammit", ".", "configuration", ".", "When", "assets", ".", "yml", "is", "being", "changed", "on", "the", "fly", "create", "a", "new", "Packager", ".", "...
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/packager.rb#L34-L49
17,510
documentcloud/jammit
lib/jammit/packager.rb
Jammit.Packager.cache
def cache(package, extension, contents, output_dir, suffix=nil, mtime=nil) FileUtils.mkdir_p(output_dir) unless File.exists?(output_dir) raise OutputNotWritable, "Jammit doesn't have permission to write to \"#{output_dir}\"" unless File.writable?(output_dir) mtime ||= latest_mtime package_for(package,...
ruby
def cache(package, extension, contents, output_dir, suffix=nil, mtime=nil) FileUtils.mkdir_p(output_dir) unless File.exists?(output_dir) raise OutputNotWritable, "Jammit doesn't have permission to write to \"#{output_dir}\"" unless File.writable?(output_dir) mtime ||= latest_mtime package_for(package,...
[ "def", "cache", "(", "package", ",", "extension", ",", "contents", ",", "output_dir", ",", "suffix", "=", "nil", ",", "mtime", "=", "nil", ")", "FileUtils", ".", "mkdir_p", "(", "output_dir", ")", "unless", "File", ".", "exists?", "(", "output_dir", ")",...
Caches a single prebuilt asset package and gzips it at the highest compression level. Ensures that the modification time of both both variants is identical, for web server caching modules, as well as MHTML.
[ "Caches", "a", "single", "prebuilt", "asset", "package", "and", "gzips", "it", "at", "the", "highest", "compression", "level", ".", "Ensures", "that", "the", "modification", "time", "of", "both", "both", "variants", "is", "identical", "for", "web", "server", ...
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/packager.rb#L54-L66
17,511
documentcloud/jammit
lib/jammit/packager.rb
Jammit.Packager.pack_stylesheets
def pack_stylesheets(package, variant=nil, asset_url=nil) compressor.compress_css(package_for(package, :css)[:paths], variant, asset_url) end
ruby
def pack_stylesheets(package, variant=nil, asset_url=nil) compressor.compress_css(package_for(package, :css)[:paths], variant, asset_url) end
[ "def", "pack_stylesheets", "(", "package", ",", "variant", "=", "nil", ",", "asset_url", "=", "nil", ")", "compressor", ".", "compress_css", "(", "package_for", "(", "package", ",", ":css", ")", "[", ":paths", "]", ",", "variant", ",", "asset_url", ")", ...
Return the compressed contents of a stylesheet package.
[ "Return", "the", "compressed", "contents", "of", "a", "stylesheet", "package", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/packager.rb#L78-L80
17,512
documentcloud/jammit
lib/jammit/packager.rb
Jammit.Packager.package_for
def package_for(package, extension) pack = @packages[extension] && @packages[extension][package] pack || not_found(package, extension) end
ruby
def package_for(package, extension) pack = @packages[extension] && @packages[extension][package] pack || not_found(package, extension) end
[ "def", "package_for", "(", "package", ",", "extension", ")", "pack", "=", "@packages", "[", "extension", "]", "&&", "@packages", "[", "extension", "]", "[", "package", "]", "pack", "||", "not_found", "(", "package", ",", "extension", ")", "end" ]
Look up a package asset list by name, raising an exception if the package has gone missing.
[ "Look", "up", "a", "package", "asset", "list", "by", "name", "raising", "an", "exception", "if", "the", "package", "has", "gone", "missing", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/packager.rb#L97-L100
17,513
documentcloud/jammit
lib/jammit/controller.rb
Jammit.Controller.package
def package parse_request template_ext = Jammit.template_extension.to_sym case @extension when :js render :js => (@contents = Jammit.packager.pack_javascripts(@package)) when template_ext render :js => (@contents = Jammit.packager.pack_templates(@package)) when :css ...
ruby
def package parse_request template_ext = Jammit.template_extension.to_sym case @extension when :js render :js => (@contents = Jammit.packager.pack_javascripts(@package)) when template_ext render :js => (@contents = Jammit.packager.pack_templates(@package)) when :css ...
[ "def", "package", "parse_request", "template_ext", "=", "Jammit", ".", "template_extension", ".", "to_sym", "case", "@extension", "when", ":js", "render", ":js", "=>", "(", "@contents", "=", "Jammit", ".", "packager", ".", "pack_javascripts", "(", "@package", ")...
The "package" action receives all requests for asset packages that haven't yet been cached. The package will be built, cached, and gzipped.
[ "The", "package", "action", "receives", "all", "requests", "for", "asset", "packages", "that", "haven", "t", "yet", "been", "cached", ".", "The", "package", "will", "be", "built", "cached", "and", "gzipped", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/controller.rb#L19-L33
17,514
documentcloud/jammit
lib/jammit/helper.rb
Jammit.Helper.include_stylesheets
def include_stylesheets(*packages) options = packages.extract_options! return html_safe(individual_stylesheets(packages, options)) unless should_package? disabled = (options.delete(:embed_assets) == false) || (options.delete(:embed_images) == false) return html_safe(packaged_stylesheets(packages...
ruby
def include_stylesheets(*packages) options = packages.extract_options! return html_safe(individual_stylesheets(packages, options)) unless should_package? disabled = (options.delete(:embed_assets) == false) || (options.delete(:embed_images) == false) return html_safe(packaged_stylesheets(packages...
[ "def", "include_stylesheets", "(", "*", "packages", ")", "options", "=", "packages", ".", "extract_options!", "return", "html_safe", "(", "individual_stylesheets", "(", "packages", ",", "options", ")", ")", "unless", "should_package?", "disabled", "=", "(", "optio...
If embed_assets is turned on, writes out links to the Data-URI and MHTML versions of the stylesheet package, otherwise the package is regular compressed CSS, and in development the stylesheet URLs are passed verbatim.
[ "If", "embed_assets", "is", "turned", "on", "writes", "out", "links", "to", "the", "Data", "-", "URI", "and", "MHTML", "versions", "of", "the", "stylesheet", "package", "otherwise", "the", "package", "is", "regular", "compressed", "CSS", "and", "in", "develo...
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/helper.rb#L17-L23
17,515
documentcloud/jammit
lib/jammit/helper.rb
Jammit.Helper.include_javascripts
def include_javascripts(*packages) options = packages.extract_options! options.merge!(:extname=>false) html_safe packages.map {|pack| should_package? ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js) }.flatten.map {|pack| "<script src=\"#{pack}\"><...
ruby
def include_javascripts(*packages) options = packages.extract_options! options.merge!(:extname=>false) html_safe packages.map {|pack| should_package? ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js) }.flatten.map {|pack| "<script src=\"#{pack}\"><...
[ "def", "include_javascripts", "(", "*", "packages", ")", "options", "=", "packages", ".", "extract_options!", "options", ".", "merge!", "(", ":extname", "=>", "false", ")", "html_safe", "packages", ".", "map", "{", "|", "pack", "|", "should_package?", "?", "...
Writes out the URL to the bundled and compressed javascript package, except in development, where it references the individual scripts.
[ "Writes", "out", "the", "URL", "to", "the", "bundled", "and", "compressed", "javascript", "package", "except", "in", "development", "where", "it", "references", "the", "individual", "scripts", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/helper.rb#L27-L35
17,516
documentcloud/jammit
lib/jammit/helper.rb
Jammit.Helper.individual_stylesheets
def individual_stylesheets(packages, options) tags_with_options(packages, options) {|p| Jammit.packager.individual_urls(p.to_sym, :css) } end
ruby
def individual_stylesheets(packages, options) tags_with_options(packages, options) {|p| Jammit.packager.individual_urls(p.to_sym, :css) } end
[ "def", "individual_stylesheets", "(", "packages", ",", "options", ")", "tags_with_options", "(", "packages", ",", "options", ")", "{", "|", "p", "|", "Jammit", ".", "packager", ".", "individual_urls", "(", "p", ".", "to_sym", ",", ":css", ")", "}", "end" ]
HTML tags, in order, for all of the individual stylesheets.
[ "HTML", "tags", "in", "order", "for", "all", "of", "the", "individual", "stylesheets", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/helper.rb#L55-L57
17,517
documentcloud/jammit
lib/jammit/helper.rb
Jammit.Helper.packaged_stylesheets
def packaged_stylesheets(packages, options) tags_with_options(packages, options) {|p| Jammit.asset_url(p, :css) } end
ruby
def packaged_stylesheets(packages, options) tags_with_options(packages, options) {|p| Jammit.asset_url(p, :css) } end
[ "def", "packaged_stylesheets", "(", "packages", ",", "options", ")", "tags_with_options", "(", "packages", ",", "options", ")", "{", "|", "p", "|", "Jammit", ".", "asset_url", "(", "p", ",", ":css", ")", "}", "end" ]
HTML tags for the stylesheet packages.
[ "HTML", "tags", "for", "the", "stylesheet", "packages", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/helper.rb#L60-L62
17,518
documentcloud/jammit
lib/jammit/helper.rb
Jammit.Helper.embedded_image_stylesheets
def embedded_image_stylesheets(packages, options) datauri_tags = tags_with_options(packages, options) {|p| Jammit.asset_url(p, :css, :datauri) } ie_tags = Jammit.mhtml_enabled ? tags_with_options(packages, options) {|p| Jammit.asset_url(p, :css, :mhtml) } : packaged_styleshee...
ruby
def embedded_image_stylesheets(packages, options) datauri_tags = tags_with_options(packages, options) {|p| Jammit.asset_url(p, :css, :datauri) } ie_tags = Jammit.mhtml_enabled ? tags_with_options(packages, options) {|p| Jammit.asset_url(p, :css, :mhtml) } : packaged_styleshee...
[ "def", "embedded_image_stylesheets", "(", "packages", ",", "options", ")", "datauri_tags", "=", "tags_with_options", "(", "packages", ",", "options", ")", "{", "|", "p", "|", "Jammit", ".", "asset_url", "(", "p", ",", ":css", ",", ":datauri", ")", "}", "ie...
HTML tags for the 'datauri', and 'mhtml' versions of the packaged stylesheets, using conditional comments to load the correct variant.
[ "HTML", "tags", "for", "the", "datauri", "and", "mhtml", "versions", "of", "the", "packaged", "stylesheets", "using", "conditional", "comments", "to", "load", "the", "correct", "variant", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/helper.rb#L66-L72
17,519
documentcloud/jammit
lib/jammit/helper.rb
Jammit.Helper.tags_with_options
def tags_with_options(packages, options) packages.dup.map {|package| yield package }.flatten.map {|package| stylesheet_link_tag package, options }.join("\n") end
ruby
def tags_with_options(packages, options) packages.dup.map {|package| yield package }.flatten.map {|package| stylesheet_link_tag package, options }.join("\n") end
[ "def", "tags_with_options", "(", "packages", ",", "options", ")", "packages", ".", "dup", ".", "map", "{", "|", "package", "|", "yield", "package", "}", ".", "flatten", ".", "map", "{", "|", "package", "|", "stylesheet_link_tag", "package", ",", "options",...
Generate the stylesheet tags for a batch of packages, with options, by yielding each package to a block.
[ "Generate", "the", "stylesheet", "tags", "for", "a", "batch", "of", "packages", "with", "options", "by", "yielding", "each", "package", "to", "a", "block", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/helper.rb#L76-L82
17,520
documentcloud/jammit
lib/jammit/compressor.rb
Jammit.Compressor.compile_jst
def compile_jst(paths) namespace = Jammit.template_namespace paths = paths.grep(Jammit.template_extension_matcher).sort base_path = find_base_path(paths) compiled = paths.map do |path| contents = read_binary_file(path) contents = contents.gsub(/\r?\n/, "\\n").gsub(...
ruby
def compile_jst(paths) namespace = Jammit.template_namespace paths = paths.grep(Jammit.template_extension_matcher).sort base_path = find_base_path(paths) compiled = paths.map do |path| contents = read_binary_file(path) contents = contents.gsub(/\r?\n/, "\\n").gsub(...
[ "def", "compile_jst", "(", "paths", ")", "namespace", "=", "Jammit", ".", "template_namespace", "paths", "=", "paths", ".", "grep", "(", "Jammit", ".", "template_extension_matcher", ")", ".", "sort", "base_path", "=", "find_base_path", "(", "paths", ")", "comp...
Compiles a single JST file by writing out a javascript that adds template properties to a top-level template namespace object. Adds a JST-compilation function to the top of the package, unless you've specified your own preferred function, or turned it off. JST templates are named with the basename of their file.
[ "Compiles", "a", "single", "JST", "file", "by", "writing", "out", "a", "javascript", "that", "adds", "template", "properties", "to", "a", "top", "-", "level", "template", "namespace", "object", ".", "Adds", "a", "JST", "-", "compilation", "function", "to", ...
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/compressor.rb#L110-L123
17,521
documentcloud/jammit
lib/jammit/compressor.rb
Jammit.Compressor.find_base_path
def find_base_path(paths) return nil if paths.length <= 1 paths.sort! first = paths.first.split('/') last = paths.last.split('/') i = 0 while first[i] == last[i] && i <= first.length i += 1 end res = first.slice(0, i).join('/') res.empty? ? nil : res en...
ruby
def find_base_path(paths) return nil if paths.length <= 1 paths.sort! first = paths.first.split('/') last = paths.last.split('/') i = 0 while first[i] == last[i] && i <= first.length i += 1 end res = first.slice(0, i).join('/') res.empty? ? nil : res en...
[ "def", "find_base_path", "(", "paths", ")", "return", "nil", "if", "paths", ".", "length", "<=", "1", "paths", ".", "sort!", "first", "=", "paths", ".", "first", ".", "split", "(", "'/'", ")", "last", "=", "paths", ".", "last", ".", "split", "(", "...
Given a set of paths, find a common prefix path.
[ "Given", "a", "set", "of", "paths", "find", "a", "common", "prefix", "path", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/compressor.rb#L129-L140
17,522
documentcloud/jammit
lib/jammit/compressor.rb
Jammit.Compressor.concatenate_and_tag_assets
def concatenate_and_tag_assets(paths, variant=nil) stylesheets = [paths].flatten.map do |css_path| contents = read_binary_file(css_path) contents.gsub(EMBED_DETECTOR) do |url| ipath, cpath = Pathname.new($1), Pathname.new(File.expand_path(css_path)) is_url = URI.parse($1).absol...
ruby
def concatenate_and_tag_assets(paths, variant=nil) stylesheets = [paths].flatten.map do |css_path| contents = read_binary_file(css_path) contents.gsub(EMBED_DETECTOR) do |url| ipath, cpath = Pathname.new($1), Pathname.new(File.expand_path(css_path)) is_url = URI.parse($1).absol...
[ "def", "concatenate_and_tag_assets", "(", "paths", ",", "variant", "=", "nil", ")", "stylesheets", "=", "[", "paths", "]", ".", "flatten", ".", "map", "do", "|", "css_path", "|", "contents", "=", "read_binary_file", "(", "css_path", ")", "contents", ".", "...
In order to support embedded assets from relative paths, we need to expand the paths before contatenating the CSS together and losing the location of the original stylesheet path. Validate the assets while we're at it.
[ "In", "order", "to", "support", "embedded", "assets", "from", "relative", "paths", "we", "need", "to", "expand", "the", "paths", "before", "contatenating", "the", "CSS", "together", "and", "losing", "the", "location", "of", "the", "original", "stylesheet", "pa...
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/compressor.rb#L153-L163
17,523
documentcloud/jammit
lib/jammit/compressor.rb
Jammit.Compressor.absolute_path
def absolute_path(asset_pathname, css_pathname) (asset_pathname.absolute? ? Pathname.new(File.join(Jammit.public_root, asset_pathname)) : css_pathname.dirname + asset_pathname).cleanpath end
ruby
def absolute_path(asset_pathname, css_pathname) (asset_pathname.absolute? ? Pathname.new(File.join(Jammit.public_root, asset_pathname)) : css_pathname.dirname + asset_pathname).cleanpath end
[ "def", "absolute_path", "(", "asset_pathname", ",", "css_pathname", ")", "(", "asset_pathname", ".", "absolute?", "?", "Pathname", ".", "new", "(", "File", ".", "join", "(", "Jammit", ".", "public_root", ",", "asset_pathname", ")", ")", ":", "css_pathname", ...
Get the site-absolute public path for an asset file path that may or may not be relative, given the path of the stylesheet that contains it.
[ "Get", "the", "site", "-", "absolute", "public", "path", "for", "an", "asset", "file", "path", "that", "may", "or", "may", "not", "be", "relative", "given", "the", "path", "of", "the", "stylesheet", "that", "contains", "it", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/compressor.rb#L201-L205
17,524
documentcloud/jammit
lib/jammit/compressor.rb
Jammit.Compressor.rails_asset_id
def rails_asset_id(path) asset_id = ENV["RAILS_ASSET_ID"] return asset_id if asset_id File.exists?(path) ? File.mtime(path).to_i.to_s : '' end
ruby
def rails_asset_id(path) asset_id = ENV["RAILS_ASSET_ID"] return asset_id if asset_id File.exists?(path) ? File.mtime(path).to_i.to_s : '' end
[ "def", "rails_asset_id", "(", "path", ")", "asset_id", "=", "ENV", "[", "\"RAILS_ASSET_ID\"", "]", "return", "asset_id", "if", "asset_id", "File", ".", "exists?", "(", "path", ")", "?", "File", ".", "mtime", "(", "path", ")", ".", "to_i", ".", "to_s", ...
Similar to the AssetTagHelper's method of the same name, this will determine the correct asset id for a file.
[ "Similar", "to", "the", "AssetTagHelper", "s", "method", "of", "the", "same", "name", "this", "will", "determine", "the", "correct", "asset", "id", "for", "a", "file", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/compressor.rb#L222-L226
17,525
documentcloud/jammit
lib/jammit/compressor.rb
Jammit.Compressor.embeddable?
def embeddable?(asset_path, variant) font = EMBED_FONTS.include?(asset_path.extname) return false unless variant return false unless asset_path.to_s.match(EMBEDDABLE) && asset_path.exist? return false unless EMBED_EXTS.include?(asset_path.extname) return false unless font || encoded_conten...
ruby
def embeddable?(asset_path, variant) font = EMBED_FONTS.include?(asset_path.extname) return false unless variant return false unless asset_path.to_s.match(EMBEDDABLE) && asset_path.exist? return false unless EMBED_EXTS.include?(asset_path.extname) return false unless font || encoded_conten...
[ "def", "embeddable?", "(", "asset_path", ",", "variant", ")", "font", "=", "EMBED_FONTS", ".", "include?", "(", "asset_path", ".", "extname", ")", "return", "false", "unless", "variant", "return", "false", "unless", "asset_path", ".", "to_s", ".", "match", "...
An asset is valid for embedding if it exists, is less than 32K, and is stored somewhere inside of a folder named "embed". IE does not support Data-URIs larger than 32K, and you probably shouldn't be embedding assets that large in any case. Because we need to check the base64 length here, save it so that we don't ha...
[ "An", "asset", "is", "valid", "for", "embedding", "if", "it", "exists", "is", "less", "than", "32K", "and", "is", "stored", "somewhere", "inside", "of", "a", "folder", "named", "embed", ".", "IE", "does", "not", "support", "Data", "-", "URIs", "larger", ...
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/compressor.rb#L233-L241
17,526
documentcloud/jammit
lib/jammit/compressor.rb
Jammit.Compressor.encoded_contents
def encoded_contents(asset_path) return @asset_contents[asset_path] if @asset_contents[asset_path] data = read_binary_file(asset_path) @asset_contents[asset_path] = Base64.encode64(data).gsub(/\n/, '') end
ruby
def encoded_contents(asset_path) return @asset_contents[asset_path] if @asset_contents[asset_path] data = read_binary_file(asset_path) @asset_contents[asset_path] = Base64.encode64(data).gsub(/\n/, '') end
[ "def", "encoded_contents", "(", "asset_path", ")", "return", "@asset_contents", "[", "asset_path", "]", "if", "@asset_contents", "[", "asset_path", "]", "data", "=", "read_binary_file", "(", "asset_path", ")", "@asset_contents", "[", "asset_path", "]", "=", "Base6...
Return the Base64-encoded contents of an asset on a single line.
[ "Return", "the", "Base64", "-", "encoded", "contents", "of", "an", "asset", "on", "a", "single", "line", "." ]
dc866f1ac3eb069d65215599c451db39d66119a7
https://github.com/documentcloud/jammit/blob/dc866f1ac3eb069d65215599c451db39d66119a7/lib/jammit/compressor.rb#L244-L248
17,527
progapandist/rubotnik
lib/rubotnik/helpers.rb
Rubotnik.Helpers.say
def say(text, quick_replies: [], user: @user) message_options = { recipient: { id: user.id }, message: { text: text } } if quick_replies && !quick_replies.empty? message_options[:message][:quick_replies] = UI::QuickReplies ....
ruby
def say(text, quick_replies: [], user: @user) message_options = { recipient: { id: user.id }, message: { text: text } } if quick_replies && !quick_replies.empty? message_options[:message][:quick_replies] = UI::QuickReplies ....
[ "def", "say", "(", "text", ",", "quick_replies", ":", "[", "]", ",", "user", ":", "@user", ")", "message_options", "=", "{", "recipient", ":", "{", "id", ":", "user", ".", "id", "}", ",", "message", ":", "{", "text", ":", "text", "}", "}", "if", ...
abstraction over Bot.deliver to send messages declaratively and directly
[ "abstraction", "over", "Bot", ".", "deliver", "to", "send", "messages", "declaratively", "and", "directly" ]
b79f54b5a3605339281508cb503fa0b6f84f3d07
https://github.com/progapandist/rubotnik/blob/b79f54b5a3605339281508cb503fa0b6f84f3d07/lib/rubotnik/helpers.rb#L12-L23
17,528
Homebrew/ruby-macho
lib/macho/fat_file.rb
MachO.FatFile.change_dylib_id
def change_dylib_id(new_id, options = {}) raise ArgumentError, "argument must be a String" unless new_id.is_a?(String) return unless machos.all?(&:dylib?) each_macho(options) do |macho| macho.change_dylib_id(new_id, options) end repopulate_raw_machos end
ruby
def change_dylib_id(new_id, options = {}) raise ArgumentError, "argument must be a String" unless new_id.is_a?(String) return unless machos.all?(&:dylib?) each_macho(options) do |macho| macho.change_dylib_id(new_id, options) end repopulate_raw_machos end
[ "def", "change_dylib_id", "(", "new_id", ",", "options", "=", "{", "}", ")", "raise", "ArgumentError", ",", "\"argument must be a String\"", "unless", "new_id", ".", "is_a?", "(", "String", ")", "return", "unless", "machos", ".", "all?", "(", ":dylib?", ")", ...
Changes the file's dylib ID to `new_id`. If the file is not a dylib, does nothing. @example file.change_dylib_id('libFoo.dylib') @param new_id [String] the new dylib ID @param options [Hash] @option options [Boolean] :strict (true) if true, fail if one slice fails. if false, fail only if all slices fail. @re...
[ "Changes", "the", "file", "s", "dylib", "ID", "to", "new_id", ".", "If", "the", "file", "is", "not", "a", "dylib", "does", "nothing", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/fat_file.rb#L180-L189
17,529
Homebrew/ruby-macho
lib/macho/fat_file.rb
MachO.FatFile.change_install_name
def change_install_name(old_name, new_name, options = {}) each_macho(options) do |macho| macho.change_install_name(old_name, new_name, options) end repopulate_raw_machos end
ruby
def change_install_name(old_name, new_name, options = {}) each_macho(options) do |macho| macho.change_install_name(old_name, new_name, options) end repopulate_raw_machos end
[ "def", "change_install_name", "(", "old_name", ",", "new_name", ",", "options", "=", "{", "}", ")", "each_macho", "(", "options", ")", "do", "|", "macho", "|", "macho", ".", "change_install_name", "(", "old_name", ",", "new_name", ",", "options", ")", "end...
Changes all dependent shared library install names from `old_name` to `new_name`. In a fat file, this changes install names in all internal Mach-Os. @example file.change_install_name('/usr/lib/libFoo.dylib', '/usr/lib/libBar.dylib') @param old_name [String] the shared library name being changed @param new_name [...
[ "Changes", "all", "dependent", "shared", "library", "install", "names", "from", "old_name", "to", "new_name", ".", "In", "a", "fat", "file", "this", "changes", "install", "names", "in", "all", "internal", "Mach", "-", "Os", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/fat_file.rb#L215-L221
17,530
Homebrew/ruby-macho
lib/macho/fat_file.rb
MachO.FatFile.change_rpath
def change_rpath(old_path, new_path, options = {}) each_macho(options) do |macho| macho.change_rpath(old_path, new_path, options) end repopulate_raw_machos end
ruby
def change_rpath(old_path, new_path, options = {}) each_macho(options) do |macho| macho.change_rpath(old_path, new_path, options) end repopulate_raw_machos end
[ "def", "change_rpath", "(", "old_path", ",", "new_path", ",", "options", "=", "{", "}", ")", "each_macho", "(", "options", ")", "do", "|", "macho", "|", "macho", ".", "change_rpath", "(", "old_path", ",", "new_path", ",", "options", ")", "end", "repopula...
Change the runtime path `old_path` to `new_path` in the file's Mach-Os. @param old_path [String] the old runtime path @param new_path [String] the new runtime path @param options [Hash] @option options [Boolean] :strict (true) if true, fail if one slice fails. if false, fail only if all slices fail. @return [voi...
[ "Change", "the", "runtime", "path", "old_path", "to", "new_path", "in", "the", "file", "s", "Mach", "-", "Os", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/fat_file.rb#L241-L247
17,531
Homebrew/ruby-macho
lib/macho/fat_file.rb
MachO.FatFile.add_rpath
def add_rpath(path, options = {}) each_macho(options) do |macho| macho.add_rpath(path, options) end repopulate_raw_machos end
ruby
def add_rpath(path, options = {}) each_macho(options) do |macho| macho.add_rpath(path, options) end repopulate_raw_machos end
[ "def", "add_rpath", "(", "path", ",", "options", "=", "{", "}", ")", "each_macho", "(", "options", ")", "do", "|", "macho", "|", "macho", ".", "add_rpath", "(", "path", ",", "options", ")", "end", "repopulate_raw_machos", "end" ]
Add the given runtime path to the file's Mach-Os. @param path [String] the new runtime path @param options [Hash] @option options [Boolean] :strict (true) if true, fail if one slice fails. if false, fail only if all slices fail. @return [void] @see MachOFile#add_rpath
[ "Add", "the", "given", "runtime", "path", "to", "the", "file", "s", "Mach", "-", "Os", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/fat_file.rb#L256-L262
17,532
Homebrew/ruby-macho
lib/macho/fat_file.rb
MachO.FatFile.delete_rpath
def delete_rpath(path, options = {}) each_macho(options) do |macho| macho.delete_rpath(path, options) end repopulate_raw_machos end
ruby
def delete_rpath(path, options = {}) each_macho(options) do |macho| macho.delete_rpath(path, options) end repopulate_raw_machos end
[ "def", "delete_rpath", "(", "path", ",", "options", "=", "{", "}", ")", "each_macho", "(", "options", ")", "do", "|", "macho", "|", "macho", ".", "delete_rpath", "(", "path", ",", "options", ")", "end", "repopulate_raw_machos", "end" ]
Delete the given runtime path from the file's Mach-Os. @param path [String] the runtime path to delete @param options [Hash] @option options [Boolean] :strict (true) if true, fail if one slice fails. if false, fail only if all slices fail. @return void @see MachOFile#delete_rpath
[ "Delete", "the", "given", "runtime", "path", "from", "the", "file", "s", "Mach", "-", "Os", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/fat_file.rb#L271-L277
17,533
Homebrew/ruby-macho
lib/macho/fat_file.rb
MachO.FatFile.populate_fat_header
def populate_fat_header # the smallest fat Mach-O header is 8 bytes raise TruncatedFileError if @raw_data.size < 8 fh = Headers::FatHeader.new_from_bin(:big, @raw_data[0, Headers::FatHeader.bytesize]) raise MagicError, fh.magic unless Utils.magic?(fh.magic) raise MachOBinaryError unless ...
ruby
def populate_fat_header # the smallest fat Mach-O header is 8 bytes raise TruncatedFileError if @raw_data.size < 8 fh = Headers::FatHeader.new_from_bin(:big, @raw_data[0, Headers::FatHeader.bytesize]) raise MagicError, fh.magic unless Utils.magic?(fh.magic) raise MachOBinaryError unless ...
[ "def", "populate_fat_header", "# the smallest fat Mach-O header is 8 bytes", "raise", "TruncatedFileError", "if", "@raw_data", ".", "size", "<", "8", "fh", "=", "Headers", "::", "FatHeader", ".", "new_from_bin", "(", ":big", ",", "@raw_data", "[", "0", ",", "Headers...
Obtain the fat header from raw file data. @return [Headers::FatHeader] the fat header @raise [TruncatedFileError] if the file is too small to have a valid header @raise [MagicError] if the magic is not valid Mach-O magic @raise [MachOBinaryError] if the magic is for a non-fat Mach-O file @raise [JavaClassFileErr...
[ "Obtain", "the", "fat", "header", "from", "raw", "file", "data", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/fat_file.rb#L324-L343
17,534
Homebrew/ruby-macho
lib/macho/fat_file.rb
MachO.FatFile.populate_fat_archs
def populate_fat_archs archs = [] fa_klass = Utils.fat_magic32?(header.magic) ? Headers::FatArch : Headers::FatArch64 fa_off = Headers::FatHeader.bytesize fa_len = fa_klass.bytesize header.nfat_arch.times do |i| archs << fa_klass.new_from_bin(:big, @raw_data[fa_off + (fa_len ...
ruby
def populate_fat_archs archs = [] fa_klass = Utils.fat_magic32?(header.magic) ? Headers::FatArch : Headers::FatArch64 fa_off = Headers::FatHeader.bytesize fa_len = fa_klass.bytesize header.nfat_arch.times do |i| archs << fa_klass.new_from_bin(:big, @raw_data[fa_off + (fa_len ...
[ "def", "populate_fat_archs", "archs", "=", "[", "]", "fa_klass", "=", "Utils", ".", "fat_magic32?", "(", "header", ".", "magic", ")", "?", "Headers", "::", "FatArch", ":", "Headers", "::", "FatArch64", "fa_off", "=", "Headers", "::", "FatHeader", ".", "byt...
Obtain an array of fat architectures from raw file data. @return [Array<Headers::FatArch>] an array of fat architectures @api private
[ "Obtain", "an", "array", "of", "fat", "architectures", "from", "raw", "file", "data", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/fat_file.rb#L348-L360
17,535
Homebrew/ruby-macho
lib/macho/fat_file.rb
MachO.FatFile.populate_machos
def populate_machos machos = [] fat_archs.each do |arch| machos << MachOFile.new_from_bin(@raw_data[arch.offset, arch.size], **options) end machos end
ruby
def populate_machos machos = [] fat_archs.each do |arch| machos << MachOFile.new_from_bin(@raw_data[arch.offset, arch.size], **options) end machos end
[ "def", "populate_machos", "machos", "=", "[", "]", "fat_archs", ".", "each", "do", "|", "arch", "|", "machos", "<<", "MachOFile", ".", "new_from_bin", "(", "@raw_data", "[", "arch", ".", "offset", ",", "arch", ".", "size", "]", ",", "**", "options", ")...
Obtain an array of Mach-O blobs from raw file data. @return [Array<MachOFile>] an array of Mach-Os @api private
[ "Obtain", "an", "array", "of", "Mach", "-", "O", "blobs", "from", "raw", "file", "data", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/fat_file.rb#L365-L373
17,536
Homebrew/ruby-macho
lib/macho/fat_file.rb
MachO.FatFile.repopulate_raw_machos
def repopulate_raw_machos machos.each_with_index do |macho, i| arch = fat_archs[i] @raw_data[arch.offset, arch.size] = macho.serialize end end
ruby
def repopulate_raw_machos machos.each_with_index do |macho, i| arch = fat_archs[i] @raw_data[arch.offset, arch.size] = macho.serialize end end
[ "def", "repopulate_raw_machos", "machos", ".", "each_with_index", "do", "|", "macho", ",", "i", "|", "arch", "=", "fat_archs", "[", "i", "]", "@raw_data", "[", "arch", ".", "offset", ",", "arch", ".", "size", "]", "=", "macho", ".", "serialize", "end", ...
Repopulate the raw Mach-O data with each internal Mach-O object. @return [void] @api private
[ "Repopulate", "the", "raw", "Mach", "-", "O", "data", "with", "each", "internal", "Mach", "-", "O", "object", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/fat_file.rb#L378-L384
17,537
Homebrew/ruby-macho
lib/macho/fat_file.rb
MachO.FatFile.each_macho
def each_macho(options = {}) strict = options.fetch(:strict, true) errors = [] machos.each_with_index do |macho, index| begin yield macho rescue RecoverableModificationError => e e.macho_slice = index # Strict mode: Immediately re-raise. Otherwise: Retai...
ruby
def each_macho(options = {}) strict = options.fetch(:strict, true) errors = [] machos.each_with_index do |macho, index| begin yield macho rescue RecoverableModificationError => e e.macho_slice = index # Strict mode: Immediately re-raise. Otherwise: Retai...
[ "def", "each_macho", "(", "options", "=", "{", "}", ")", "strict", "=", "options", ".", "fetch", "(", ":strict", ",", "true", ")", "errors", "=", "[", "]", "machos", ".", "each_with_index", "do", "|", "macho", ",", "index", "|", "begin", "yield", "ma...
Yield each Mach-O object in the file, rescuing and accumulating errors. @param options [Hash] @option options [Boolean] :strict (true) whether or not to fail loudly with an exception if at least one Mach-O raises an exception. If false, only raises an exception if *all* Mach-Os raise exceptions. @raise [Recovera...
[ "Yield", "each", "Mach", "-", "O", "object", "in", "the", "file", "rescuing", "and", "accumulating", "errors", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/fat_file.rb#L394-L413
17,538
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.insert_command
def insert_command(offset, lc, options = {}) context = LoadCommands::LoadCommand::SerializationContext.context_for(self) cmd_raw = lc.serialize(context) fileoff = offset + cmd_raw.bytesize raise OffsetInsertionError, offset if offset < header.class.bytesize || fileoff > low_fileoff new_s...
ruby
def insert_command(offset, lc, options = {}) context = LoadCommands::LoadCommand::SerializationContext.context_for(self) cmd_raw = lc.serialize(context) fileoff = offset + cmd_raw.bytesize raise OffsetInsertionError, offset if offset < header.class.bytesize || fileoff > low_fileoff new_s...
[ "def", "insert_command", "(", "offset", ",", "lc", ",", "options", "=", "{", "}", ")", "context", "=", "LoadCommands", "::", "LoadCommand", "::", "SerializationContext", ".", "context_for", "(", "self", ")", "cmd_raw", "=", "lc", ".", "serialize", "(", "co...
Inserts a load command at the given offset. @param offset [Integer] the offset to insert at @param lc [LoadCommands::LoadCommand] the load command to insert @param options [Hash] @option options [Boolean] :repopulate (true) whether or not to repopulate the instance fields @raise [OffsetInsertionError] if the off...
[ "Inserts", "a", "load", "command", "at", "the", "given", "offset", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L155-L174
17,539
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.replace_command
def replace_command(old_lc, new_lc) context = LoadCommands::LoadCommand::SerializationContext.context_for(self) cmd_raw = new_lc.serialize(context) new_sizeofcmds = sizeofcmds + cmd_raw.bytesize - old_lc.cmdsize raise HeaderPadError, @filename if header.class.bytesize + new_sizeofcmds > low_fil...
ruby
def replace_command(old_lc, new_lc) context = LoadCommands::LoadCommand::SerializationContext.context_for(self) cmd_raw = new_lc.serialize(context) new_sizeofcmds = sizeofcmds + cmd_raw.bytesize - old_lc.cmdsize raise HeaderPadError, @filename if header.class.bytesize + new_sizeofcmds > low_fil...
[ "def", "replace_command", "(", "old_lc", ",", "new_lc", ")", "context", "=", "LoadCommands", "::", "LoadCommand", "::", "SerializationContext", ".", "context_for", "(", "self", ")", "cmd_raw", "=", "new_lc", ".", "serialize", "(", "context", ")", "new_sizeofcmds...
Replace a load command with another command in the Mach-O, preserving location. @param old_lc [LoadCommands::LoadCommand] the load command being replaced @param new_lc [LoadCommands::LoadCommand] the load command being added @return [void] @raise [HeaderPadError] if the new command exceeds the header pad buffer @s...
[ "Replace", "a", "load", "command", "with", "another", "command", "in", "the", "Mach", "-", "O", "preserving", "location", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L183-L192
17,540
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.delete_command
def delete_command(lc, options = {}) @raw_data.slice!(lc.view.offset, lc.cmdsize) # update Mach-O header fields to account for deleted load command update_ncmds(ncmds - 1) update_sizeofcmds(sizeofcmds - lc.cmdsize) # pad the space after the load commands to preserve offsets @raw_da...
ruby
def delete_command(lc, options = {}) @raw_data.slice!(lc.view.offset, lc.cmdsize) # update Mach-O header fields to account for deleted load command update_ncmds(ncmds - 1) update_sizeofcmds(sizeofcmds - lc.cmdsize) # pad the space after the load commands to preserve offsets @raw_da...
[ "def", "delete_command", "(", "lc", ",", "options", "=", "{", "}", ")", "@raw_data", ".", "slice!", "(", "lc", ".", "view", ".", "offset", ",", "lc", ".", "cmdsize", ")", "# update Mach-O header fields to account for deleted load command", "update_ncmds", "(", "...
Delete a load command from the Mach-O. @param lc [LoadCommands::LoadCommand] the load command being deleted @param options [Hash] @option options [Boolean] :repopulate (true) whether or not to repopulate the instance fields @return [void] @note This is public, but methods like {#delete_rpath} should be preferred...
[ "Delete", "a", "load", "command", "from", "the", "Mach", "-", "O", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L219-L230
17,541
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.segment_alignment
def segment_alignment # special cases: 12 for x86/64/PPC/PP64, 14 for ARM/ARM64 return 12 if %i[i386 x86_64 ppc ppc64].include?(cputype) return 14 if %i[arm arm64].include?(cputype) cur_align = Sections::MAX_SECT_ALIGN segments.each do |segment| if filetype == :object #...
ruby
def segment_alignment # special cases: 12 for x86/64/PPC/PP64, 14 for ARM/ARM64 return 12 if %i[i386 x86_64 ppc ppc64].include?(cputype) return 14 if %i[arm arm64].include?(cputype) cur_align = Sections::MAX_SECT_ALIGN segments.each do |segment| if filetype == :object #...
[ "def", "segment_alignment", "# special cases: 12 for x86/64/PPC/PP64, 14 for ARM/ARM64", "return", "12", "if", "%i[", "i386", "x86_64", "ppc", "ppc64", "]", ".", "include?", "(", "cputype", ")", "return", "14", "if", "%i[", "arm", "arm64", "]", ".", "include?", "(...
The segment alignment for the Mach-O. Guesses conservatively. @return [Integer] the alignment, as a power of 2 @note This is **not** the same as {#alignment}! @note See `get_align` and `get_align_64` in `cctools/misc/lipo.c`
[ "The", "segment", "alignment", "for", "the", "Mach", "-", "O", ".", "Guesses", "conservatively", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L263-L284
17,542
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.change_dylib_id
def change_dylib_id(new_id, _options = {}) raise ArgumentError, "new ID must be a String" unless new_id.is_a?(String) return unless dylib? old_lc = command(:LC_ID_DYLIB).first raise DylibIdMissingError unless old_lc new_lc = LoadCommands::LoadCommand.create(:LC_ID_DYLIB, new_id, ...
ruby
def change_dylib_id(new_id, _options = {}) raise ArgumentError, "new ID must be a String" unless new_id.is_a?(String) return unless dylib? old_lc = command(:LC_ID_DYLIB).first raise DylibIdMissingError unless old_lc new_lc = LoadCommands::LoadCommand.create(:LC_ID_DYLIB, new_id, ...
[ "def", "change_dylib_id", "(", "new_id", ",", "_options", "=", "{", "}", ")", "raise", "ArgumentError", ",", "\"new ID must be a String\"", "unless", "new_id", ".", "is_a?", "(", "String", ")", "return", "unless", "dylib?", "old_lc", "=", "command", "(", ":LC_...
Changes the Mach-O's dylib ID to `new_id`. Does nothing if not a dylib. @example file.change_dylib_id("libFoo.dylib") @param new_id [String] the dylib's new ID @param _options [Hash] @return [void] @raise [ArgumentError] if `new_id` is not a String @note `_options` is currently unused and is provided for signat...
[ "Changes", "the", "Mach", "-", "O", "s", "dylib", "ID", "to", "new_id", ".", "Does", "nothing", "if", "not", "a", "dylib", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L307-L320
17,543
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.change_install_name
def change_install_name(old_name, new_name, _options = {}) old_lc = dylib_load_commands.find { |d| d.name.to_s == old_name } raise DylibUnknownError, old_name if old_lc.nil? new_lc = LoadCommands::LoadCommand.create(old_lc.type, new_name, old_lc.timesta...
ruby
def change_install_name(old_name, new_name, _options = {}) old_lc = dylib_load_commands.find { |d| d.name.to_s == old_name } raise DylibUnknownError, old_name if old_lc.nil? new_lc = LoadCommands::LoadCommand.create(old_lc.type, new_name, old_lc.timesta...
[ "def", "change_install_name", "(", "old_name", ",", "new_name", ",", "_options", "=", "{", "}", ")", "old_lc", "=", "dylib_load_commands", ".", "find", "{", "|", "d", "|", "d", ".", "name", ".", "to_s", "==", "old_name", "}", "raise", "DylibUnknownError", ...
Changes the shared library `old_name` to `new_name` @example file.change_install_name("abc.dylib", "def.dylib") @param old_name [String] the shared library's old name @param new_name [String] the shared library's new name @param _options [Hash] @return [void] @raise [DylibUnknownError] if no shared library has ...
[ "Changes", "the", "shared", "library", "old_name", "to", "new_name" ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L344-L354
17,544
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.change_rpath
def change_rpath(old_path, new_path, _options = {}) old_lc = command(:LC_RPATH).find { |r| r.path.to_s == old_path } raise RpathUnknownError, old_path if old_lc.nil? raise RpathExistsError, new_path if rpaths.include?(new_path) new_lc = LoadCommands::LoadCommand.create(:LC_RPATH, new_path) ...
ruby
def change_rpath(old_path, new_path, _options = {}) old_lc = command(:LC_RPATH).find { |r| r.path.to_s == old_path } raise RpathUnknownError, old_path if old_lc.nil? raise RpathExistsError, new_path if rpaths.include?(new_path) new_lc = LoadCommands::LoadCommand.create(:LC_RPATH, new_path) ...
[ "def", "change_rpath", "(", "old_path", ",", "new_path", ",", "_options", "=", "{", "}", ")", "old_lc", "=", "command", "(", ":LC_RPATH", ")", ".", "find", "{", "|", "r", "|", "r", ".", "path", ".", "to_s", "==", "old_path", "}", "raise", "RpathUnkno...
Changes the runtime path `old_path` to `new_path` @example file.change_rpath("/usr/lib", "/usr/local/lib") @param old_path [String] the old runtime path @param new_path [String] the new runtime path @param _options [Hash] @return [void] @raise [RpathUnknownError] if no such old runtime path exists @raise [Rpat...
[ "Changes", "the", "runtime", "path", "old_path", "to", "new_path" ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L375-L384
17,545
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.add_rpath
def add_rpath(path, _options = {}) raise RpathExistsError, path if rpaths.include?(path) rpath_cmd = LoadCommands::LoadCommand.create(:LC_RPATH, path) add_command(rpath_cmd) end
ruby
def add_rpath(path, _options = {}) raise RpathExistsError, path if rpaths.include?(path) rpath_cmd = LoadCommands::LoadCommand.create(:LC_RPATH, path) add_command(rpath_cmd) end
[ "def", "add_rpath", "(", "path", ",", "_options", "=", "{", "}", ")", "raise", "RpathExistsError", ",", "path", "if", "rpaths", ".", "include?", "(", "path", ")", "rpath_cmd", "=", "LoadCommands", "::", "LoadCommand", ".", "create", "(", ":LC_RPATH", ",", ...
Add the given runtime path to the Mach-O. @example file.rpaths # => ["/lib"] file.add_rpath("/usr/lib") file.rpaths # => ["/lib", "/usr/lib"] @param path [String] the new runtime path @param _options [Hash] @return [void] @raise [RpathExistsError] if the runtime path already exists @note `_options` is curre...
[ "Add", "the", "given", "runtime", "path", "to", "the", "Mach", "-", "O", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L397-L402
17,546
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.delete_rpath
def delete_rpath(path, _options = {}) rpath_cmds = command(:LC_RPATH).select { |r| r.path.to_s == path } raise RpathUnknownError, path if rpath_cmds.empty? # delete the commands in reverse order, offset descending. this # allows us to defer (expensive) field population until the very end ...
ruby
def delete_rpath(path, _options = {}) rpath_cmds = command(:LC_RPATH).select { |r| r.path.to_s == path } raise RpathUnknownError, path if rpath_cmds.empty? # delete the commands in reverse order, offset descending. this # allows us to defer (expensive) field population until the very end ...
[ "def", "delete_rpath", "(", "path", ",", "_options", "=", "{", "}", ")", "rpath_cmds", "=", "command", "(", ":LC_RPATH", ")", ".", "select", "{", "|", "r", "|", "r", ".", "path", ".", "to_s", "==", "path", "}", "raise", "RpathUnknownError", ",", "pat...
Delete the given runtime path from the Mach-O. @example file.rpaths # => ["/lib"] file.delete_rpath("/lib") file.rpaths # => [] @param path [String] the runtime path to delete @param _options [Hash] @return void @raise [RpathUnknownError] if no such runtime path exists @note `_options` is currently unused a...
[ "Delete", "the", "given", "runtime", "path", "from", "the", "Mach", "-", "O", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L415-L424
17,547
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.populate_mach_header
def populate_mach_header # the smallest Mach-O header is 28 bytes raise TruncatedFileError if @raw_data.size < 28 magic = populate_and_check_magic mh_klass = Utils.magic32?(magic) ? Headers::MachHeader : Headers::MachHeader64 mh = mh_klass.new_from_bin(endianness, @raw_data[0, mh_klass.by...
ruby
def populate_mach_header # the smallest Mach-O header is 28 bytes raise TruncatedFileError if @raw_data.size < 28 magic = populate_and_check_magic mh_klass = Utils.magic32?(magic) ? Headers::MachHeader : Headers::MachHeader64 mh = mh_klass.new_from_bin(endianness, @raw_data[0, mh_klass.by...
[ "def", "populate_mach_header", "# the smallest Mach-O header is 28 bytes", "raise", "TruncatedFileError", "if", "@raw_data", ".", "size", "<", "28", "magic", "=", "populate_and_check_magic", "mh_klass", "=", "Utils", ".", "magic32?", "(", "magic", ")", "?", "Headers", ...
The file's Mach-O header structure. @return [Headers::MachHeader] if the Mach-O is 32-bit @return [Headers::MachHeader64] if the Mach-O is 64-bit @raise [TruncatedFileError] if the file is too small to have a valid header @api private
[ "The", "file", "s", "Mach", "-", "O", "header", "structure", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L458-L471
17,548
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.populate_and_check_magic
def populate_and_check_magic magic = @raw_data[0..3].unpack("N").first raise MagicError, magic unless Utils.magic?(magic) raise FatBinaryError if Utils.fat_magic?(magic) @endianness = Utils.little_magic?(magic) ? :little : :big magic end
ruby
def populate_and_check_magic magic = @raw_data[0..3].unpack("N").first raise MagicError, magic unless Utils.magic?(magic) raise FatBinaryError if Utils.fat_magic?(magic) @endianness = Utils.little_magic?(magic) ? :little : :big magic end
[ "def", "populate_and_check_magic", "magic", "=", "@raw_data", "[", "0", "..", "3", "]", ".", "unpack", "(", "\"N\"", ")", ".", "first", "raise", "MagicError", ",", "magic", "unless", "Utils", ".", "magic?", "(", "magic", ")", "raise", "FatBinaryError", "if...
Read just the file's magic number and check its validity. @return [Integer] the magic @raise [MagicError] if the magic is not valid Mach-O magic @raise [FatBinaryError] if the magic is for a Fat file @api private
[ "Read", "just", "the", "file", "s", "magic", "number", "and", "check", "its", "validity", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L478-L487
17,549
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.populate_load_commands
def populate_load_commands permissive = options.fetch(:permissive, false) offset = header.class.bytesize load_commands = [] header.ncmds.times do fmt = Utils.specialize_format("L=", endianness) cmd = @raw_data.slice(offset, 4).unpack(fmt).first cmd_sym = LoadCommands::LO...
ruby
def populate_load_commands permissive = options.fetch(:permissive, false) offset = header.class.bytesize load_commands = [] header.ncmds.times do fmt = Utils.specialize_format("L=", endianness) cmd = @raw_data.slice(offset, 4).unpack(fmt).first cmd_sym = LoadCommands::LO...
[ "def", "populate_load_commands", "permissive", "=", "options", ".", "fetch", "(", ":permissive", ",", "false", ")", "offset", "=", "header", ".", "class", ".", "bytesize", "load_commands", "=", "[", "]", "header", ".", "ncmds", ".", "times", "do", "fmt", "...
All load commands in the file. @return [Array<LoadCommands::LoadCommand>] an array of load commands @raise [LoadCommandError] if an unknown load command is encountered @api private
[ "All", "load", "commands", "in", "the", "file", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L518-L546
17,550
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.update_ncmds
def update_ncmds(ncmds) fmt = Utils.specialize_format("L=", endianness) ncmds_raw = [ncmds].pack(fmt) @raw_data[16..19] = ncmds_raw end
ruby
def update_ncmds(ncmds) fmt = Utils.specialize_format("L=", endianness) ncmds_raw = [ncmds].pack(fmt) @raw_data[16..19] = ncmds_raw end
[ "def", "update_ncmds", "(", "ncmds", ")", "fmt", "=", "Utils", ".", "specialize_format", "(", "\"L=\"", ",", "endianness", ")", "ncmds_raw", "=", "[", "ncmds", "]", ".", "pack", "(", "fmt", ")", "@raw_data", "[", "16", "..", "19", "]", "=", "ncmds_raw"...
Updates the number of load commands in the raw data. @param ncmds [Integer] the new number of commands @return [void] @api private
[ "Updates", "the", "number", "of", "load", "commands", "in", "the", "raw", "data", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L572-L576
17,551
Homebrew/ruby-macho
lib/macho/macho_file.rb
MachO.MachOFile.update_sizeofcmds
def update_sizeofcmds(size) fmt = Utils.specialize_format("L=", endianness) size_raw = [size].pack(fmt) @raw_data[20..23] = size_raw end
ruby
def update_sizeofcmds(size) fmt = Utils.specialize_format("L=", endianness) size_raw = [size].pack(fmt) @raw_data[20..23] = size_raw end
[ "def", "update_sizeofcmds", "(", "size", ")", "fmt", "=", "Utils", ".", "specialize_format", "(", "\"L=\"", ",", "endianness", ")", "size_raw", "=", "[", "size", "]", ".", "pack", "(", "fmt", ")", "@raw_data", "[", "20", "..", "23", "]", "=", "size_raw...
Updates the size of all load commands in the raw data. @param size [Integer] the new size, in bytes @return [void] @api private
[ "Updates", "the", "size", "of", "all", "load", "commands", "in", "the", "raw", "data", "." ]
a1dedc25bc78a9bd6366988d12e122ee3d420e8c
https://github.com/Homebrew/ruby-macho/blob/a1dedc25bc78a9bd6366988d12e122ee3d420e8c/lib/macho/macho_file.rb#L582-L586
17,552
makaroni4/sandi_meter
lib/sandi_meter/analyzer.rb
SandiMeter.Analyzer.number_of_arguments
def number_of_arguments(method_sexp) arguments = method_sexp[2] arguments = arguments[1] if arguments.first == :paren arguments[1] == nil ? 0 : arguments[1].size end
ruby
def number_of_arguments(method_sexp) arguments = method_sexp[2] arguments = arguments[1] if arguments.first == :paren arguments[1] == nil ? 0 : arguments[1].size end
[ "def", "number_of_arguments", "(", "method_sexp", ")", "arguments", "=", "method_sexp", "[", "2", "]", "arguments", "=", "arguments", "[", "1", "]", "if", "arguments", ".", "first", "==", ":paren", "arguments", "[", "1", "]", "==", "nil", "?", "0", ":", ...
MOVE to method scanner class
[ "MOVE", "to", "method", "scanner", "class" ]
a8d04630cc196edf748ae8cdd66b9c53f0878de0
https://github.com/makaroni4/sandi_meter/blob/a8d04630cc196edf748ae8cdd66b9c53f0878de0/lib/sandi_meter/analyzer.rb#L67-L72
17,553
dnsimple/dnsimple-ruby
lib/dnsimple/client.rb
Dnsimple.Client.execute
def execute(method, path, data = nil, options = {}) response = request(method, path, data, options) case response.code when 200..299 response when 401 raise AuthenticationFailed, response["message"] when 404 raise NotFoundError, response else raise Re...
ruby
def execute(method, path, data = nil, options = {}) response = request(method, path, data, options) case response.code when 200..299 response when 401 raise AuthenticationFailed, response["message"] when 404 raise NotFoundError, response else raise Re...
[ "def", "execute", "(", "method", ",", "path", ",", "data", "=", "nil", ",", "options", "=", "{", "}", ")", "response", "=", "request", "(", "method", ",", "path", ",", "data", ",", "options", ")", "case", "response", ".", "code", "when", "200", ".....
Executes a request, validates and returns the response. @param [String] method The HTTP method @param [String] path The path, relative to {#base_url} @param [Hash] data The body for the request @param [Hash] options The query and header params for the request @return [HTTParty::Response] @raise [RequestErro...
[ "Executes", "a", "request", "validates", "and", "returns", "the", "response", "." ]
cb75e47ec4de89954e56a80498796269717beb23
https://github.com/dnsimple/dnsimple-ruby/blob/cb75e47ec4de89954e56a80498796269717beb23/lib/dnsimple/client.rb#L154-L167
17,554
dnsimple/dnsimple-ruby
lib/dnsimple/client.rb
Dnsimple.Client.request
def request(method, path, data = nil, options = {}) request_options = request_options(options) if data request_options[:headers]["Content-Type"] = content_type(request_options[:headers]) request_options[:body] = content_data(request_options[:headers], data) end HTTParty.send(me...
ruby
def request(method, path, data = nil, options = {}) request_options = request_options(options) if data request_options[:headers]["Content-Type"] = content_type(request_options[:headers]) request_options[:body] = content_data(request_options[:headers], data) end HTTParty.send(me...
[ "def", "request", "(", "method", ",", "path", ",", "data", "=", "nil", ",", "options", "=", "{", "}", ")", "request_options", "=", "request_options", "(", "options", ")", "if", "data", "request_options", "[", ":headers", "]", "[", "\"Content-Type\"", "]", ...
Make a HTTP request. This method doesn't validate the response and never raise errors even in case of HTTP error codes, except for connection errors raised by the underlying HTTP client. Therefore, it's up to the caller to properly handle and validate the response. @param [String] method The HTTP method @para...
[ "Make", "a", "HTTP", "request", "." ]
cb75e47ec4de89954e56a80498796269717beb23
https://github.com/dnsimple/dnsimple-ruby/blob/cb75e47ec4de89954e56a80498796269717beb23/lib/dnsimple/client.rb#L182-L191
17,555
jpmobile/jpmobile
lib/jpmobile/request_with_mobile.rb
Jpmobile.RequestWithMobile.remote_addr
def remote_addr if respond_to?(:remote_ip) __send__(:remote_ip) # for Rails elsif respond_to?(:ip) __send__(:ip) # for Rack else if env['HTTP_X_FORWARDED_FOR'] env['HTTP_X_FORWARDED_FOR'].split(',').pop else env['REMOTE_ADDR'] end ...
ruby
def remote_addr if respond_to?(:remote_ip) __send__(:remote_ip) # for Rails elsif respond_to?(:ip) __send__(:ip) # for Rack else if env['HTTP_X_FORWARDED_FOR'] env['HTTP_X_FORWARDED_FOR'].split(',').pop else env['REMOTE_ADDR'] end ...
[ "def", "remote_addr", "if", "respond_to?", "(", ":remote_ip", ")", "__send__", "(", ":remote_ip", ")", "# for Rails", "elsif", "respond_to?", "(", ":ip", ")", "__send__", "(", ":ip", ")", "# for Rack", "else", "if", "env", "[", "'HTTP_X_FORWARDED_FOR'", "]", "...
for reverse proxy.
[ "for", "reverse", "proxy", "." ]
4758f4a3fafbd8dc8c6051f3b79b231e4742612b
https://github.com/jpmobile/jpmobile/blob/4758f4a3fafbd8dc8c6051f3b79b231e4742612b/lib/jpmobile/request_with_mobile.rb#L13-L25
17,556
jpmobile/jpmobile
lib/jpmobile/mobile/abstract_mobile.rb
Jpmobile::Mobile.AbstractMobile.variants
def variants return @_variants if @_variants @_variants = self.class.ancestors.select {|c| c.to_s =~ /^Jpmobile/ && c.to_s !~ /Emoticon/ }.map do |klass| klass = klass.to_s. gsub(/Jpmobile::/, ''). gsub(/AbstractMobile::/, ''). gsub(/Mobile::Sma...
ruby
def variants return @_variants if @_variants @_variants = self.class.ancestors.select {|c| c.to_s =~ /^Jpmobile/ && c.to_s !~ /Emoticon/ }.map do |klass| klass = klass.to_s. gsub(/Jpmobile::/, ''). gsub(/AbstractMobile::/, ''). gsub(/Mobile::Sma...
[ "def", "variants", "return", "@_variants", "if", "@_variants", "@_variants", "=", "self", ".", "class", ".", "ancestors", ".", "select", "{", "|", "c", "|", "c", ".", "to_s", "=~", "/", "/", "&&", "c", ".", "to_s", "!~", "/", "/", "}", ".", "map", ...
for view selector
[ "for", "view", "selector" ]
4758f4a3fafbd8dc8c6051f3b79b231e4742612b
https://github.com/jpmobile/jpmobile/blob/4758f4a3fafbd8dc8c6051f3b79b231e4742612b/lib/jpmobile/mobile/abstract_mobile.rb#L94-L117
17,557
code-mancers/rapidfire
app/models/rapidfire/question.rb
Rapidfire.Question.validate_answer
def validate_answer(answer) if rules[:presence] == "1" answer.validates_presence_of :answer_text end if rules[:minimum].present? || rules[:maximum].present? min_max = { minimum: rules[:minimum].to_i } min_max[:maximum] = rules[:maximum].to_i if rules[:maximum].present? ...
ruby
def validate_answer(answer) if rules[:presence] == "1" answer.validates_presence_of :answer_text end if rules[:minimum].present? || rules[:maximum].present? min_max = { minimum: rules[:minimum].to_i } min_max[:maximum] = rules[:maximum].to_i if rules[:maximum].present? ...
[ "def", "validate_answer", "(", "answer", ")", "if", "rules", "[", ":presence", "]", "==", "\"1\"", "answer", ".", "validates_presence_of", ":answer_text", "end", "if", "rules", "[", ":minimum", "]", ".", "present?", "||", "rules", "[", ":maximum", "]", ".", ...
answer will delegate its validation to question, and question will inturn add validations on answer on the fly!
[ "answer", "will", "delegate", "its", "validation", "to", "question", "and", "question", "will", "inturn", "add", "validations", "on", "answer", "on", "the", "fly!" ]
f536c489bd2a8a5195c19275f7dce6d3e980524d
https://github.com/code-mancers/rapidfire/blob/f536c489bd2a8a5195c19275f7dce6d3e980524d/app/models/rapidfire/question.rb#L31-L42
17,558
tdiary/tdiary-core
misc/plugin/category-legacy.rb
Category.Cache.replace_sections
def replace_sections(diary) return if diary.nil? or !diary.categorizable? categorized = categorize_diary(diary) categories = restore_categories deleted = [] ymd = diary.date.strftime('%Y%m%d') @plugin.__send__(:transaction, 'category') do |db| categories.each do |c| cat = get(db, c) || {} if di...
ruby
def replace_sections(diary) return if diary.nil? or !diary.categorizable? categorized = categorize_diary(diary) categories = restore_categories deleted = [] ymd = diary.date.strftime('%Y%m%d') @plugin.__send__(:transaction, 'category') do |db| categories.each do |c| cat = get(db, c) || {} if di...
[ "def", "replace_sections", "(", "diary", ")", "return", "if", "diary", ".", "nil?", "or", "!", "diary", ".", "categorizable?", "categorized", "=", "categorize_diary", "(", "diary", ")", "categories", "=", "restore_categories", "deleted", "=", "[", "]", "ymd", ...
cache each section of diary used in update_proc
[ "cache", "each", "section", "of", "diary", "used", "in", "update_proc" ]
688b9378a872d6530ebd51788355fcd56b0f5b2d
https://github.com/tdiary/tdiary-core/blob/688b9378a872d6530ebd51788355fcd56b0f5b2d/misc/plugin/category-legacy.rb#L435-L465
17,559
tdiary/tdiary-core
misc/plugin/category-legacy.rb
Category.Cache.categorize
def categorize(category, years) categories = category - ['ALL'] if categories.empty? categories = restore_categories else categories &= restore_categories end categorized = {} begin categorized.clear categories.each do |c| @plugin.__send__(:transaction, 'category') do |db| categorized[...
ruby
def categorize(category, years) categories = category - ['ALL'] if categories.empty? categories = restore_categories else categories &= restore_categories end categorized = {} begin categorized.clear categories.each do |c| @plugin.__send__(:transaction, 'category') do |db| categorized[...
[ "def", "categorize", "(", "category", ",", "years", ")", "categories", "=", "category", "-", "[", "'ALL'", "]", "if", "categories", ".", "empty?", "categories", "=", "restore_categories", "else", "categories", "&=", "restore_categories", "end", "categorized", "=...
categorize sections of category of years {"category" => {"yyyymmdd" => [[idx, title, excerpt], ...], ...}, ...}
[ "categorize", "sections", "of", "category", "of", "years" ]
688b9378a872d6530ebd51788355fcd56b0f5b2d
https://github.com/tdiary/tdiary-core/blob/688b9378a872d6530ebd51788355fcd56b0f5b2d/misc/plugin/category-legacy.rb#L501-L530
17,560
tdiary/tdiary-core
misc/plugin/category-legacy.rb
Category.Cache.categorize_diary
def categorize_diary(diary) categorized = {} ymd = diary.date.strftime('%Y%m%d') idx = 1 diary.each_section do |s| shorten = begin body = %Q|apply_plugin(#{s.body_to_html.dump}, true)| @conf.shorten(eval(body, @binding)) rescue NameError "" end s.categories.each do |c| categorized[c...
ruby
def categorize_diary(diary) categorized = {} ymd = diary.date.strftime('%Y%m%d') idx = 1 diary.each_section do |s| shorten = begin body = %Q|apply_plugin(#{s.body_to_html.dump}, true)| @conf.shorten(eval(body, @binding)) rescue NameError "" end s.categories.each do |c| categorized[c...
[ "def", "categorize_diary", "(", "diary", ")", "categorized", "=", "{", "}", "ymd", "=", "diary", ".", "date", ".", "strftime", "(", "'%Y%m%d'", ")", "idx", "=", "1", "diary", ".", "each_section", "do", "|", "s", "|", "shorten", "=", "begin", "body", ...
categorize sections of diary {"category" => {"yyyymmdd" => [[idx, title, excerpt], ...]}}
[ "categorize", "sections", "of", "diary" ]
688b9378a872d6530ebd51788355fcd56b0f5b2d
https://github.com/tdiary/tdiary-core/blob/688b9378a872d6530ebd51788355fcd56b0f5b2d/misc/plugin/category-legacy.rb#L546-L567
17,561
tdiary/tdiary-core
lib/tdiary/dispatcher.rb
TDiary.Dispatcher.dispatch_cgi
def dispatch_cgi(request, cgi) result = @target.run( request, cgi ) result.headers.reject!{|k,v| k.to_s.downcase == "status" } result.to_a end
ruby
def dispatch_cgi(request, cgi) result = @target.run( request, cgi ) result.headers.reject!{|k,v| k.to_s.downcase == "status" } result.to_a end
[ "def", "dispatch_cgi", "(", "request", ",", "cgi", ")", "result", "=", "@target", ".", "run", "(", "request", ",", "cgi", ")", "result", ".", "headers", ".", "reject!", "{", "|", "k", ",", "v", "|", "k", ".", "to_s", ".", "downcase", "==", "\"statu...
FIXME rename method name to more suitable one.
[ "FIXME", "rename", "method", "name", "to", "more", "suitable", "one", "." ]
688b9378a872d6530ebd51788355fcd56b0f5b2d
https://github.com/tdiary/tdiary-core/blob/688b9378a872d6530ebd51788355fcd56b0f5b2d/lib/tdiary/dispatcher.rb#L24-L28
17,562
tdiary/tdiary-core
lib/tdiary/dispatcher.rb
TDiary.Dispatcher.fake_stdin_as_params
def fake_stdin_as_params stdin_spy = StringIO.new if $RACK_ENV && $RACK_ENV['rack.input'] stdin_spy.print($RACK_ENV['rack.input'].read) stdin_spy.rewind end $stdin = stdin_spy end
ruby
def fake_stdin_as_params stdin_spy = StringIO.new if $RACK_ENV && $RACK_ENV['rack.input'] stdin_spy.print($RACK_ENV['rack.input'].read) stdin_spy.rewind end $stdin = stdin_spy end
[ "def", "fake_stdin_as_params", "stdin_spy", "=", "StringIO", ".", "new", "if", "$RACK_ENV", "&&", "$RACK_ENV", "[", "'rack.input'", "]", "stdin_spy", ".", "print", "(", "$RACK_ENV", "[", "'rack.input'", "]", ".", "read", ")", "stdin_spy", ".", "rewind", "end",...
FIXME dirty hack
[ "FIXME", "dirty", "hack" ]
688b9378a872d6530ebd51788355fcd56b0f5b2d
https://github.com/tdiary/tdiary-core/blob/688b9378a872d6530ebd51788355fcd56b0f5b2d/lib/tdiary/dispatcher.rb#L80-L87
17,563
tdiary/tdiary-core
lib/tdiary/configuration.rb
TDiary.Configuration.load_cgi_conf
def load_cgi_conf def_vars1 = '' def_vars2 = '' [ :tdiary_version, :html_title, :author_name, :author_mail, :index_page, :hour_offset, :description, :icon, :banner, :x_frame_options, :header, :footer, :section_anchor, :comment_anchor, :date_format, :latest_limit, :show_nyear, :theme, :c...
ruby
def load_cgi_conf def_vars1 = '' def_vars2 = '' [ :tdiary_version, :html_title, :author_name, :author_mail, :index_page, :hour_offset, :description, :icon, :banner, :x_frame_options, :header, :footer, :section_anchor, :comment_anchor, :date_format, :latest_limit, :show_nyear, :theme, :c...
[ "def", "load_cgi_conf", "def_vars1", "=", "''", "def_vars2", "=", "''", "[", ":tdiary_version", ",", ":html_title", ",", ":author_name", ",", ":author_mail", ",", ":index_page", ",", ":hour_offset", ",", ":description", ",", ":icon", ",", ":banner", ",", ":x_fra...
loading tdiary.conf in @data_path.
[ "loading", "tdiary", ".", "conf", "in" ]
688b9378a872d6530ebd51788355fcd56b0f5b2d
https://github.com/tdiary/tdiary-core/blob/688b9378a872d6530ebd51788355fcd56b0f5b2d/lib/tdiary/configuration.rb#L83-L129
17,564
tdiary/tdiary-core
lib/tdiary/configuration.rb
TDiary.Configuration.configure_attrs
def configure_attrs @options = {} eval( File::open( 'tdiary.conf' ) {|f| f.read }, nil, "(tdiary.conf)", 1 ) # language setup @lang = 'ja' unless @lang begin instance_eval( File::open( "#{TDiary::PATH}/tdiary/lang/#{@lang}.rb" ){|f| f.read }, "(tdiary/lang/#{@lang}.rb)", 1 ) rescue Errno::ENOENT...
ruby
def configure_attrs @options = {} eval( File::open( 'tdiary.conf' ) {|f| f.read }, nil, "(tdiary.conf)", 1 ) # language setup @lang = 'ja' unless @lang begin instance_eval( File::open( "#{TDiary::PATH}/tdiary/lang/#{@lang}.rb" ){|f| f.read }, "(tdiary/lang/#{@lang}.rb)", 1 ) rescue Errno::ENOENT...
[ "def", "configure_attrs", "@options", "=", "{", "}", "eval", "(", "File", "::", "open", "(", "'tdiary.conf'", ")", "{", "|", "f", "|", "f", ".", "read", "}", ",", "nil", ",", "\"(tdiary.conf)\"", ",", "1", ")", "# language setup", "@lang", "=", "'ja'",...
loading tdiary.conf in current directory
[ "loading", "tdiary", ".", "conf", "in", "current", "directory" ]
688b9378a872d6530ebd51788355fcd56b0f5b2d
https://github.com/tdiary/tdiary-core/blob/688b9378a872d6530ebd51788355fcd56b0f5b2d/lib/tdiary/configuration.rb#L132-L197
17,565
josevalim/rails-footnotes
lib/rails-footnotes/filter.rb
Footnotes.Filter.close!
def close!(controller) self.each_with_rescue(@@klasses) {|klass| klass.close!(controller)} self.each_with_rescue(Footnotes.after_hooks) {|hook| hook.call(controller, self)} end
ruby
def close!(controller) self.each_with_rescue(@@klasses) {|klass| klass.close!(controller)} self.each_with_rescue(Footnotes.after_hooks) {|hook| hook.call(controller, self)} end
[ "def", "close!", "(", "controller", ")", "self", ".", "each_with_rescue", "(", "@@klasses", ")", "{", "|", "klass", "|", "klass", ".", "close!", "(", "controller", ")", "}", "self", ".", "each_with_rescue", "(", "Footnotes", ".", "after_hooks", ")", "{", ...
Calls the class method close! in each note Sometimes notes need to finish their work even after being read This method allows this kind of work
[ "Calls", "the", "class", "method", "close!", "in", "each", "note", "Sometimes", "notes", "need", "to", "finish", "their", "work", "even", "after", "being", "read", "This", "method", "allows", "this", "kind", "of", "work" ]
0ca9f4c4ce404113994f81552c304d8fd326ac1c
https://github.com/josevalim/rails-footnotes/blob/0ca9f4c4ce404113994f81552c304d8fd326ac1c/lib/rails-footnotes/filter.rb#L83-L86
17,566
josevalim/rails-footnotes
lib/rails-footnotes/filter.rb
Footnotes.Filter.close
def close javascript = '' each_with_rescue(@notes) do |note| next unless note.has_fieldset? javascript << close_helper(note) end javascript end
ruby
def close javascript = '' each_with_rescue(@notes) do |note| next unless note.has_fieldset? javascript << close_helper(note) end javascript end
[ "def", "close", "javascript", "=", "''", "each_with_rescue", "(", "@notes", ")", "do", "|", "note", "|", "next", "unless", "note", ".", "has_fieldset?", "javascript", "<<", "close_helper", "(", "note", ")", "end", "javascript", "end" ]
Process notes to get javascript code to close them. This method is only used when multiple_notes is false.
[ "Process", "notes", "to", "get", "javascript", "code", "to", "close", "them", ".", "This", "method", "is", "only", "used", "when", "multiple_notes", "is", "false", "." ]
0ca9f4c4ce404113994f81552c304d8fd326ac1c
https://github.com/josevalim/rails-footnotes/blob/0ca9f4c4ce404113994f81552c304d8fd326ac1c/lib/rails-footnotes/filter.rb#L300-L307
17,567
josevalim/rails-footnotes
lib/rails-footnotes/filter.rb
Footnotes.Filter.link_helper
def link_helper(note) onclick = note.onclick unless href = note.link href = '#' onclick ||= "Footnotes.hideAllAndToggle('#{note.to_sym}_debug_info');return false;" if note.has_fieldset? end "<a href=\"#{href}\" onclick=\"#{onclick}\">#{note.title}</a>" end
ruby
def link_helper(note) onclick = note.onclick unless href = note.link href = '#' onclick ||= "Footnotes.hideAllAndToggle('#{note.to_sym}_debug_info');return false;" if note.has_fieldset? end "<a href=\"#{href}\" onclick=\"#{onclick}\">#{note.title}</a>" end
[ "def", "link_helper", "(", "note", ")", "onclick", "=", "note", ".", "onclick", "unless", "href", "=", "note", ".", "link", "href", "=", "'#'", "onclick", "||=", "\"Footnotes.hideAllAndToggle('#{note.to_sym}_debug_info');return false;\"", "if", "note", ".", "has_fie...
Helper that creates the link and javascript code when note is clicked
[ "Helper", "that", "creates", "the", "link", "and", "javascript", "code", "when", "note", "is", "clicked" ]
0ca9f4c4ce404113994f81552c304d8fd326ac1c
https://github.com/josevalim/rails-footnotes/blob/0ca9f4c4ce404113994f81552c304d8fd326ac1c/lib/rails-footnotes/filter.rb#L321-L329
17,568
apache/predictionio-sdk-ruby
lib/predictionio/connection.rb
PredictionIO.Connection.request
def request(method, request) response = AsyncResponse.new(request) @packages.push(method: method, request: request, response: response) response end
ruby
def request(method, request) response = AsyncResponse.new(request) @packages.push(method: method, request: request, response: response) response end
[ "def", "request", "(", "method", ",", "request", ")", "response", "=", "AsyncResponse", ".", "new", "(", "request", ")", "@packages", ".", "push", "(", "method", ":", "method", ",", "request", ":", "request", ",", "response", ":", "response", ")", "respo...
Spawns a number of threads with persistent HTTP connection to the specified URI. Sets a default timeout of 60 seconds. Create an asynchronous request and response package, put it in the pending queue, and return the response object.
[ "Spawns", "a", "number", "of", "threads", "with", "persistent", "HTTP", "connection", "to", "the", "specified", "URI", ".", "Sets", "a", "default", "timeout", "of", "60", "seconds", ".", "Create", "an", "asynchronous", "request", "and", "response", "package", ...
a1777db9f89a4287d252c8ca166a279fb2af64b7
https://github.com/apache/predictionio-sdk-ruby/blob/a1777db9f89a4287d252c8ca166a279fb2af64b7/lib/predictionio/connection.rb#L108-L112
17,569
apache/predictionio-sdk-ruby
lib/predictionio/event_client.rb
PredictionIO.EventClient.get_status
def get_status status = @http.aget(PredictionIO::AsyncRequest.new('/')).get begin status.body rescue status end end
ruby
def get_status status = @http.aget(PredictionIO::AsyncRequest.new('/')).get begin status.body rescue status end end
[ "def", "get_status", "status", "=", "@http", ".", "aget", "(", "PredictionIO", "::", "AsyncRequest", ".", "new", "(", "'/'", ")", ")", ".", "get", "begin", "status", ".", "body", "rescue", "status", "end", "end" ]
Returns PredictionIO's status in string.
[ "Returns", "PredictionIO", "s", "status", "in", "string", "." ]
a1777db9f89a4287d252c8ca166a279fb2af64b7
https://github.com/apache/predictionio-sdk-ruby/blob/a1777db9f89a4287d252c8ca166a279fb2af64b7/lib/predictionio/event_client.rb#L112-L119
17,570
remvee/exifr
lib/exifr/jpeg.rb
EXIFR.JPEG.to_hash
def to_hash h = {:width => width, :height => height, :bits => bits, :comment => comment} h.merge!(exif) if exif? h end
ruby
def to_hash h = {:width => width, :height => height, :bits => bits, :comment => comment} h.merge!(exif) if exif? h end
[ "def", "to_hash", "h", "=", "{", ":width", "=>", "width", ",", ":height", "=>", "height", ",", ":bits", "=>", "bits", ",", ":comment", "=>", "comment", "}", "h", ".", "merge!", "(", "exif", ")", "if", "exif?", "h", "end" ]
Get a hash presentation of the image.
[ "Get", "a", "hash", "presentation", "of", "the", "image", "." ]
1e7b29befed53be8e0bd59fc62e4a98ca603c44a
https://github.com/remvee/exifr/blob/1e7b29befed53be8e0bd59fc62e4a98ca603c44a/lib/exifr/jpeg.rb#L51-L55
17,571
remvee/exifr
lib/exifr/jpeg.rb
EXIFR.JPEG.method_missing
def method_missing(method, *args) super unless args.empty? super unless methods.include?(method) @exif.send method if defined?(@exif) && @exif end
ruby
def method_missing(method, *args) super unless args.empty? super unless methods.include?(method) @exif.send method if defined?(@exif) && @exif end
[ "def", "method_missing", "(", "method", ",", "*", "args", ")", "super", "unless", "args", ".", "empty?", "super", "unless", "methods", ".", "include?", "(", "method", ")", "@exif", ".", "send", "method", "if", "defined?", "(", "@exif", ")", "&&", "@exif"...
Dispatch to EXIF. When no EXIF data is available but the +method+ does exist for EXIF data +nil+ will be returned.
[ "Dispatch", "to", "EXIF", ".", "When", "no", "EXIF", "data", "is", "available", "but", "the", "+", "method", "+", "does", "exist", "for", "EXIF", "data", "+", "nil", "+", "will", "be", "returned", "." ]
1e7b29befed53be8e0bd59fc62e4a98ca603c44a
https://github.com/remvee/exifr/blob/1e7b29befed53be8e0bd59fc62e4a98ca603c44a/lib/exifr/jpeg.rb#L59-L63
17,572
remvee/exifr
lib/exifr/tiff.rb
EXIFR.TIFF.method_missing
def method_missing(method, *args) super unless args.empty? if @ifds.first.respond_to?(method) @ifds.first.send(method) elsif TAGS.include?(method) @ifds.first.to_hash[method] else super end end
ruby
def method_missing(method, *args) super unless args.empty? if @ifds.first.respond_to?(method) @ifds.first.send(method) elsif TAGS.include?(method) @ifds.first.to_hash[method] else super end end
[ "def", "method_missing", "(", "method", ",", "*", "args", ")", "super", "unless", "args", ".", "empty?", "if", "@ifds", ".", "first", ".", "respond_to?", "(", "method", ")", "@ifds", ".", "first", ".", "send", "(", "method", ")", "elsif", "TAGS", ".", ...
Dispatch to first image.
[ "Dispatch", "to", "first", "image", "." ]
1e7b29befed53be8e0bd59fc62e4a98ca603c44a
https://github.com/remvee/exifr/blob/1e7b29befed53be8e0bd59fc62e4a98ca603c44a/lib/exifr/tiff.rb#L409-L419
17,573
remvee/exifr
lib/exifr/tiff.rb
EXIFR.TIFF.gps
def gps return nil unless gps_latitude && gps_longitude altitude = gps_altitude.is_a?(Array) ? gps_altitude.first : gps_altitude GPS.new(gps_latitude.to_f * (gps_latitude_ref == 'S' ? -1 : 1), gps_longitude.to_f * (gps_longitude_ref == 'W' ? -1 : 1), altitude && (altitude...
ruby
def gps return nil unless gps_latitude && gps_longitude altitude = gps_altitude.is_a?(Array) ? gps_altitude.first : gps_altitude GPS.new(gps_latitude.to_f * (gps_latitude_ref == 'S' ? -1 : 1), gps_longitude.to_f * (gps_longitude_ref == 'W' ? -1 : 1), altitude && (altitude...
[ "def", "gps", "return", "nil", "unless", "gps_latitude", "&&", "gps_longitude", "altitude", "=", "gps_altitude", ".", "is_a?", "(", "Array", ")", "?", "gps_altitude", ".", "first", ":", "gps_altitude", "GPS", ".", "new", "(", "gps_latitude", ".", "to_f", "*"...
Get GPS location, altitude and image direction return nil when not available.
[ "Get", "GPS", "location", "altitude", "and", "image", "direction", "return", "nil", "when", "not", "available", "." ]
1e7b29befed53be8e0bd59fc62e4a98ca603c44a
https://github.com/remvee/exifr/blob/1e7b29befed53be8e0bd59fc62e4a98ca603c44a/lib/exifr/tiff.rb#L462-L471
17,574
nathanl/authority
lib/authority/controller.rb
Authority.Controller.authorize_action_for
def authorize_action_for(authority_resource, *options) # `action_name` comes from ActionController authority_action = self.class.authority_action_map[action_name.to_sym] if authority_action.nil? raise MissingAction.new("No authority action defined for #{action_name}") end Authorit...
ruby
def authorize_action_for(authority_resource, *options) # `action_name` comes from ActionController authority_action = self.class.authority_action_map[action_name.to_sym] if authority_action.nil? raise MissingAction.new("No authority action defined for #{action_name}") end Authorit...
[ "def", "authorize_action_for", "(", "authority_resource", ",", "*", "options", ")", "# `action_name` comes from ActionController", "authority_action", "=", "self", ".", "class", ".", "authority_action_map", "[", "action_name", ".", "to_sym", "]", "if", "authority_action",...
To be run in a `before_filter`; ensure this controller action is allowed for the user Can be used directly within a controller action as well, given an instance or class with or without options to delegate to the authorizer. @param [Class] authority_resource, the model class associated with this controller @param ...
[ "To", "be", "run", "in", "a", "before_filter", ";", "ensure", "this", "controller", "action", "is", "allowed", "for", "the", "user", "Can", "be", "used", "directly", "within", "a", "controller", "action", "as", "well", "given", "an", "instance", "or", "cla...
35176d8bffb99824bc49e8bb5f2ddfe54ff863ad
https://github.com/nathanl/authority/blob/35176d8bffb99824bc49e8bb5f2ddfe54ff863ad/lib/authority/controller.rb#L128-L141
17,575
nathanl/authority
lib/authority/controller.rb
Authority.Controller.authority_forbidden
def authority_forbidden(error) Authority.logger.warn(error.message) render :file => Rails.root.join('public', '403.html'), :status => 403, :layout => false end
ruby
def authority_forbidden(error) Authority.logger.warn(error.message) render :file => Rails.root.join('public', '403.html'), :status => 403, :layout => false end
[ "def", "authority_forbidden", "(", "error", ")", "Authority", ".", "logger", ".", "warn", "(", "error", ".", "message", ")", "render", ":file", "=>", "Rails", ".", "root", ".", "join", "(", "'public'", ",", "'403.html'", ")", ",", ":status", "=>", "403",...
Renders a static file to minimize the chances of further errors. @param [Exception] error, an error that indicates the user tried to perform a forbidden action.
[ "Renders", "a", "static", "file", "to", "minimize", "the", "chances", "of", "further", "errors", "." ]
35176d8bffb99824bc49e8bb5f2ddfe54ff863ad
https://github.com/nathanl/authority/blob/35176d8bffb99824bc49e8bb5f2ddfe54ff863ad/lib/authority/controller.rb#L146-L149
17,576
nathanl/authority
lib/authority/controller.rb
Authority.Controller.run_authorization_check
def run_authorization_check if instance_authority_resource.is_a?(Array) # Array includes options; pass as separate args authorize_action_for(*instance_authority_resource, *authority_arguments) else # *resource would be interpreted as resource.to_a, which is wrong and # actual...
ruby
def run_authorization_check if instance_authority_resource.is_a?(Array) # Array includes options; pass as separate args authorize_action_for(*instance_authority_resource, *authority_arguments) else # *resource would be interpreted as resource.to_a, which is wrong and # actual...
[ "def", "run_authorization_check", "if", "instance_authority_resource", ".", "is_a?", "(", "Array", ")", "# Array includes options; pass as separate args", "authorize_action_for", "(", "instance_authority_resource", ",", "authority_arguments", ")", "else", "# *resource would be inte...
The `before_filter` that will be setup to run when the class method `authorize_actions_for` is called
[ "The", "before_filter", "that", "will", "be", "setup", "to", "run", "when", "the", "class", "method", "authorize_actions_for", "is", "called" ]
35176d8bffb99824bc49e8bb5f2ddfe54ff863ad
https://github.com/nathanl/authority/blob/35176d8bffb99824bc49e8bb5f2ddfe54ff863ad/lib/authority/controller.rb#L160-L169
17,577
theforeman/foreman_docker
app/models/service/registry_api.rb
Service.RegistryApi.search
def search(query) get('/v1/search'.freeze, { q: query }) rescue => e logger.warn "API v1 - Search failed #{e.backtrace}" { 'results' => catalog(query) } end
ruby
def search(query) get('/v1/search'.freeze, { q: query }) rescue => e logger.warn "API v1 - Search failed #{e.backtrace}" { 'results' => catalog(query) } end
[ "def", "search", "(", "query", ")", "get", "(", "'/v1/search'", ".", "freeze", ",", "{", "q", ":", "query", "}", ")", "rescue", "=>", "e", "logger", ".", "warn", "\"API v1 - Search failed #{e.backtrace}\"", "{", "'results'", "=>", "catalog", "(", "query", ...
Since the Registry API v2 does not support a search the v1 endpoint is used Newer registries will fail, the v2 catalog endpoint is used
[ "Since", "the", "Registry", "API", "v2", "does", "not", "support", "a", "search", "the", "v1", "endpoint", "is", "used", "Newer", "registries", "will", "fail", "the", "v2", "catalog", "endpoint", "is", "used" ]
f785e5ae3f44e9f5c60f30dab351d30d2a1e1038
https://github.com/theforeman/foreman_docker/blob/f785e5ae3f44e9f5c60f30dab351d30d2a1e1038/app/models/service/registry_api.rb#L34-L39
17,578
NUBIC/surveyor
lib/surveyor/acts_as_response.rb
Surveyor.ActsAsResponse.as
def as(type_symbol) return case type_symbol.to_sym when :string, :text, :integer, :float, :datetime self.send("#{type_symbol}_value".to_sym) when :date self.datetime_value.nil? ? nil : self.datetime_value.to_date when :time self.datetime_value.nil? ? nil : self.datetime_v...
ruby
def as(type_symbol) return case type_symbol.to_sym when :string, :text, :integer, :float, :datetime self.send("#{type_symbol}_value".to_sym) when :date self.datetime_value.nil? ? nil : self.datetime_value.to_date when :time self.datetime_value.nil? ? nil : self.datetime_v...
[ "def", "as", "(", "type_symbol", ")", "return", "case", "type_symbol", ".", "to_sym", "when", ":string", ",", ":text", ",", ":integer", ",", ":float", ",", ":datetime", "self", ".", "send", "(", "\"#{type_symbol}_value\"", ".", "to_sym", ")", "when", ":date"...
Returns the response as a particular response_class type
[ "Returns", "the", "response", "as", "a", "particular", "response_class", "type" ]
d4fe8df2586ba26126bac3c4b3498e67ba813baf
https://github.com/NUBIC/surveyor/blob/d4fe8df2586ba26126bac3c4b3498e67ba813baf/lib/surveyor/acts_as_response.rb#L6-L17
17,579
NUBIC/surveyor
lib/surveyor/parser.rb
Surveyor.Parser.method_missing
def method_missing(missing_method, *args, &block) method_name, reference_identifier = missing_method.to_s.split("_", 2) type = full(method_name) Surveyor::Parser.raise_error( "\"#{type}\" is not a surveyor method." )if !%w(survey survey_translation survey_section question_group question dependency dep...
ruby
def method_missing(missing_method, *args, &block) method_name, reference_identifier = missing_method.to_s.split("_", 2) type = full(method_name) Surveyor::Parser.raise_error( "\"#{type}\" is not a surveyor method." )if !%w(survey survey_translation survey_section question_group question dependency dep...
[ "def", "method_missing", "(", "missing_method", ",", "*", "args", ",", "&", "block", ")", "method_name", ",", "reference_identifier", "=", "missing_method", ".", "to_s", ".", "split", "(", "\"_\"", ",", "2", ")", "type", "=", "full", "(", "method_name", ")...
This method_missing does all the heavy lifting for the DSL
[ "This", "method_missing", "does", "all", "the", "heavy", "lifting", "for", "the", "DSL" ]
d4fe8df2586ba26126bac3c4b3498e67ba813baf
https://github.com/NUBIC/surveyor/blob/d4fe8df2586ba26126bac3c4b3498e67ba813baf/lib/surveyor/parser.rb#L69-L103
17,580
rgrove/larch
lib/larch/config.rb
Larch.Config.validate
def validate ['from', 'to'].each do |s| raise Error, "'#{s}' must be a valid IMAP URI (e.g. imap://example.com)" unless fetch(s) =~ IMAP::REGEX_URI end unless Logger::LEVELS.has_key?(verbosity.to_sym) raise Error, "'verbosity' must be one of: #{Logger::LEVELS.keys.join(', ')}" end if e...
ruby
def validate ['from', 'to'].each do |s| raise Error, "'#{s}' must be a valid IMAP URI (e.g. imap://example.com)" unless fetch(s) =~ IMAP::REGEX_URI end unless Logger::LEVELS.has_key?(verbosity.to_sym) raise Error, "'verbosity' must be one of: #{Logger::LEVELS.keys.join(', ')}" end if e...
[ "def", "validate", "[", "'from'", ",", "'to'", "]", ".", "each", "do", "|", "s", "|", "raise", "Error", ",", "\"'#{s}' must be a valid IMAP URI (e.g. imap://example.com)\"", "unless", "fetch", "(", "s", ")", "=~", "IMAP", "::", "REGEX_URI", "end", "unless", "L...
Validates the config and resolves conflicting settings.
[ "Validates", "the", "config", "and", "resolves", "conflicting", "settings", "." ]
64eb3bd1e3d3335a52e656c7641d9b5b10d6ed42
https://github.com/rgrove/larch/blob/64eb3bd1e3d3335a52e656c7641d9b5b10d6ed42/lib/larch/config.rb#L73-L108
17,581
rgrove/larch
lib/larch/config.rb
Larch.Config.cache_config
def cache_config @cached = {} @lookup.reverse.each do |c| c.each {|k, v| @cached[k] = config_merge(@cached[k] || {}, v) } end end
ruby
def cache_config @cached = {} @lookup.reverse.each do |c| c.each {|k, v| @cached[k] = config_merge(@cached[k] || {}, v) } end end
[ "def", "cache_config", "@cached", "=", "{", "}", "@lookup", ".", "reverse", ".", "each", "do", "|", "c", "|", "c", ".", "each", "{", "|", "k", ",", "v", "|", "@cached", "[", "k", "]", "=", "config_merge", "(", "@cached", "[", "k", "]", "||", "{...
Merges configs such that those earlier in the lookup chain override those later in the chain.
[ "Merges", "configs", "such", "that", "those", "earlier", "in", "the", "lookup", "chain", "override", "those", "later", "in", "the", "chain", "." ]
64eb3bd1e3d3335a52e656c7641d9b5b10d6ed42
https://github.com/rgrove/larch/blob/64eb3bd1e3d3335a52e656c7641d9b5b10d6ed42/lib/larch/config.rb#L114-L120
17,582
rgrove/larch
lib/larch/imap.rb
Larch.IMAP.safely
def safely safe_connect retries = 0 begin yield rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::ENOTCONN, Errno::EPIPE, Errno::ETIMEDOUT, IOError, Net::IMAP::ByeResponseError, OpenSSL::SSL::SSLError => e r...
ruby
def safely safe_connect retries = 0 begin yield rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::ENOTCONN, Errno::EPIPE, Errno::ETIMEDOUT, IOError, Net::IMAP::ByeResponseError, OpenSSL::SSL::SSLError => e r...
[ "def", "safely", "safe_connect", "retries", "=", "0", "begin", "yield", "rescue", "Errno", "::", "ECONNABORTED", ",", "Errno", "::", "ECONNRESET", ",", "Errno", "::", "ENOTCONN", ",", "Errno", "::", "EPIPE", ",", "Errno", "::", "ETIMEDOUT", ",", "IOError", ...
Connect if necessary, execute the given block, retry if a recoverable error occurs, die if an unrecoverable error occurs.
[ "Connect", "if", "necessary", "execute", "the", "given", "block", "retry", "if", "a", "recoverable", "error", "occurs", "die", "if", "an", "unrecoverable", "error", "occurs", "." ]
64eb3bd1e3d3335a52e656c7641d9b5b10d6ed42
https://github.com/rgrove/larch/blob/64eb3bd1e3d3335a52e656c7641d9b5b10d6ed42/lib/larch/imap.rb#L185-L231
17,583
rgrove/larch
lib/larch/imap.rb
Larch.IMAP.uri_mailbox
def uri_mailbox mb = @uri.path[1..-1] mb.nil? || mb.empty? ? nil : CGI.unescape(mb) end
ruby
def uri_mailbox mb = @uri.path[1..-1] mb.nil? || mb.empty? ? nil : CGI.unescape(mb) end
[ "def", "uri_mailbox", "mb", "=", "@uri", ".", "path", "[", "1", "..", "-", "1", "]", "mb", ".", "nil?", "||", "mb", ".", "empty?", "?", "nil", ":", "CGI", ".", "unescape", "(", "mb", ")", "end" ]
Gets the IMAP mailbox specified in the URI, or +nil+ if none.
[ "Gets", "the", "IMAP", "mailbox", "specified", "in", "the", "URI", "or", "+", "nil", "+", "if", "none", "." ]
64eb3bd1e3d3335a52e656c7641d9b5b10d6ed42
https://github.com/rgrove/larch/blob/64eb3bd1e3d3335a52e656c7641d9b5b10d6ed42/lib/larch/imap.rb#L244-L247
17,584
rgrove/larch
lib/larch/imap.rb
Larch.IMAP.check_quirks
def check_quirks return unless @conn && @conn.greeting.kind_of?(Net::IMAP::UntaggedResponse) && @conn.greeting.data.kind_of?(Net::IMAP::ResponseText) if @conn.greeting.data.text =~ /^Gimap ready/ @quirks[:gmail] = true debug "looks like Gmail" elsif host =~ /^imap(?:-ssl)?\.mai...
ruby
def check_quirks return unless @conn && @conn.greeting.kind_of?(Net::IMAP::UntaggedResponse) && @conn.greeting.data.kind_of?(Net::IMAP::ResponseText) if @conn.greeting.data.text =~ /^Gimap ready/ @quirks[:gmail] = true debug "looks like Gmail" elsif host =~ /^imap(?:-ssl)?\.mai...
[ "def", "check_quirks", "return", "unless", "@conn", "&&", "@conn", ".", "greeting", ".", "kind_of?", "(", "Net", "::", "IMAP", "::", "UntaggedResponse", ")", "&&", "@conn", ".", "greeting", ".", "data", ".", "kind_of?", "(", "Net", "::", "IMAP", "::", "R...
Tries to identify server implementations with certain quirks that we'll need to work around.
[ "Tries", "to", "identify", "server", "implementations", "with", "certain", "quirks", "that", "we", "ll", "need", "to", "work", "around", "." ]
64eb3bd1e3d3335a52e656c7641d9b5b10d6ed42
https://github.com/rgrove/larch/blob/64eb3bd1e3d3335a52e656c7641d9b5b10d6ed42/lib/larch/imap.rb#L258-L275
17,585
autoforce/APIcasso
app/controllers/apicasso/crud_controller.rb
Apicasso.CrudController.set_object
def set_object id = params[:id] @object = resource.friendly.find(id) rescue NoMethodError @object = resource.find(id) ensure authorize! action_to_cancancan, @object end
ruby
def set_object id = params[:id] @object = resource.friendly.find(id) rescue NoMethodError @object = resource.find(id) ensure authorize! action_to_cancancan, @object end
[ "def", "set_object", "id", "=", "params", "[", ":id", "]", "@object", "=", "resource", ".", "friendly", ".", "find", "(", "id", ")", "rescue", "NoMethodError", "@object", "=", "resource", ".", "find", "(", "id", ")", "ensure", "authorize!", "action_to_canc...
Common setup to stablish which object this request is querying
[ "Common", "setup", "to", "stablish", "which", "object", "this", "request", "is", "querying" ]
a95b5fc894eeacd71271ccf33f05d286b5c32b9f
https://github.com/autoforce/APIcasso/blob/a95b5fc894eeacd71271ccf33f05d286b5c32b9f/app/controllers/apicasso/crud_controller.rb#L87-L94
17,586
autoforce/APIcasso
app/controllers/apicasso/crud_controller.rb
Apicasso.CrudController.set_records
def set_records authorize! :read, resource.name.underscore.to_sym @records = request_collection.ransack(parsed_query).result @object = request_collection.new key_scope_records reorder_records if params[:sort].present? select_fields if params[:select].present? include_relations ...
ruby
def set_records authorize! :read, resource.name.underscore.to_sym @records = request_collection.ransack(parsed_query).result @object = request_collection.new key_scope_records reorder_records if params[:sort].present? select_fields if params[:select].present? include_relations ...
[ "def", "set_records", "authorize!", ":read", ",", "resource", ".", "name", ".", "underscore", ".", "to_sym", "@records", "=", "request_collection", ".", "ransack", "(", "parsed_query", ")", ".", "result", "@object", "=", "request_collection", ".", "new", "key_sc...
Used to setup the records from the selected resource that are going to be rendered, if authorized
[ "Used", "to", "setup", "the", "records", "from", "the", "selected", "resource", "that", "are", "going", "to", "be", "rendered", "if", "authorized" ]
a95b5fc894eeacd71271ccf33f05d286b5c32b9f
https://github.com/autoforce/APIcasso/blob/a95b5fc894eeacd71271ccf33f05d286b5c32b9f/app/controllers/apicasso/crud_controller.rb#L98-L106
17,587
autoforce/APIcasso
app/controllers/apicasso/crud_controller.rb
Apicasso.CrudController.index_json
def index_json if params[:group].present? @records.group(params[:group][:by].split(',')) .send(:calculate, params[:group][:calculate], params[:group][:field]) else collection_response end end
ruby
def index_json if params[:group].present? @records.group(params[:group][:by].split(',')) .send(:calculate, params[:group][:calculate], params[:group][:field]) else collection_response end end
[ "def", "index_json", "if", "params", "[", ":group", "]", ".", "present?", "@records", ".", "group", "(", "params", "[", ":group", "]", "[", ":by", "]", ".", "split", "(", "','", ")", ")", ".", "send", "(", ":calculate", ",", "params", "[", ":group", ...
The response for index action, which can be a pagination of a record collection or a grouped count of attributes
[ "The", "response", "for", "index", "action", "which", "can", "be", "a", "pagination", "of", "a", "record", "collection", "or", "a", "grouped", "count", "of", "attributes" ]
a95b5fc894eeacd71271ccf33f05d286b5c32b9f
https://github.com/autoforce/APIcasso/blob/a95b5fc894eeacd71271ccf33f05d286b5c32b9f/app/controllers/apicasso/crud_controller.rb#L133-L142
17,588
autoforce/APIcasso
app/controllers/apicasso/application_controller.rb
Apicasso.ApplicationController.request_metadata
def request_metadata { uuid: request.uuid, url: request.original_url, headers: request.env.select { |key, _v| key =~ /^HTTP_/ }, ip: request.remote_ip } end
ruby
def request_metadata { uuid: request.uuid, url: request.original_url, headers: request.env.select { |key, _v| key =~ /^HTTP_/ }, ip: request.remote_ip } end
[ "def", "request_metadata", "{", "uuid", ":", "request", ".", "uuid", ",", "url", ":", "request", ".", "original_url", ",", "headers", ":", "request", ".", "env", ".", "select", "{", "|", "key", ",", "_v", "|", "key", "=~", "/", "/", "}", ",", "ip",...
Information that gets inserted on `register_api_request` as auditing data about the request. Returns a Hash with UUID, URL, HTTP Headers and IP
[ "Information", "that", "gets", "inserted", "on", "register_api_request", "as", "auditing", "data", "about", "the", "request", ".", "Returns", "a", "Hash", "with", "UUID", "URL", "HTTP", "Headers", "and", "IP" ]
a95b5fc894eeacd71271ccf33f05d286b5c32b9f
https://github.com/autoforce/APIcasso/blob/a95b5fc894eeacd71271ccf33f05d286b5c32b9f/app/controllers/apicasso/application_controller.rb#L49-L56
17,589
autoforce/APIcasso
app/models/apicasso/ability.rb
Apicasso.Ability.build_permissions
def build_permissions(opts = {}) permission = opts[:permission].to_sym clearances = opts[:clearance] # To have full read access to the whole APIcasso just set a # true key scope operation. # Usage: # To have full read access to the system the scope would be: # => `{read: true}`...
ruby
def build_permissions(opts = {}) permission = opts[:permission].to_sym clearances = opts[:clearance] # To have full read access to the whole APIcasso just set a # true key scope operation. # Usage: # To have full read access to the system the scope would be: # => `{read: true}`...
[ "def", "build_permissions", "(", "opts", "=", "{", "}", ")", "permission", "=", "opts", "[", ":permission", "]", ".", "to_sym", "clearances", "=", "opts", "[", ":clearance", "]", "# To have full read access to the whole APIcasso just set a", "# true key scope operation....
Method that initializes CanCanCan with the scope of permissions based on current key from request @param key [Object] a key object by APIcasso to CanCanCan with ability
[ "Method", "that", "initializes", "CanCanCan", "with", "the", "scope", "of", "permissions", "based", "on", "current", "key", "from", "request" ]
a95b5fc894eeacd71271ccf33f05d286b5c32b9f
https://github.com/autoforce/APIcasso/blob/a95b5fc894eeacd71271ccf33f05d286b5c32b9f/app/models/apicasso/ability.rb#L20-L46
17,590
rom-rb/rom-factory
lib/rom/factory/factories.rb
ROM::Factory.Factories.define
def define(spec, **opts, &block) name, parent = spec.is_a?(Hash) ? spec.flatten(1) : spec if registry.key?(name) raise ArgumentError, "#{name.inspect} factory has been already defined" end builder = if parent extend_builder(name, registry[parent], &block) else...
ruby
def define(spec, **opts, &block) name, parent = spec.is_a?(Hash) ? spec.flatten(1) : spec if registry.key?(name) raise ArgumentError, "#{name.inspect} factory has been already defined" end builder = if parent extend_builder(name, registry[parent], &block) else...
[ "def", "define", "(", "spec", ",", "**", "opts", ",", "&", "block", ")", "name", ",", "parent", "=", "spec", ".", "is_a?", "(", "Hash", ")", "?", "spec", ".", "flatten", "(", "1", ")", ":", "spec", "if", "registry", ".", "key?", "(", "name", ")...
Define a new builder @example a simple builder MyFactory.define(:user) do |f| f.name "Jane" f.email "jane@doe.org" end @example a builder using auto-generated fake values MyFactory.define(:user) do |f| f.name { fake(:name) } f.email { fake(:internet, :email) } end @example a builde...
[ "Define", "a", "new", "builder" ]
ca7425bbc5fa0ff3ae1913d79fc84b1ef86ccf9f
https://github.com/rom-rb/rom-factory/blob/ca7425bbc5fa0ff3ae1913d79fc84b1ef86ccf9f/lib/rom/factory/factories.rb#L132-L149
17,591
rom-rb/rom-factory
lib/rom/factory/factories.rb
ROM::Factory.Factories.struct_namespace
def struct_namespace(namespace = Undefined) if namespace.equal?(Undefined) options[:struct_namespace] else with(struct_namespace: namespace) end end
ruby
def struct_namespace(namespace = Undefined) if namespace.equal?(Undefined) options[:struct_namespace] else with(struct_namespace: namespace) end end
[ "def", "struct_namespace", "(", "namespace", "=", "Undefined", ")", "if", "namespace", ".", "equal?", "(", "Undefined", ")", "options", "[", ":struct_namespace", "]", "else", "with", "(", "struct_namespace", ":", "namespace", ")", "end", "end" ]
Get factories with a custom struct namespace @example EntityFactory = MyFactory.struct_namespace(MyApp::Entities) EntityFactory[:user] # => #<MyApp::Entities::User id=2 ...> @param [Module] namespace @return [Factories] @api public
[ "Get", "factories", "with", "a", "custom", "struct", "namespace" ]
ca7425bbc5fa0ff3ae1913d79fc84b1ef86ccf9f
https://github.com/rom-rb/rom-factory/blob/ca7425bbc5fa0ff3ae1913d79fc84b1ef86ccf9f/lib/rom/factory/factories.rb#L191-L197
17,592
kylewlacy/timerizer
lib/timerizer/wall_clock.rb
Timerizer.WallClock.hour
def hour(system = :twenty_four_hour) hour = self.to_duration.to_units(:hour, :minute, :second).fetch(:hour) if system == :twelve_hour if hour == 0 12 elsif hour > 12 hour - 12 else hour end elsif (system == :twenty_four_hour) hour ...
ruby
def hour(system = :twenty_four_hour) hour = self.to_duration.to_units(:hour, :minute, :second).fetch(:hour) if system == :twelve_hour if hour == 0 12 elsif hour > 12 hour - 12 else hour end elsif (system == :twenty_four_hour) hour ...
[ "def", "hour", "(", "system", "=", ":twenty_four_hour", ")", "hour", "=", "self", ".", "to_duration", ".", "to_units", "(", ":hour", ",", ":minute", ",", ":second", ")", ".", "fetch", "(", ":hour", ")", "if", "system", "==", ":twelve_hour", "if", "hour",...
Get the hour of the WallClock. @param [Symbol] system The houring system to use (either `:twelve_hour` or `:twenty_four_hour`; default `:twenty_four_hour`) @return [Integer] The hour component of the WallClock
[ "Get", "the", "hour", "of", "the", "WallClock", "." ]
3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8
https://github.com/kylewlacy/timerizer/blob/3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8/lib/timerizer/wall_clock.rb#L136-L151
17,593
kylewlacy/timerizer
lib/timerizer/duration.rb
Timerizer.Duration.after
def after(time) time = time.to_time prev_day = time.mday prev_month = time.month prev_year = time.year units = self.to_units(:years, :months, :days, :seconds) date_in_month = self.class.build_date( prev_year + units[:years], prev_month + units[:months], pre...
ruby
def after(time) time = time.to_time prev_day = time.mday prev_month = time.month prev_year = time.year units = self.to_units(:years, :months, :days, :seconds) date_in_month = self.class.build_date( prev_year + units[:years], prev_month + units[:months], pre...
[ "def", "after", "(", "time", ")", "time", "=", "time", ".", "to_time", "prev_day", "=", "time", ".", "mday", "prev_month", "=", "time", ".", "month", "prev_year", "=", "time", ".", "year", "units", "=", "self", ".", "to_units", "(", ":years", ",", ":...
Returns the time `self` later than the given time. @param [Time] time The initial time. @return [Time] The time after this {Duration} has elapsed past the given time. @example 5 minutes after January 1st, 2000 at noon 5.minutes.after(Time.new(2000, 1, 1, 12, 00, 00)) # => 2000-01-01 12:05:00 -0800 @see ...
[ "Returns", "the", "time", "self", "later", "than", "the", "given", "time", "." ]
3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8
https://github.com/kylewlacy/timerizer/blob/3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8/lib/timerizer/duration.rb#L234-L258
17,594
kylewlacy/timerizer
lib/timerizer/duration.rb
Timerizer.Duration.to_unit
def to_unit(unit) unit_details = self.class.resolve_unit(unit) if unit_details.has_key?(:seconds) seconds = self.normalize.get(:seconds) self.class.div(seconds, unit_details.fetch(:seconds)) elsif unit_details.has_key?(:months) months = self.denormalize.get(:months) se...
ruby
def to_unit(unit) unit_details = self.class.resolve_unit(unit) if unit_details.has_key?(:seconds) seconds = self.normalize.get(:seconds) self.class.div(seconds, unit_details.fetch(:seconds)) elsif unit_details.has_key?(:months) months = self.denormalize.get(:months) se...
[ "def", "to_unit", "(", "unit", ")", "unit_details", "=", "self", ".", "class", ".", "resolve_unit", "(", "unit", ")", "if", "unit_details", ".", "has_key?", "(", ":seconds", ")", "seconds", "=", "self", ".", "normalize", ".", "get", "(", ":seconds", ")",...
Convert the duration to a given unit. @param [Symbol] unit The unit to convert to. See {UNIT_ALIASES} for a list of valid unit names. @return [Integer] The quantity of the given unit present in `self`. Note that, if `self` cannot be represented exactly by `unit`, then the result will be truncated (rounded ...
[ "Convert", "the", "duration", "to", "a", "given", "unit", "." ]
3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8
https://github.com/kylewlacy/timerizer/blob/3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8/lib/timerizer/duration.rb#L293-L305
17,595
kylewlacy/timerizer
lib/timerizer/duration.rb
Timerizer.Duration.-
def -(other) case other when 0 self when Duration Duration.new( seconds: @seconds - other.get(:seconds), months: @months - other.get(:months) ) else raise ArgumentError, "Cannot subtract #{other.inspect} from Duration #{self}" end end
ruby
def -(other) case other when 0 self when Duration Duration.new( seconds: @seconds - other.get(:seconds), months: @months - other.get(:months) ) else raise ArgumentError, "Cannot subtract #{other.inspect} from Duration #{self}" end end
[ "def", "-", "(", "other", ")", "case", "other", "when", "0", "self", "when", "Duration", "Duration", ".", "new", "(", "seconds", ":", "@seconds", "-", "other", ".", "get", "(", ":seconds", ")", ",", "months", ":", "@months", "-", "other", ".", "get",...
Subtract two durations. @param [Duration] other The duration to subtract. @return [Duration] The resulting duration with each component subtracted from the input duration. @example 1.day - 1.hour == 23.hours
[ "Subtract", "two", "durations", "." ]
3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8
https://github.com/kylewlacy/timerizer/blob/3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8/lib/timerizer/duration.rb#L504-L516
17,596
kylewlacy/timerizer
lib/timerizer/duration.rb
Timerizer.Duration.*
def *(other) case other when Integer Duration.new( seconds: @seconds * other, months: @months * other ) else raise ArgumentError, "Cannot multiply Duration #{self} by #{other.inspect}" end end
ruby
def *(other) case other when Integer Duration.new( seconds: @seconds * other, months: @months * other ) else raise ArgumentError, "Cannot multiply Duration #{self} by #{other.inspect}" end end
[ "def", "*", "(", "other", ")", "case", "other", "when", "Integer", "Duration", ".", "new", "(", "seconds", ":", "@seconds", "*", "other", ",", "months", ":", "@months", "*", "other", ")", "else", "raise", "ArgumentError", ",", "\"Cannot multiply Duration #{s...
Multiply a duration by a scalar. @param [Integer] other The scalar to multiply by. @return [Duration] The resulting duration with each component multiplied by the scalar. @example 1.day * 7 == 1.week
[ "Multiply", "a", "duration", "by", "a", "scalar", "." ]
3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8
https://github.com/kylewlacy/timerizer/blob/3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8/lib/timerizer/duration.rb#L527-L537
17,597
kylewlacy/timerizer
lib/timerizer/duration.rb
Timerizer.Duration.to_s
def to_s(format = :long, options = nil) format = case format when Symbol FORMATS.fetch(format) when Hash FORMATS.fetch(:long).merge(format) else raise ArgumentError, "Expected #{format.inspect} to be a Symbol or Hash" end format = format...
ruby
def to_s(format = :long, options = nil) format = case format when Symbol FORMATS.fetch(format) when Hash FORMATS.fetch(:long).merge(format) else raise ArgumentError, "Expected #{format.inspect} to be a Symbol or Hash" end format = format...
[ "def", "to_s", "(", "format", "=", ":long", ",", "options", "=", "nil", ")", "format", "=", "case", "format", "when", "Symbol", "FORMATS", ".", "fetch", "(", "format", ")", "when", "Hash", "FORMATS", ".", "fetch", "(", ":long", ")", ".", "merge", "("...
Convert a duration to a human-readable string. @param [Symbol, Hash] format The format type to format the duration with. `format` can either be a key from the {FORMATS} hash or a hash with the same shape as `options`. @param [Hash, nil] options Additional options to use to override default format options. ...
[ "Convert", "a", "duration", "to", "a", "human", "-", "readable", "string", "." ]
3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8
https://github.com/kylewlacy/timerizer/blob/3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8/lib/timerizer/duration.rb#L606-L654
17,598
kylewlacy/timerizer
lib/timerizer/duration.rb
Timerizer.Duration.to_rounded_s
def to_rounded_s(format = :min_long, options = nil) format = case format when Symbol FORMATS.fetch(format) when Hash FORMATS.fetch(:long).merge(format) else raise ArgumentError, "Expected #{format.inspect} to be a Symbol or Hash" end format = format.mer...
ruby
def to_rounded_s(format = :min_long, options = nil) format = case format when Symbol FORMATS.fetch(format) when Hash FORMATS.fetch(:long).merge(format) else raise ArgumentError, "Expected #{format.inspect} to be a Symbol or Hash" end format = format.mer...
[ "def", "to_rounded_s", "(", "format", "=", ":min_long", ",", "options", "=", "nil", ")", "format", "=", "case", "format", "when", "Symbol", "FORMATS", ".", "fetch", "(", "format", ")", "when", "Hash", "FORMATS", ".", "fetch", "(", ":long", ")", ".", "m...
Convert a Duration to a human-readable string using a rounded value. By 'rounded', we mean that the resulting value is rounded up if the input includes a value of more than half of one of the least-significant unit to be returned. For example, `(17.hours 43.minutes 31.seconds)`, when rounded to two units (hours an...
[ "Convert", "a", "Duration", "to", "a", "human", "-", "readable", "string", "using", "a", "rounded", "value", "." ]
3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8
https://github.com/kylewlacy/timerizer/blob/3d9949ad95d167e40a7b9b1f8b9d0817cdace4c8/lib/timerizer/duration.rb#L702-L722
17,599
github/elastomer-client
lib/elastomer/client/rest_api_spec/api_spec.rb
Elastomer::Client::RestApiSpec.ApiSpec.select_params
def select_params(api:, from:) rest_api = get(api) return from if rest_api.nil? rest_api.select_params(from: from) end
ruby
def select_params(api:, from:) rest_api = get(api) return from if rest_api.nil? rest_api.select_params(from: from) end
[ "def", "select_params", "(", "api", ":", ",", "from", ":", ")", "rest_api", "=", "get", "(", "api", ")", "return", "from", "if", "rest_api", ".", "nil?", "rest_api", ".", "select_params", "(", "from", ":", "from", ")", "end" ]
Given an API descriptor name and a set of request parameters, select those params that are accepted by the API endpoint. api - the api descriptor name as a String from - the Hash containing the request params Returns a new Hash containing the valid params for the api
[ "Given", "an", "API", "descriptor", "name", "and", "a", "set", "of", "request", "parameters", "select", "those", "params", "that", "are", "accepted", "by", "the", "API", "endpoint", "." ]
b02aa42f23df9776443449d44c176f1dcea5e08d
https://github.com/github/elastomer-client/blob/b02aa42f23df9776443449d44c176f1dcea5e08d/lib/elastomer/client/rest_api_spec/api_spec.rb#L26-L30