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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
10,200 | chetan/bixby-common | lib/bixby-common/command_spec.rb | Bixby.CommandSpec.manifest | def manifest
if File.exists?(manifest_file) && File.readable?(manifest_file) then
MultiJson.load(File.read(manifest_file))
else
{}
end
end | ruby | def manifest
if File.exists?(manifest_file) && File.readable?(manifest_file) then
MultiJson.load(File.read(manifest_file))
else
{}
end
end | [
"def",
"manifest",
"if",
"File",
".",
"exists?",
"(",
"manifest_file",
")",
"&&",
"File",
".",
"readable?",
"(",
"manifest_file",
")",
"then",
"MultiJson",
".",
"load",
"(",
"File",
".",
"read",
"(",
"manifest_file",
")",
")",
"else",
"{",
"}",
"end",
... | Retrieve the command's Manifest, loading it from disk if necessary
If no Manifest is available, returns an empty hash
@return [Hash] | [
"Retrieve",
"the",
"command",
"s",
"Manifest",
"loading",
"it",
"from",
"disk",
"if",
"necessary",
"If",
"no",
"Manifest",
"is",
"available",
"returns",
"an",
"empty",
"hash"
] | 3fb8829987b115fc53ec820d97a20b4a8c49b4a2 | https://github.com/chetan/bixby-common/blob/3fb8829987b115fc53ec820d97a20b4a8c49b4a2/lib/bixby-common/command_spec.rb#L100-L106 |
10,201 | chetan/bixby-common | lib/bixby-common/command_spec.rb | Bixby.CommandSpec.to_s | def to_s # :nocov:
s = []
s << "CommandSpec:#{self.object_id}"
s << " digest: #{self.digest}"
s << " repo: #{self.repo}"
s << " bundle: #{self.bundle}"
s << " command: #{self.command}"
s << " args: #{self.args}"
s << " user: #{self.user}"
s << " group: #{se... | ruby | def to_s # :nocov:
s = []
s << "CommandSpec:#{self.object_id}"
s << " digest: #{self.digest}"
s << " repo: #{self.repo}"
s << " bundle: #{self.bundle}"
s << " command: #{self.command}"
s << " args: #{self.args}"
s << " user: #{self.user}"
s << " group: #{se... | [
"def",
"to_s",
"# :nocov:",
"s",
"=",
"[",
"]",
"s",
"<<",
"\"CommandSpec:#{self.object_id}\"",
"s",
"<<",
"\" digest: #{self.digest}\"",
"s",
"<<",
"\" repo: #{self.repo}\"",
"s",
"<<",
"\" bundle: #{self.bundle}\"",
"s",
"<<",
"\" command: #{self.command}\"",... | Convert object to String, useful for debugging
@return [String] | [
"Convert",
"object",
"to",
"String",
"useful",
"for",
"debugging"
] | 3fb8829987b115fc53ec820d97a20b4a8c49b4a2 | https://github.com/chetan/bixby-common/blob/3fb8829987b115fc53ec820d97a20b4a8c49b4a2/lib/bixby-common/command_spec.rb#L173-L186 |
10,202 | ideonetwork/lato-blog | app/models/lato_blog/category.rb | LatoBlog.Category.check_category_father_circular_dependency | def check_category_father_circular_dependency
return unless self.lato_blog_category_id
all_children = self.get_all_category_children
same_children = all_children.select { |child| child.id === self.lato_blog_category_id }
if same_children.length > 0
errors.add('Category father', 'can no... | ruby | def check_category_father_circular_dependency
return unless self.lato_blog_category_id
all_children = self.get_all_category_children
same_children = all_children.select { |child| child.id === self.lato_blog_category_id }
if same_children.length > 0
errors.add('Category father', 'can no... | [
"def",
"check_category_father_circular_dependency",
"return",
"unless",
"self",
".",
"lato_blog_category_id",
"all_children",
"=",
"self",
".",
"get_all_category_children",
"same_children",
"=",
"all_children",
".",
"select",
"{",
"|",
"child",
"|",
"child",
".",
"id",
... | This function check the category parent of the category do not create a circular dependency. | [
"This",
"function",
"check",
"the",
"category",
"parent",
"of",
"the",
"category",
"do",
"not",
"create",
"a",
"circular",
"dependency",
"."
] | a0d92de299a0e285851743b9d4a902f611187cba | https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/category.rb#L80-L90 |
10,203 | ideonetwork/lato-blog | app/models/lato_blog/category.rb | LatoBlog.Category.check_lato_blog_category_parent | def check_lato_blog_category_parent
category_parent = LatoBlog::CategoryParent.find_by(id: lato_blog_category_parent_id)
if !category_parent
errors.add('Category parent', 'not exist for the category')
throw :abort
return
end
same_language_category = category_parent.categ... | ruby | def check_lato_blog_category_parent
category_parent = LatoBlog::CategoryParent.find_by(id: lato_blog_category_parent_id)
if !category_parent
errors.add('Category parent', 'not exist for the category')
throw :abort
return
end
same_language_category = category_parent.categ... | [
"def",
"check_lato_blog_category_parent",
"category_parent",
"=",
"LatoBlog",
"::",
"CategoryParent",
".",
"find_by",
"(",
"id",
":",
"lato_blog_category_parent_id",
")",
"if",
"!",
"category_parent",
"errors",
".",
"add",
"(",
"'Category parent'",
",",
"'not exist for ... | This function check that the category parent exist and has not others categories for the same language. | [
"This",
"function",
"check",
"that",
"the",
"category",
"parent",
"exist",
"and",
"has",
"not",
"others",
"categories",
"for",
"the",
"same",
"language",
"."
] | a0d92de299a0e285851743b9d4a902f611187cba | https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/category.rb#L102-L116 |
10,204 | nsi-iff/nsivideogranulate-ruby | lib/nsivideogranulate/fake_server.rb | NSIVideoGranulate.FakeServerManager.start_server | def start_server(port=9886)
@thread = Thread.new do
Server.prepare
Server.run! :port => port
end
sleep(1)
self
end | ruby | def start_server(port=9886)
@thread = Thread.new do
Server.prepare
Server.run! :port => port
end
sleep(1)
self
end | [
"def",
"start_server",
"(",
"port",
"=",
"9886",
")",
"@thread",
"=",
"Thread",
".",
"new",
"do",
"Server",
".",
"prepare",
"Server",
".",
"run!",
":port",
"=>",
"port",
"end",
"sleep",
"(",
"1",
")",
"self",
"end"
] | Start the nsi.videogranulate fake server
@param [Fixnum] port the port where the fake server will listen
* make sure there's not anything else listenning on this port | [
"Start",
"the",
"nsi",
".",
"videogranulate",
"fake",
"server"
] | 794f44630ba6cac019a320288229ccccee00864d | https://github.com/nsi-iff/nsivideogranulate-ruby/blob/794f44630ba6cac019a320288229ccccee00864d/lib/nsivideogranulate/fake_server.rb#L56-L63 |
10,205 | sugaryourcoffee/syclink | lib/syclink/importer.rb | SycLink.Importer.links | def links
rows.map do |row|
attributes = Link::ATTRS.dup - [:url]
Link.new(row.shift, Hash[row.map { |v| [attributes.shift, v] }])
end
end | ruby | def links
rows.map do |row|
attributes = Link::ATTRS.dup - [:url]
Link.new(row.shift, Hash[row.map { |v| [attributes.shift, v] }])
end
end | [
"def",
"links",
"rows",
".",
"map",
"do",
"|",
"row",
"|",
"attributes",
"=",
"Link",
"::",
"ATTRS",
".",
"dup",
"-",
"[",
":url",
"]",
"Link",
".",
"new",
"(",
"row",
".",
"shift",
",",
"Hash",
"[",
"row",
".",
"map",
"{",
"|",
"v",
"|",
"["... | Links returned as Link objects | [
"Links",
"returned",
"as",
"Link",
"objects"
] | 941ee2045c946daa1e0db394eb643aa82c1254cc | https://github.com/sugaryourcoffee/syclink/blob/941ee2045c946daa1e0db394eb643aa82c1254cc/lib/syclink/importer.rb#L38-L43 |
10,206 | petebrowne/machined | lib/machined/server.rb | Machined.Server.to_app | def to_app # :nodoc:
Rack::Builder.new.tap do |app|
app.use Middleware::Static, machined.output_path
app.use Middleware::RootIndex
app.run Rack::URLMap.new(sprockets_map)
end
end | ruby | def to_app # :nodoc:
Rack::Builder.new.tap do |app|
app.use Middleware::Static, machined.output_path
app.use Middleware::RootIndex
app.run Rack::URLMap.new(sprockets_map)
end
end | [
"def",
"to_app",
"# :nodoc:",
"Rack",
"::",
"Builder",
".",
"new",
".",
"tap",
"do",
"|",
"app",
"|",
"app",
".",
"use",
"Middleware",
"::",
"Static",
",",
"machined",
".",
"output_path",
"app",
".",
"use",
"Middleware",
"::",
"RootIndex",
"app",
".",
... | Creates a Rack app with the current Machined
environment configuration. | [
"Creates",
"a",
"Rack",
"app",
"with",
"the",
"current",
"Machined",
"environment",
"configuration",
"."
] | 4f3921bc5098104096474300e933f009f1b4f7dd | https://github.com/petebrowne/machined/blob/4f3921bc5098104096474300e933f009f1b4f7dd/lib/machined/server.rb#L52-L58 |
10,207 | checkdin/checkdin-ruby | lib/checkdin/twitter_hashtag_streams.rb | Checkdin.TwitterHashtagStreams.twitter_hashtag_streams | def twitter_hashtag_streams(campaign_id, options={})
response = connection.get do |req|
req.url "campaigns/#{campaign_id}/twitter_hashtag_streams", options
end
return_error_or_body(response)
end | ruby | def twitter_hashtag_streams(campaign_id, options={})
response = connection.get do |req|
req.url "campaigns/#{campaign_id}/twitter_hashtag_streams", options
end
return_error_or_body(response)
end | [
"def",
"twitter_hashtag_streams",
"(",
"campaign_id",
",",
"options",
"=",
"{",
"}",
")",
"response",
"=",
"connection",
".",
"get",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"\"campaigns/#{campaign_id}/twitter_hashtag_streams\"",
",",
"options",
"end",
"return_er... | Retrieve Twitter Hashtag Streams for a campaign
param [Integer] campaign_id The ID of the campaign to fetch the twitter hashtag stream for.
@param [Hash] options | [
"Retrieve",
"Twitter",
"Hashtag",
"Streams",
"for",
"a",
"campaign"
] | c3c4b38b0f8c710e1f805100dcf3a70649215b48 | https://github.com/checkdin/checkdin-ruby/blob/c3c4b38b0f8c710e1f805100dcf3a70649215b48/lib/checkdin/twitter_hashtag_streams.rb#L9-L14 |
10,208 | checkdin/checkdin-ruby | lib/checkdin/twitter_hashtag_streams.rb | Checkdin.TwitterHashtagStreams.twitter_hashtag_stream | def twitter_hashtag_stream(campaign_id, id, options={})
response = connection.get do |req|
req.url "campaigns/#{campaign_id}/twitter_hashtag_streams/#{id}", options
end
return_error_or_body(response)
end | ruby | def twitter_hashtag_stream(campaign_id, id, options={})
response = connection.get do |req|
req.url "campaigns/#{campaign_id}/twitter_hashtag_streams/#{id}", options
end
return_error_or_body(response)
end | [
"def",
"twitter_hashtag_stream",
"(",
"campaign_id",
",",
"id",
",",
"options",
"=",
"{",
"}",
")",
"response",
"=",
"connection",
".",
"get",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"\"campaigns/#{campaign_id}/twitter_hashtag_streams/#{id}\"",
",",
"options",
... | Retrieve Single Twitter Hashtag Stream for a campaign
param [Integer] campaign_id The ID of the campaign to fetch the twitter hashtag stream for.
param [Integer] id The ID of the twitter_hashtag_stream to fetch.
@param [Hash] options | [
"Retrieve",
"Single",
"Twitter",
"Hashtag",
"Stream",
"for",
"a",
"campaign"
] | c3c4b38b0f8c710e1f805100dcf3a70649215b48 | https://github.com/checkdin/checkdin-ruby/blob/c3c4b38b0f8c710e1f805100dcf3a70649215b48/lib/checkdin/twitter_hashtag_streams.rb#L22-L27 |
10,209 | pixeltrix/rails_legacy_mapper | lib/rails_legacy_mapper/mapper.rb | RailsLegacyMapper.Mapper.root | def root(options = {})
if options.is_a?(Symbol)
if source_route = @set.named_routes.routes[options]
options = source_route.defaults.merge({ :conditions => source_route.conditions })
end
end
named_route("root", '', options)
end | ruby | def root(options = {})
if options.is_a?(Symbol)
if source_route = @set.named_routes.routes[options]
options = source_route.defaults.merge({ :conditions => source_route.conditions })
end
end
named_route("root", '', options)
end | [
"def",
"root",
"(",
"options",
"=",
"{",
"}",
")",
"if",
"options",
".",
"is_a?",
"(",
"Symbol",
")",
"if",
"source_route",
"=",
"@set",
".",
"named_routes",
".",
"routes",
"[",
"options",
"]",
"options",
"=",
"source_route",
".",
"defaults",
".",
"mer... | Creates a named route called "root" for matching the root level request. | [
"Creates",
"a",
"named",
"route",
"called",
"root",
"for",
"matching",
"the",
"root",
"level",
"request",
"."
] | d841d25b76fed96595f5dff19d4772c7017b3b71 | https://github.com/pixeltrix/rails_legacy_mapper/blob/d841d25b76fed96595f5dff19d4772c7017b3b71/lib/rails_legacy_mapper/mapper.rb#L157-L164 |
10,210 | ideonetwork/lato-blog | app/controllers/lato_blog/back/categories_controller.rb | LatoBlog.Back::CategoriesController.index | def index
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:categories])
# find categories to show
@categories = LatoBlog::Category.where(meta_language: cookies[:lato_blog__current_language]).order('title ASC')
@widget_index_categories = core__widgets_index(@categories, search: '... | ruby | def index
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:categories])
# find categories to show
@categories = LatoBlog::Category.where(meta_language: cookies[:lato_blog__current_language]).order('title ASC')
@widget_index_categories = core__widgets_index(@categories, search: '... | [
"def",
"index",
"core__set_header_active_page_title",
"(",
"LANGUAGES",
"[",
":lato_blog",
"]",
"[",
":pages",
"]",
"[",
":categories",
"]",
")",
"# find categories to show",
"@categories",
"=",
"LatoBlog",
"::",
"Category",
".",
"where",
"(",
"meta_language",
":",
... | This function shows the list of possible categories. | [
"This",
"function",
"shows",
"the",
"list",
"of",
"possible",
"categories",
"."
] | a0d92de299a0e285851743b9d4a902f611187cba | https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/categories_controller.rb#L9-L14 |
10,211 | ideonetwork/lato-blog | app/controllers/lato_blog/back/categories_controller.rb | LatoBlog.Back::CategoriesController.new | def new
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:categories_new])
@category = LatoBlog::Category.new
if params[:language]
set_current_language params[:language]
end
if params[:parent]
@category_parent = LatoBlog::CategoryParent.find_by(id: params[... | ruby | def new
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:categories_new])
@category = LatoBlog::Category.new
if params[:language]
set_current_language params[:language]
end
if params[:parent]
@category_parent = LatoBlog::CategoryParent.find_by(id: params[... | [
"def",
"new",
"core__set_header_active_page_title",
"(",
"LANGUAGES",
"[",
":lato_blog",
"]",
"[",
":pages",
"]",
"[",
":categories_new",
"]",
")",
"@category",
"=",
"LatoBlog",
"::",
"Category",
".",
"new",
"if",
"params",
"[",
":language",
"]",
"set_current_la... | This function shows the view to create a new category. | [
"This",
"function",
"shows",
"the",
"view",
"to",
"create",
"a",
"new",
"category",
"."
] | a0d92de299a0e285851743b9d4a902f611187cba | https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/categories_controller.rb#L23-L36 |
10,212 | ideonetwork/lato-blog | app/controllers/lato_blog/back/categories_controller.rb | LatoBlog.Back::CategoriesController.create | def create
@category = LatoBlog::Category.new(new_category_params)
if !@category.save
flash[:danger] = @category.errors.full_messages.to_sentence
redirect_to lato_blog.new_category_path
return
end
flash[:success] = LANGUAGES[:lato_blog][:flashes][:category_create_succes... | ruby | def create
@category = LatoBlog::Category.new(new_category_params)
if !@category.save
flash[:danger] = @category.errors.full_messages.to_sentence
redirect_to lato_blog.new_category_path
return
end
flash[:success] = LANGUAGES[:lato_blog][:flashes][:category_create_succes... | [
"def",
"create",
"@category",
"=",
"LatoBlog",
"::",
"Category",
".",
"new",
"(",
"new_category_params",
")",
"if",
"!",
"@category",
".",
"save",
"flash",
"[",
":danger",
"]",
"=",
"@category",
".",
"errors",
".",
"full_messages",
".",
"to_sentence",
"redir... | This function creates a new category. | [
"This",
"function",
"creates",
"a",
"new",
"category",
"."
] | a0d92de299a0e285851743b9d4a902f611187cba | https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/categories_controller.rb#L39-L50 |
10,213 | ideonetwork/lato-blog | app/controllers/lato_blog/back/categories_controller.rb | LatoBlog.Back::CategoriesController.edit | def edit
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:categories_edit])
@category = LatoBlog::Category.find_by(id: params[:id])
return unless check_category_presence
if @category.meta_language != cookies[:lato_blog__current_language]
set_current_language @category.m... | ruby | def edit
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:categories_edit])
@category = LatoBlog::Category.find_by(id: params[:id])
return unless check_category_presence
if @category.meta_language != cookies[:lato_blog__current_language]
set_current_language @category.m... | [
"def",
"edit",
"core__set_header_active_page_title",
"(",
"LANGUAGES",
"[",
":lato_blog",
"]",
"[",
":pages",
"]",
"[",
":categories_edit",
"]",
")",
"@category",
"=",
"LatoBlog",
"::",
"Category",
".",
"find_by",
"(",
"id",
":",
"params",
"[",
":id",
"]",
"... | This function show the view to edit a category. | [
"This",
"function",
"show",
"the",
"view",
"to",
"edit",
"a",
"category",
"."
] | a0d92de299a0e285851743b9d4a902f611187cba | https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/categories_controller.rb#L53-L63 |
10,214 | ideonetwork/lato-blog | app/controllers/lato_blog/back/categories_controller.rb | LatoBlog.Back::CategoriesController.update | def update
@category = LatoBlog::Category.find_by(id: params[:id])
return unless check_category_presence
if !@category.update(edit_category_params)
flash[:danger] = @category.errors.full_messages.to_sentence
redirect_to lato_blog.edit_category_path(@category.id)
return
e... | ruby | def update
@category = LatoBlog::Category.find_by(id: params[:id])
return unless check_category_presence
if !@category.update(edit_category_params)
flash[:danger] = @category.errors.full_messages.to_sentence
redirect_to lato_blog.edit_category_path(@category.id)
return
e... | [
"def",
"update",
"@category",
"=",
"LatoBlog",
"::",
"Category",
".",
"find_by",
"(",
"id",
":",
"params",
"[",
":id",
"]",
")",
"return",
"unless",
"check_category_presence",
"if",
"!",
"@category",
".",
"update",
"(",
"edit_category_params",
")",
"flash",
... | This function updates a category. | [
"This",
"function",
"updates",
"a",
"category",
"."
] | a0d92de299a0e285851743b9d4a902f611187cba | https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/categories_controller.rb#L66-L78 |
10,215 | ideonetwork/lato-blog | app/controllers/lato_blog/back/categories_controller.rb | LatoBlog.Back::CategoriesController.destroy | def destroy
@category = LatoBlog::Category.find_by(id: params[:id])
return unless check_category_presence
if !@category.destroy
flash[:danger] = @category.category_parent.errors.full_messages.to_sentence
redirect_to lato_blog.edit_category_path(@category.id)
return
end
... | ruby | def destroy
@category = LatoBlog::Category.find_by(id: params[:id])
return unless check_category_presence
if !@category.destroy
flash[:danger] = @category.category_parent.errors.full_messages.to_sentence
redirect_to lato_blog.edit_category_path(@category.id)
return
end
... | [
"def",
"destroy",
"@category",
"=",
"LatoBlog",
"::",
"Category",
".",
"find_by",
"(",
"id",
":",
"params",
"[",
":id",
"]",
")",
"return",
"unless",
"check_category_presence",
"if",
"!",
"@category",
".",
"destroy",
"flash",
"[",
":danger",
"]",
"=",
"@ca... | This function destroyes a category. | [
"This",
"function",
"destroyes",
"a",
"category",
"."
] | a0d92de299a0e285851743b9d4a902f611187cba | https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/categories_controller.rb#L81-L93 |
10,216 | yolk/pump | lib/pump/encoder.rb | Pump.Encoder.encode | def encode(object, options={})
object = object.to_a if defined?(ActiveRecord::Relation) && object.is_a?(ActiveRecord::Relation)
fields_to_hash(options)
if object.is_a?(Array)
if options[:fields]
encode_partial_array(object, options)
else
encode_array(object, options... | ruby | def encode(object, options={})
object = object.to_a if defined?(ActiveRecord::Relation) && object.is_a?(ActiveRecord::Relation)
fields_to_hash(options)
if object.is_a?(Array)
if options[:fields]
encode_partial_array(object, options)
else
encode_array(object, options... | [
"def",
"encode",
"(",
"object",
",",
"options",
"=",
"{",
"}",
")",
"object",
"=",
"object",
".",
"to_a",
"if",
"defined?",
"(",
"ActiveRecord",
"::",
"Relation",
")",
"&&",
"object",
".",
"is_a?",
"(",
"ActiveRecord",
"::",
"Relation",
")",
"fields_to_h... | Creates a new XML-encoder with a root tag named after +root_name+.
@example Create a simple encoder for a person with a name attribute:
Pump::Xml.new :person do
tag :name
end
@example Create the same without usage of the DSL:
Pump::Xml.new :person, [{:name => :name}]
@example Create the same but wit... | [
"Creates",
"a",
"new",
"XML",
"-",
"encoder",
"with",
"a",
"root",
"tag",
"named",
"after",
"+",
"root_name",
"+",
"."
] | 164281df30363302ff43ad2a250d9407b3aa3af4 | https://github.com/yolk/pump/blob/164281df30363302ff43ad2a250d9407b3aa3af4/lib/pump/encoder.rb#L55-L69 |
10,217 | dlindahl/network_executive | lib/network_executive/channel_schedule.rb | NetworkExecutive.ChannelSchedule.extend_off_air | def extend_off_air( programs, program, stop )
prev = programs.pop + program
program = prev.program
occurrence = prev.occurrence
remainder = time_left( occurrence.start_time, occurrence.end_time, stop )
[ program, occurrence, remainder ]
end | ruby | def extend_off_air( programs, program, stop )
prev = programs.pop + program
program = prev.program
occurrence = prev.occurrence
remainder = time_left( occurrence.start_time, occurrence.end_time, stop )
[ program, occurrence, remainder ]
end | [
"def",
"extend_off_air",
"(",
"programs",
",",
"program",
",",
"stop",
")",
"prev",
"=",
"programs",
".",
"pop",
"+",
"program",
"program",
"=",
"prev",
".",
"program",
"occurrence",
"=",
"prev",
".",
"occurrence",
"remainder",
"=",
"time_left",
"(",
"occu... | Extends the previous Off Air schedule | [
"Extends",
"the",
"previous",
"Off",
"Air",
"schedule"
] | 4802e8b20225d7058c82f5ded05bfa6c84918e3d | https://github.com/dlindahl/network_executive/blob/4802e8b20225d7058c82f5ded05bfa6c84918e3d/lib/network_executive/channel_schedule.rb#L55-L62 |
10,218 | jimjh/reaction | lib/reaction/client/signer.rb | Reaction.Client::Signer.outgoing | def outgoing(message, callback)
# Allow non-data messages to pass through.
return callback.call(message) if %r{^/meta/} =~ message['channel']
message['ext'] ||= {}
signature = OpenSSL::HMAC.digest('sha256', @key, message['data'])
message['ext']['signature'] = Base64.encode64(si... | ruby | def outgoing(message, callback)
# Allow non-data messages to pass through.
return callback.call(message) if %r{^/meta/} =~ message['channel']
message['ext'] ||= {}
signature = OpenSSL::HMAC.digest('sha256', @key, message['data'])
message['ext']['signature'] = Base64.encode64(si... | [
"def",
"outgoing",
"(",
"message",
",",
"callback",
")",
"# Allow non-data messages to pass through.",
"return",
"callback",
".",
"call",
"(",
"message",
")",
"if",
"%r{",
"}",
"=~",
"message",
"[",
"'channel'",
"]",
"message",
"[",
"'ext'",
"]",
"||=",
"{",
... | Initializes the signer with a secret key.
@param [String] key secret key, used to sign messages
Adds a signature to every outgoing publish message. | [
"Initializes",
"the",
"signer",
"with",
"a",
"secret",
"key",
"."
] | 8aff9633dbd177ea536b79f59115a2825b5adf0a | https://github.com/jimjh/reaction/blob/8aff9633dbd177ea536b79f59115a2825b5adf0a/lib/reaction/client/signer.rb#L14-L25 |
10,219 | mntnorv/puttext | lib/puttext/extractor.rb | PutText.Extractor.extract | def extract(path)
files = files_in_path(path)
supported_files = filter_files(files)
parse_files(supported_files)
end | ruby | def extract(path)
files = files_in_path(path)
supported_files = filter_files(files)
parse_files(supported_files)
end | [
"def",
"extract",
"(",
"path",
")",
"files",
"=",
"files_in_path",
"(",
"path",
")",
"supported_files",
"=",
"filter_files",
"(",
"files",
")",
"parse_files",
"(",
"supported_files",
")",
"end"
] | Extract strings from files in the given path.
@param [String] path the path of a directory or file to extract strings
from.
@return [POFile] a POFile object, representing the strings extracted from
the files or file in the specified path. | [
"Extract",
"strings",
"from",
"files",
"in",
"the",
"given",
"path",
"."
] | c5c210dff4e11f714418b6b426dc9e2739fe9876 | https://github.com/mntnorv/puttext/blob/c5c210dff4e11f714418b6b426dc9e2739fe9876/lib/puttext/extractor.rb#L45-L50 |
10,220 | TuftsUniversity/whowas | lib/whowas/validatable.rb | Whowas.Validatable.validate | def validate(input)
(check_exists(required_inputs, input) &&
check_format(input_formats, input)) ||
(raise Errors::InvalidInput, "Invalid input for #{self.class.name}")
end | ruby | def validate(input)
(check_exists(required_inputs, input) &&
check_format(input_formats, input)) ||
(raise Errors::InvalidInput, "Invalid input for #{self.class.name}")
end | [
"def",
"validate",
"(",
"input",
")",
"(",
"check_exists",
"(",
"required_inputs",
",",
"input",
")",
"&&",
"check_format",
"(",
"input_formats",
",",
"input",
")",
")",
"||",
"(",
"raise",
"Errors",
"::",
"InvalidInput",
",",
"\"Invalid input for #{self.class.n... | Checks for required inputs and input formats
that the adapter will need to process the search.
It does *not* matter if there are other, non-required parameters
in the input hash; they will be ignored later. | [
"Checks",
"for",
"required",
"inputs",
"and",
"input",
"formats",
"that",
"the",
"adapter",
"will",
"need",
"to",
"process",
"the",
"search",
"."
] | 65197b1dd9ca8170c12eaa239f6bcfb9c2061a9c | https://github.com/TuftsUniversity/whowas/blob/65197b1dd9ca8170c12eaa239f6bcfb9c2061a9c/lib/whowas/validatable.rb#L8-L12 |
10,221 | TuftsUniversity/whowas | lib/whowas/validatable.rb | Whowas.Validatable.check_exists | def check_exists(required, input)
required.inject(true) do |result, key|
input[key] && result
end
end | ruby | def check_exists(required, input)
required.inject(true) do |result, key|
input[key] && result
end
end | [
"def",
"check_exists",
"(",
"required",
",",
"input",
")",
"required",
".",
"inject",
"(",
"true",
")",
"do",
"|",
"result",
",",
"key",
"|",
"input",
"[",
"key",
"]",
"&&",
"result",
"end",
"end"
] | Required keys must exist in the input hash and must have a non-nil,
non-empty value. | [
"Required",
"keys",
"must",
"exist",
"in",
"the",
"input",
"hash",
"and",
"must",
"have",
"a",
"non",
"-",
"nil",
"non",
"-",
"empty",
"value",
"."
] | 65197b1dd9ca8170c12eaa239f6bcfb9c2061a9c | https://github.com/TuftsUniversity/whowas/blob/65197b1dd9ca8170c12eaa239f6bcfb9c2061a9c/lib/whowas/validatable.rb#L29-L33 |
10,222 | Noah2610/MachineConfigure | lib/machine_configure/exporter.rb | MachineConfigure.Exporter.get_files | def get_files
return @dir.values.map do |dir|
next get_files_recursively_from dir
end .reject { |x| !x } .flatten
end | ruby | def get_files
return @dir.values.map do |dir|
next get_files_recursively_from dir
end .reject { |x| !x } .flatten
end | [
"def",
"get_files",
"return",
"@dir",
".",
"values",
".",
"map",
"do",
"|",
"dir",
"|",
"next",
"get_files_recursively_from",
"dir",
"end",
".",
"reject",
"{",
"|",
"x",
"|",
"!",
"x",
"}",
".",
"flatten",
"end"
] | Returns all necessary filepaths. | [
"Returns",
"all",
"necessary",
"filepaths",
"."
] | 8dc94112a1da91a72fa32b84dc53ac41ec0ec00a | https://github.com/Noah2610/MachineConfigure/blob/8dc94112a1da91a72fa32b84dc53ac41ec0ec00a/lib/machine_configure/exporter.rb#L42-L46 |
10,223 | mufid/kanade | lib/kanade/engine.rb | Kanade.Engine.deserialize_object | def deserialize_object(definition, hash)
return nil if hash.nil?
result = definition.new
result.__fields.each do |field|
name = field.key_json || name_to_json(field.sym)
if field.options[:as] == :list
value = deserialize_list(hash[name], field)
elsif field.options[:a... | ruby | def deserialize_object(definition, hash)
return nil if hash.nil?
result = definition.new
result.__fields.each do |field|
name = field.key_json || name_to_json(field.sym)
if field.options[:as] == :list
value = deserialize_list(hash[name], field)
elsif field.options[:a... | [
"def",
"deserialize_object",
"(",
"definition",
",",
"hash",
")",
"return",
"nil",
"if",
"hash",
".",
"nil?",
"result",
"=",
"definition",
".",
"new",
"result",
".",
"__fields",
".",
"each",
"do",
"|",
"field",
"|",
"name",
"=",
"field",
".",
"key_json",... | IF engine contains deserialization logic, we can no more
unit test the converters. Seems like, the conversion logic
must be outsourced to its respective converter | [
"IF",
"engine",
"contains",
"deserialization",
"logic",
"we",
"can",
"no",
"more",
"unit",
"test",
"the",
"converters",
".",
"Seems",
"like",
"the",
"conversion",
"logic",
"must",
"be",
"outsourced",
"to",
"its",
"respective",
"converter"
] | b0666e306df89d19fed87e956d82ca869a647006 | https://github.com/mufid/kanade/blob/b0666e306df89d19fed87e956d82ca869a647006/lib/kanade/engine.rb#L70-L89 |
10,224 | seamusabshere/cohort_scope | lib/cohort_scope/big_cohort.rb | CohortScope.BigCohort.reduce! | def reduce!
@reduced_characteristics = if @reduced_characteristics.keys.length < 2
{}
else
most_restrictive_characteristic = @reduced_characteristics.keys.max_by do |key|
conditions = CohortScope.conditions_for @reduced_characteristics.except(key)
@active_record_relation.... | ruby | def reduce!
@reduced_characteristics = if @reduced_characteristics.keys.length < 2
{}
else
most_restrictive_characteristic = @reduced_characteristics.keys.max_by do |key|
conditions = CohortScope.conditions_for @reduced_characteristics.except(key)
@active_record_relation.... | [
"def",
"reduce!",
"@reduced_characteristics",
"=",
"if",
"@reduced_characteristics",
".",
"keys",
".",
"length",
"<",
"2",
"{",
"}",
"else",
"most_restrictive_characteristic",
"=",
"@reduced_characteristics",
".",
"keys",
".",
"max_by",
"do",
"|",
"key",
"|",
"con... | Reduce characteristics by removing them one by one and counting the results.
The characteristic whose removal leads to the highest record count is removed from the overall characteristic set. | [
"Reduce",
"characteristics",
"by",
"removing",
"them",
"one",
"by",
"one",
"and",
"counting",
"the",
"results",
"."
] | 62e2f67a4bfeaae9c8befce318bf0a9bb40e4350 | https://github.com/seamusabshere/cohort_scope/blob/62e2f67a4bfeaae9c8befce318bf0a9bb40e4350/lib/cohort_scope/big_cohort.rb#L6-L16 |
10,225 | ryanuber/ruby-aptly | lib/aptly/snapshot.rb | Aptly.Snapshot.pull | def pull name, source, dest, kwargs={}
packages = kwargs.arg :packages, []
deps = kwargs.arg :deps, true
remove = kwargs.arg :remove, true
if packages.length == 0
raise AptlyError.new "1 or more package names are required"
end
cmd = 'aptly snapshot pull'
cmd += ' -no-... | ruby | def pull name, source, dest, kwargs={}
packages = kwargs.arg :packages, []
deps = kwargs.arg :deps, true
remove = kwargs.arg :remove, true
if packages.length == 0
raise AptlyError.new "1 or more package names are required"
end
cmd = 'aptly snapshot pull'
cmd += ' -no-... | [
"def",
"pull",
"name",
",",
"source",
",",
"dest",
",",
"kwargs",
"=",
"{",
"}",
"packages",
"=",
"kwargs",
".",
"arg",
":packages",
",",
"[",
"]",
"deps",
"=",
"kwargs",
".",
"arg",
":deps",
",",
"true",
"remove",
"=",
"kwargs",
".",
"arg",
":remo... | Pull packages from a snapshot into another, creating a new snapshot.
== Parameters:
name::
The name of the snapshot to pull to
source::
The repository containing the packages to pull in
dest::
The name for the new snapshot which will be created
packages::
An array of package names to search
deps::
... | [
"Pull",
"packages",
"from",
"a",
"snapshot",
"into",
"another",
"creating",
"a",
"new",
"snapshot",
"."
] | 9581c38da30119d6a61b7ddac6334ab17fc67164 | https://github.com/ryanuber/ruby-aptly/blob/9581c38da30119d6a61b7ddac6334ab17fc67164/lib/aptly/snapshot.rb#L200-L219 |
10,226 | ryanuber/ruby-aptly | lib/aptly/snapshot.rb | Aptly.Snapshot.pull_from | def pull_from source, dest, kwargs={}
packages = kwargs.arg :packages, []
deps = kwargs.arg :deps, true
remove = kwargs.arg :remove, true
pull @name, source, dest, :packages => packages, :deps => deps, :remove => remove
end | ruby | def pull_from source, dest, kwargs={}
packages = kwargs.arg :packages, []
deps = kwargs.arg :deps, true
remove = kwargs.arg :remove, true
pull @name, source, dest, :packages => packages, :deps => deps, :remove => remove
end | [
"def",
"pull_from",
"source",
",",
"dest",
",",
"kwargs",
"=",
"{",
"}",
"packages",
"=",
"kwargs",
".",
"arg",
":packages",
",",
"[",
"]",
"deps",
"=",
"kwargs",
".",
"arg",
":deps",
",",
"true",
"remove",
"=",
"kwargs",
".",
"arg",
":remove",
",",
... | Shortcut method to pull packages to the current snapshot | [
"Shortcut",
"method",
"to",
"pull",
"packages",
"to",
"the",
"current",
"snapshot"
] | 9581c38da30119d6a61b7ddac6334ab17fc67164 | https://github.com/ryanuber/ruby-aptly/blob/9581c38da30119d6a61b7ddac6334ab17fc67164/lib/aptly/snapshot.rb#L223-L229 |
10,227 | bradfeehan/derelict | lib/derelict/parser/status.rb | Derelict.Parser::Status.exists? | def exists?(vm_name = nil)
return (vm_names.count > 0) if vm_name.nil?
vm_names.include? vm_name.to_sym
end | ruby | def exists?(vm_name = nil)
return (vm_names.count > 0) if vm_name.nil?
vm_names.include? vm_name.to_sym
end | [
"def",
"exists?",
"(",
"vm_name",
"=",
"nil",
")",
"return",
"(",
"vm_names",
".",
"count",
">",
"0",
")",
"if",
"vm_name",
".",
"nil?",
"vm_names",
".",
"include?",
"vm_name",
".",
"to_sym",
"end"
] | Determines if a particular virtual machine exists in the output
* vm_name: The name of the virtual machine to look for | [
"Determines",
"if",
"a",
"particular",
"virtual",
"machine",
"exists",
"in",
"the",
"output"
] | c9d70f04562280a34083dd060b0e4099e6f32d8d | https://github.com/bradfeehan/derelict/blob/c9d70f04562280a34083dd060b0e4099e6f32d8d/lib/derelict/parser/status.rb#L32-L35 |
10,228 | bradfeehan/derelict | lib/derelict/parser/status.rb | Derelict.Parser::Status.state | def state(vm_name)
unless states.include? vm_name.to_sym
raise Derelict::VirtualMachine::NotFound.new vm_name
end
states[vm_name.to_sym]
end | ruby | def state(vm_name)
unless states.include? vm_name.to_sym
raise Derelict::VirtualMachine::NotFound.new vm_name
end
states[vm_name.to_sym]
end | [
"def",
"state",
"(",
"vm_name",
")",
"unless",
"states",
".",
"include?",
"vm_name",
".",
"to_sym",
"raise",
"Derelict",
"::",
"VirtualMachine",
"::",
"NotFound",
".",
"new",
"vm_name",
"end",
"states",
"[",
"vm_name",
".",
"to_sym",
"]",
"end"
] | Determines the state of a particular virtual machine
The state is returned as a symbol, e.g. :running.
* vm_name: The name of the virtual machine to retrieve state | [
"Determines",
"the",
"state",
"of",
"a",
"particular",
"virtual",
"machine"
] | c9d70f04562280a34083dd060b0e4099e6f32d8d | https://github.com/bradfeehan/derelict/blob/c9d70f04562280a34083dd060b0e4099e6f32d8d/lib/derelict/parser/status.rb#L42-L48 |
10,229 | bradfeehan/derelict | lib/derelict/parser/status.rb | Derelict.Parser::Status.vm_lines | def vm_lines
output.match(PARSE_LIST_FROM_OUTPUT).tap {|list|
logger.debug "Parsing VM list from output using #{description}"
raise InvalidFormat.new "Couldn't find VM list" if list.nil?
}.captures[0].lines
end | ruby | def vm_lines
output.match(PARSE_LIST_FROM_OUTPUT).tap {|list|
logger.debug "Parsing VM list from output using #{description}"
raise InvalidFormat.new "Couldn't find VM list" if list.nil?
}.captures[0].lines
end | [
"def",
"vm_lines",
"output",
".",
"match",
"(",
"PARSE_LIST_FROM_OUTPUT",
")",
".",
"tap",
"{",
"|",
"list",
"|",
"logger",
".",
"debug",
"\"Parsing VM list from output using #{description}\"",
"raise",
"InvalidFormat",
".",
"new",
"\"Couldn't find VM list\"",
"if",
"... | Retrieves the virtual machine list section of the output | [
"Retrieves",
"the",
"virtual",
"machine",
"list",
"section",
"of",
"the",
"output"
] | c9d70f04562280a34083dd060b0e4099e6f32d8d | https://github.com/bradfeehan/derelict/blob/c9d70f04562280a34083dd060b0e4099e6f32d8d/lib/derelict/parser/status.rb#L59-L64 |
10,230 | marcboeker/mongolicious | lib/mongolicious/db.rb | Mongolicious.DB.get_opts | def get_opts(db_uri)
uri = URI.parse(db_uri)
{
:host => uri.host,
:port => uri.port,
:user => uri.user,
:password => uri.password,
:db => uri.path.gsub('/', '')
}
end | ruby | def get_opts(db_uri)
uri = URI.parse(db_uri)
{
:host => uri.host,
:port => uri.port,
:user => uri.user,
:password => uri.password,
:db => uri.path.gsub('/', '')
}
end | [
"def",
"get_opts",
"(",
"db_uri",
")",
"uri",
"=",
"URI",
".",
"parse",
"(",
"db_uri",
")",
"{",
":host",
"=>",
"uri",
".",
"host",
",",
":port",
"=>",
"uri",
".",
"port",
",",
":user",
"=>",
"uri",
".",
"user",
",",
":password",
"=>",
"uri",
"."... | Initialize a ne DB object.
@return [DB]
Parse the MongoDB URI.
@param [String] db_uri the DB URI.
@return [Hash] | [
"Initialize",
"a",
"ne",
"DB",
"object",
"."
] | bc1553188df97d3df825de6d826b34ab7185a431 | https://github.com/marcboeker/mongolicious/blob/bc1553188df97d3df825de6d826b34ab7185a431/lib/mongolicious/db.rb#L16-L26 |
10,231 | marcboeker/mongolicious | lib/mongolicious/db.rb | Mongolicious.DB.dump | def dump(db, path)
Mongolicious.logger.info("Dumping database #{db[:db]}")
cmd = "mongodump -d #{db[:db]} -h #{db[:host]}:#{db[:port]} -o #{path}"
cmd << " -u '#{db[:user]}' -p '#{db[:password]}'" unless (db[:user].nil? || db[:user].empty?)
cmd << " > /dev/null"
system(cmd)
raise "... | ruby | def dump(db, path)
Mongolicious.logger.info("Dumping database #{db[:db]}")
cmd = "mongodump -d #{db[:db]} -h #{db[:host]}:#{db[:port]} -o #{path}"
cmd << " -u '#{db[:user]}' -p '#{db[:password]}'" unless (db[:user].nil? || db[:user].empty?)
cmd << " > /dev/null"
system(cmd)
raise "... | [
"def",
"dump",
"(",
"db",
",",
"path",
")",
"Mongolicious",
".",
"logger",
".",
"info",
"(",
"\"Dumping database #{db[:db]}\"",
")",
"cmd",
"=",
"\"mongodump -d #{db[:db]} -h #{db[:host]}:#{db[:port]} -o #{path}\"",
"cmd",
"<<",
"\" -u '#{db[:user]}' -p '#{db[:password]}'\"",... | Dump database using mongodump.
@param [Hash] db the DB connection opts.
@param [String] path the path, where the dump should be stored.
@return [nil] | [
"Dump",
"database",
"using",
"mongodump",
"."
] | bc1553188df97d3df825de6d826b34ab7185a431 | https://github.com/marcboeker/mongolicious/blob/bc1553188df97d3df825de6d826b34ab7185a431/lib/mongolicious/db.rb#L34-L43 |
10,232 | postmodern/wsoc | lib/wsoc/runner.rb | WSOC.Runner.run | def run(*args)
optparse(*args)
options = {
:env => :production,
:host => @host,
:port => @port
}
options.merge!(:server => @handler) if @handler
App.run!(options)
end | ruby | def run(*args)
optparse(*args)
options = {
:env => :production,
:host => @host,
:port => @port
}
options.merge!(:server => @handler) if @handler
App.run!(options)
end | [
"def",
"run",
"(",
"*",
"args",
")",
"optparse",
"(",
"args",
")",
"options",
"=",
"{",
":env",
"=>",
":production",
",",
":host",
"=>",
"@host",
",",
":port",
"=>",
"@port",
"}",
"options",
".",
"merge!",
"(",
":server",
"=>",
"@handler",
")",
"if",... | Runs the runner.
@param [Array<String>] args
The arguments to run the runner with.
@since 0.1.0 | [
"Runs",
"the",
"runner",
"."
] | b8b82f0cef0fd8594c48c45d3b213bc65412b455 | https://github.com/postmodern/wsoc/blob/b8b82f0cef0fd8594c48c45d3b213bc65412b455/lib/wsoc/runner.rb#L67-L79 |
10,233 | rodrigopinto/biju | lib/biju/modem.rb | Biju.Modem.messages | def messages(which = "ALL")
# read message from all storage in the mobile phone (sim+mem)
cmd('AT+CPMS="MT"')
# get message list
sms = cmd('AT+CMGL="%s"' % which )
# collect messages
msgs = sms.scan(/\+CMGL\:\s*?(\d+)\,.*?\,\"(.+?)\"\,.*?\,\"(.+?)\".*?\n(.*)/)
return nil unless... | ruby | def messages(which = "ALL")
# read message from all storage in the mobile phone (sim+mem)
cmd('AT+CPMS="MT"')
# get message list
sms = cmd('AT+CMGL="%s"' % which )
# collect messages
msgs = sms.scan(/\+CMGL\:\s*?(\d+)\,.*?\,\"(.+?)\"\,.*?\,\"(.+?)\".*?\n(.*)/)
return nil unless... | [
"def",
"messages",
"(",
"which",
"=",
"\"ALL\"",
")",
"# read message from all storage in the mobile phone (sim+mem)",
"cmd",
"(",
"'AT+CPMS=\"MT\"'",
")",
"# get message list",
"sms",
"=",
"cmd",
"(",
"'AT+CMGL=\"%s\"'",
"%",
"which",
")",
"# collect messages",
"msgs",
... | Return an Array of Sms if there is messages nad return nil if not. | [
"Return",
"an",
"Array",
"of",
"Sms",
"if",
"there",
"is",
"messages",
"nad",
"return",
"nil",
"if",
"not",
"."
] | 898d8d73a9cac0f6bca68731927c37343b9e0ff6 | https://github.com/rodrigopinto/biju/blob/898d8d73a9cac0f6bca68731927c37343b9e0ff6/lib/biju/modem.rb#L34-L43 |
10,234 | djhworld/gmail-mailer | lib/gmail-mailer.rb | GmailMailer.Mailer.send_smtp | def send_smtp(mail)
smtp = Net::SMTP.new(SMTP_SERVER, SMTP_PORT)
smtp.enable_starttls_auto
secret = {
:consumer_key => SMTP_CONSUMER_KEY,
:consumer_secret => SMTP_CONSUMER_SECRET,
:token => @email_credentials[:smtp_oauth_token],
:token_secret => @email_credentials[:smt... | ruby | def send_smtp(mail)
smtp = Net::SMTP.new(SMTP_SERVER, SMTP_PORT)
smtp.enable_starttls_auto
secret = {
:consumer_key => SMTP_CONSUMER_KEY,
:consumer_secret => SMTP_CONSUMER_SECRET,
:token => @email_credentials[:smtp_oauth_token],
:token_secret => @email_credentials[:smt... | [
"def",
"send_smtp",
"(",
"mail",
")",
"smtp",
"=",
"Net",
"::",
"SMTP",
".",
"new",
"(",
"SMTP_SERVER",
",",
"SMTP_PORT",
")",
"smtp",
".",
"enable_starttls_auto",
"secret",
"=",
"{",
":consumer_key",
"=>",
"SMTP_CONSUMER_KEY",
",",
":consumer_secret",
"=>",
... | Use gmail_xoauth to send email | [
"Use",
"gmail_xoauth",
"to",
"send",
"email"
] | b63c259d124950b612d20bcad1e82d260984f0e9 | https://github.com/djhworld/gmail-mailer/blob/b63c259d124950b612d20bcad1e82d260984f0e9/lib/gmail-mailer.rb#L49-L63 |
10,235 | ryansobol/mango | lib/mango/application.rb | Mango.Application.render_404_public_file! | def render_404_public_file!(file_name)
four_oh_four_path = File.expand_path("#{file_name}.html", settings.public_dir)
return unless File.file?(four_oh_four_path)
send_file four_oh_four_path, status: 404
end | ruby | def render_404_public_file!(file_name)
four_oh_four_path = File.expand_path("#{file_name}.html", settings.public_dir)
return unless File.file?(four_oh_four_path)
send_file four_oh_four_path, status: 404
end | [
"def",
"render_404_public_file!",
"(",
"file_name",
")",
"four_oh_four_path",
"=",
"File",
".",
"expand_path",
"(",
"\"#{file_name}.html\"",
",",
"settings",
".",
"public_dir",
")",
"return",
"unless",
"File",
".",
"file?",
"(",
"four_oh_four_path",
")",
"send_file"... | Given a file name, attempts to send an public 404 file, if it exists, and halt
@param [String] file_name | [
"Given",
"a",
"file",
"name",
"attempts",
"to",
"send",
"an",
"public",
"404",
"file",
"if",
"it",
"exists",
"and",
"halt"
] | f28f1fb9ff2820f11e6b9f96cdd92576774da12f | https://github.com/ryansobol/mango/blob/f28f1fb9ff2820f11e6b9f96cdd92576774da12f/lib/mango/application.rb#L275-L279 |
10,236 | ryansobol/mango | lib/mango/application.rb | Mango.Application.render_404_template! | def render_404_template!(template_name)
VIEW_TEMPLATE_ENGINES.each do |engine, extension|
@preferred_extension = extension.to_s
find_template(settings.views, template_name, engine) do |file|
next unless File.file?(file)
halt send(extension, template_name.to_sym, layout: false)
... | ruby | def render_404_template!(template_name)
VIEW_TEMPLATE_ENGINES.each do |engine, extension|
@preferred_extension = extension.to_s
find_template(settings.views, template_name, engine) do |file|
next unless File.file?(file)
halt send(extension, template_name.to_sym, layout: false)
... | [
"def",
"render_404_template!",
"(",
"template_name",
")",
"VIEW_TEMPLATE_ENGINES",
".",
"each",
"do",
"|",
"engine",
",",
"extension",
"|",
"@preferred_extension",
"=",
"extension",
".",
"to_s",
"find_template",
"(",
"settings",
".",
"views",
",",
"template_name",
... | Given a template name, and with a prioritized list of template engines, attempts to render a
404 template, if one exists, and halt.
@param [String] template_name
@see VIEW_TEMPLATE_ENGINES | [
"Given",
"a",
"template",
"name",
"and",
"with",
"a",
"prioritized",
"list",
"of",
"template",
"engines",
"attempts",
"to",
"render",
"a",
"404",
"template",
"if",
"one",
"exists",
"and",
"halt",
"."
] | f28f1fb9ff2820f11e6b9f96cdd92576774da12f | https://github.com/ryansobol/mango/blob/f28f1fb9ff2820f11e6b9f96cdd92576774da12f/lib/mango/application.rb#L287-L295 |
10,237 | ryansobol/mango | lib/mango/application.rb | Mango.Application.render_javascript_template! | def render_javascript_template!(uri_path)
javascript_match = File.join(settings.javascripts, "*")
javascript_path = File.expand_path(uri_path, settings.javascripts)
return unless File.fnmatch(javascript_match, javascript_path)
JAVASCRIPT_TEMPLATE_ENGINES.each do |engine, extension|
@p... | ruby | def render_javascript_template!(uri_path)
javascript_match = File.join(settings.javascripts, "*")
javascript_path = File.expand_path(uri_path, settings.javascripts)
return unless File.fnmatch(javascript_match, javascript_path)
JAVASCRIPT_TEMPLATE_ENGINES.each do |engine, extension|
@p... | [
"def",
"render_javascript_template!",
"(",
"uri_path",
")",
"javascript_match",
"=",
"File",
".",
"join",
"(",
"settings",
".",
"javascripts",
",",
"\"*\"",
")",
"javascript_path",
"=",
"File",
".",
"expand_path",
"(",
"uri_path",
",",
"settings",
".",
"javascri... | Given a URI path, attempts to render a JavaScript template, if it exists, and halt
@param [String] uri_path
@see JAVASCRIPT_TEMPLATE_ENGINES | [
"Given",
"a",
"URI",
"path",
"attempts",
"to",
"render",
"a",
"JavaScript",
"template",
"if",
"it",
"exists",
"and",
"halt"
] | f28f1fb9ff2820f11e6b9f96cdd92576774da12f | https://github.com/ryansobol/mango/blob/f28f1fb9ff2820f11e6b9f96cdd92576774da12f/lib/mango/application.rb#L355-L368 |
10,238 | ryansobol/mango | lib/mango/application.rb | Mango.Application.render_stylesheet_template! | def render_stylesheet_template!(uri_path)
stylesheet_match = File.join(settings.stylesheets, "*")
stylesheet_path = File.expand_path(uri_path, settings.stylesheets)
return unless File.fnmatch(stylesheet_match, stylesheet_path)
STYLESHEET_TEMPLATE_ENGINES.each do |engine, extension|
@p... | ruby | def render_stylesheet_template!(uri_path)
stylesheet_match = File.join(settings.stylesheets, "*")
stylesheet_path = File.expand_path(uri_path, settings.stylesheets)
return unless File.fnmatch(stylesheet_match, stylesheet_path)
STYLESHEET_TEMPLATE_ENGINES.each do |engine, extension|
@p... | [
"def",
"render_stylesheet_template!",
"(",
"uri_path",
")",
"stylesheet_match",
"=",
"File",
".",
"join",
"(",
"settings",
".",
"stylesheets",
",",
"\"*\"",
")",
"stylesheet_path",
"=",
"File",
".",
"expand_path",
"(",
"uri_path",
",",
"settings",
".",
"styleshe... | Given a URI path, attempts to render a stylesheet template, if it exists, and halt
@param [String] uri_path
@see STYLESHEET_TEMPLATE_ENGINES | [
"Given",
"a",
"URI",
"path",
"attempts",
"to",
"render",
"a",
"stylesheet",
"template",
"if",
"it",
"exists",
"and",
"halt"
] | f28f1fb9ff2820f11e6b9f96cdd92576774da12f | https://github.com/ryansobol/mango/blob/f28f1fb9ff2820f11e6b9f96cdd92576774da12f/lib/mango/application.rb#L425-L438 |
10,239 | ryansobol/mango | lib/mango/application.rb | Mango.Application.render_index_file! | def render_index_file!(uri_path)
return unless URI.directory?(uri_path)
index_match = File.join(settings.public_dir, "*")
index_file_path = File.expand_path(uri_path + "index.html", settings.public_dir)
return unless File.fnmatch(index_match, index_file_path)
return unless File.file?... | ruby | def render_index_file!(uri_path)
return unless URI.directory?(uri_path)
index_match = File.join(settings.public_dir, "*")
index_file_path = File.expand_path(uri_path + "index.html", settings.public_dir)
return unless File.fnmatch(index_match, index_file_path)
return unless File.file?... | [
"def",
"render_index_file!",
"(",
"uri_path",
")",
"return",
"unless",
"URI",
".",
"directory?",
"(",
"uri_path",
")",
"index_match",
"=",
"File",
".",
"join",
"(",
"settings",
".",
"public_dir",
",",
"\"*\"",
")",
"index_file_path",
"=",
"File",
".",
"expan... | Given a URI path, attempts to send an index.html file, if it exists, and halt
@param [String] uri_path | [
"Given",
"a",
"URI",
"path",
"attempts",
"to",
"send",
"an",
"index",
".",
"html",
"file",
"if",
"it",
"exists",
"and",
"halt"
] | f28f1fb9ff2820f11e6b9f96cdd92576774da12f | https://github.com/ryansobol/mango/blob/f28f1fb9ff2820f11e6b9f96cdd92576774da12f/lib/mango/application.rb#L504-L514 |
10,240 | ryansobol/mango | lib/mango/application.rb | Mango.Application.render_content_page! | def render_content_page!(uri_path)
uri_path += "index" if URI.directory?(uri_path)
content_match = File.join(settings.content, "*")
content_page_path = File.expand_path(uri_path, settings.content)
return unless File.fnmatch(content_match, content_page_path)
begin
content_page... | ruby | def render_content_page!(uri_path)
uri_path += "index" if URI.directory?(uri_path)
content_match = File.join(settings.content, "*")
content_page_path = File.expand_path(uri_path, settings.content)
return unless File.fnmatch(content_match, content_page_path)
begin
content_page... | [
"def",
"render_content_page!",
"(",
"uri_path",
")",
"uri_path",
"+=",
"\"index\"",
"if",
"URI",
".",
"directory?",
"(",
"uri_path",
")",
"content_match",
"=",
"File",
".",
"join",
"(",
"settings",
".",
"content",
",",
"\"*\"",
")",
"content_page_path",
"=",
... | Given a URI path, attempts to render a content page, if it exists, and halt
@param [String] uri_path
@raise [RegisteredEngineNotFound] Raised when a registered engine for the content page's
view template cannot be found
@raise [ViewTemplateNotFound] Raised when the content page's view template cannot be found | [
"Given",
"a",
"URI",
"path",
"attempts",
"to",
"render",
"a",
"content",
"page",
"if",
"it",
"exists",
"and",
"halt"
] | f28f1fb9ff2820f11e6b9f96cdd92576774da12f | https://github.com/ryansobol/mango/blob/f28f1fb9ff2820f11e6b9f96cdd92576774da12f/lib/mango/application.rb#L533-L561 |
10,241 | ryansobol/mango | lib/mango/application.rb | Mango.Application.find_content_page | def find_content_page(uri_path)
ContentPage::TEMPLATE_ENGINES.each do |engine, extension|
@preferred_extension = extension.to_s
find_template(settings.content, uri_path, engine) do |file|
next unless File.file?(file)
return ContentPage.new(data: File.read(file), engine: engine)... | ruby | def find_content_page(uri_path)
ContentPage::TEMPLATE_ENGINES.each do |engine, extension|
@preferred_extension = extension.to_s
find_template(settings.content, uri_path, engine) do |file|
next unless File.file?(file)
return ContentPage.new(data: File.read(file), engine: engine)... | [
"def",
"find_content_page",
"(",
"uri_path",
")",
"ContentPage",
"::",
"TEMPLATE_ENGINES",
".",
"each",
"do",
"|",
"engine",
",",
"extension",
"|",
"@preferred_extension",
"=",
"extension",
".",
"to_s",
"find_template",
"(",
"settings",
".",
"content",
",",
"uri... | Given a URI path, creates a new `ContentPage` instance by searching for and reading a content
file from disk. Content files are searched consecutively until a page with a supported
content page template engine is found.
@param [String] uri_path
@raise [ContentPageNotFound] Raised when a content page cannot be foun... | [
"Given",
"a",
"URI",
"path",
"creates",
"a",
"new",
"ContentPage",
"instance",
"by",
"searching",
"for",
"and",
"reading",
"a",
"content",
"file",
"from",
"disk",
".",
"Content",
"files",
"are",
"searched",
"consecutively",
"until",
"a",
"page",
"with",
"a",... | f28f1fb9ff2820f11e6b9f96cdd92576774da12f | https://github.com/ryansobol/mango/blob/f28f1fb9ff2820f11e6b9f96cdd92576774da12f/lib/mango/application.rb#L572-L582 |
10,242 | skift/estore_conventions | lib/estore_conventions.rb | EstoreConventions.ClassMethods.factory_build_for_store | def factory_build_for_store(atts_hash, identifier_conditions = {}, full_data_object={}, &blk)
if identifier_conditions.empty?
record = self.new
else
record = self.where(identifier_conditions).first_or_initialize
end
record.assign_attributes(atts_hash, :without_protection =>... | ruby | def factory_build_for_store(atts_hash, identifier_conditions = {}, full_data_object={}, &blk)
if identifier_conditions.empty?
record = self.new
else
record = self.where(identifier_conditions).first_or_initialize
end
record.assign_attributes(atts_hash, :without_protection =>... | [
"def",
"factory_build_for_store",
"(",
"atts_hash",
",",
"identifier_conditions",
"=",
"{",
"}",
",",
"full_data_object",
"=",
"{",
"}",
",",
"&",
"blk",
")",
"if",
"identifier_conditions",
".",
"empty?",
"record",
"=",
"self",
".",
"new",
"else",
"record",
... | atts_hash are the attributes to assign to the Record
identifier_conditions is what the scope for first_or_initialize is called upon
so that an existing object is updated
full_data_object is passed in to be saved as a blob | [
"atts_hash",
"are",
"the",
"attributes",
"to",
"assign",
"to",
"the",
"Record",
"identifier_conditions",
"is",
"what",
"the",
"scope",
"for",
"first_or_initialize",
"is",
"called",
"upon",
"so",
"that",
"an",
"existing",
"object",
"is",
"updated",
"full_data_objec... | b9f1dfa45d476ecbadaa0a50729aeef064961183 | https://github.com/skift/estore_conventions/blob/b9f1dfa45d476ecbadaa0a50729aeef064961183/lib/estore_conventions.rb#L40-L53 |
10,243 | wwidea/rexport | lib/rexport/tree_node.rb | Rexport.TreeNode.add_child | def add_child(*names)
names.flatten!
return unless name = names.shift
node = children.find { |c| c.name == name }
node ? node.add_child(names) : (children << TreeNode.new(name, names))
end | ruby | def add_child(*names)
names.flatten!
return unless name = names.shift
node = children.find { |c| c.name == name }
node ? node.add_child(names) : (children << TreeNode.new(name, names))
end | [
"def",
"add_child",
"(",
"*",
"names",
")",
"names",
".",
"flatten!",
"return",
"unless",
"name",
"=",
"names",
".",
"shift",
"node",
"=",
"children",
".",
"find",
"{",
"|",
"c",
"|",
"c",
".",
"name",
"==",
"name",
"}",
"node",
"?",
"node",
".",
... | Initialize a tree node setting name and adding a child if one was passed
Add one or more children to the tree | [
"Initialize",
"a",
"tree",
"node",
"setting",
"name",
"and",
"adding",
"a",
"child",
"if",
"one",
"was",
"passed",
"Add",
"one",
"or",
"more",
"children",
"to",
"the",
"tree"
] | f4f978dd0327ddba3a4318dd24090fbc6d4e4e59 | https://github.com/wwidea/rexport/blob/f4f978dd0327ddba3a4318dd24090fbc6d4e4e59/lib/rexport/tree_node.rb#L14-L19 |
10,244 | lkdjiin/bookmarks | lib/bookmarks/document.rb | Bookmarks.Document.parse_a_bookmark | def parse_a_bookmark line
line = line.strip
if line =~ /^<DT><H3/
@h3_tags << h3_tags(line)
elsif line =~ /^<\/DL>/
@h3_tags.pop
elsif line =~ /<DT><A HREF="http/
@bookmarks << NetscapeBookmark.from_string(line)
if (not @h3_tags.empty?) && (not @bookmarks.last.nil... | ruby | def parse_a_bookmark line
line = line.strip
if line =~ /^<DT><H3/
@h3_tags << h3_tags(line)
elsif line =~ /^<\/DL>/
@h3_tags.pop
elsif line =~ /<DT><A HREF="http/
@bookmarks << NetscapeBookmark.from_string(line)
if (not @h3_tags.empty?) && (not @bookmarks.last.nil... | [
"def",
"parse_a_bookmark",
"line",
"line",
"=",
"line",
".",
"strip",
"if",
"line",
"=~",
"/",
"/",
"@h3_tags",
"<<",
"h3_tags",
"(",
"line",
")",
"elsif",
"line",
"=~",
"/",
"\\/",
"/",
"@h3_tags",
".",
"pop",
"elsif",
"line",
"=~",
"/",
"/",
"@book... | Parse a single line from a bookmarks file.
line - String.
Returns nothing.
TODO This should have its own parser class. | [
"Parse",
"a",
"single",
"line",
"from",
"a",
"bookmarks",
"file",
"."
] | 6f6bdf94f2de5347a9db19d01ad0721033cf0123 | https://github.com/lkdjiin/bookmarks/blob/6f6bdf94f2de5347a9db19d01ad0721033cf0123/lib/bookmarks/document.rb#L78-L92 |
10,245 | nickcharlton/atlas-ruby | lib/atlas/box_version.rb | Atlas.BoxVersion.save | def save # rubocop:disable Metrics/AbcSize
body = { version: to_hash }
# providers are saved seperately
body[:version].delete(:providers)
begin
response = Atlas.client.put(url_builder.box_version_url, body: body)
rescue Atlas::Errors::NotFoundError
response = Atlas.client... | ruby | def save # rubocop:disable Metrics/AbcSize
body = { version: to_hash }
# providers are saved seperately
body[:version].delete(:providers)
begin
response = Atlas.client.put(url_builder.box_version_url, body: body)
rescue Atlas::Errors::NotFoundError
response = Atlas.client... | [
"def",
"save",
"# rubocop:disable Metrics/AbcSize",
"body",
"=",
"{",
"version",
":",
"to_hash",
"}",
"# providers are saved seperately",
"body",
"[",
":version",
"]",
".",
"delete",
"(",
":providers",
")",
"begin",
"response",
"=",
"Atlas",
".",
"client",
".",
... | Save the version.
@return [Hash] Atlas response object. | [
"Save",
"the",
"version",
"."
] | 2170c04496682e0d8e7c959bd9f267f62fa84c1d | https://github.com/nickcharlton/atlas-ruby/blob/2170c04496682e0d8e7c959bd9f267f62fa84c1d/lib/atlas/box_version.rb#L80-L97 |
10,246 | sight-labs/enchanted_quill | lib/enchanted_quill/label.rb | EnchantedQuill.Label.textRectForBounds | def textRectForBounds(bounds, limitedToNumberOfLines: num_of_lines)
required_rect = rect_fitting_text_for_container_size(bounds.size, for_number_of_line: num_of_lines)
text_container.size = required_rect.size
required_rect
end | ruby | def textRectForBounds(bounds, limitedToNumberOfLines: num_of_lines)
required_rect = rect_fitting_text_for_container_size(bounds.size, for_number_of_line: num_of_lines)
text_container.size = required_rect.size
required_rect
end | [
"def",
"textRectForBounds",
"(",
"bounds",
",",
"limitedToNumberOfLines",
":",
"num_of_lines",
")",
"required_rect",
"=",
"rect_fitting_text_for_container_size",
"(",
"bounds",
".",
"size",
",",
"for_number_of_line",
":",
"num_of_lines",
")",
"text_container",
".",
"siz... | Override UILabel Methods | [
"Override",
"UILabel",
"Methods"
] | d8c70f50fea320878249fec7ed3ea134a4975f32 | https://github.com/sight-labs/enchanted_quill/blob/d8c70f50fea320878249fec7ed3ea134a4975f32/lib/enchanted_quill/label.rb#L66-L70 |
10,247 | sight-labs/enchanted_quill | lib/enchanted_quill/label.rb | EnchantedQuill.Label.add_link_attribute | def add_link_attribute(mut_attr_string)
range_pointer = Pointer.new(NSRange.type)
attributes = mut_attr_string.attributesAtIndex(0, effectiveRange: range_pointer).dup
attributes[NSFontAttributeName] = self.font
attributes[NSForegroundColorAttributeName] = self.textColor
mut_attr_string.ad... | ruby | def add_link_attribute(mut_attr_string)
range_pointer = Pointer.new(NSRange.type)
attributes = mut_attr_string.attributesAtIndex(0, effectiveRange: range_pointer).dup
attributes[NSFontAttributeName] = self.font
attributes[NSForegroundColorAttributeName] = self.textColor
mut_attr_string.ad... | [
"def",
"add_link_attribute",
"(",
"mut_attr_string",
")",
"range_pointer",
"=",
"Pointer",
".",
"new",
"(",
"NSRange",
".",
"type",
")",
"attributes",
"=",
"mut_attr_string",
".",
"attributesAtIndex",
"(",
"0",
",",
"effectiveRange",
":",
"range_pointer",
")",
"... | add link attribute | [
"add",
"link",
"attribute"
] | d8c70f50fea320878249fec7ed3ea134a4975f32 | https://github.com/sight-labs/enchanted_quill/blob/d8c70f50fea320878249fec7ed3ea134a4975f32/lib/enchanted_quill/label.rb#L384-L404 |
10,248 | bradleyd/shelltastic | lib/shelltastic/utils.rb | ShellTastic.Utils.empty_nil_blank? | def empty_nil_blank?(str, raize=false)
result = (str !~ /[^[:space:]]/ || str.nil? || str.empty?)
raise ShellTastic::CommandException.new("Command is emtpy or nil") if result and raize
result
end | ruby | def empty_nil_blank?(str, raize=false)
result = (str !~ /[^[:space:]]/ || str.nil? || str.empty?)
raise ShellTastic::CommandException.new("Command is emtpy or nil") if result and raize
result
end | [
"def",
"empty_nil_blank?",
"(",
"str",
",",
"raize",
"=",
"false",
")",
"result",
"=",
"(",
"str",
"!~",
"/",
"/",
"||",
"str",
".",
"nil?",
"||",
"str",
".",
"empty?",
")",
"raise",
"ShellTastic",
"::",
"CommandException",
".",
"new",
"(",
"\"Command ... | like the other methods but allow to set an exception flag
@param [String] str the string the needs to be checked
@param [Boolean] to raise an exception or not. DEFAULT is false
@return [Boolean]
@return [ShellTastic::CommandException] | [
"like",
"the",
"other",
"methods",
"but",
"allow",
"to",
"set",
"an",
"exception",
"flag"
] | 4004c2b98efb8882d5b702b9c5d69e15cc38cc38 | https://github.com/bradleyd/shelltastic/blob/4004c2b98efb8882d5b702b9c5d69e15cc38cc38/lib/shelltastic/utils.rb#L25-L29 |
10,249 | hamidp/nadb | lib/nadb.rb | Nadb.Tool.load_config | def load_config
path = ENV['HOME'] + '/.nadb.config'
if !File.exists?(path)
return
end
@config = JSON.parse(File.read(path))
end | ruby | def load_config
path = ENV['HOME'] + '/.nadb.config'
if !File.exists?(path)
return
end
@config = JSON.parse(File.read(path))
end | [
"def",
"load_config",
"path",
"=",
"ENV",
"[",
"'HOME'",
"]",
"+",
"'/.nadb.config'",
"if",
"!",
"File",
".",
"exists?",
"(",
"path",
")",
"return",
"end",
"@config",
"=",
"JSON",
".",
"parse",
"(",
"File",
".",
"read",
"(",
"path",
")",
")",
"end"
] | Load config from the file if any exists | [
"Load",
"config",
"from",
"the",
"file",
"if",
"any",
"exists"
] | 8d97f00045af988d551a1e9dc5aa076615628035 | https://github.com/hamidp/nadb/blob/8d97f00045af988d551a1e9dc5aa076615628035/lib/nadb.rb#L41-L48 |
10,250 | hamidp/nadb | lib/nadb.rb | Nadb.Tool.run_adb_command | def run_adb_command(command, device = nil)
full_command = construct_adb_command command, device
puts full_command
pio = IO.popen(full_command, 'w')
Process.wait(pio.pid)
end | ruby | def run_adb_command(command, device = nil)
full_command = construct_adb_command command, device
puts full_command
pio = IO.popen(full_command, 'w')
Process.wait(pio.pid)
end | [
"def",
"run_adb_command",
"(",
"command",
",",
"device",
"=",
"nil",
")",
"full_command",
"=",
"construct_adb_command",
"command",
",",
"device",
"puts",
"full_command",
"pio",
"=",
"IO",
".",
"popen",
"(",
"full_command",
",",
"'w'",
")",
"Process",
".",
"w... | Run an adb commd on specified device, optionally printing the output | [
"Run",
"an",
"adb",
"commd",
"on",
"specified",
"device",
"optionally",
"printing",
"the",
"output"
] | 8d97f00045af988d551a1e9dc5aa076615628035 | https://github.com/hamidp/nadb/blob/8d97f00045af988d551a1e9dc5aa076615628035/lib/nadb.rb#L66-L72 |
10,251 | hamidp/nadb | lib/nadb.rb | Nadb.Tool.get_connected_devices | def get_connected_devices
get_adb_command_output('devices')
.drop(1)
.map { |line| line.split[0] }
.reject { |d| d.nil? || d.empty? }
end | ruby | def get_connected_devices
get_adb_command_output('devices')
.drop(1)
.map { |line| line.split[0] }
.reject { |d| d.nil? || d.empty? }
end | [
"def",
"get_connected_devices",
"get_adb_command_output",
"(",
"'devices'",
")",
".",
"drop",
"(",
"1",
")",
".",
"map",
"{",
"|",
"line",
"|",
"line",
".",
"split",
"[",
"0",
"]",
"}",
".",
"reject",
"{",
"|",
"d",
"|",
"d",
".",
"nil?",
"||",
"d"... | Get all currently connected android devices | [
"Get",
"all",
"currently",
"connected",
"android",
"devices"
] | 8d97f00045af988d551a1e9dc5aa076615628035 | https://github.com/hamidp/nadb/blob/8d97f00045af988d551a1e9dc5aa076615628035/lib/nadb.rb#L75-L80 |
10,252 | fridge-cms/jekyll-fridge | lib/jekyll-fridge/fridge_filters.rb | Jekyll.FridgeFilters.fridge_asset | def fridge_asset(input)
return input unless input
if input.respond_to?('first')
input = input.first['name']
end
site = @context.registers[:site]
asset_dir = site.config['fridge'].config['asset_dir']
dest_path = File.join(site.dest, asset_dir, input)
path = File.join(ass... | ruby | def fridge_asset(input)
return input unless input
if input.respond_to?('first')
input = input.first['name']
end
site = @context.registers[:site]
asset_dir = site.config['fridge'].config['asset_dir']
dest_path = File.join(site.dest, asset_dir, input)
path = File.join(ass... | [
"def",
"fridge_asset",
"(",
"input",
")",
"return",
"input",
"unless",
"input",
"if",
"input",
".",
"respond_to?",
"(",
"'first'",
")",
"input",
"=",
"input",
".",
"first",
"[",
"'name'",
"]",
"end",
"site",
"=",
"@context",
".",
"registers",
"[",
":site... | Filter for fetching assets
Writes static file to asset_dir and returns absolute file path | [
"Filter",
"for",
"fetching",
"assets",
"Writes",
"static",
"file",
"to",
"asset_dir",
"and",
"returns",
"absolute",
"file",
"path"
] | ac5fa7bd861ba6544ca14cf47eafcf0d15601e4c | https://github.com/fridge-cms/jekyll-fridge/blob/ac5fa7bd861ba6544ca14cf47eafcf0d15601e4c/lib/jekyll-fridge/fridge_filters.rb#L5-L31 |
10,253 | lacravate/git-trifle | lib/git/trifle.rb | Git.Trifle.cover | def cover(path, options={})
reset = options.delete :reset
cook_layer do
@dressing << Proc.new { self.reset if commits.any? } if reset
Git::Base.open path if can_cover? path
end
end | ruby | def cover(path, options={})
reset = options.delete :reset
cook_layer do
@dressing << Proc.new { self.reset if commits.any? } if reset
Git::Base.open path if can_cover? path
end
end | [
"def",
"cover",
"(",
"path",
",",
"options",
"=",
"{",
"}",
")",
"reset",
"=",
"options",
".",
"delete",
":reset",
"cook_layer",
"do",
"@dressing",
"<<",
"Proc",
".",
"new",
"{",
"self",
".",
"reset",
"if",
"commits",
".",
"any?",
"}",
"if",
"reset",... | hands on the handler | [
"hands",
"on",
"the",
"handler"
] | 43d18284c5b772bb5a2ecd412e8d11d4e8444531 | https://github.com/lacravate/git-trifle/blob/43d18284c5b772bb5a2ecd412e8d11d4e8444531/lib/git/trifle.rb#L54-L61 |
10,254 | tubbo/active_copy | lib/active_copy/finders.rb | ActiveCopy.Finders.matches? | def matches? query
query.reduce(true) do |matches, (key, value)|
matches = if key == 'tag'
return false unless tags.present?
tags.include? value
else
attributes[key] == value
end
end
end | ruby | def matches? query
query.reduce(true) do |matches, (key, value)|
matches = if key == 'tag'
return false unless tags.present?
tags.include? value
else
attributes[key] == value
end
end
end | [
"def",
"matches?",
"query",
"query",
".",
"reduce",
"(",
"true",
")",
"do",
"|",
"matches",
",",
"(",
"key",
",",
"value",
")",
"|",
"matches",
"=",
"if",
"key",
"==",
"'tag'",
"return",
"false",
"unless",
"tags",
".",
"present?",
"tags",
".",
"inclu... | Test if the query matches this particular model. | [
"Test",
"if",
"the",
"query",
"matches",
"this",
"particular",
"model",
"."
] | 63716fdd9283231e9ed0d8ac6af97633d3e97210 | https://github.com/tubbo/active_copy/blob/63716fdd9283231e9ed0d8ac6af97633d3e97210/lib/active_copy/finders.rb#L9-L18 |
10,255 | alfa-jpn/rails-kvs-driver | lib/rails_kvs_driver/validation_driver_config.rb | RailsKvsDriver.ValidationDriverConfig.validate_driver_config! | def validate_driver_config!(driver_config)
raise_argument_error!(:host) unless driver_config.has_key? :host
raise_argument_error!(:port) unless driver_config.has_key? :port
raise_argument_error!(:namespace) unless driver_config.has_key? :namespace
raise_argument_error!(:timeout_s... | ruby | def validate_driver_config!(driver_config)
raise_argument_error!(:host) unless driver_config.has_key? :host
raise_argument_error!(:port) unless driver_config.has_key? :port
raise_argument_error!(:namespace) unless driver_config.has_key? :namespace
raise_argument_error!(:timeout_s... | [
"def",
"validate_driver_config!",
"(",
"driver_config",
")",
"raise_argument_error!",
"(",
":host",
")",
"unless",
"driver_config",
".",
"has_key?",
":host",
"raise_argument_error!",
"(",
":port",
")",
"unless",
"driver_config",
".",
"has_key?",
":port",
"raise_argument... | Validate driver_config.
This method raise ArgumentError, if missing driver_config.
@param driver_config [Hash] driver config.
@return [Hash] driver_config | [
"Validate",
"driver_config",
".",
"This",
"method",
"raise",
"ArgumentError",
"if",
"missing",
"driver_config",
"."
] | 0eaf5c649071f9d82dc5f2ff2f4d7efcf32d8982 | https://github.com/alfa-jpn/rails-kvs-driver/blob/0eaf5c649071f9d82dc5f2ff2f4d7efcf32d8982/lib/rails_kvs_driver/validation_driver_config.rb#L8-L18 |
10,256 | jasonrclark/hometown | lib/hometown/creation_tracer.rb | Hometown.CreationTracer.update_on_instance_created | def update_on_instance_created(clazz, on_instance_created)
return unless on_instance_created
clazz.instance_eval do
def instance_hooks
hooks = (self.ancestors + [self]).map do |target|
target.instance_variable_get(:@instance_hooks)
end
hooks.flatten!
... | ruby | def update_on_instance_created(clazz, on_instance_created)
return unless on_instance_created
clazz.instance_eval do
def instance_hooks
hooks = (self.ancestors + [self]).map do |target|
target.instance_variable_get(:@instance_hooks)
end
hooks.flatten!
... | [
"def",
"update_on_instance_created",
"(",
"clazz",
",",
"on_instance_created",
")",
"return",
"unless",
"on_instance_created",
"clazz",
".",
"instance_eval",
"do",
"def",
"instance_hooks",
"hooks",
"=",
"(",
"self",
".",
"ancestors",
"+",
"[",
"self",
"]",
")",
... | This hook allows other tracing in Hometown to get a whack at an object
after it's been created without forcing them to patch new themselves | [
"This",
"hook",
"allows",
"other",
"tracing",
"in",
"Hometown",
"to",
"get",
"a",
"whack",
"at",
"an",
"object",
"after",
"it",
"s",
"been",
"created",
"without",
"forcing",
"them",
"to",
"patch",
"new",
"themselves"
] | 1d955bd684d5f9a81134332ae0b474252b793687 | https://github.com/jasonrclark/hometown/blob/1d955bd684d5f9a81134332ae0b474252b793687/lib/hometown/creation_tracer.rb#L64-L81 |
10,257 | mnipper/serket | lib/serket/field_encrypter.rb | Serket.FieldEncrypter.encrypt | def encrypt(field)
return if field !~ /\S/
aes = OpenSSL::Cipher.new(symmetric_algorithm)
aes_key = aes.random_key
iv = aes.random_iv
encrypt_data(iv, aes_key, field.force_encoding(encoding))
end | ruby | def encrypt(field)
return if field !~ /\S/
aes = OpenSSL::Cipher.new(symmetric_algorithm)
aes_key = aes.random_key
iv = aes.random_iv
encrypt_data(iv, aes_key, field.force_encoding(encoding))
end | [
"def",
"encrypt",
"(",
"field",
")",
"return",
"if",
"field",
"!~",
"/",
"\\S",
"/",
"aes",
"=",
"OpenSSL",
"::",
"Cipher",
".",
"new",
"(",
"symmetric_algorithm",
")",
"aes_key",
"=",
"aes",
".",
"random_key",
"iv",
"=",
"aes",
".",
"random_iv",
"encr... | Return encrypted string according to specified format.
Return nil if field is whitespace. | [
"Return",
"encrypted",
"string",
"according",
"to",
"specified",
"format",
".",
"Return",
"nil",
"if",
"field",
"is",
"whitespace",
"."
] | a4606071fde8982d794ff1f8fc09c399ac92ba17 | https://github.com/mnipper/serket/blob/a4606071fde8982d794ff1f8fc09c399ac92ba17/lib/serket/field_encrypter.rb#L22-L28 |
10,258 | mnipper/serket | lib/serket/field_encrypter.rb | Serket.FieldEncrypter.parse | def parse(iv, encrypted_key, encrypted_text)
case @format
when :delimited
[iv, field_delimiter, encrypted_key, field_delimiter, encrypted_text].join('')
when :json
hash = {}
hash['iv'] = iv
hash['key'] = encrypted_key
hash['message'] = encrypted_... | ruby | def parse(iv, encrypted_key, encrypted_text)
case @format
when :delimited
[iv, field_delimiter, encrypted_key, field_delimiter, encrypted_text].join('')
when :json
hash = {}
hash['iv'] = iv
hash['key'] = encrypted_key
hash['message'] = encrypted_... | [
"def",
"parse",
"(",
"iv",
",",
"encrypted_key",
",",
"encrypted_text",
")",
"case",
"@format",
"when",
":delimited",
"[",
"iv",
",",
"field_delimiter",
",",
"encrypted_key",
",",
"field_delimiter",
",",
"encrypted_text",
"]",
".",
"join",
"(",
"''",
")",
"w... | Format the final encrypted string to be returned depending
on specified format. | [
"Format",
"the",
"final",
"encrypted",
"string",
"to",
"be",
"returned",
"depending",
"on",
"specified",
"format",
"."
] | a4606071fde8982d794ff1f8fc09c399ac92ba17 | https://github.com/mnipper/serket/blob/a4606071fde8982d794ff1f8fc09c399ac92ba17/lib/serket/field_encrypter.rb#L55-L66 |
10,259 | sunchess/cfror | lib/cfror.rb | Cfror.Data.save_cfror_fields | def save_cfror_fields(fields)
fields.each do |field, value|
field = Cfror::Field.find(field)
field.save_value!(self, value)
end
end | ruby | def save_cfror_fields(fields)
fields.each do |field, value|
field = Cfror::Field.find(field)
field.save_value!(self, value)
end
end | [
"def",
"save_cfror_fields",
"(",
"fields",
")",
"fields",
".",
"each",
"do",
"|",
"field",
",",
"value",
"|",
"field",
"=",
"Cfror",
"::",
"Field",
".",
"find",
"(",
"field",
")",
"field",
".",
"save_value!",
"(",
"self",
",",
"value",
")",
"end",
"e... | save fields value | [
"save",
"fields",
"value"
] | 0e5771f7eb50bfab84992c6187572080a63e7a58 | https://github.com/sunchess/cfror/blob/0e5771f7eb50bfab84992c6187572080a63e7a58/lib/cfror.rb#L45-L50 |
10,260 | sunchess/cfror | lib/cfror.rb | Cfror.Data.value_fields_for | def value_fields_for(source, order=nil)
fields = self.send(source).fields
fields = fields.order(order) if order
fields.each do |i|
i.set_value_for(self)
end
fields
end | ruby | def value_fields_for(source, order=nil)
fields = self.send(source).fields
fields = fields.order(order) if order
fields.each do |i|
i.set_value_for(self)
end
fields
end | [
"def",
"value_fields_for",
"(",
"source",
",",
"order",
"=",
"nil",
")",
"fields",
"=",
"self",
".",
"send",
"(",
"source",
")",
".",
"fields",
"fields",
"=",
"fields",
".",
"order",
"(",
"order",
")",
"if",
"order",
"fields",
".",
"each",
"do",
"|",... | set values for fields
@param source is symbol of relation method contains include Cfror::Fields | [
"set",
"values",
"for",
"fields"
] | 0e5771f7eb50bfab84992c6187572080a63e7a58 | https://github.com/sunchess/cfror/blob/0e5771f7eb50bfab84992c6187572080a63e7a58/lib/cfror.rb#L54-L64 |
10,261 | bilus/kawaii | lib/kawaii/formats.rb | Kawaii.FormatHandler.method_missing | def method_missing(meth, *_args, &block)
format = FormatRegistry.formats[meth]
return unless format && format.match?(@route_handler.request)
@candidates << format
@blocks[meth] = block
end | ruby | def method_missing(meth, *_args, &block)
format = FormatRegistry.formats[meth]
return unless format && format.match?(@route_handler.request)
@candidates << format
@blocks[meth] = block
end | [
"def",
"method_missing",
"(",
"meth",
",",
"*",
"_args",
",",
"&",
"block",
")",
"format",
"=",
"FormatRegistry",
".",
"formats",
"[",
"meth",
"]",
"return",
"unless",
"format",
"&&",
"format",
".",
"match?",
"(",
"@route_handler",
".",
"request",
")",
"... | Creates a format handler for a route handler
@param [Kawaii::RouteHandler] current route handler
@return {FormatHandler}
Matches method invoked in end-user code with {FormatBase#key}.
If format matches the current request, it saves it for negotiation
in {FormatHandler#response}. | [
"Creates",
"a",
"format",
"handler",
"for",
"a",
"route",
"handler"
] | a72be28e713b0ed2b2cfc180a38bebe0c968b0b3 | https://github.com/bilus/kawaii/blob/a72be28e713b0ed2b2cfc180a38bebe0c968b0b3/lib/kawaii/formats.rb#L31-L36 |
10,262 | bilus/kawaii | lib/kawaii/formats.rb | Kawaii.JsonFormat.parse_params | def parse_params(request)
json = request.body.read
JSON.parse(json).symbolize_keys if json.is_a?(String) && !json.empty?
end | ruby | def parse_params(request)
json = request.body.read
JSON.parse(json).symbolize_keys if json.is_a?(String) && !json.empty?
end | [
"def",
"parse_params",
"(",
"request",
")",
"json",
"=",
"request",
".",
"body",
".",
"read",
"JSON",
".",
"parse",
"(",
"json",
")",
".",
"symbolize_keys",
"if",
"json",
".",
"is_a?",
"(",
"String",
")",
"&&",
"!",
"json",
".",
"empty?",
"end"
] | Parses JSON string in request body if present and converts it to a hash.
@param request [Rack::Request] contains information about the current HTTP
request
@return {Hash} including parsed params or nil | [
"Parses",
"JSON",
"string",
"in",
"request",
"body",
"if",
"present",
"and",
"converts",
"it",
"to",
"a",
"hash",
"."
] | a72be28e713b0ed2b2cfc180a38bebe0c968b0b3 | https://github.com/bilus/kawaii/blob/a72be28e713b0ed2b2cfc180a38bebe0c968b0b3/lib/kawaii/formats.rb#L126-L129 |
10,263 | bilus/kawaii | lib/kawaii/formats.rb | Kawaii.JsonFormat.encode | def encode(response)
json = response.to_json
[200,
{ Rack::CONTENT_TYPE => 'application/json',
Rack::CONTENT_LENGTH => json.length.to_s },
[json]]
end | ruby | def encode(response)
json = response.to_json
[200,
{ Rack::CONTENT_TYPE => 'application/json',
Rack::CONTENT_LENGTH => json.length.to_s },
[json]]
end | [
"def",
"encode",
"(",
"response",
")",
"json",
"=",
"response",
".",
"to_json",
"[",
"200",
",",
"{",
"Rack",
"::",
"CONTENT_TYPE",
"=>",
"'application/json'",
",",
"Rack",
"::",
"CONTENT_LENGTH",
"=>",
"json",
".",
"length",
".",
"to_s",
"}",
",",
"[",
... | Encodes response appropriately by converting it to a JSON string.
@param response [String, Hash, Array] response from format handler block.
@return Rack response {Array} | [
"Encodes",
"response",
"appropriately",
"by",
"converting",
"it",
"to",
"a",
"JSON",
"string",
"."
] | a72be28e713b0ed2b2cfc180a38bebe0c968b0b3 | https://github.com/bilus/kawaii/blob/a72be28e713b0ed2b2cfc180a38bebe0c968b0b3/lib/kawaii/formats.rb#L134-L140 |
10,264 | wenzowski/closync | lib/closync/sync.rb | Closync.Sync.upload! | def upload!(local_file)
@remote.directory.files.create(
key: local_file.key,
body: local_file.body,
cache_control: "public, max-age=#{max_age(local_file)}",
public: true
)
end | ruby | def upload!(local_file)
@remote.directory.files.create(
key: local_file.key,
body: local_file.body,
cache_control: "public, max-age=#{max_age(local_file)}",
public: true
)
end | [
"def",
"upload!",
"(",
"local_file",
")",
"@remote",
".",
"directory",
".",
"files",
".",
"create",
"(",
"key",
":",
"local_file",
".",
"key",
",",
"body",
":",
"local_file",
".",
"body",
",",
"cache_control",
":",
"\"public, max-age=#{max_age(local_file)}\"",
... | If file already exists on remote it will be overwritten. | [
"If",
"file",
"already",
"exists",
"on",
"remote",
"it",
"will",
"be",
"overwritten",
"."
] | 67730c160bcbd25420fb03d749ac086be429284c | https://github.com/wenzowski/closync/blob/67730c160bcbd25420fb03d749ac086be429284c/lib/closync/sync.rb#L46-L53 |
10,265 | seblindberg/ruby-adam6050 | lib/adam6050/password.rb | ADAM6050.Password.obfuscate | def obfuscate(plain)
codepoints = plain.codepoints
raise FormatError if codepoints.length > 8
password = Array.new(8, 0x0E)
codepoints.each_with_index do |c, i|
password[i] = (c & 0x40) | (~c & 0x3F)
end
password.pack 'c*'
end | ruby | def obfuscate(plain)
codepoints = plain.codepoints
raise FormatError if codepoints.length > 8
password = Array.new(8, 0x0E)
codepoints.each_with_index do |c, i|
password[i] = (c & 0x40) | (~c & 0x3F)
end
password.pack 'c*'
end | [
"def",
"obfuscate",
"(",
"plain",
")",
"codepoints",
"=",
"plain",
".",
"codepoints",
"raise",
"FormatError",
"if",
"codepoints",
".",
"length",
">",
"8",
"password",
"=",
"Array",
".",
"new",
"(",
"8",
",",
"0x0E",
")",
"codepoints",
".",
"each_with_index... | Transforms a plain text password into an 8 character string recognised by
the ADAM-6050. The algorithm, if you can even call it that, used to
perform the transformation was found by trial and error.
@raise [FormatError] if the plain text password is longer than 8
characters.
@param plain [String] the plain te... | [
"Transforms",
"a",
"plain",
"text",
"password",
"into",
"an",
"8",
"character",
"string",
"recognised",
"by",
"the",
"ADAM",
"-",
"6050",
".",
"The",
"algorithm",
"if",
"you",
"can",
"even",
"call",
"it",
"that",
"used",
"to",
"perform",
"the",
"transforma... | 7a8e8c344cc770b25d18ddf43f105d0f19e14d50 | https://github.com/seblindberg/ruby-adam6050/blob/7a8e8c344cc770b25d18ddf43f105d0f19e14d50/lib/adam6050/password.rb#L54-L64 |
10,266 | ktonon/code_node | spec/fixtures/activerecord/src/active_record/base.rb | ActiveRecord.Base.to_yaml | def to_yaml(opts = {}) #:nodoc:
if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
super
else
coder = {}
encode_with(coder)
YAML.quick_emit(self, opts) do |out|
out.map(taguri, to_yaml_style) do |map|
coder.each { |k, v| map.add(k, v)... | ruby | def to_yaml(opts = {}) #:nodoc:
if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
super
else
coder = {}
encode_with(coder)
YAML.quick_emit(self, opts) do |out|
out.map(taguri, to_yaml_style) do |map|
coder.each { |k, v| map.add(k, v)... | [
"def",
"to_yaml",
"(",
"opts",
"=",
"{",
"}",
")",
"#:nodoc:",
"if",
"YAML",
".",
"const_defined?",
"(",
":ENGINE",
")",
"&&",
"!",
"YAML",
"::",
"ENGINE",
".",
"syck?",
"super",
"else",
"coder",
"=",
"{",
"}",
"encode_with",
"(",
"coder",
")",
"YAML... | Hackery to accomodate Syck. Remove for 4.0. | [
"Hackery",
"to",
"accomodate",
"Syck",
".",
"Remove",
"for",
"4",
".",
"0",
"."
] | 48d5d1a7442d9cade602be4fb782a1b56c7677f5 | https://github.com/ktonon/code_node/blob/48d5d1a7442d9cade602be4fb782a1b56c7677f5/spec/fixtures/activerecord/src/active_record/base.rb#L652-L664 |
10,267 | ktonon/code_node | lib/code_node/sexp_walker.rb | CodeNode.SexpWalker.walk | def walk(s = nil)
s ||= @root
if [:module, :class].member?(s[0])
add_node s
elsif find_relations? && s[0] == :call && s.length >= 4 && [:extend, :include].member?(s[2]) && !@graph.scope.empty?
add_relation s
else
walk_siblings s.slice(1..-1)
end
end | ruby | def walk(s = nil)
s ||= @root
if [:module, :class].member?(s[0])
add_node s
elsif find_relations? && s[0] == :call && s.length >= 4 && [:extend, :include].member?(s[2]) && !@graph.scope.empty?
add_relation s
else
walk_siblings s.slice(1..-1)
end
end | [
"def",
"walk",
"(",
"s",
"=",
"nil",
")",
"s",
"||=",
"@root",
"if",
"[",
":module",
",",
":class",
"]",
".",
"member?",
"(",
"s",
"[",
"0",
"]",
")",
"add_node",
"s",
"elsif",
"find_relations?",
"&&",
"s",
"[",
"0",
"]",
"==",
":call",
"&&",
"... | Initialize a walker with a graph and sexp
All files in a code base should be walked once in <tt>:find_nodes</tt> mode, and then walked again in <tt>:find_relations</tt> mode.
@param graph [IR::Graph] a graph to which nodes and relations will be added
@param sexp [Sexp] the root sexp of a ruby file
@option opt [Sy... | [
"Initialize",
"a",
"walker",
"with",
"a",
"graph",
"and",
"sexp"
] | 48d5d1a7442d9cade602be4fb782a1b56c7677f5 | https://github.com/ktonon/code_node/blob/48d5d1a7442d9cade602be4fb782a1b56c7677f5/lib/code_node/sexp_walker.rb#L23-L32 |
10,268 | mbj/aql | lib/aql/buffer.rb | AQL.Buffer.delimited | def delimited(nodes, delimiter = ', ')
max = nodes.length - 1
nodes.each_with_index do |element, index|
element.visit(self)
append(delimiter) if index < max
end
self
end | ruby | def delimited(nodes, delimiter = ', ')
max = nodes.length - 1
nodes.each_with_index do |element, index|
element.visit(self)
append(delimiter) if index < max
end
self
end | [
"def",
"delimited",
"(",
"nodes",
",",
"delimiter",
"=",
"', '",
")",
"max",
"=",
"nodes",
".",
"length",
"-",
"1",
"nodes",
".",
"each_with_index",
"do",
"|",
"element",
",",
"index",
"|",
"element",
".",
"visit",
"(",
"self",
")",
"append",
"(",
"d... | Emit delimited nodes
@param [Enumerable<Node>] nodes
@return [self]
@api private | [
"Emit",
"delimited",
"nodes"
] | b271162935d8351d99be50dab5025d56c972fa25 | https://github.com/mbj/aql/blob/b271162935d8351d99be50dab5025d56c972fa25/lib/aql/buffer.rb#L52-L59 |
10,269 | FronteraConsulting/oanda_ruby_client | lib/oanda_ruby_client/exchange_rates_client.rb | OandaRubyClient.ExchangeRatesClient.rates | def rates(rates_request)
rates_uri = "#{oanda_endpoint}#{RATES_BASE_PATH}#{rates_request.base_currency}.json?#{rates_request.query_string}"
rates_response = HTTParty.get(rates_uri, headers: oanda_headers)
handle_response(rates_response.response)
OpenStruct.new(rates_response.parsed_response)
... | ruby | def rates(rates_request)
rates_uri = "#{oanda_endpoint}#{RATES_BASE_PATH}#{rates_request.base_currency}.json?#{rates_request.query_string}"
rates_response = HTTParty.get(rates_uri, headers: oanda_headers)
handle_response(rates_response.response)
OpenStruct.new(rates_response.parsed_response)
... | [
"def",
"rates",
"(",
"rates_request",
")",
"rates_uri",
"=",
"\"#{oanda_endpoint}#{RATES_BASE_PATH}#{rates_request.base_currency}.json?#{rates_request.query_string}\"",
"rates_response",
"=",
"HTTParty",
".",
"get",
"(",
"rates_uri",
",",
"headers",
":",
"oanda_headers",
")",
... | Returns the exchanges rates based on the specified request
@param rates_request [OandaRubyClient::RatesRequest] Request criteria
@return [OpenStruct] An object structured similarly to the response from the Exchange Rate API | [
"Returns",
"the",
"exchanges",
"rates",
"based",
"on",
"the",
"specified",
"request"
] | 1230e6a011ea4448597349ea7f46548bcbff2e86 | https://github.com/FronteraConsulting/oanda_ruby_client/blob/1230e6a011ea4448597349ea7f46548bcbff2e86/lib/oanda_ruby_client/exchange_rates_client.rb#L30-L35 |
10,270 | FronteraConsulting/oanda_ruby_client | lib/oanda_ruby_client/exchange_rates_client.rb | OandaRubyClient.ExchangeRatesClient.remaining_quotes | def remaining_quotes
remaining_quotes_response = HTTParty.get("#{oanda_endpoint}#{REMAINING_QUOTES_PATH}", headers: oanda_headers)
handle_response(remaining_quotes_response.response)
remaining_quotes_response.parsed_response['remaining_quotes']
end | ruby | def remaining_quotes
remaining_quotes_response = HTTParty.get("#{oanda_endpoint}#{REMAINING_QUOTES_PATH}", headers: oanda_headers)
handle_response(remaining_quotes_response.response)
remaining_quotes_response.parsed_response['remaining_quotes']
end | [
"def",
"remaining_quotes",
"remaining_quotes_response",
"=",
"HTTParty",
".",
"get",
"(",
"\"#{oanda_endpoint}#{REMAINING_QUOTES_PATH}\"",
",",
"headers",
":",
"oanda_headers",
")",
"handle_response",
"(",
"remaining_quotes_response",
".",
"response",
")",
"remaining_quotes_r... | Returns the number of remaining quote requests
@return [Fixnum, 'unlimited'] Number of remaining quote requests | [
"Returns",
"the",
"number",
"of",
"remaining",
"quote",
"requests"
] | 1230e6a011ea4448597349ea7f46548bcbff2e86 | https://github.com/FronteraConsulting/oanda_ruby_client/blob/1230e6a011ea4448597349ea7f46548bcbff2e86/lib/oanda_ruby_client/exchange_rates_client.rb#L40-L44 |
10,271 | docwhat/lego_nxt | lib/lego_nxt/low_level/brick.rb | LegoNXT::LowLevel.Brick.reset_motor_position | def reset_motor_position port, set_relative
transmit(
DirectOps::NO_RESPONSE,
DirectOps::RESETMOTORPOSITION,
normalize_motor_port(port),
normalize_boolean(set_relative)
)
end | ruby | def reset_motor_position port, set_relative
transmit(
DirectOps::NO_RESPONSE,
DirectOps::RESETMOTORPOSITION,
normalize_motor_port(port),
normalize_boolean(set_relative)
)
end | [
"def",
"reset_motor_position",
"port",
",",
"set_relative",
"transmit",
"(",
"DirectOps",
"::",
"NO_RESPONSE",
",",
"DirectOps",
"::",
"RESETMOTORPOSITION",
",",
"normalize_motor_port",
"(",
"port",
")",
",",
"normalize_boolean",
"(",
"set_relative",
")",
")",
"end"... | Resets the tracking for the motor position.
@param [Symbol] port The port the motor is attached to. Should be `:a`, `:b`, or `:c`
@param [Boolean] set_relative Sets the position tracking to relative if true, otherwise absolute if false.
@return [nil] | [
"Resets",
"the",
"tracking",
"for",
"the",
"motor",
"position",
"."
] | 74f6ea3e019bce0be68fa974eaa0a41185b6c4a8 | https://github.com/docwhat/lego_nxt/blob/74f6ea3e019bce0be68fa974eaa0a41185b6c4a8/lib/lego_nxt/low_level/brick.rb#L104-L111 |
10,272 | docwhat/lego_nxt | lib/lego_nxt/low_level/brick.rb | LegoNXT::LowLevel.Brick.run_motor | def run_motor port, power=100
raise ArgumentError.new("Power must be -100 through 100") if power < -100 || power > 100
transmit(
DirectOps::NO_RESPONSE,
DirectOps::SETOUTPUTSTATE,
normalize_motor_port(port, true),
sbyte(power), # power set point
byte(1), # mode
... | ruby | def run_motor port, power=100
raise ArgumentError.new("Power must be -100 through 100") if power < -100 || power > 100
transmit(
DirectOps::NO_RESPONSE,
DirectOps::SETOUTPUTSTATE,
normalize_motor_port(port, true),
sbyte(power), # power set point
byte(1), # mode
... | [
"def",
"run_motor",
"port",
",",
"power",
"=",
"100",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Power must be -100 through 100\"",
")",
"if",
"power",
"<",
"-",
"100",
"||",
"power",
">",
"100",
"transmit",
"(",
"DirectOps",
"::",
"NO_RESPONSE",
",",
"Di... | Runs the motor
@param [Symbol] port The port the motor is attached to. Should be `:a`, `:b`, `:c`, `:all`
@param [Integer] power A number between -100 through 100 inclusive. Defaults to 100.
@return [nil] | [
"Runs",
"the",
"motor"
] | 74f6ea3e019bce0be68fa974eaa0a41185b6c4a8 | https://github.com/docwhat/lego_nxt/blob/74f6ea3e019bce0be68fa974eaa0a41185b6c4a8/lib/lego_nxt/low_level/brick.rb#L118-L131 |
10,273 | docwhat/lego_nxt | lib/lego_nxt/low_level/brick.rb | LegoNXT::LowLevel.Brick.transceive | def transceive *bits
bitstring = bits.map(&:byte_string).join("")
retval = connection.transceive bitstring
# Check that it's a response bit.
raise ::LegoNXT::BadResponseError unless retval[0] == "\x02"
# Check that it's for this command.
raise ::LegoNXT::BadResponseError unless retva... | ruby | def transceive *bits
bitstring = bits.map(&:byte_string).join("")
retval = connection.transceive bitstring
# Check that it's a response bit.
raise ::LegoNXT::BadResponseError unless retval[0] == "\x02"
# Check that it's for this command.
raise ::LegoNXT::BadResponseError unless retva... | [
"def",
"transceive",
"*",
"bits",
"bitstring",
"=",
"bits",
".",
"map",
"(",
":byte_string",
")",
".",
"join",
"(",
"\"\"",
")",
"retval",
"=",
"connection",
".",
"transceive",
"bitstring",
"# Check that it's a response bit.",
"raise",
"::",
"LegoNXT",
"::",
"... | A wrapper around the transceive function for the connection.
The first three bytes of the return value are stripped off. Errors are
raised if they show a problem.
@param [LegoNXT::Type] bits A list of bytes.
@return [String] The bytes returned; bytes 0 through 2 are stripped. | [
"A",
"wrapper",
"around",
"the",
"transceive",
"function",
"for",
"the",
"connection",
"."
] | 74f6ea3e019bce0be68fa974eaa0a41185b6c4a8 | https://github.com/docwhat/lego_nxt/blob/74f6ea3e019bce0be68fa974eaa0a41185b6c4a8/lib/lego_nxt/low_level/brick.rb#L157-L168 |
10,274 | rails/rails | actionview/lib/action_view/renderer/renderer.rb | ActionView.Renderer.render_body | def render_body(context, options)
if options.key?(:partial)
[render_partial(context, options)]
else
StreamingTemplateRenderer.new(@lookup_context).render(context, options)
end
end | ruby | def render_body(context, options)
if options.key?(:partial)
[render_partial(context, options)]
else
StreamingTemplateRenderer.new(@lookup_context).render(context, options)
end
end | [
"def",
"render_body",
"(",
"context",
",",
"options",
")",
"if",
"options",
".",
"key?",
"(",
":partial",
")",
"[",
"render_partial",
"(",
"context",
",",
"options",
")",
"]",
"else",
"StreamingTemplateRenderer",
".",
"new",
"(",
"@lookup_context",
")",
".",... | Render but returns a valid Rack body. If fibers are defined, we return
a streaming body that renders the template piece by piece.
Note that partials are not supported to be rendered with streaming,
so in such cases, we just wrap them in an array. | [
"Render",
"but",
"returns",
"a",
"valid",
"Rack",
"body",
".",
"If",
"fibers",
"are",
"defined",
"we",
"return",
"a",
"streaming",
"body",
"that",
"renders",
"the",
"template",
"piece",
"by",
"piece",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/renderer/renderer.rb#L38-L44 |
10,275 | rails/rails | activemodel/lib/active_model/attribute_methods.rb | ActiveModel.AttributeMethods.attribute_missing | def attribute_missing(match, *args, &block)
__send__(match.target, match.attr_name, *args, &block)
end | ruby | def attribute_missing(match, *args, &block)
__send__(match.target, match.attr_name, *args, &block)
end | [
"def",
"attribute_missing",
"(",
"match",
",",
"*",
"args",
",",
"&",
"block",
")",
"__send__",
"(",
"match",
".",
"target",
",",
"match",
".",
"attr_name",
",",
"args",
",",
"block",
")",
"end"
] | +attribute_missing+ is like +method_missing+, but for attributes. When
+method_missing+ is called we check to see if there is a matching
attribute method. If so, we tell +attribute_missing+ to dispatch the
attribute. This method can be overloaded to customize the behavior. | [
"+",
"attribute_missing",
"+",
"is",
"like",
"+",
"method_missing",
"+",
"but",
"for",
"attributes",
".",
"When",
"+",
"method_missing",
"+",
"is",
"called",
"we",
"check",
"to",
"see",
"if",
"there",
"is",
"a",
"matching",
"attribute",
"method",
".",
"If"... | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/attribute_methods.rb#L439-L441 |
10,276 | rails/rails | activemodel/lib/active_model/attribute_methods.rb | ActiveModel.AttributeMethods.matched_attribute_method | def matched_attribute_method(method_name)
matches = self.class.send(:attribute_method_matchers_matching, method_name)
matches.detect { |match| attribute_method?(match.attr_name) }
end | ruby | def matched_attribute_method(method_name)
matches = self.class.send(:attribute_method_matchers_matching, method_name)
matches.detect { |match| attribute_method?(match.attr_name) }
end | [
"def",
"matched_attribute_method",
"(",
"method_name",
")",
"matches",
"=",
"self",
".",
"class",
".",
"send",
"(",
":attribute_method_matchers_matching",
",",
"method_name",
")",
"matches",
".",
"detect",
"{",
"|",
"match",
"|",
"attribute_method?",
"(",
"match",... | Returns a struct representing the matching attribute method.
The struct's attributes are prefix, base and suffix. | [
"Returns",
"a",
"struct",
"representing",
"the",
"matching",
"attribute",
"method",
".",
"The",
"struct",
"s",
"attributes",
"are",
"prefix",
"base",
"and",
"suffix",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/attribute_methods.rb#L466-L469 |
10,277 | rails/rails | activesupport/lib/active_support/inflector/methods.rb | ActiveSupport.Inflector.demodulize | def demodulize(path)
path = path.to_s
if i = path.rindex("::")
path[(i + 2)..-1]
else
path
end
end | ruby | def demodulize(path)
path = path.to_s
if i = path.rindex("::")
path[(i + 2)..-1]
else
path
end
end | [
"def",
"demodulize",
"(",
"path",
")",
"path",
"=",
"path",
".",
"to_s",
"if",
"i",
"=",
"path",
".",
"rindex",
"(",
"\"::\"",
")",
"path",
"[",
"(",
"i",
"+",
"2",
")",
"..",
"-",
"1",
"]",
"else",
"path",
"end",
"end"
] | Removes the module part from the expression in the string.
demodulize('ActiveSupport::Inflector::Inflections') # => "Inflections"
demodulize('Inflections') # => "Inflections"
demodulize('::Inflections') # => "Inflections"
demodulize('') ... | [
"Removes",
"the",
"module",
"part",
"from",
"the",
"expression",
"in",
"the",
"string",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/inflector/methods.rb#L220-L227 |
10,278 | rails/rails | activesupport/lib/active_support/inflector/methods.rb | ActiveSupport.Inflector.const_regexp | def const_regexp(camel_cased_word)
parts = camel_cased_word.split("::")
return Regexp.escape(camel_cased_word) if parts.blank?
last = parts.pop
parts.reverse.inject(last) do |acc, part|
part.empty? ? acc : "#{part}(::#{acc})?"
end
end | ruby | def const_regexp(camel_cased_word)
parts = camel_cased_word.split("::")
return Regexp.escape(camel_cased_word) if parts.blank?
last = parts.pop
parts.reverse.inject(last) do |acc, part|
part.empty? ? acc : "#{part}(::#{acc})?"
end
end | [
"def",
"const_regexp",
"(",
"camel_cased_word",
")",
"parts",
"=",
"camel_cased_word",
".",
"split",
"(",
"\"::\"",
")",
"return",
"Regexp",
".",
"escape",
"(",
"camel_cased_word",
")",
"if",
"parts",
".",
"blank?",
"last",
"=",
"parts",
".",
"pop",
"parts",... | Mounts a regular expression, returned as a string to ease interpolation,
that will match part by part the given constant.
const_regexp("Foo::Bar::Baz") # => "Foo(::Bar(::Baz)?)?"
const_regexp("::") # => "::" | [
"Mounts",
"a",
"regular",
"expression",
"returned",
"as",
"a",
"string",
"to",
"ease",
"interpolation",
"that",
"will",
"match",
"part",
"by",
"part",
"the",
"given",
"constant",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/inflector/methods.rb#L368-L378 |
10,279 | rails/rails | activesupport/lib/active_support/inflector/methods.rb | ActiveSupport.Inflector.apply_inflections | def apply_inflections(word, rules, locale = :en)
result = word.to_s.dup
if word.empty? || inflections(locale).uncountables.uncountable?(result)
result
else
rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
result
end
end | ruby | def apply_inflections(word, rules, locale = :en)
result = word.to_s.dup
if word.empty? || inflections(locale).uncountables.uncountable?(result)
result
else
rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
result
end
end | [
"def",
"apply_inflections",
"(",
"word",
",",
"rules",
",",
"locale",
"=",
":en",
")",
"result",
"=",
"word",
".",
"to_s",
".",
"dup",
"if",
"word",
".",
"empty?",
"||",
"inflections",
"(",
"locale",
")",
".",
"uncountables",
".",
"uncountable?",
"(",
... | Applies inflection rules for +singularize+ and +pluralize+.
If passed an optional +locale+ parameter, the uncountables will be
found for that locale.
apply_inflections('post', inflections.plurals, :en) # => "posts"
apply_inflections('posts', inflections.singulars, :en) # => "post" | [
"Applies",
"inflection",
"rules",
"for",
"+",
"singularize",
"+",
"and",
"+",
"pluralize",
"+",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/inflector/methods.rb#L387-L396 |
10,280 | rails/rails | activesupport/lib/active_support/dependencies.rb | ActiveSupport.Dependencies.autoload_module! | def autoload_module!(into, const_name, qualified_name, path_suffix)
return nil unless base_path = autoloadable_module?(path_suffix)
mod = Module.new
into.const_set const_name, mod
log("constant #{qualified_name} autoloaded (module autovivified from #{File.join(base_path, path_suffix)})")
a... | ruby | def autoload_module!(into, const_name, qualified_name, path_suffix)
return nil unless base_path = autoloadable_module?(path_suffix)
mod = Module.new
into.const_set const_name, mod
log("constant #{qualified_name} autoloaded (module autovivified from #{File.join(base_path, path_suffix)})")
a... | [
"def",
"autoload_module!",
"(",
"into",
",",
"const_name",
",",
"qualified_name",
",",
"path_suffix",
")",
"return",
"nil",
"unless",
"base_path",
"=",
"autoloadable_module?",
"(",
"path_suffix",
")",
"mod",
"=",
"Module",
".",
"new",
"into",
".",
"const_set",
... | Attempt to autoload the provided module name by searching for a directory
matching the expected path suffix. If found, the module is created and
assigned to +into+'s constants with the name +const_name+. Provided that
the directory was loaded from a reloadable base path, it is added to the
set of constants that are... | [
"Attempt",
"to",
"autoload",
"the",
"provided",
"module",
"name",
"by",
"searching",
"for",
"a",
"directory",
"matching",
"the",
"expected",
"path",
"suffix",
".",
"If",
"found",
"the",
"module",
"is",
"created",
"and",
"assigned",
"to",
"+",
"into",
"+",
... | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/dependencies.rb#L464-L472 |
10,281 | rails/rails | activesupport/lib/active_support/xml_mini/rexml.rb | ActiveSupport.XmlMini_REXML.parse | def parse(data)
if !data.respond_to?(:read)
data = StringIO.new(data || "")
end
if data.eof?
{}
else
silence_warnings { require "rexml/document" } unless defined?(REXML::Document)
doc = REXML::Document.new(data)
if doc.root
merge_element!({}, d... | ruby | def parse(data)
if !data.respond_to?(:read)
data = StringIO.new(data || "")
end
if data.eof?
{}
else
silence_warnings { require "rexml/document" } unless defined?(REXML::Document)
doc = REXML::Document.new(data)
if doc.root
merge_element!({}, d... | [
"def",
"parse",
"(",
"data",
")",
"if",
"!",
"data",
".",
"respond_to?",
"(",
":read",
")",
"data",
"=",
"StringIO",
".",
"new",
"(",
"data",
"||",
"\"\"",
")",
"end",
"if",
"data",
".",
"eof?",
"{",
"}",
"else",
"silence_warnings",
"{",
"require",
... | Parse an XML Document string or IO into a simple hash.
Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
and uses the defaults from Active Support.
data::
XML Document string or IO to parse | [
"Parse",
"an",
"XML",
"Document",
"string",
"or",
"IO",
"into",
"a",
"simple",
"hash",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/xml_mini/rexml.rb#L20-L38 |
10,282 | rails/rails | activerecord/lib/active_record/connection_handling.rb | ActiveRecord.ConnectionHandling.connects_to | def connects_to(database: {})
connections = []
database.each do |role, database_key|
config_hash = resolve_config_for_connection(database_key)
handler = lookup_connection_handler(role.to_sym)
connections << handler.establish_connection(config_hash)
end
connections
... | ruby | def connects_to(database: {})
connections = []
database.each do |role, database_key|
config_hash = resolve_config_for_connection(database_key)
handler = lookup_connection_handler(role.to_sym)
connections << handler.establish_connection(config_hash)
end
connections
... | [
"def",
"connects_to",
"(",
"database",
":",
"{",
"}",
")",
"connections",
"=",
"[",
"]",
"database",
".",
"each",
"do",
"|",
"role",
",",
"database_key",
"|",
"config_hash",
"=",
"resolve_config_for_connection",
"(",
"database_key",
")",
"handler",
"=",
"loo... | Connects a model to the databases specified. The +database+ keyword
takes a hash consisting of a +role+ and a +database_key+.
This will create a connection handler for switching between connections,
look up the config hash using the +database_key+ and finally
establishes a connection to that config.
class Anim... | [
"Connects",
"a",
"model",
"to",
"the",
"databases",
"specified",
".",
"The",
"+",
"database",
"+",
"keyword",
"takes",
"a",
"hash",
"consisting",
"of",
"a",
"+",
"role",
"+",
"and",
"a",
"+",
"database_key",
"+",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/connection_handling.rb#L68-L79 |
10,283 | rails/rails | activerecord/lib/active_record/connection_handling.rb | ActiveRecord.ConnectionHandling.clear_query_caches_for_current_thread | def clear_query_caches_for_current_thread
ActiveRecord::Base.connection_handlers.each_value do |handler|
handler.connection_pool_list.each do |pool|
pool.connection.clear_query_cache if pool.active_connection?
end
end
end | ruby | def clear_query_caches_for_current_thread
ActiveRecord::Base.connection_handlers.each_value do |handler|
handler.connection_pool_list.each do |pool|
pool.connection.clear_query_cache if pool.active_connection?
end
end
end | [
"def",
"clear_query_caches_for_current_thread",
"ActiveRecord",
"::",
"Base",
".",
"connection_handlers",
".",
"each_value",
"do",
"|",
"handler",
"|",
"handler",
".",
"connection_pool_list",
".",
"each",
"do",
"|",
"pool",
"|",
"pool",
".",
"connection",
".",
"cl... | Clears the query cache for all connections associated with the current thread. | [
"Clears",
"the",
"query",
"cache",
"for",
"all",
"connections",
"associated",
"with",
"the",
"current",
"thread",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/connection_handling.rb#L187-L193 |
10,284 | rails/rails | activerecord/lib/active_record/schema_dumper.rb | ActiveRecord.SchemaDumper.formatted_version | def formatted_version
stringified = @version.to_s
return stringified unless stringified.length == 14
stringified.insert(4, "_").insert(7, "_").insert(10, "_")
end | ruby | def formatted_version
stringified = @version.to_s
return stringified unless stringified.length == 14
stringified.insert(4, "_").insert(7, "_").insert(10, "_")
end | [
"def",
"formatted_version",
"stringified",
"=",
"@version",
".",
"to_s",
"return",
"stringified",
"unless",
"stringified",
".",
"length",
"==",
"14",
"stringified",
".",
"insert",
"(",
"4",
",",
"\"_\"",
")",
".",
"insert",
"(",
"7",
",",
"\"_\"",
")",
"."... | turns 20170404131909 into "2017_04_04_131909" | [
"turns",
"20170404131909",
"into",
"2017_04_04_131909"
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/schema_dumper.rb#L59-L63 |
10,285 | rails/rails | activerecord/lib/active_record/schema_dumper.rb | ActiveRecord.SchemaDumper.indexes | def indexes(table, stream)
if (indexes = @connection.indexes(table)).any?
add_index_statements = indexes.map do |index|
table_name = remove_prefix_and_suffix(index.table).inspect
" add_index #{([table_name] + index_parts(index)).join(', ')}"
end
stream.put... | ruby | def indexes(table, stream)
if (indexes = @connection.indexes(table)).any?
add_index_statements = indexes.map do |index|
table_name = remove_prefix_and_suffix(index.table).inspect
" add_index #{([table_name] + index_parts(index)).join(', ')}"
end
stream.put... | [
"def",
"indexes",
"(",
"table",
",",
"stream",
")",
"if",
"(",
"indexes",
"=",
"@connection",
".",
"indexes",
"(",
"table",
")",
")",
".",
"any?",
"add_index_statements",
"=",
"indexes",
".",
"map",
"do",
"|",
"index",
"|",
"table_name",
"=",
"remove_pre... | Keep it for indexing materialized views | [
"Keep",
"it",
"for",
"indexing",
"materialized",
"views"
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/schema_dumper.rb#L171-L181 |
10,286 | rails/rails | activesupport/lib/active_support/time_with_zone.rb | ActiveSupport.TimeWithZone.formatted_offset | def formatted_offset(colon = true, alternate_utc_string = nil)
utc? && alternate_utc_string || TimeZone.seconds_to_utc_offset(utc_offset, colon)
end | ruby | def formatted_offset(colon = true, alternate_utc_string = nil)
utc? && alternate_utc_string || TimeZone.seconds_to_utc_offset(utc_offset, colon)
end | [
"def",
"formatted_offset",
"(",
"colon",
"=",
"true",
",",
"alternate_utc_string",
"=",
"nil",
")",
"utc?",
"&&",
"alternate_utc_string",
"||",
"TimeZone",
".",
"seconds_to_utc_offset",
"(",
"utc_offset",
",",
"colon",
")",
"end"
] | Returns a formatted string of the offset from UTC, or an alternative
string if the time zone is already UTC.
Time.zone = 'Eastern Time (US & Canada)' # => "Eastern Time (US & Canada)"
Time.zone.now.formatted_offset(true) # => "-05:00"
Time.zone.now.formatted_offset(false) # => "-0500"
Time.zo... | [
"Returns",
"a",
"formatted",
"string",
"of",
"the",
"offset",
"from",
"UTC",
"or",
"an",
"alternative",
"string",
"if",
"the",
"time",
"zone",
"is",
"already",
"UTC",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/time_with_zone.rb#L126-L128 |
10,287 | rails/rails | activesupport/lib/active_support/time_with_zone.rb | ActiveSupport.TimeWithZone.advance | def advance(options)
# If we're advancing a value of variable length (i.e., years, weeks, months, days), advance from #time,
# otherwise advance from #utc, for accuracy when moving across DST boundaries
if options.values_at(:years, :weeks, :months, :days).any?
method_missing(:advance, options)... | ruby | def advance(options)
# If we're advancing a value of variable length (i.e., years, weeks, months, days), advance from #time,
# otherwise advance from #utc, for accuracy when moving across DST boundaries
if options.values_at(:years, :weeks, :months, :days).any?
method_missing(:advance, options)... | [
"def",
"advance",
"(",
"options",
")",
"# If we're advancing a value of variable length (i.e., years, weeks, months, days), advance from #time,",
"# otherwise advance from #utc, for accuracy when moving across DST boundaries",
"if",
"options",
".",
"values_at",
"(",
":years",
",",
":week... | Uses Date to provide precise Time calculations for years, months, and days
according to the proleptic Gregorian calendar. The result is returned as a
new TimeWithZone object.
The +options+ parameter takes a hash with any of these keys:
<tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>,
<tt>:hours... | [
"Uses",
"Date",
"to",
"provide",
"precise",
"Time",
"calculations",
"for",
"years",
"months",
"and",
"days",
"according",
"to",
"the",
"proleptic",
"Gregorian",
"calendar",
".",
"The",
"result",
"is",
"returned",
"as",
"a",
"new",
"TimeWithZone",
"object",
"."... | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/time_with_zone.rb#L402-L410 |
10,288 | rails/rails | actionpack/lib/abstract_controller/base.rb | AbstractController.Base.process | def process(action, *args)
@_action_name = action.to_s
unless action_name = _find_action_name(@_action_name)
raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
end
@_response_body = nil
process_action(action_name, *args)
end | ruby | def process(action, *args)
@_action_name = action.to_s
unless action_name = _find_action_name(@_action_name)
raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
end
@_response_body = nil
process_action(action_name, *args)
end | [
"def",
"process",
"(",
"action",
",",
"*",
"args",
")",
"@_action_name",
"=",
"action",
".",
"to_s",
"unless",
"action_name",
"=",
"_find_action_name",
"(",
"@_action_name",
")",
"raise",
"ActionNotFound",
",",
"\"The action '#{action}' could not be found for #{self.cla... | Calls the action going through the entire action dispatch stack.
The actual method that is called is determined by calling
#method_for_action. If no method can handle the action, then an
AbstractController::ActionNotFound error is raised.
==== Returns
* <tt>self</tt> | [
"Calls",
"the",
"action",
"going",
"through",
"the",
"entire",
"action",
"dispatch",
"stack",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/abstract_controller/base.rb#L127-L137 |
10,289 | rails/rails | activesupport/lib/active_support/array_inquirer.rb | ActiveSupport.ArrayInquirer.any? | def any?(*candidates)
if candidates.none?
super
else
candidates.any? do |candidate|
include?(candidate.to_sym) || include?(candidate.to_s)
end
end
end | ruby | def any?(*candidates)
if candidates.none?
super
else
candidates.any? do |candidate|
include?(candidate.to_sym) || include?(candidate.to_s)
end
end
end | [
"def",
"any?",
"(",
"*",
"candidates",
")",
"if",
"candidates",
".",
"none?",
"super",
"else",
"candidates",
".",
"any?",
"do",
"|",
"candidate",
"|",
"include?",
"(",
"candidate",
".",
"to_sym",
")",
"||",
"include?",
"(",
"candidate",
".",
"to_s",
")",... | Passes each element of +candidates+ collection to ArrayInquirer collection.
The method returns true if any element from the ArrayInquirer collection
is equal to the stringified or symbolized form of any element in the +candidates+ collection.
If +candidates+ collection is not given, method returns true.
variant... | [
"Passes",
"each",
"element",
"of",
"+",
"candidates",
"+",
"collection",
"to",
"ArrayInquirer",
"collection",
".",
"The",
"method",
"returns",
"true",
"if",
"any",
"element",
"from",
"the",
"ArrayInquirer",
"collection",
"is",
"equal",
"to",
"the",
"stringified"... | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/array_inquirer.rb#L25-L33 |
10,290 | rails/rails | activerecord/lib/active_record/integration.rb | ActiveRecord.Integration.cache_key | def cache_key
if new_record?
"#{model_name.cache_key}/new"
else
if cache_version
"#{model_name.cache_key}/#{id}"
else
timestamp = max_updated_column_timestamp
if timestamp
timestamp = timestamp.utc.to_s(cache_timestamp_format)
"#... | ruby | def cache_key
if new_record?
"#{model_name.cache_key}/new"
else
if cache_version
"#{model_name.cache_key}/#{id}"
else
timestamp = max_updated_column_timestamp
if timestamp
timestamp = timestamp.utc.to_s(cache_timestamp_format)
"#... | [
"def",
"cache_key",
"if",
"new_record?",
"\"#{model_name.cache_key}/new\"",
"else",
"if",
"cache_version",
"\"#{model_name.cache_key}/#{id}\"",
"else",
"timestamp",
"=",
"max_updated_column_timestamp",
"if",
"timestamp",
"timestamp",
"=",
"timestamp",
".",
"utc",
".",
"to_s... | Returns a stable cache key that can be used to identify this record.
Product.new.cache_key # => "products/new"
Product.find(5).cache_key # => "products/5"
If ActiveRecord::Base.cache_versioning is turned off, as it was in Rails 5.1 and earlier,
the cache key will also include a version.
Product.cache_... | [
"Returns",
"a",
"stable",
"cache",
"key",
"that",
"can",
"be",
"used",
"to",
"identify",
"this",
"record",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/integration.rb#L72-L89 |
10,291 | rails/rails | actionmailer/lib/action_mailer/mail_helper.rb | ActionMailer.MailHelper.format_paragraph | def format_paragraph(text, len = 72, indent = 2)
sentences = [[]]
text.split.each do |word|
if sentences.first.present? && (sentences.last + [word]).join(" ").length > len
sentences << [word]
else
sentences.last << word
end
end
indentation = " " * in... | ruby | def format_paragraph(text, len = 72, indent = 2)
sentences = [[]]
text.split.each do |word|
if sentences.first.present? && (sentences.last + [word]).join(" ").length > len
sentences << [word]
else
sentences.last << word
end
end
indentation = " " * in... | [
"def",
"format_paragraph",
"(",
"text",
",",
"len",
"=",
"72",
",",
"indent",
"=",
"2",
")",
"sentences",
"=",
"[",
"[",
"]",
"]",
"text",
".",
"split",
".",
"each",
"do",
"|",
"word",
"|",
"if",
"sentences",
".",
"first",
".",
"present?",
"&&",
... | Returns +text+ wrapped at +len+ columns and indented +indent+ spaces.
By default column length +len+ equals 72 characters and indent
+indent+ equal two spaces.
my_text = 'Here is a sample text with more than 40 characters'
format_paragraph(my_text, 25, 4)
# => " Here is a sample text with\n more than... | [
"Returns",
"+",
"text",
"+",
"wrapped",
"at",
"+",
"len",
"+",
"columns",
"and",
"indented",
"+",
"indent",
"+",
"spaces",
".",
"By",
"default",
"column",
"length",
"+",
"len",
"+",
"equals",
"72",
"characters",
"and",
"indent",
"+",
"indent",
"+",
"eq... | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionmailer/lib/action_mailer/mail_helper.rb#L55-L70 |
10,292 | rails/rails | activerecord/lib/active_record/relation/batches.rb | ActiveRecord.Batches.find_in_batches | def find_in_batches(start: nil, finish: nil, batch_size: 1000, error_on_ignore: nil)
relation = self
unless block_given?
return to_enum(:find_in_batches, start: start, finish: finish, batch_size: batch_size, error_on_ignore: error_on_ignore) do
total = apply_limits(relation, start, finish)... | ruby | def find_in_batches(start: nil, finish: nil, batch_size: 1000, error_on_ignore: nil)
relation = self
unless block_given?
return to_enum(:find_in_batches, start: start, finish: finish, batch_size: batch_size, error_on_ignore: error_on_ignore) do
total = apply_limits(relation, start, finish)... | [
"def",
"find_in_batches",
"(",
"start",
":",
"nil",
",",
"finish",
":",
"nil",
",",
"batch_size",
":",
"1000",
",",
"error_on_ignore",
":",
"nil",
")",
"relation",
"=",
"self",
"unless",
"block_given?",
"return",
"to_enum",
"(",
":find_in_batches",
",",
"sta... | Yields each batch of records that was found by the find options as
an array.
Person.where("age > 21").find_in_batches do |group|
sleep(50) # Make sure it doesn't get too crowded in there!
group.each { |person| person.party_all_night! }
end
If you do not provide a block to #find_in_batches, it will r... | [
"Yields",
"each",
"batch",
"of",
"records",
"that",
"was",
"found",
"by",
"the",
"find",
"options",
"as",
"an",
"array",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation/batches.rb#L126-L138 |
10,293 | rails/rails | activemodel/lib/active_model/error.rb | ActiveModel.Error.match? | def match?(attribute, type = nil, **options)
if @attribute != attribute || (type && @type != type)
return false
end
options.each do |key, value|
if @options[key] != value
return false
end
end
true
end | ruby | def match?(attribute, type = nil, **options)
if @attribute != attribute || (type && @type != type)
return false
end
options.each do |key, value|
if @options[key] != value
return false
end
end
true
end | [
"def",
"match?",
"(",
"attribute",
",",
"type",
"=",
"nil",
",",
"**",
"options",
")",
"if",
"@attribute",
"!=",
"attribute",
"||",
"(",
"type",
"&&",
"@type",
"!=",
"type",
")",
"return",
"false",
"end",
"options",
".",
"each",
"do",
"|",
"key",
","... | See if error matches provided +attribute+, +type+ and +options+. | [
"See",
"if",
"error",
"matches",
"provided",
"+",
"attribute",
"+",
"+",
"type",
"+",
"and",
"+",
"options",
"+",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/error.rb#L46-L58 |
10,294 | rails/rails | actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb | ActionView.CollectionCaching.fetch_or_cache_partial | def fetch_or_cache_partial(cached_partials, template, order_by:)
order_by.each_with_object({}) do |cache_key, hash|
hash[cache_key] =
if content = cached_partials[cache_key]
build_rendered_template(content, template)
else
yield.tap do |rend... | ruby | def fetch_or_cache_partial(cached_partials, template, order_by:)
order_by.each_with_object({}) do |cache_key, hash|
hash[cache_key] =
if content = cached_partials[cache_key]
build_rendered_template(content, template)
else
yield.tap do |rend... | [
"def",
"fetch_or_cache_partial",
"(",
"cached_partials",
",",
"template",
",",
"order_by",
":",
")",
"order_by",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"cache_key",
",",
"hash",
"|",
"hash",
"[",
"cache_key",
"]",
"=",
"if",
"content",
"="... | `order_by` is an enumerable object containing keys of the cache,
all keys are passed in whether found already or not.
`cached_partials` is a hash. If the value exists
it represents the rendered partial from the cache
otherwise `Hash#fetch` will take the value of its block.
This method expects a block that will ... | [
"order_by",
"is",
"an",
"enumerable",
"object",
"containing",
"keys",
"of",
"the",
"cache",
"all",
"keys",
"are",
"passed",
"in",
"whether",
"found",
"already",
"or",
"not",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb#L90-L101 |
10,295 | rails/rails | activesupport/lib/active_support/callbacks.rb | ActiveSupport.Callbacks.run_callbacks | def run_callbacks(kind)
callbacks = __callbacks[kind.to_sym]
if callbacks.empty?
yield if block_given?
else
env = Filters::Environment.new(self, false, nil)
next_sequence = callbacks.compile
invoke_sequence = Proc.new do
skipped = nil
while true
... | ruby | def run_callbacks(kind)
callbacks = __callbacks[kind.to_sym]
if callbacks.empty?
yield if block_given?
else
env = Filters::Environment.new(self, false, nil)
next_sequence = callbacks.compile
invoke_sequence = Proc.new do
skipped = nil
while true
... | [
"def",
"run_callbacks",
"(",
"kind",
")",
"callbacks",
"=",
"__callbacks",
"[",
"kind",
".",
"to_sym",
"]",
"if",
"callbacks",
".",
"empty?",
"yield",
"if",
"block_given?",
"else",
"env",
"=",
"Filters",
"::",
"Environment",
".",
"new",
"(",
"self",
",",
... | Runs the callbacks for the given event.
Calls the before and around callbacks in the order they were set, yields
the block (if given one), and then runs the after callbacks in reverse
order.
If the callback chain was halted, returns +false+. Otherwise returns the
result of the block, +nil+ if no callbacks have b... | [
"Runs",
"the",
"callbacks",
"for",
"the",
"given",
"event",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/callbacks.rb#L97-L142 |
10,296 | rails/rails | railties/lib/rails/source_annotation_extractor.rb | Rails.SourceAnnotationExtractor.extract_annotations_from | def extract_annotations_from(file, pattern)
lineno = 0
result = File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
lineno += 1
next list unless line =~ pattern
list << Annotation.new(lineno, $1, $2)
end
result.empty? ? {} : { file => result }
... | ruby | def extract_annotations_from(file, pattern)
lineno = 0
result = File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
lineno += 1
next list unless line =~ pattern
list << Annotation.new(lineno, $1, $2)
end
result.empty? ? {} : { file => result }
... | [
"def",
"extract_annotations_from",
"(",
"file",
",",
"pattern",
")",
"lineno",
"=",
"0",
"result",
"=",
"File",
".",
"readlines",
"(",
"file",
",",
"encoding",
":",
"Encoding",
"::",
"BINARY",
")",
".",
"inject",
"(",
"[",
"]",
")",
"do",
"|",
"list",
... | If +file+ is the filename of a file that contains annotations this method returns
a hash with a single entry that maps +file+ to an array of its annotations.
Otherwise it returns an empty hash. | [
"If",
"+",
"file",
"+",
"is",
"the",
"filename",
"of",
"a",
"file",
"that",
"contains",
"annotations",
"this",
"method",
"returns",
"a",
"hash",
"with",
"a",
"single",
"entry",
"that",
"maps",
"+",
"file",
"+",
"to",
"an",
"array",
"of",
"its",
"annota... | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/source_annotation_extractor.rb#L139-L147 |
10,297 | rails/rails | actionpack/lib/action_controller/metal/params_wrapper.rb | ActionController.ParamsWrapper._wrapper_enabled? | def _wrapper_enabled?
return false unless request.has_content_type?
ref = request.content_mime_type.ref
_wrapper_formats.include?(ref) && _wrapper_key && !request.parameters.key?(_wrapper_key)
end | ruby | def _wrapper_enabled?
return false unless request.has_content_type?
ref = request.content_mime_type.ref
_wrapper_formats.include?(ref) && _wrapper_key && !request.parameters.key?(_wrapper_key)
end | [
"def",
"_wrapper_enabled?",
"return",
"false",
"unless",
"request",
".",
"has_content_type?",
"ref",
"=",
"request",
".",
"content_mime_type",
".",
"ref",
"_wrapper_formats",
".",
"include?",
"(",
"ref",
")",
"&&",
"_wrapper_key",
"&&",
"!",
"request",
".",
"par... | Checks if we should perform parameters wrapping. | [
"Checks",
"if",
"we",
"should",
"perform",
"parameters",
"wrapping",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/params_wrapper.rb#L275-L280 |
10,298 | rails/rails | railties/lib/rails/console/app.rb | Rails.ConsoleMethods.new_session | def new_session
app = Rails.application
session = ActionDispatch::Integration::Session.new(app)
yield session if block_given?
# This makes app.url_for and app.foo_path available in the console
session.extend(app.routes.url_helpers)
session.extend(app.routes.mounted_helpers)
s... | ruby | def new_session
app = Rails.application
session = ActionDispatch::Integration::Session.new(app)
yield session if block_given?
# This makes app.url_for and app.foo_path available in the console
session.extend(app.routes.url_helpers)
session.extend(app.routes.mounted_helpers)
s... | [
"def",
"new_session",
"app",
"=",
"Rails",
".",
"application",
"session",
"=",
"ActionDispatch",
"::",
"Integration",
"::",
"Session",
".",
"new",
"(",
"app",
")",
"yield",
"session",
"if",
"block_given?",
"# This makes app.url_for and app.foo_path available in the cons... | create a new session. If a block is given, the new session will be yielded
to the block before being returned. | [
"create",
"a",
"new",
"session",
".",
"If",
"a",
"block",
"is",
"given",
"the",
"new",
"session",
"will",
"be",
"yielded",
"to",
"the",
"block",
"before",
"being",
"returned",
"."
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/console/app.rb#L19-L29 |
10,299 | rails/rails | railties/lib/rails/console/app.rb | Rails.ConsoleMethods.reload! | def reload!(print = true)
puts "Reloading..." if print
Rails.application.reloader.reload!
true
end | ruby | def reload!(print = true)
puts "Reloading..." if print
Rails.application.reloader.reload!
true
end | [
"def",
"reload!",
"(",
"print",
"=",
"true",
")",
"puts",
"\"Reloading...\"",
"if",
"print",
"Rails",
".",
"application",
".",
"reloader",
".",
"reload!",
"true",
"end"
] | reloads the environment | [
"reloads",
"the",
"environment"
] | 85a8bc644be69908f05740a5886ec19cd3679df5 | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/console/app.rb#L32-L36 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.