repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
sequence
docstring
stringlengths
8
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
94
266
partition
stringclasses
1 value
petebrowne/machined
lib/machined/environment.rb
Machined.Environment.append_path
def append_path(sprocket, path) # :nodoc: path = Pathname.new(path).expand_path(root) sprocket.append_path(path) if path.exist? end
ruby
def append_path(sprocket, path) # :nodoc: path = Pathname.new(path).expand_path(root) sprocket.append_path(path) if path.exist? end
[ "def", "append_path", "(", "sprocket", ",", "path", ")", "# :nodoc:", "path", "=", "Pathname", ".", "new", "(", "path", ")", ".", "expand_path", "(", "root", ")", "sprocket", ".", "append_path", "(", "path", ")", "if", "path", ".", "exist?", "end" ]
Appends the given +path+ to the given +sprocket+ This makes sure the path is relative to the `root` path or an absolute path pointing somewhere else. It also checks if it exists before appending it.
[ "Appends", "the", "given", "+", "path", "+", "to", "the", "given", "+", "sprocket", "+", "This", "makes", "sure", "the", "path", "is", "relative", "to", "the", "root", "path", "or", "an", "absolute", "path", "pointing", "somewhere", "else", ".", "It", "also", "checks", "if", "it", "exists", "before", "appending", "it", "." ]
4f3921bc5098104096474300e933f009f1b4f7dd
https://github.com/petebrowne/machined/blob/4f3921bc5098104096474300e933f009f1b4f7dd/lib/machined/environment.rb#L420-L423
train
petebrowne/machined
lib/machined/environment.rb
Machined.Environment.append_paths
def append_paths(sprocket, paths) # :nodoc: paths or return paths.each do |path| append_path sprocket, path end end
ruby
def append_paths(sprocket, paths) # :nodoc: paths or return paths.each do |path| append_path sprocket, path end end
[ "def", "append_paths", "(", "sprocket", ",", "paths", ")", "# :nodoc:", "paths", "or", "return", "paths", ".", "each", "do", "|", "path", "|", "append_path", "sprocket", ",", "path", "end", "end" ]
Appends the given `Array` of +paths+ to the given +sprocket+.
[ "Appends", "the", "given", "Array", "of", "+", "paths", "+", "to", "the", "given", "+", "sprocket", "+", "." ]
4f3921bc5098104096474300e933f009f1b4f7dd
https://github.com/petebrowne/machined/blob/4f3921bc5098104096474300e933f009f1b4f7dd/lib/machined/environment.rb#L426-L431
train
petebrowne/machined
lib/machined/environment.rb
Machined.Environment.js_compressor
def js_compressor # :nodoc: case config.js_compressor when Crush::Engine config.js_compressor when Symbol, String JS_COMPRESSORS[config.js_compressor.to_sym] else Crush.register_js Tilt['js'] end end
ruby
def js_compressor # :nodoc: case config.js_compressor when Crush::Engine config.js_compressor when Symbol, String JS_COMPRESSORS[config.js_compressor.to_sym] else Crush.register_js Tilt['js'] end end
[ "def", "js_compressor", "# :nodoc:", "case", "config", ".", "js_compressor", "when", "Crush", "::", "Engine", "config", ".", "js_compressor", "when", "Symbol", ",", "String", "JS_COMPRESSORS", "[", "config", ".", "js_compressor", ".", "to_sym", "]", "else", "Crush", ".", "register_js", "Tilt", "[", "'js'", "]", "end", "end" ]
Returns the Javascript compression engine, based on what's set in `config.js_compressor`. If `config.js_compressor` is nil, let Tilt + Crush decide which one to use.
[ "Returns", "the", "Javascript", "compression", "engine", "based", "on", "what", "s", "set", "in", "config", ".", "js_compressor", ".", "If", "config", ".", "js_compressor", "is", "nil", "let", "Tilt", "+", "Crush", "decide", "which", "one", "to", "use", "." ]
4f3921bc5098104096474300e933f009f1b4f7dd
https://github.com/petebrowne/machined/blob/4f3921bc5098104096474300e933f009f1b4f7dd/lib/machined/environment.rb#L436-L446
train
petebrowne/machined
lib/machined/environment.rb
Machined.Environment.css_compressor
def css_compressor # :nodoc: case config.css_compressor when Crush::Engine config.css_compressor when Symbol, String CSS_COMPRESSORS[config.css_compressor.to_sym] else Crush.register_css Tilt['css'] end end
ruby
def css_compressor # :nodoc: case config.css_compressor when Crush::Engine config.css_compressor when Symbol, String CSS_COMPRESSORS[config.css_compressor.to_sym] else Crush.register_css Tilt['css'] end end
[ "def", "css_compressor", "# :nodoc:", "case", "config", ".", "css_compressor", "when", "Crush", "::", "Engine", "config", ".", "css_compressor", "when", "Symbol", ",", "String", "CSS_COMPRESSORS", "[", "config", ".", "css_compressor", ".", "to_sym", "]", "else", "Crush", ".", "register_css", "Tilt", "[", "'css'", "]", "end", "end" ]
Returns the CSS compression engine, based on what's set in `config.css_compressor`. If `config.css_compressor` is nil, let Tilt + Crush decide which one to use.
[ "Returns", "the", "CSS", "compression", "engine", "based", "on", "what", "s", "set", "in", "config", ".", "css_compressor", ".", "If", "config", ".", "css_compressor", "is", "nil", "let", "Tilt", "+", "Crush", "decide", "which", "one", "to", "use", "." ]
4f3921bc5098104096474300e933f009f1b4f7dd
https://github.com/petebrowne/machined/blob/4f3921bc5098104096474300e933f009f1b4f7dd/lib/machined/environment.rb#L451-L461
train
nsi-iff/nsivideogranulate-ruby
lib/nsivideogranulate/client.rb
NSIVideoGranulate.Client.granulate
def granulate(options = {}) @request_data = Hash.new if options[:video_link] insert_download_data options elsif options[:sam_uid] && options[:filename] file_data = {:video_uid => options[:sam_uid], :filename => options[:filename]} @request_data.merge! file_data elsif options[:file] && options[:filename] file_data = {:video => options[:file], :filename => options[:filename]} @request_data.merge! file_data else raise NSIVideoGranulate::Errors::Client::MissingParametersError end insert_callback_data options request = prepare_request :POST, @request_data.to_json execute_request(request) end
ruby
def granulate(options = {}) @request_data = Hash.new if options[:video_link] insert_download_data options elsif options[:sam_uid] && options[:filename] file_data = {:video_uid => options[:sam_uid], :filename => options[:filename]} @request_data.merge! file_data elsif options[:file] && options[:filename] file_data = {:video => options[:file], :filename => options[:filename]} @request_data.merge! file_data else raise NSIVideoGranulate::Errors::Client::MissingParametersError end insert_callback_data options request = prepare_request :POST, @request_data.to_json execute_request(request) end
[ "def", "granulate", "(", "options", "=", "{", "}", ")", "@request_data", "=", "Hash", ".", "new", "if", "options", "[", ":video_link", "]", "insert_download_data", "options", "elsif", "options", "[", ":sam_uid", "]", "&&", "options", "[", ":filename", "]", "file_data", "=", "{", ":video_uid", "=>", "options", "[", ":sam_uid", "]", ",", ":filename", "=>", "options", "[", ":filename", "]", "}", "@request_data", ".", "merge!", "file_data", "elsif", "options", "[", ":file", "]", "&&", "options", "[", ":filename", "]", "file_data", "=", "{", ":video", "=>", "options", "[", ":file", "]", ",", ":filename", "=>", "options", "[", ":filename", "]", "}", "@request_data", ".", "merge!", "file_data", "else", "raise", "NSIVideoGranulate", "::", "Errors", "::", "Client", "::", "MissingParametersError", "end", "insert_callback_data", "options", "request", "=", "prepare_request", ":POST", ",", "@request_data", ".", "to_json", "execute_request", "(", "request", ")", "end" ]
Initialize a client to a VideoGranulate node @param [Hash] options used to connect to the VideoGranulate node @options options [String] host to connect @options options [String] port to connect @options options [String] user to authenticatie with @options options [String] password to the refered user @return [Client] the object itself @example videogranulate = NSIVideoGranulate::Client.new host: 'localhost', port: '8886', user: 'test', password: 'test' @note if you had used the 'configure' method, you can use it without parameters and those you provided before will be used (see Client#configure) Send a video be granulated by a nsi.videogranulate node @param [Hash] options used to send a video to be graulated @option options [String] file the base64 encoded file to be granulated @option options [String] sam_uid the UID of a video at SAM @option options [String] filename the filename of the video @note the filename is very importante, the videogranulate node will use the proper coding/encoding option for the video type @option options [String] video_link link to the video that'll be granulated @note if provided both video_link and file options, file will be ignored and the client will download the video instead @option options [String] callback a callback url to the file granulation @option options [String] verb the callback request verb, when not provided, nsi.videogranulate defaults to POST @example A simple granulation require 'base64' video = Base64.encode64(File.new('video.ogv', 'r').read) response = nsivideogranulate.granulate(:file => video, :filename => 'video.ogv') nsivideogranulate.done(response["video_key"]) nsivideogranulate.grains_keys_for(response["video_key"]) @example Granulating from a SAM uid video = Base64.encode64(File.new('video.ogv', 'r').read) response = sam.store({:doc => doc}) video_key = response["key"] response = nsivideogranulate.granulate(:sam_uid => video_key, :filename => 'video.ogv') nsivideogranulate.done(response["video_key"]) nsivideogranulate.grains_keys_for(response["video_key"]) @example Downloading and granulating from web response = nsivideogranulate.granulate(:video_link => 'http://google.com/video.ogv') nsivideogranulate.done(response["video_key"]) nsivideogranulate.grains_keys_for(response["video_key"]) @example Sending a callback url video = Base64.encode64(File.new('video.ogv', 'r').read) nsivideogranulate.granulate(:file => video, :filename => 'video.ogv', :callback => 'http://google.com') nsivideogranulate.granulate(:video_link => 'http://google.com/video.ogv', :callback => 'http://google.com') @example Using a custom verb to the callback video = Base64.encode64(File.new('video.ogv', 'r').read) nsivideogranulate.granulate(:file => video, :filename => 'video.ogv', :callback => 'http://google.com', :verb => "PUT") nsivideogranulate.granulate(:video_link => 'http://google.com/video.ogv', :callback => 'http://google.com', :verb => "PUT") @return [Hash] response * "video_key" [String] the key to access the granulated video in the sam node it was stored @raise NSIVideoGranulate::Errors::Client::MissingParametersError when an invalid or incomplete set of parameters is provided @raise NSIVideoGranulate::Errors::Client::SAMConnectionError when cannot connect to the SAM node @raise NSIVideoGranulate::Errors::Client::AuthenticationError when invalids user and/or password are provided @raise NSIVideoGranulate::Errors::Client::KeyNotFoundError when an invalid sam_uid is provided
[ "Initialize", "a", "client", "to", "a", "VideoGranulate", "node" ]
794f44630ba6cac019a320288229ccccee00864d
https://github.com/nsi-iff/nsivideogranulate-ruby/blob/794f44630ba6cac019a320288229ccccee00864d/lib/nsivideogranulate/client.rb#L77-L93
train
nsi-iff/nsivideogranulate-ruby
lib/nsivideogranulate/client.rb
NSIVideoGranulate.Client.grains_keys_for
def grains_keys_for(video_key) request = prepare_request :GET, {:video_key => video_key, :grains => true}.to_json execute_request(request).select { |key| ['images', 'videos'].include? key } end
ruby
def grains_keys_for(video_key) request = prepare_request :GET, {:video_key => video_key, :grains => true}.to_json execute_request(request).select { |key| ['images', 'videos'].include? key } end
[ "def", "grains_keys_for", "(", "video_key", ")", "request", "=", "prepare_request", ":GET", ",", "{", ":video_key", "=>", "video_key", ",", ":grains", "=>", "true", "}", ".", "to_json", "execute_request", "(", "request", ")", ".", "select", "{", "|", "key", "|", "[", "'images'", ",", "'videos'", "]", ".", "include?", "key", "}", "end" ]
Return the keys of the grains of a video @param [String] key of the desired video @return [Hash] response * "images" [String] keys to the images grains of the video * "files" [String] keys to the files grains of the video @example nsivideogranulate.grains_keys_for("some key") @raise NSIVideoGranulate::Errors::Client::SAMConnectionError when cannot connect to the SAM node @raise NSIVideoGranulate::Errors::Client::AuthenticationError when invalids user and/or password are provided @raise NSIVideoGranulate::Errors::Client::KeyNotFoundError when an invalid key is provided
[ "Return", "the", "keys", "of", "the", "grains", "of", "a", "video" ]
794f44630ba6cac019a320288229ccccee00864d
https://github.com/nsi-iff/nsivideogranulate-ruby/blob/794f44630ba6cac019a320288229ccccee00864d/lib/nsivideogranulate/client.rb#L129-L132
train
0000marcell/simple_commander
lib/simple_commander/cli.rb
SimpleCommander.CLI.set_exec_path
def set_exec_path(path) yml = YAML.load_file(@config_file) yml[:exec_path] = File.expand_path(path) File.open(@config_file, 'w+'){|f| f.write(yml.to_yaml)} end
ruby
def set_exec_path(path) yml = YAML.load_file(@config_file) yml[:exec_path] = File.expand_path(path) File.open(@config_file, 'w+'){|f| f.write(yml.to_yaml)} end
[ "def", "set_exec_path", "(", "path", ")", "yml", "=", "YAML", ".", "load_file", "(", "@config_file", ")", "yml", "[", ":exec_path", "]", "=", "File", ".", "expand_path", "(", "path", ")", "File", ".", "open", "(", "@config_file", ",", "'w+'", ")", "{", "|", "f", "|", "f", ".", "write", "(", "yml", ".", "to_yaml", ")", "}", "end" ]
set exec path
[ "set", "exec", "path" ]
337c2e0d9926c643ce131b1a1ebd3740241e4424
https://github.com/0000marcell/simple_commander/blob/337c2e0d9926c643ce131b1a1ebd3740241e4424/lib/simple_commander/cli.rb#L99-L103
train
NUBIC/aker
lib/aker/rack/session_timer.rb
Aker::Rack.SessionTimer.call
def call(env) now = Time.now.to_i session = env['rack.session'] window_size = window_size(env) previous_timeout = session['aker.last_request_at'] return @app.call(env) unless window_size > 0 env['aker.timeout_at'] = now + window_size session['aker.last_request_at'] = now return @app.call(env) unless previous_timeout if now >= previous_timeout + window_size env['aker.session_expired'] = true env['warden'].logout end @app.call(env) end
ruby
def call(env) now = Time.now.to_i session = env['rack.session'] window_size = window_size(env) previous_timeout = session['aker.last_request_at'] return @app.call(env) unless window_size > 0 env['aker.timeout_at'] = now + window_size session['aker.last_request_at'] = now return @app.call(env) unless previous_timeout if now >= previous_timeout + window_size env['aker.session_expired'] = true env['warden'].logout end @app.call(env) end
[ "def", "call", "(", "env", ")", "now", "=", "Time", ".", "now", ".", "to_i", "session", "=", "env", "[", "'rack.session'", "]", "window_size", "=", "window_size", "(", "env", ")", "previous_timeout", "=", "session", "[", "'aker.last_request_at'", "]", "return", "@app", ".", "call", "(", "env", ")", "unless", "window_size", ">", "0", "env", "[", "'aker.timeout_at'", "]", "=", "now", "+", "window_size", "session", "[", "'aker.last_request_at'", "]", "=", "now", "return", "@app", ".", "call", "(", "env", ")", "unless", "previous_timeout", "if", "now", ">=", "previous_timeout", "+", "window_size", "env", "[", "'aker.session_expired'", "]", "=", "true", "env", "[", "'warden'", "]", ".", "logout", "end", "@app", ".", "call", "(", "env", ")", "end" ]
Determines whether the incoming request arrived within the timeout window. If it did, then the request is passed onto the rest of the Rack stack; otherwise, the user is redirected to the configured logout path.
[ "Determines", "whether", "the", "incoming", "request", "arrived", "within", "the", "timeout", "window", ".", "If", "it", "did", "then", "the", "request", "is", "passed", "onto", "the", "rest", "of", "the", "Rack", "stack", ";", "otherwise", "the", "user", "is", "redirected", "to", "the", "configured", "logout", "path", "." ]
ff43606a8812e38f96bbe71b46e7f631cbeacf1c
https://github.com/NUBIC/aker/blob/ff43606a8812e38f96bbe71b46e7f631cbeacf1c/lib/aker/rack/session_timer.rb#L69-L87
train
fanfilmu/conflow
lib/conflow/future.rb
Conflow.Future.build_promise
def build_promise(depending_job, param_key) Promise.new.tap do |promise| promise.assign_attributes(job_id: job.id, hash_field: param_key, result_key: result_key) depending_job.promise_ids << promise.id end end
ruby
def build_promise(depending_job, param_key) Promise.new.tap do |promise| promise.assign_attributes(job_id: job.id, hash_field: param_key, result_key: result_key) depending_job.promise_ids << promise.id end end
[ "def", "build_promise", "(", "depending_job", ",", "param_key", ")", "Promise", ".", "new", ".", "tap", "do", "|", "promise", "|", "promise", ".", "assign_attributes", "(", "job_id", ":", "job", ".", "id", ",", "hash_field", ":", "param_key", ",", "result_key", ":", "result_key", ")", "depending_job", ".", "promise_ids", "<<", "promise", ".", "id", "end", "end" ]
Builds promise from this future @api private @param depending_job [Conflow::Job] job which will use new promise @param param_key [Symbol, String] key in result hash that holds promised value @return [Conflow::Promise] promise object
[ "Builds", "promise", "from", "this", "future" ]
74b8fc2eb5a3a2a2a8918e1797d1e35c8ec9fdfb
https://github.com/fanfilmu/conflow/blob/74b8fc2eb5a3a2a2a8918e1797d1e35c8ec9fdfb/lib/conflow/future.rb#L46-L51
train
thriventures/storage_room_gem
lib/storage_room/accessors.rb
StorageRoom.Accessors.to_hash
def to_hash(args = {}) # :nodoc: args ||= {} hash = {} self.attributes.each do |name, value| hash[name] = if value.is_a?(::Array) value.map {|x| x.respond_to?(:to_hash) ? call_method_with_optional_parameters(x, :to_hash, :nested => true) : x} elsif value.respond_to?(:to_hash) call_method_with_optional_parameters(value, :to_hash, :nested => true) elsif value.respond_to?(:as_json) value.as_json(:nested => true) else value end end hash end
ruby
def to_hash(args = {}) # :nodoc: args ||= {} hash = {} self.attributes.each do |name, value| hash[name] = if value.is_a?(::Array) value.map {|x| x.respond_to?(:to_hash) ? call_method_with_optional_parameters(x, :to_hash, :nested => true) : x} elsif value.respond_to?(:to_hash) call_method_with_optional_parameters(value, :to_hash, :nested => true) elsif value.respond_to?(:as_json) value.as_json(:nested => true) else value end end hash end
[ "def", "to_hash", "(", "args", "=", "{", "}", ")", "# :nodoc:", "args", "||=", "{", "}", "hash", "=", "{", "}", "self", ".", "attributes", ".", "each", "do", "|", "name", ",", "value", "|", "hash", "[", "name", "]", "=", "if", "value", ".", "is_a?", "(", "::", "Array", ")", "value", ".", "map", "{", "|", "x", "|", "x", ".", "respond_to?", "(", ":to_hash", ")", "?", "call_method_with_optional_parameters", "(", "x", ",", ":to_hash", ",", ":nested", "=>", "true", ")", ":", "x", "}", "elsif", "value", ".", "respond_to?", "(", ":to_hash", ")", "call_method_with_optional_parameters", "(", "value", ",", ":to_hash", ",", ":nested", "=>", "true", ")", "elsif", "value", ".", "respond_to?", "(", ":as_json", ")", "value", ".", "as_json", "(", ":nested", "=>", "true", ")", "else", "value", "end", "end", "hash", "end" ]
ActiveSupport seemed to cause problems when just using as_json, so using to_hash
[ "ActiveSupport", "seemed", "to", "cause", "problems", "when", "just", "using", "as_json", "so", "using", "to_hash" ]
cadf132b865ff82f7b09fadfec1d294a714c6728
https://github.com/thriventures/storage_room_gem/blob/cadf132b865ff82f7b09fadfec1d294a714c6728/lib/storage_room/accessors.rb#L137-L154
train
thriventures/storage_room_gem
lib/storage_room/accessors.rb
StorageRoom.Accessors.call_method_with_optional_parameters
def call_method_with_optional_parameters(object, method_name, parameters) if object.respond_to?(method_name) if object.method(method_name).arity == -1 object.send(method_name, parameters) else object.send(method_name) end end end
ruby
def call_method_with_optional_parameters(object, method_name, parameters) if object.respond_to?(method_name) if object.method(method_name).arity == -1 object.send(method_name, parameters) else object.send(method_name) end end end
[ "def", "call_method_with_optional_parameters", "(", "object", ",", "method_name", ",", "parameters", ")", "if", "object", ".", "respond_to?", "(", "method_name", ")", "if", "object", ".", "method", "(", "method_name", ")", ".", "arity", "==", "-", "1", "object", ".", "send", "(", "method_name", ",", "parameters", ")", "else", "object", ".", "send", "(", "method_name", ")", "end", "end", "end" ]
Helper to not call to_hash with the wrong number of arguments
[ "Helper", "to", "not", "call", "to_hash", "with", "the", "wrong", "number", "of", "arguments" ]
cadf132b865ff82f7b09fadfec1d294a714c6728
https://github.com/thriventures/storage_room_gem/blob/cadf132b865ff82f7b09fadfec1d294a714c6728/lib/storage_room/accessors.rb#L190-L198
train
thriventures/storage_room_gem
lib/storage_room/accessors.rb
StorageRoom.Accessors.initialize_from_response_data
def initialize_from_response_data # :nodoc: run_callbacks :initialize_from_response_data do self.class.attribute_options_including_superclasses.each do |name, options| value = if options[:type] == :key self[name].blank? ? options[:default] : self[name] elsif options[:type] == :one hash = self[name.to_s] hash && hash['@type'] ? self.class.new_from_response_data(hash) : nil elsif options[:type] == :many response_data[name] && response_data[name].map{|hash| self.class.new_from_response_data(hash)} || [] else raise "Invalid type: #{options[:type]}" end send("#{name}=", value) end end end
ruby
def initialize_from_response_data # :nodoc: run_callbacks :initialize_from_response_data do self.class.attribute_options_including_superclasses.each do |name, options| value = if options[:type] == :key self[name].blank? ? options[:default] : self[name] elsif options[:type] == :one hash = self[name.to_s] hash && hash['@type'] ? self.class.new_from_response_data(hash) : nil elsif options[:type] == :many response_data[name] && response_data[name].map{|hash| self.class.new_from_response_data(hash)} || [] else raise "Invalid type: #{options[:type]}" end send("#{name}=", value) end end end
[ "def", "initialize_from_response_data", "# :nodoc:", "run_callbacks", ":initialize_from_response_data", "do", "self", ".", "class", ".", "attribute_options_including_superclasses", ".", "each", "do", "|", "name", ",", "options", "|", "value", "=", "if", "options", "[", ":type", "]", "==", ":key", "self", "[", "name", "]", ".", "blank?", "?", "options", "[", ":default", "]", ":", "self", "[", "name", "]", "elsif", "options", "[", ":type", "]", "==", ":one", "hash", "=", "self", "[", "name", ".", "to_s", "]", "hash", "&&", "hash", "[", "'@type'", "]", "?", "self", ".", "class", ".", "new_from_response_data", "(", "hash", ")", ":", "nil", "elsif", "options", "[", ":type", "]", "==", ":many", "response_data", "[", "name", "]", "&&", "response_data", "[", "name", "]", ".", "map", "{", "|", "hash", "|", "self", ".", "class", ".", "new_from_response_data", "(", "hash", ")", "}", "||", "[", "]", "else", "raise", "\"Invalid type: #{options[:type]}\"", "end", "send", "(", "\"#{name}=\"", ",", "value", ")", "end", "end", "end" ]
Iterate over the response data and initialize the attributes
[ "Iterate", "over", "the", "response", "data", "and", "initialize", "the", "attributes" ]
cadf132b865ff82f7b09fadfec1d294a714c6728
https://github.com/thriventures/storage_room_gem/blob/cadf132b865ff82f7b09fadfec1d294a714c6728/lib/storage_room/accessors.rb#L201-L218
train
ludocracy/Duxml
lib/duxml/meta/history.rb
Duxml.History.xml
def xml h = Element.new('history') events.each do |event| h << event.xml end h end
ruby
def xml h = Element.new('history') events.each do |event| h << event.xml end h end
[ "def", "xml", "h", "=", "Element", ".", "new", "(", "'history'", ")", "events", ".", "each", "do", "|", "event", "|", "h", "<<", "event", ".", "xml", "end", "h", "end" ]
used when creating a new metadata file for a static XML file @return [Doc] returns self as XML document
[ "used", "when", "creating", "a", "new", "metadata", "file", "for", "a", "static", "XML", "file" ]
b7d16c0bd27195825620091dfa60e21712221720
https://github.com/ludocracy/Duxml/blob/b7d16c0bd27195825620091dfa60e21712221720/lib/duxml/meta/history.rb#L44-L48
train
mkj-is/Truty
lib/truty/general.rb
Truty.General.general
def general(input, convert = [:all]) output = input output = ellipsis(output) if (convert.include?(:all) || convert.include?(:ellipsis)) output = multicharacters(output) if (convert.include? (:all) || convert.include?(:characters)) output = brackets_whitespace(output) if (convert.include?(:all) || convert.include?(:brackets)) output = emdash(output) if (convert.include?(:all) || convert.include?(:dashes)) output = endash(output) if (convert.include?(:all) || convert.include?(:dashes)) output = name_abbreviations(output) if (convert.include?(:all) || convert.include?(:abbreviations)) output = multiplication_sign(output) if (convert.include?(:all) || convert.include?(:multiplication)) output = space_between_numbers(output) if (convert.include?(:all) || convert.include?(:numbers)) output = units(output) if (convert.include?(:all) || convert.include?(:units)) output = widows(output) if (convert.include?(:all) || convert.include?(:widows)) output end
ruby
def general(input, convert = [:all]) output = input output = ellipsis(output) if (convert.include?(:all) || convert.include?(:ellipsis)) output = multicharacters(output) if (convert.include? (:all) || convert.include?(:characters)) output = brackets_whitespace(output) if (convert.include?(:all) || convert.include?(:brackets)) output = emdash(output) if (convert.include?(:all) || convert.include?(:dashes)) output = endash(output) if (convert.include?(:all) || convert.include?(:dashes)) output = name_abbreviations(output) if (convert.include?(:all) || convert.include?(:abbreviations)) output = multiplication_sign(output) if (convert.include?(:all) || convert.include?(:multiplication)) output = space_between_numbers(output) if (convert.include?(:all) || convert.include?(:numbers)) output = units(output) if (convert.include?(:all) || convert.include?(:units)) output = widows(output) if (convert.include?(:all) || convert.include?(:widows)) output end
[ "def", "general", "(", "input", ",", "convert", "=", "[", ":all", "]", ")", "output", "=", "input", "output", "=", "ellipsis", "(", "output", ")", "if", "(", "convert", ".", "include?", "(", ":all", ")", "||", "convert", ".", "include?", "(", ":ellipsis", ")", ")", "output", "=", "multicharacters", "(", "output", ")", "if", "(", "convert", ".", "include?", "(", ":all", ")", "||", "convert", ".", "include?", "(", ":characters", ")", ")", "output", "=", "brackets_whitespace", "(", "output", ")", "if", "(", "convert", ".", "include?", "(", ":all", ")", "||", "convert", ".", "include?", "(", ":brackets", ")", ")", "output", "=", "emdash", "(", "output", ")", "if", "(", "convert", ".", "include?", "(", ":all", ")", "||", "convert", ".", "include?", "(", ":dashes", ")", ")", "output", "=", "endash", "(", "output", ")", "if", "(", "convert", ".", "include?", "(", ":all", ")", "||", "convert", ".", "include?", "(", ":dashes", ")", ")", "output", "=", "name_abbreviations", "(", "output", ")", "if", "(", "convert", ".", "include?", "(", ":all", ")", "||", "convert", ".", "include?", "(", ":abbreviations", ")", ")", "output", "=", "multiplication_sign", "(", "output", ")", "if", "(", "convert", ".", "include?", "(", ":all", ")", "||", "convert", ".", "include?", "(", ":multiplication", ")", ")", "output", "=", "space_between_numbers", "(", "output", ")", "if", "(", "convert", ".", "include?", "(", ":all", ")", "||", "convert", ".", "include?", "(", ":numbers", ")", ")", "output", "=", "units", "(", "output", ")", "if", "(", "convert", ".", "include?", "(", ":all", ")", "||", "convert", ".", "include?", "(", ":units", ")", ")", "output", "=", "widows", "(", "output", ")", "if", "(", "convert", ".", "include?", "(", ":all", ")", "||", "convert", ".", "include?", "(", ":widows", ")", ")", "output", "end" ]
Improves basic non-language specific issues in typography. @param input [String] The paragraph which will be converted. @param convert [Array] Array of symbols with features that should be improved (possibilities: +all+, +hyphens+, +quotes+, +ellipsis+, +dashes+, +abbreviations+, +prepositions+, +numbers+, +dates+, +characters+, +brackets+, +multiplication+, +units+, +widows+) @return [String] Paragraph with improved typography.
[ "Improves", "basic", "non", "-", "language", "specific", "issues", "in", "typography", "." ]
315f49ad73cc2fa814a7793aa1b19657870ce98f
https://github.com/mkj-is/Truty/blob/315f49ad73cc2fa814a7793aa1b19657870ce98f/lib/truty/general.rb#L25-L38
train
mkj-is/Truty
lib/truty/general.rb
Truty.General.brackets_whitespace
def brackets_whitespace(input) output = input.gsub(/([\(\[\{])\s*/, '\1') output = output.gsub(/\s*([\]\)\}])/, '\1') output = output.gsub(/\s+([\(\[\{])\s*/, ' \1') output = output.gsub(/\s*([\]\)\}])\s+/, '\1 ') end
ruby
def brackets_whitespace(input) output = input.gsub(/([\(\[\{])\s*/, '\1') output = output.gsub(/\s*([\]\)\}])/, '\1') output = output.gsub(/\s+([\(\[\{])\s*/, ' \1') output = output.gsub(/\s*([\]\)\}])\s+/, '\1 ') end
[ "def", "brackets_whitespace", "(", "input", ")", "output", "=", "input", ".", "gsub", "(", "/", "\\(", "\\[", "\\{", "\\s", "/", ",", "'\\1'", ")", "output", "=", "output", ".", "gsub", "(", "/", "\\s", "\\]", "\\)", "\\}", "/", ",", "'\\1'", ")", "output", "=", "output", ".", "gsub", "(", "/", "\\s", "\\(", "\\[", "\\{", "\\s", "/", ",", "' \\1'", ")", "output", "=", "output", ".", "gsub", "(", "/", "\\s", "\\]", "\\)", "\\}", "\\s", "/", ",", "'\\1 '", ")", "end" ]
Fixes spaces around various brackets. @param input [String] The paragraph which will be converted. @return [String] Paragraph with correct spaces around brackets.
[ "Fixes", "spaces", "around", "various", "brackets", "." ]
315f49ad73cc2fa814a7793aa1b19657870ce98f
https://github.com/mkj-is/Truty/blob/315f49ad73cc2fa814a7793aa1b19657870ce98f/lib/truty/general.rb#L118-L123
train
xufeisofly/organismo
lib/organismo/element.rb
Organismo.Element.create
def create if text.match(/\_QUOTE/) require 'organismo/element/quote' Organismo::Element::Quote.new(text, location) elsif text.match(/\_SRC/) require 'organismo/element/code' Organismo::Element::Code.new(text, location) elsif text.match(/\_EXAMPLE/) require 'organismo/element/example' Organismo::Element::Example.new(text, location) elsif text.match(/\*/) require 'organismo/element/header' Organismo::Element::Header.new(text, location) elsif text.match(/\[\[\S*(\.png)|(\jpg)|(\.jpeg)\]\]/) require 'organismo/element/image' Organismo::Element::Image.new(text, location) elsif text.match(/\[\[\S*\]\]/) require 'organismo/element/link' Organismo::Element::Link.new(text, location) elsif text.match(/\-/) require 'organismo/element/plain_list' Organismo::Element::PlainList.new(text, location) else require 'organismo/element/text' Organismo::Element::Text.new(text, location) end end
ruby
def create if text.match(/\_QUOTE/) require 'organismo/element/quote' Organismo::Element::Quote.new(text, location) elsif text.match(/\_SRC/) require 'organismo/element/code' Organismo::Element::Code.new(text, location) elsif text.match(/\_EXAMPLE/) require 'organismo/element/example' Organismo::Element::Example.new(text, location) elsif text.match(/\*/) require 'organismo/element/header' Organismo::Element::Header.new(text, location) elsif text.match(/\[\[\S*(\.png)|(\jpg)|(\.jpeg)\]\]/) require 'organismo/element/image' Organismo::Element::Image.new(text, location) elsif text.match(/\[\[\S*\]\]/) require 'organismo/element/link' Organismo::Element::Link.new(text, location) elsif text.match(/\-/) require 'organismo/element/plain_list' Organismo::Element::PlainList.new(text, location) else require 'organismo/element/text' Organismo::Element::Text.new(text, location) end end
[ "def", "create", "if", "text", ".", "match", "(", "/", "\\_", "/", ")", "require", "'organismo/element/quote'", "Organismo", "::", "Element", "::", "Quote", ".", "new", "(", "text", ",", "location", ")", "elsif", "text", ".", "match", "(", "/", "\\_", "/", ")", "require", "'organismo/element/code'", "Organismo", "::", "Element", "::", "Code", ".", "new", "(", "text", ",", "location", ")", "elsif", "text", ".", "match", "(", "/", "\\_", "/", ")", "require", "'organismo/element/example'", "Organismo", "::", "Element", "::", "Example", ".", "new", "(", "text", ",", "location", ")", "elsif", "text", ".", "match", "(", "/", "\\*", "/", ")", "require", "'organismo/element/header'", "Organismo", "::", "Element", "::", "Header", ".", "new", "(", "text", ",", "location", ")", "elsif", "text", ".", "match", "(", "/", "\\[", "\\[", "\\S", "\\.", "\\j", "\\.", "\\]", "\\]", "/", ")", "require", "'organismo/element/image'", "Organismo", "::", "Element", "::", "Image", ".", "new", "(", "text", ",", "location", ")", "elsif", "text", ".", "match", "(", "/", "\\[", "\\[", "\\S", "\\]", "\\]", "/", ")", "require", "'organismo/element/link'", "Organismo", "::", "Element", "::", "Link", ".", "new", "(", "text", ",", "location", ")", "elsif", "text", ".", "match", "(", "/", "\\-", "/", ")", "require", "'organismo/element/plain_list'", "Organismo", "::", "Element", "::", "PlainList", ".", "new", "(", "text", ",", "location", ")", "else", "require", "'organismo/element/text'", "Organismo", "::", "Element", "::", "Text", ".", "new", "(", "text", ",", "location", ")", "end", "end" ]
require and initialize different instance depending on string regex
[ "require", "and", "initialize", "different", "instance", "depending", "on", "string", "regex" ]
cc133fc1c6206cb0efbff28daa7c9309481cd03e
https://github.com/xufeisofly/organismo/blob/cc133fc1c6206cb0efbff28daa7c9309481cd03e/lib/organismo/element.rb#L12-L38
train
octoai/gem-octocore-cassandra
lib/octocore-cassandra/email.rb
Octo.Email.send
def send(email, subject, opts = {}) if email.nil? or subject.nil? raise ArgumentError, 'Email Address or Subject is missing' else message = { from_name: Octo.get_config(:email_sender).fetch(:name), from_email: Octo.get_config(:email_sender).fetch(:email), subject: subject, text: opts.fetch('text', nil), html: opts.fetch('html', nil), to: [{ email: email, name: opts.fetch('name', nil) }] } # Pass the message to resque only when mandrill key is present _mandrill_config = ENV['MANDRILL_API_KEY'] || Octo.get_config(:mandrill_api_key) if _mandrill_config and !_mandrill_config.empty? enqueue_msg(message) end end end
ruby
def send(email, subject, opts = {}) if email.nil? or subject.nil? raise ArgumentError, 'Email Address or Subject is missing' else message = { from_name: Octo.get_config(:email_sender).fetch(:name), from_email: Octo.get_config(:email_sender).fetch(:email), subject: subject, text: opts.fetch('text', nil), html: opts.fetch('html', nil), to: [{ email: email, name: opts.fetch('name', nil) }] } # Pass the message to resque only when mandrill key is present _mandrill_config = ENV['MANDRILL_API_KEY'] || Octo.get_config(:mandrill_api_key) if _mandrill_config and !_mandrill_config.empty? enqueue_msg(message) end end end
[ "def", "send", "(", "email", ",", "subject", ",", "opts", "=", "{", "}", ")", "if", "email", ".", "nil?", "or", "subject", ".", "nil?", "raise", "ArgumentError", ",", "'Email Address or Subject is missing'", "else", "message", "=", "{", "from_name", ":", "Octo", ".", "get_config", "(", ":email_sender", ")", ".", "fetch", "(", ":name", ")", ",", "from_email", ":", "Octo", ".", "get_config", "(", ":email_sender", ")", ".", "fetch", "(", ":email", ")", ",", "subject", ":", "subject", ",", "text", ":", "opts", ".", "fetch", "(", "'text'", ",", "nil", ")", ",", "html", ":", "opts", ".", "fetch", "(", "'html'", ",", "nil", ")", ",", "to", ":", "[", "{", "email", ":", "email", ",", "name", ":", "opts", ".", "fetch", "(", "'name'", ",", "nil", ")", "}", "]", "}", "# Pass the message to resque only when mandrill key is present", "_mandrill_config", "=", "ENV", "[", "'MANDRILL_API_KEY'", "]", "||", "Octo", ".", "get_config", "(", ":mandrill_api_key", ")", "if", "_mandrill_config", "and", "!", "_mandrill_config", ".", "empty?", "enqueue_msg", "(", "message", ")", "end", "end", "end" ]
Send Emails using mandrill api @param [Text] email Email Address of the receiver @param [Text] subject Subject of Email @param [Hash] opt Hash contain other message details
[ "Send", "Emails", "using", "mandrill", "api" ]
c0977dce5ba0eb174ff810f161aba151069935df
https://github.com/octoai/gem-octocore-cassandra/blob/c0977dce5ba0eb174ff810f161aba151069935df/lib/octocore-cassandra/email.rb#L14-L38
train
andytinycat/debeasy
lib/debeasy/package.rb
Debeasy.Package.parse_control_file
def parse_control_file @control_file_contents.scan(/^([\w-]+?): (.*?)\n(?! )/m).each do |entry| field, value = entry @fields[field.gsub("-", "_").downcase] = value end @fields["installed_size"] = @fields["installed_size"].to_i * 1024 unless @fields["installed_size"].nil? end
ruby
def parse_control_file @control_file_contents.scan(/^([\w-]+?): (.*?)\n(?! )/m).each do |entry| field, value = entry @fields[field.gsub("-", "_").downcase] = value end @fields["installed_size"] = @fields["installed_size"].to_i * 1024 unless @fields["installed_size"].nil? end
[ "def", "parse_control_file", "@control_file_contents", ".", "scan", "(", "/", "\\w", "\\n", "/m", ")", ".", "each", "do", "|", "entry", "|", "field", ",", "value", "=", "entry", "@fields", "[", "field", ".", "gsub", "(", "\"-\"", ",", "\"_\"", ")", ".", "downcase", "]", "=", "value", "end", "@fields", "[", "\"installed_size\"", "]", "=", "@fields", "[", "\"installed_size\"", "]", ".", "to_i", "*", "1024", "unless", "@fields", "[", "\"installed_size\"", "]", ".", "nil?", "end" ]
Parse the available fields out of the Debian control file.
[ "Parse", "the", "available", "fields", "out", "of", "the", "Debian", "control", "file", "." ]
5f3a17a29eb47a12bb1e6d385d02e4426e379eb5
https://github.com/andytinycat/debeasy/blob/5f3a17a29eb47a12bb1e6d385d02e4426e379eb5/lib/debeasy/package.rb#L116-L122
train
RuthThompson/elastic_queue
lib/elastic_queue/query.rb
ElasticQueue.Query.method_missing
def method_missing(method, *args, &block) if @queue.respond_to?(method) proc = @queue.scopes[method] instance_exec *args, &proc end end
ruby
def method_missing(method, *args, &block) if @queue.respond_to?(method) proc = @queue.scopes[method] instance_exec *args, &proc end end
[ "def", "method_missing", "(", "method", ",", "*", "args", ",", "&", "block", ")", "if", "@queue", ".", "respond_to?", "(", "method", ")", "proc", "=", "@queue", ".", "scopes", "[", "method", "]", "instance_exec", "args", ",", "proc", "end", "end" ]
this allows you to chain scopes the 2+ scopes in the chain will be called on a query object and not on the base object
[ "this", "allows", "you", "to", "chain", "scopes", "the", "2", "+", "scopes", "in", "the", "chain", "will", "be", "called", "on", "a", "query", "object", "and", "not", "on", "the", "base", "object" ]
f91842c389a60145ff44ccd990e697a8094c7309
https://github.com/RuthThompson/elastic_queue/blob/f91842c389a60145ff44ccd990e697a8094c7309/lib/elastic_queue/query.rb#L84-L89
train
rike422/loose-leaf
app/channels/loose_leaf/collaboration_channel.rb
LooseLeaf.CollaborationChannel.document
def document(data) document = collaborative_model.find_by_collaborative_key(data['id']) @documents ||= [] @documents << document send_attribute_versions(document) stream_from "loose_leaf.documents.#{document.id}.operations" end
ruby
def document(data) document = collaborative_model.find_by_collaborative_key(data['id']) @documents ||= [] @documents << document send_attribute_versions(document) stream_from "loose_leaf.documents.#{document.id}.operations" end
[ "def", "document", "(", "data", ")", "document", "=", "collaborative_model", ".", "find_by_collaborative_key", "(", "data", "[", "'id'", "]", ")", "@documents", "||=", "[", "]", "@documents", "<<", "document", "send_attribute_versions", "(", "document", ")", "stream_from", "\"loose_leaf.documents.#{document.id}.operations\"", "end" ]
Subscribe to changes to a document
[ "Subscribe", "to", "changes", "to", "a", "document" ]
ea3cb93667f83e5f4abb3c7879fc0220157aeb81
https://github.com/rike422/loose-leaf/blob/ea3cb93667f83e5f4abb3c7879fc0220157aeb81/app/channels/loose_leaf/collaboration_channel.rb#L13-L22
train
rike422/loose-leaf
app/channels/loose_leaf/collaboration_channel.rb
LooseLeaf.CollaborationChannel.send_attribute_versions
def send_attribute_versions(document) collaborative_model.collaborative_attributes.each do |attribute_name| attribute = document.collaborative_attribute(attribute_name) transmit( document_id: document.id, action: 'attribute', attribute: attribute_name, version: attribute.version ) end end
ruby
def send_attribute_versions(document) collaborative_model.collaborative_attributes.each do |attribute_name| attribute = document.collaborative_attribute(attribute_name) transmit( document_id: document.id, action: 'attribute', attribute: attribute_name, version: attribute.version ) end end
[ "def", "send_attribute_versions", "(", "document", ")", "collaborative_model", ".", "collaborative_attributes", ".", "each", "do", "|", "attribute_name", "|", "attribute", "=", "document", ".", "collaborative_attribute", "(", "attribute_name", ")", "transmit", "(", "document_id", ":", "document", ".", "id", ",", "action", ":", "'attribute'", ",", "attribute", ":", "attribute_name", ",", "version", ":", "attribute", ".", "version", ")", "end", "end" ]
Send out initial versions
[ "Send", "out", "initial", "versions" ]
ea3cb93667f83e5f4abb3c7879fc0220157aeb81
https://github.com/rike422/loose-leaf/blob/ea3cb93667f83e5f4abb3c7879fc0220157aeb81/app/channels/loose_leaf/collaboration_channel.rb#L43-L54
train
maxjacobson/todo_lint
lib/todo_lint/cli.rb
TodoLint.Cli.load_files
def load_files(file_finder) if file_finder.options.fetch(:files).empty? file_finder.list(*options[:extensions]) else file_finder.options.fetch(:files) { [] } end end
ruby
def load_files(file_finder) if file_finder.options.fetch(:files).empty? file_finder.list(*options[:extensions]) else file_finder.options.fetch(:files) { [] } end end
[ "def", "load_files", "(", "file_finder", ")", "if", "file_finder", ".", "options", ".", "fetch", "(", ":files", ")", ".", "empty?", "file_finder", ".", "list", "(", "options", "[", ":extensions", "]", ")", "else", "file_finder", ".", "options", ".", "fetch", "(", ":files", ")", "{", "[", "]", "}", "end", "end" ]
Loads the files to be read @return [Array<String>] @example cli.load_files(file_finder) @api public
[ "Loads", "the", "files", "to", "be", "read" ]
0d1061383ea205ef4c74edc64568e308ac1af990
https://github.com/maxjacobson/todo_lint/blob/0d1061383ea205ef4c74edc64568e308ac1af990/lib/todo_lint/cli.rb#L39-L45
train
maxjacobson/todo_lint
lib/todo_lint/cli.rb
TodoLint.Cli.print_report
def print_report todos = [] finder = FileFinder.new(path, options) files = load_files(finder) files.each do |file| todos += Todo.within(File.open(file), :config => @options) end todos.sort.each.with_index do |todo, num| due_date = if todo.due_date tag_context = " via #{todo.tag}" if todo.tag? Rainbow(" (due #{todo.due_date.to_date}#{tag_context})") .public_send(todo.due_date.overdue? ? :red : :blue) else Rainbow(" (no due date)").red end puts "#{num + 1}. #{todo.task}#{due_date} " + Rainbow( "(#{todo.relative_path}:#{todo.line_number}:" \ "#{todo.character_number})" ).yellow end exit 0 end
ruby
def print_report todos = [] finder = FileFinder.new(path, options) files = load_files(finder) files.each do |file| todos += Todo.within(File.open(file), :config => @options) end todos.sort.each.with_index do |todo, num| due_date = if todo.due_date tag_context = " via #{todo.tag}" if todo.tag? Rainbow(" (due #{todo.due_date.to_date}#{tag_context})") .public_send(todo.due_date.overdue? ? :red : :blue) else Rainbow(" (no due date)").red end puts "#{num + 1}. #{todo.task}#{due_date} " + Rainbow( "(#{todo.relative_path}:#{todo.line_number}:" \ "#{todo.character_number})" ).yellow end exit 0 end
[ "def", "print_report", "todos", "=", "[", "]", "finder", "=", "FileFinder", ".", "new", "(", "path", ",", "options", ")", "files", "=", "load_files", "(", "finder", ")", "files", ".", "each", "do", "|", "file", "|", "todos", "+=", "Todo", ".", "within", "(", "File", ".", "open", "(", "file", ")", ",", ":config", "=>", "@options", ")", "end", "todos", ".", "sort", ".", "each", ".", "with_index", "do", "|", "todo", ",", "num", "|", "due_date", "=", "if", "todo", ".", "due_date", "tag_context", "=", "\" via #{todo.tag}\"", "if", "todo", ".", "tag?", "Rainbow", "(", "\" (due #{todo.due_date.to_date}#{tag_context})\"", ")", ".", "public_send", "(", "todo", ".", "due_date", ".", "overdue?", "?", ":red", ":", ":blue", ")", "else", "Rainbow", "(", "\" (no due date)\"", ")", ".", "red", "end", "puts", "\"#{num + 1}. #{todo.task}#{due_date} \"", "+", "Rainbow", "(", "\"(#{todo.relative_path}:#{todo.line_number}:\"", "\"#{todo.character_number})\"", ")", ".", "yellow", "end", "exit", "0", "end" ]
Print report of todos in codebase, then exit @return by exiting with 0 @api private
[ "Print", "report", "of", "todos", "in", "codebase", "then", "exit" ]
0d1061383ea205ef4c74edc64568e308ac1af990
https://github.com/maxjacobson/todo_lint/blob/0d1061383ea205ef4c74edc64568e308ac1af990/lib/todo_lint/cli.rb#L94-L117
train
aprescott/redhead
lib/redhead/header_set.rb
Redhead.HeaderSet.[]=
def []=(key, value) h = self[key] if h h.value = value else new_header = Redhead::Header.new(key, TO_RAW[key], value) self << new_header end end
ruby
def []=(key, value) h = self[key] if h h.value = value else new_header = Redhead::Header.new(key, TO_RAW[key], value) self << new_header end end
[ "def", "[]=", "(", "key", ",", "value", ")", "h", "=", "self", "[", "key", "]", "if", "h", "h", ".", "value", "=", "value", "else", "new_header", "=", "Redhead", "::", "Header", ".", "new", "(", "key", ",", "TO_RAW", "[", "key", "]", ",", "value", ")", "self", "<<", "new_header", "end", "end" ]
If there is a header in the set with a key matching _key_, then set its value to _value_. If there is no header matching _key_, create a new header with the given key and value.
[ "If", "there", "is", "a", "header", "in", "the", "set", "with", "a", "key", "matching", "_key_", "then", "set", "its", "value", "to", "_value_", ".", "If", "there", "is", "no", "header", "matching", "_key_", "create", "a", "new", "header", "with", "the", "given", "key", "and", "value", "." ]
4fe032029e6d3e5ebe88d61bbb0d5150fe204b3d
https://github.com/aprescott/redhead/blob/4fe032029e6d3e5ebe88d61bbb0d5150fe204b3d/lib/redhead/header_set.rb#L43-L51
train
aprescott/redhead
lib/redhead/header_set.rb
Redhead.HeaderSet.delete
def delete(key) header = self[key] @headers.reject! { |header| header.key == key } ? header : nil end
ruby
def delete(key) header = self[key] @headers.reject! { |header| header.key == key } ? header : nil end
[ "def", "delete", "(", "key", ")", "header", "=", "self", "[", "key", "]", "@headers", ".", "reject!", "{", "|", "header", "|", "header", ".", "key", "==", "key", "}", "?", "header", ":", "nil", "end" ]
Removes any headers with key names matching _key_ from the set.
[ "Removes", "any", "headers", "with", "key", "names", "matching", "_key_", "from", "the", "set", "." ]
4fe032029e6d3e5ebe88d61bbb0d5150fe204b3d
https://github.com/aprescott/redhead/blob/4fe032029e6d3e5ebe88d61bbb0d5150fe204b3d/lib/redhead/header_set.rb#L66-L69
train
erpe/acts_as_referred
lib/acts_as_referred/controller.rb
ActsAsReferred.Controller._supply_model_hook
def _supply_model_hook # 3.2.1 -> adwords auto-tagging - (show hint to manual tag adwords): # ?gclid=xxxx # 3.2.2 -> manual tagging # ?utm_source=google&utm_medium=cpc&utm_term=my_keyword&utm_campaign=my_summerdeal # 3.2.3 -> manual url-tagging specific for piwik # ?pk_campaign=my_summerdeal&pk_kwd=my_keyword # cookie / session persisted: # e.g.: "req=http://foo/baz?utm_campaign=plonk|ref=http://google.com/search|count=0" tmp = session[:__reqref] _struct = nil if tmp arr = tmp.split('|') _struct = OpenStruct.new( request_url: arr[0].split('=',2)[1], referrer_url: minlength_or_nil(arr[1].split('=',2)[1]), visit_count: arr[2].split('=',2)[1].to_i ) end ActiveRecord::Base.send( :define_method, '_get_reqref', proc{ _struct } ) end
ruby
def _supply_model_hook # 3.2.1 -> adwords auto-tagging - (show hint to manual tag adwords): # ?gclid=xxxx # 3.2.2 -> manual tagging # ?utm_source=google&utm_medium=cpc&utm_term=my_keyword&utm_campaign=my_summerdeal # 3.2.3 -> manual url-tagging specific for piwik # ?pk_campaign=my_summerdeal&pk_kwd=my_keyword # cookie / session persisted: # e.g.: "req=http://foo/baz?utm_campaign=plonk|ref=http://google.com/search|count=0" tmp = session[:__reqref] _struct = nil if tmp arr = tmp.split('|') _struct = OpenStruct.new( request_url: arr[0].split('=',2)[1], referrer_url: minlength_or_nil(arr[1].split('=',2)[1]), visit_count: arr[2].split('=',2)[1].to_i ) end ActiveRecord::Base.send( :define_method, '_get_reqref', proc{ _struct } ) end
[ "def", "_supply_model_hook", "# 3.2.1 -> adwords auto-tagging - (show hint to manual tag adwords):", "# ?gclid=xxxx ", "# 3.2.2 -> manual tagging ", "# ?utm_source=google&utm_medium=cpc&utm_term=my_keyword&utm_campaign=my_summerdeal ", "# 3.2.3 -> manual url-tagging specific for piwik ", "# ?pk_campaign=my_summerdeal&pk_kwd=my_keyword ", "# cookie / session persisted:", "# e.g.: \"req=http://foo/baz?utm_campaign=plonk|ref=http://google.com/search|count=0\"", "tmp", "=", "session", "[", ":__reqref", "]", "_struct", "=", "nil", "if", "tmp", "arr", "=", "tmp", ".", "split", "(", "'|'", ")", "_struct", "=", "OpenStruct", ".", "new", "(", "request_url", ":", "arr", "[", "0", "]", ".", "split", "(", "'='", ",", "2", ")", "[", "1", "]", ",", "referrer_url", ":", "minlength_or_nil", "(", "arr", "[", "1", "]", ".", "split", "(", "'='", ",", "2", ")", "[", "1", "]", ")", ",", "visit_count", ":", "arr", "[", "2", "]", ".", "split", "(", "'='", ",", "2", ")", "[", "1", "]", ".", "to_i", ")", "end", "ActiveRecord", "::", "Base", ".", "send", "(", ":define_method", ",", "'_get_reqref'", ",", "proc", "{", "_struct", "}", ")", "end" ]
The before_filter which processes necessary data for +acts_as_referred+ - models
[ "The", "before_filter", "which", "processes", "necessary", "data", "for", "+", "acts_as_referred", "+", "-", "models" ]
d1ffb3208e6e358c9888cec71c7bd76d30a0fdd3
https://github.com/erpe/acts_as_referred/blob/d1ffb3208e6e358c9888cec71c7bd76d30a0fdd3/lib/acts_as_referred/controller.rb#L16-L43
train
quixoten/queue_to_the_future
lib/queue_to_the_future/coordinator.rb
QueueToTheFuture.Coordinator.shutdown
def shutdown(force = false) @workforce.mu_synchronize do Thread.pass until @job_queue.empty? unless force while worker = @workforce.shift; worker.terminate; end end nil end
ruby
def shutdown(force = false) @workforce.mu_synchronize do Thread.pass until @job_queue.empty? unless force while worker = @workforce.shift; worker.terminate; end end nil end
[ "def", "shutdown", "(", "force", "=", "false", ")", "@workforce", ".", "mu_synchronize", "do", "Thread", ".", "pass", "until", "@job_queue", ".", "empty?", "unless", "force", "while", "worker", "=", "@workforce", ".", "shift", ";", "worker", ".", "terminate", ";", "end", "end", "nil", "end" ]
Prevents more workers from being created and waits for all jobs to finish. Once the jobs have completed the workers are terminated. To start up again just QueueToTheFuture::schedule more jobs once this method returns. @param [true, false] force If set to true, shutdown immediately and clear the queue without waiting for any jobs to complete.
[ "Prevents", "more", "workers", "from", "being", "created", "and", "waits", "for", "all", "jobs", "to", "finish", ".", "Once", "the", "jobs", "have", "completed", "the", "workers", "are", "terminated", "." ]
dd8260fa165ee42b95e6d76bc665fdf68339dfd6
https://github.com/quixoten/queue_to_the_future/blob/dd8260fa165ee42b95e6d76bc665fdf68339dfd6/lib/queue_to_the_future/coordinator.rb#L69-L76
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.authenticate
def authenticate(username, password) begin options = {authorization: basic_auth_encryption(username, password)} url = url_for_path('/authenticateduser/') client.get(url, options) do |response| if response.code == 200 a_hash = parse response Resource::User.from_coach a_hash else false end end rescue raise 'Error: Could not authenticate user!' end end
ruby
def authenticate(username, password) begin options = {authorization: basic_auth_encryption(username, password)} url = url_for_path('/authenticateduser/') client.get(url, options) do |response| if response.code == 200 a_hash = parse response Resource::User.from_coach a_hash else false end end rescue raise 'Error: Could not authenticate user!' end end
[ "def", "authenticate", "(", "username", ",", "password", ")", "begin", "options", "=", "{", "authorization", ":", "basic_auth_encryption", "(", "username", ",", "password", ")", "}", "url", "=", "url_for_path", "(", "'/authenticateduser/'", ")", "client", ".", "get", "(", "url", ",", "options", ")", "do", "|", "response", "|", "if", "response", ".", "code", "==", "200", "a_hash", "=", "parse", "response", "Resource", "::", "User", ".", "from_coach", "a_hash", "else", "false", "end", "end", "rescue", "raise", "'Error: Could not authenticate user!'", "end", "end" ]
Creates a Coach client for the cyber coach webservcie. @param [Client] client @param [ResponseParser] response_parser @param [Boolean] debug @return [Coach] Authenticates a user against the Cyber Coach Webservice. @param username @param password @return [User] ====Example @example @coach.authenticate('arueedlinger', 'test')
[ "Creates", "a", "Coach", "client", "for", "the", "cyber", "coach", "webservcie", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L30-L45
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.user_exists?
def user_exists?(username) begin url = url_for_path(user_path(username)) client.get(url) { |response| response.code == 200 } rescue raise 'Error: Could not test user existence!' end end
ruby
def user_exists?(username) begin url = url_for_path(user_path(username)) client.get(url) { |response| response.code == 200 } rescue raise 'Error: Could not test user existence!' end end
[ "def", "user_exists?", "(", "username", ")", "begin", "url", "=", "url_for_path", "(", "user_path", "(", "username", ")", ")", "client", ".", "get", "(", "url", ")", "{", "|", "response", "|", "response", ".", "code", "==", "200", "}", "rescue", "raise", "'Error: Could not test user existence!'", "end", "end" ]
Tests if the user given its username exists.. @param username @return [Boolean] ====Examples @example @coach.user_exsists?('arueedlinger')
[ "Tests", "if", "the", "user", "given", "its", "username", "exists", ".." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L74-L81
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.create_user
def create_user(options={}, &block) builder = Builder::User.new(public_visible: Privacy::Public) block.call(builder) url = url_for_path(user_path(builder.username)) begin client.put(url, builder.to_xml, options) do |response| a_hash = parse response Resource::User.from_coach a_hash end rescue =>e raise e if debug false end end
ruby
def create_user(options={}, &block) builder = Builder::User.new(public_visible: Privacy::Public) block.call(builder) url = url_for_path(user_path(builder.username)) begin client.put(url, builder.to_xml, options) do |response| a_hash = parse response Resource::User.from_coach a_hash end rescue =>e raise e if debug false end end
[ "def", "create_user", "(", "options", "=", "{", "}", ",", "&", "block", ")", "builder", "=", "Builder", "::", "User", ".", "new", "(", "public_visible", ":", "Privacy", "::", "Public", ")", "block", ".", "call", "(", "builder", ")", "url", "=", "url_for_path", "(", "user_path", "(", "builder", ".", "username", ")", ")", "begin", "client", ".", "put", "(", "url", ",", "builder", ".", "to_xml", ",", "options", ")", "do", "|", "response", "|", "a_hash", "=", "parse", "response", "Resource", "::", "User", ".", "from_coach", "a_hash", "end", "rescue", "=>", "e", "raise", "e", "if", "debug", "false", "end", "end" ]
Creates a user with public visibility as default. @param [Hash] options @param [Block] block @return [User] ====Examples @example @coach.create_user do |user| user.real_name= 'the hoff' user.username= 'wantsomemoney' user.password= 'test' user.email= '[email protected]' user.public_visible= 2 end
[ "Creates", "a", "user", "with", "public", "visibility", "as", "default", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L113-L127
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.delete_user
def delete_user(user, options={}) raise 'Error: Param user is nil!' if user.nil? url = if user.is_a?(Resource::User) url_for_resource(user) elsif user.is_a?(String) url_for_path(user_path(user)) else raise 'Error: Invalid parameters!' end begin client.delete(url, options) do |response| response.code == 200 end rescue => e raise e if debug end end
ruby
def delete_user(user, options={}) raise 'Error: Param user is nil!' if user.nil? url = if user.is_a?(Resource::User) url_for_resource(user) elsif user.is_a?(String) url_for_path(user_path(user)) else raise 'Error: Invalid parameters!' end begin client.delete(url, options) do |response| response.code == 200 end rescue => e raise e if debug end end
[ "def", "delete_user", "(", "user", ",", "options", "=", "{", "}", ")", "raise", "'Error: Param user is nil!'", "if", "user", ".", "nil?", "url", "=", "if", "user", ".", "is_a?", "(", "Resource", "::", "User", ")", "url_for_resource", "(", "user", ")", "elsif", "user", ".", "is_a?", "(", "String", ")", "url_for_path", "(", "user_path", "(", "user", ")", ")", "else", "raise", "'Error: Invalid parameters!'", "end", "begin", "client", ".", "delete", "(", "url", ",", "options", ")", "do", "|", "response", "|", "response", ".", "code", "==", "200", "end", "rescue", "=>", "e", "raise", "e", "if", "debug", "end", "end" ]
Deletes a user. @param [User\String] user @param [Hash] options @return [Boolean] ====Examples @example @coach.delete_user(user) @example @coach.delete_user('arueedlinger')
[ "Deletes", "a", "user", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L181-L198
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.create_partnership
def create_partnership(first_user, second_user, options={}, &block) raise 'Error: Param first_user is nil!' if first_user.nil? raise 'Error: Param second_user is nil!' if second_user.nil? path = if first_user.is_a?(Resource::User) && second_user.is_a?(Resource::User) partnership_path(first_user.username, second_user.username) elsif first_user.is_a?(String) && second_user.is_a?(String) partnership_path(first_user, second_user) else raise 'Error: Invalid parameters!' end url = url_for_path(path) builder = Builder::Partnership.new(public_visible: Privacy::Public) block.call(builder) if block_given? begin client.put(url, builder.to_xml, options) do |response| a_hash = parse response Resource::Partnership.from_coach a_hash end rescue => e raise e if debug false end end
ruby
def create_partnership(first_user, second_user, options={}, &block) raise 'Error: Param first_user is nil!' if first_user.nil? raise 'Error: Param second_user is nil!' if second_user.nil? path = if first_user.is_a?(Resource::User) && second_user.is_a?(Resource::User) partnership_path(first_user.username, second_user.username) elsif first_user.is_a?(String) && second_user.is_a?(String) partnership_path(first_user, second_user) else raise 'Error: Invalid parameters!' end url = url_for_path(path) builder = Builder::Partnership.new(public_visible: Privacy::Public) block.call(builder) if block_given? begin client.put(url, builder.to_xml, options) do |response| a_hash = parse response Resource::Partnership.from_coach a_hash end rescue => e raise e if debug false end end
[ "def", "create_partnership", "(", "first_user", ",", "second_user", ",", "options", "=", "{", "}", ",", "&", "block", ")", "raise", "'Error: Param first_user is nil!'", "if", "first_user", ".", "nil?", "raise", "'Error: Param second_user is nil!'", "if", "second_user", ".", "nil?", "path", "=", "if", "first_user", ".", "is_a?", "(", "Resource", "::", "User", ")", "&&", "second_user", ".", "is_a?", "(", "Resource", "::", "User", ")", "partnership_path", "(", "first_user", ".", "username", ",", "second_user", ".", "username", ")", "elsif", "first_user", ".", "is_a?", "(", "String", ")", "&&", "second_user", ".", "is_a?", "(", "String", ")", "partnership_path", "(", "first_user", ",", "second_user", ")", "else", "raise", "'Error: Invalid parameters!'", "end", "url", "=", "url_for_path", "(", "path", ")", "builder", "=", "Builder", "::", "Partnership", ".", "new", "(", "public_visible", ":", "Privacy", "::", "Public", ")", "block", ".", "call", "(", "builder", ")", "if", "block_given?", "begin", "client", ".", "put", "(", "url", ",", "builder", ".", "to_xml", ",", "options", ")", "do", "|", "response", "|", "a_hash", "=", "parse", "response", "Resource", "::", "Partnership", ".", "from_coach", "a_hash", "end", "rescue", "=>", "e", "raise", "e", "if", "debug", "false", "end", "end" ]
Creates a partnership with public visibility as default. @param [User|String] first_user @param [User|String] second_user @param [Hash] options @return [Partnership] ====Examples @example @coach.create_partnership('arueedlinger','wanze2') @example @coach.create_partnership('arueedlinger','wanze2') do |p| p.public_visible = Coach4rb::Private end
[ "Creates", "a", "partnership", "with", "public", "visibility", "as", "default", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L217-L240
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.delete_partnership
def delete_partnership(partnership, options={}) raise 'Error: Param partnership is nil!' if partnership.nil? url = url_for_resource(partnership) begin client.delete(url, options) do |response| response.code == 200 end rescue => e raise e if debug false end end
ruby
def delete_partnership(partnership, options={}) raise 'Error: Param partnership is nil!' if partnership.nil? url = url_for_resource(partnership) begin client.delete(url, options) do |response| response.code == 200 end rescue => e raise e if debug false end end
[ "def", "delete_partnership", "(", "partnership", ",", "options", "=", "{", "}", ")", "raise", "'Error: Param partnership is nil!'", "if", "partnership", ".", "nil?", "url", "=", "url_for_resource", "(", "partnership", ")", "begin", "client", ".", "delete", "(", "url", ",", "options", ")", "do", "|", "response", "|", "response", ".", "code", "==", "200", "end", "rescue", "=>", "e", "raise", "e", "if", "debug", "false", "end", "end" ]
Deletes a partnership @param [Partnership] partnership @param [Hash] options @return [Boolean]
[ "Deletes", "a", "partnership" ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L249-L261
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.breakup_between
def breakup_between(first_user, second_user, options={}) raise 'Error: Param first_user is nil!' if first_user.nil? raise 'Error: Param second_user is nil!' if second_user.nil? path = if first_user.is_a?(Resource::User) && second_user.is_a?(Resource::User) partnership_path(first_user.username, second_user.username) elsif first_user.is_a?(String) && second_user.is_a?(String) partnership_path(first_user, second_user) else raise 'Error: Invalid parameters!' end url = url_for_path(path) begin client.delete(url, options) do |response| response.code == 200 end rescue => e raise e if debug false end end
ruby
def breakup_between(first_user, second_user, options={}) raise 'Error: Param first_user is nil!' if first_user.nil? raise 'Error: Param second_user is nil!' if second_user.nil? path = if first_user.is_a?(Resource::User) && second_user.is_a?(Resource::User) partnership_path(first_user.username, second_user.username) elsif first_user.is_a?(String) && second_user.is_a?(String) partnership_path(first_user, second_user) else raise 'Error: Invalid parameters!' end url = url_for_path(path) begin client.delete(url, options) do |response| response.code == 200 end rescue => e raise e if debug false end end
[ "def", "breakup_between", "(", "first_user", ",", "second_user", ",", "options", "=", "{", "}", ")", "raise", "'Error: Param first_user is nil!'", "if", "first_user", ".", "nil?", "raise", "'Error: Param second_user is nil!'", "if", "second_user", ".", "nil?", "path", "=", "if", "first_user", ".", "is_a?", "(", "Resource", "::", "User", ")", "&&", "second_user", ".", "is_a?", "(", "Resource", "::", "User", ")", "partnership_path", "(", "first_user", ".", "username", ",", "second_user", ".", "username", ")", "elsif", "first_user", ".", "is_a?", "(", "String", ")", "&&", "second_user", ".", "is_a?", "(", "String", ")", "partnership_path", "(", "first_user", ",", "second_user", ")", "else", "raise", "'Error: Invalid parameters!'", "end", "url", "=", "url_for_path", "(", "path", ")", "begin", "client", ".", "delete", "(", "url", ",", "options", ")", "do", "|", "response", "|", "response", ".", "code", "==", "200", "end", "rescue", "=>", "e", "raise", "e", "if", "debug", "false", "end", "end" ]
Breaks up a partnership between two users. @param [User|String] first_user @param [User|String] second_user @param [Hash] options @return [Boolean]
[ "Breaks", "up", "a", "partnership", "between", "two", "users", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L271-L291
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.create_subscription
def create_subscription(user_partnership, sport, options={}, &block) raise 'Error: Param user_partnership is nil!' if user_partnership.nil? raise 'Error: Param sport is nil!' if sport.nil? url = if user_partnership.is_a?(Resource::User) url_for_path(subscription_user_path(user_partnership.username, sport)) elsif user_partnership.is_a?(Resource::Partnership) first_username = user_partnership.first_user.username second_username = user_partnership.second_user.username url_for_path(subscription_partnership_path(first_username, second_username, sport)) elsif user_partnership.is_a?(String) url_for_uri(user_partnership) else raise 'Error: Invalid parameter!' end builder = Builder::Subscription.new(public_visible: Privacy::Public) block.call(builder) if block_given? begin client.put(url, builder.to_xml, options) do |response| a_hash = parse response Resource::Subscription.from_coach a_hash end rescue => e raise e if debug false end end
ruby
def create_subscription(user_partnership, sport, options={}, &block) raise 'Error: Param user_partnership is nil!' if user_partnership.nil? raise 'Error: Param sport is nil!' if sport.nil? url = if user_partnership.is_a?(Resource::User) url_for_path(subscription_user_path(user_partnership.username, sport)) elsif user_partnership.is_a?(Resource::Partnership) first_username = user_partnership.first_user.username second_username = user_partnership.second_user.username url_for_path(subscription_partnership_path(first_username, second_username, sport)) elsif user_partnership.is_a?(String) url_for_uri(user_partnership) else raise 'Error: Invalid parameter!' end builder = Builder::Subscription.new(public_visible: Privacy::Public) block.call(builder) if block_given? begin client.put(url, builder.to_xml, options) do |response| a_hash = parse response Resource::Subscription.from_coach a_hash end rescue => e raise e if debug false end end
[ "def", "create_subscription", "(", "user_partnership", ",", "sport", ",", "options", "=", "{", "}", ",", "&", "block", ")", "raise", "'Error: Param user_partnership is nil!'", "if", "user_partnership", ".", "nil?", "raise", "'Error: Param sport is nil!'", "if", "sport", ".", "nil?", "url", "=", "if", "user_partnership", ".", "is_a?", "(", "Resource", "::", "User", ")", "url_for_path", "(", "subscription_user_path", "(", "user_partnership", ".", "username", ",", "sport", ")", ")", "elsif", "user_partnership", ".", "is_a?", "(", "Resource", "::", "Partnership", ")", "first_username", "=", "user_partnership", ".", "first_user", ".", "username", "second_username", "=", "user_partnership", ".", "second_user", ".", "username", "url_for_path", "(", "subscription_partnership_path", "(", "first_username", ",", "second_username", ",", "sport", ")", ")", "elsif", "user_partnership", ".", "is_a?", "(", "String", ")", "url_for_uri", "(", "user_partnership", ")", "else", "raise", "'Error: Invalid parameter!'", "end", "builder", "=", "Builder", "::", "Subscription", ".", "new", "(", "public_visible", ":", "Privacy", "::", "Public", ")", "block", ".", "call", "(", "builder", ")", "if", "block_given?", "begin", "client", ".", "put", "(", "url", ",", "builder", ".", "to_xml", ",", "options", ")", "do", "|", "response", "|", "a_hash", "=", "parse", "response", "Resource", "::", "Subscription", ".", "from_coach", "a_hash", "end", "rescue", "=>", "e", "raise", "e", "if", "debug", "false", "end", "end" ]
Creates a subscription with public visibility as default. @param [User|Partnership|String] user_partnership @param [String] sport @param [Hash] options @param [Block] block @return [Subscription] ====Examples @example @coach.create_subscription(user, :boxing) do |subscription| subscription.public_visible = Coach4rb::Privacy::Public end @example @coach.create_subscription(user, :boxing) @example partnership = @coach.partnership 'arueedlinger', 'asarteam5' @coach.subscribe(partnership, :running)
[ "Creates", "a", "subscription", "with", "public", "visibility", "as", "default", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L315-L343
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.create_entry
def create_entry(user_partnership, sport, options={}, &block) raise 'Error: Param user_partnership is nil!' if user_partnership.nil? raise 'Error: Param sport is nil!' if sport.nil? entry_type = sport.downcase.to_sym builder = Builder::Entry.builder(entry_type) url = if user_partnership.is_a?(Resource::Entity) url_for_resource(user_partnership) + sport.to_s elsif user_partnership.is_a?(String) url_for_uri(user_partnership) + sport.to_s else raise 'Error: Invalid parameter!' end block.call(builder) if block_given? begin client.post(url, builder.to_xml, options) do |response| if uri = response.headers[:location] entry_by_uri(uri, options) else false end end rescue => e raise e if debug false end end
ruby
def create_entry(user_partnership, sport, options={}, &block) raise 'Error: Param user_partnership is nil!' if user_partnership.nil? raise 'Error: Param sport is nil!' if sport.nil? entry_type = sport.downcase.to_sym builder = Builder::Entry.builder(entry_type) url = if user_partnership.is_a?(Resource::Entity) url_for_resource(user_partnership) + sport.to_s elsif user_partnership.is_a?(String) url_for_uri(user_partnership) + sport.to_s else raise 'Error: Invalid parameter!' end block.call(builder) if block_given? begin client.post(url, builder.to_xml, options) do |response| if uri = response.headers[:location] entry_by_uri(uri, options) else false end end rescue => e raise e if debug false end end
[ "def", "create_entry", "(", "user_partnership", ",", "sport", ",", "options", "=", "{", "}", ",", "&", "block", ")", "raise", "'Error: Param user_partnership is nil!'", "if", "user_partnership", ".", "nil?", "raise", "'Error: Param sport is nil!'", "if", "sport", ".", "nil?", "entry_type", "=", "sport", ".", "downcase", ".", "to_sym", "builder", "=", "Builder", "::", "Entry", ".", "builder", "(", "entry_type", ")", "url", "=", "if", "user_partnership", ".", "is_a?", "(", "Resource", "::", "Entity", ")", "url_for_resource", "(", "user_partnership", ")", "+", "sport", ".", "to_s", "elsif", "user_partnership", ".", "is_a?", "(", "String", ")", "url_for_uri", "(", "user_partnership", ")", "+", "sport", ".", "to_s", "else", "raise", "'Error: Invalid parameter!'", "end", "block", ".", "call", "(", "builder", ")", "if", "block_given?", "begin", "client", ".", "post", "(", "url", ",", "builder", ".", "to_xml", ",", "options", ")", "do", "|", "response", "|", "if", "uri", "=", "response", ".", "headers", "[", ":location", "]", "entry_by_uri", "(", "uri", ",", "options", ")", "else", "false", "end", "end", "rescue", "=>", "e", "raise", "e", "if", "debug", "false", "end", "end" ]
Creates an entry with public visibility as default. @param [User|Partnership|String] user_partnership @param [Hash] options @param [Block] block @return [Entry|Boolean] ====Examples @example entry = @coach.create_entry(@user, :running) do |e| e.comment = 'test' e.number_of_rounds = 10 e.public_visible = Coach4rb::Privacy::Public end @example entry = @coach.create_entry(@user, :soccer) do |e| e.comment = 'test' e.number_of_rounds = 10 end
[ "Creates", "an", "entry", "with", "public", "visibility", "as", "default", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L432-L461
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.update_entry
def update_entry(entry, options={}, &block) raise 'Error: Param entry is nil!' if entry.nil? url, entry_type = if entry.is_a?(Resource::Entry) [url_for_resource(entry), entry.type] else *, type, id = url_for_uri(entry).split('/') type = type.downcase.to_sym [url_for_uri(entry), type] end builder = Builder::Entry.builder(entry_type) block.call(builder) begin client.put(url, builder.to_xml, options) do |response| a_hash = parse(response) Resource::Entry.from_coach a_hash end rescue => e raise e if debug false end end
ruby
def update_entry(entry, options={}, &block) raise 'Error: Param entry is nil!' if entry.nil? url, entry_type = if entry.is_a?(Resource::Entry) [url_for_resource(entry), entry.type] else *, type, id = url_for_uri(entry).split('/') type = type.downcase.to_sym [url_for_uri(entry), type] end builder = Builder::Entry.builder(entry_type) block.call(builder) begin client.put(url, builder.to_xml, options) do |response| a_hash = parse(response) Resource::Entry.from_coach a_hash end rescue => e raise e if debug false end end
[ "def", "update_entry", "(", "entry", ",", "options", "=", "{", "}", ",", "&", "block", ")", "raise", "'Error: Param entry is nil!'", "if", "entry", ".", "nil?", "url", ",", "entry_type", "=", "if", "entry", ".", "is_a?", "(", "Resource", "::", "Entry", ")", "[", "url_for_resource", "(", "entry", ")", ",", "entry", ".", "type", "]", "else", "*", ",", "type", ",", "id", "=", "url_for_uri", "(", "entry", ")", ".", "split", "(", "'/'", ")", "type", "=", "type", ".", "downcase", ".", "to_sym", "[", "url_for_uri", "(", "entry", ")", ",", "type", "]", "end", "builder", "=", "Builder", "::", "Entry", ".", "builder", "(", "entry_type", ")", "block", ".", "call", "(", "builder", ")", "begin", "client", ".", "put", "(", "url", ",", "builder", ".", "to_xml", ",", "options", ")", "do", "|", "response", "|", "a_hash", "=", "parse", "(", "response", ")", "Resource", "::", "Entry", ".", "from_coach", "a_hash", "end", "rescue", "=>", "e", "raise", "e", "if", "debug", "false", "end", "end" ]
Updates an entry. @param [Entry|String] entry @param [Hash] options @param [Block] block @return [Entry|Boolean] ====Examples @example entry = @coach.entry_by_uri '/CyberCoachServer/resources/users/wantsomemoney/Running/1138/' updated_entry = @proxy.update_entry(entry) do |entry| entry.comment = 'Test!!' end @example uri = '/CyberCoachServer/resources/users/wantsomemoney/Running/1138/' res = @proxy.update_entry(uri) do |entry| entry.comment = 'Test!' end
[ "Updates", "an", "entry", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L484-L506
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.delete_entry
def delete_entry(entry, options={}) raise 'Error: Param entry is nil!' if entry.nil? url = if entry.is_a?(Resource::Entry) url_for_resource(entry) elsif entry.is_a?(String) url_for_uri(entry) else raise 'Error: Invalid parameter!' end begin client.delete(url, options) do |response| response.code == 200 end rescue => e raise e if debug false end end
ruby
def delete_entry(entry, options={}) raise 'Error: Param entry is nil!' if entry.nil? url = if entry.is_a?(Resource::Entry) url_for_resource(entry) elsif entry.is_a?(String) url_for_uri(entry) else raise 'Error: Invalid parameter!' end begin client.delete(url, options) do |response| response.code == 200 end rescue => e raise e if debug false end end
[ "def", "delete_entry", "(", "entry", ",", "options", "=", "{", "}", ")", "raise", "'Error: Param entry is nil!'", "if", "entry", ".", "nil?", "url", "=", "if", "entry", ".", "is_a?", "(", "Resource", "::", "Entry", ")", "url_for_resource", "(", "entry", ")", "elsif", "entry", ".", "is_a?", "(", "String", ")", "url_for_uri", "(", "entry", ")", "else", "raise", "'Error: Invalid parameter!'", "end", "begin", "client", ".", "delete", "(", "url", ",", "options", ")", "do", "|", "response", "|", "response", ".", "code", "==", "200", "end", "rescue", "=>", "e", "raise", "e", "if", "debug", "false", "end", "end" ]
Deletes an entry.. @param [Entry|String] entry @param [Hash] options @return [Boolean]
[ "Deletes", "an", "entry", ".." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L515-L533
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.user
def user(user, options={}) raise 'Error: Param user is nil!' if user.nil? url = if user.is_a?(Resource::User) url_for_resource(user) elsif user.is_a?(String) url_for_path(user_path(user)) else raise 'Error: Invalid parameter!' end url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::User.from_coach a_hash end end
ruby
def user(user, options={}) raise 'Error: Param user is nil!' if user.nil? url = if user.is_a?(Resource::User) url_for_resource(user) elsif user.is_a?(String) url_for_path(user_path(user)) else raise 'Error: Invalid parameter!' end url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::User.from_coach a_hash end end
[ "def", "user", "(", "user", ",", "options", "=", "{", "}", ")", "raise", "'Error: Param user is nil!'", "if", "user", ".", "nil?", "url", "=", "if", "user", ".", "is_a?", "(", "Resource", "::", "User", ")", "url_for_resource", "(", "user", ")", "elsif", "user", ".", "is_a?", "(", "String", ")", "url_for_path", "(", "user_path", "(", "user", ")", ")", "else", "raise", "'Error: Invalid parameter!'", "end", "url", "=", "append_query_params", "(", "url", ",", "options", ")", "client", ".", "get", "(", "url", ",", "options", ")", "do", "|", "response", "|", "a_hash", "=", "parse", "(", "response", ")", "Resource", "::", "User", ".", "from_coach", "a_hash", "end", "end" ]
Retrieves a user by its username. @param [String|User] username | user @param [Hash] options @return [User] ====Examples @example user = @coach.user a_user @example user = @coach.user 'arueedlinger' @example user = @coach.user 'arueedlinger', query: { start: 0, soze: 10 }
[ "Retrieves", "a", "user", "by", "its", "username", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L550-L565
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.user_by_uri
def user_by_uri(uri, options={}) raise 'Error: Param uri is nil!' if uri.nil? url = url_for_uri(uri) url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::User.from_coach a_hash end end
ruby
def user_by_uri(uri, options={}) raise 'Error: Param uri is nil!' if uri.nil? url = url_for_uri(uri) url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::User.from_coach a_hash end end
[ "def", "user_by_uri", "(", "uri", ",", "options", "=", "{", "}", ")", "raise", "'Error: Param uri is nil!'", "if", "uri", ".", "nil?", "url", "=", "url_for_uri", "(", "uri", ")", "url", "=", "append_query_params", "(", "url", ",", "options", ")", "client", ".", "get", "(", "url", ",", "options", ")", "do", "|", "response", "|", "a_hash", "=", "parse", "(", "response", ")", "Resource", "::", "User", ".", "from_coach", "a_hash", "end", "end" ]
Retrieves a user by its uri. @param [String] uri @param [Hash] options @return [User] ====Examples @example user = @coach.user_by_uri '/CyberCoachServer/resources/users/arueedlinger', query: { start: 0, soze: 10 } @example user = @coach.user_by_uri '/CyberCoachServer/resources/users/arueedlinger'
[ "Retrieves", "a", "user", "by", "its", "uri", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L581-L590
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.users
def users(options={query: {}}) url = url_for_path(user_path) url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::Page.from_coach a_hash, Resource::User end end
ruby
def users(options={query: {}}) url = url_for_path(user_path) url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::Page.from_coach a_hash, Resource::User end end
[ "def", "users", "(", "options", "=", "{", "query", ":", "{", "}", "}", ")", "url", "=", "url_for_path", "(", "user_path", ")", "url", "=", "append_query_params", "(", "url", ",", "options", ")", "client", ".", "get", "(", "url", ",", "options", ")", "do", "|", "response", "|", "a_hash", "=", "parse", "(", "response", ")", "Resource", "::", "Page", ".", "from_coach", "a_hash", ",", "Resource", "::", "User", "end", "end" ]
Retrieves users. @param [Hash] options @return [PageResource] ====Examples @example users = @coach.users @example users = @coach.users query: { start: 0, size: 10}
[ "Retrieves", "users", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L604-L611
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.partnership_by_uri
def partnership_by_uri(uri, options={}) raise 'Error: Param uri is nil!' if uri.nil? url = url_for_uri(uri) url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::Partnership.from_coach a_hash end end
ruby
def partnership_by_uri(uri, options={}) raise 'Error: Param uri is nil!' if uri.nil? url = url_for_uri(uri) url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::Partnership.from_coach a_hash end end
[ "def", "partnership_by_uri", "(", "uri", ",", "options", "=", "{", "}", ")", "raise", "'Error: Param uri is nil!'", "if", "uri", ".", "nil?", "url", "=", "url_for_uri", "(", "uri", ")", "url", "=", "append_query_params", "(", "url", ",", "options", ")", "client", ".", "get", "(", "url", ",", "options", ")", "do", "|", "response", "|", "a_hash", "=", "parse", "(", "response", ")", "Resource", "::", "Partnership", ".", "from_coach", "a_hash", "end", "end" ]
Retrieves a partnership by its uri. @param [String] uri @param [Hash] options @return [Partnership] ====Examples @example partnership = @coach.partnership_by_uri '/CyberCoachServer/resources/partnerships/arueedlinger;asarteam5/'
[ "Retrieves", "a", "partnership", "by", "its", "uri", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L624-L633
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.partnership
def partnership(first_username, second_username, options={}) raise 'Error: Param first_username is nil!' if first_username.nil? raise 'Error: Param second_username is nil!' if second_username.nil? url = url_for_path(partnership_path(first_username, second_username)) url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::Partnership.from_coach a_hash end end
ruby
def partnership(first_username, second_username, options={}) raise 'Error: Param first_username is nil!' if first_username.nil? raise 'Error: Param second_username is nil!' if second_username.nil? url = url_for_path(partnership_path(first_username, second_username)) url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::Partnership.from_coach a_hash end end
[ "def", "partnership", "(", "first_username", ",", "second_username", ",", "options", "=", "{", "}", ")", "raise", "'Error: Param first_username is nil!'", "if", "first_username", ".", "nil?", "raise", "'Error: Param second_username is nil!'", "if", "second_username", ".", "nil?", "url", "=", "url_for_path", "(", "partnership_path", "(", "first_username", ",", "second_username", ")", ")", "url", "=", "append_query_params", "(", "url", ",", "options", ")", "client", ".", "get", "(", "url", ",", "options", ")", "do", "|", "response", "|", "a_hash", "=", "parse", "(", "response", ")", "Resource", "::", "Partnership", ".", "from_coach", "a_hash", "end", "end" ]
Retrieves a partnership by the first username and second username. @param [String] first_username @param [String] second_username @param [Hash] options @return [Partnership] ====Examples @example partnership = @coach.partnership 'arueedlinger', 'asarteam5'
[ "Retrieves", "a", "partnership", "by", "the", "first", "username", "and", "second", "username", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L647-L657
train
lexruee/coach4rb
lib/coach4rb/coach.rb
Coach4rb.Coach.partnerships
def partnerships(options={query: {}}) url = url_for_path(partnership_path) url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::Page.from_coach a_hash, Resource::Partnership end end
ruby
def partnerships(options={query: {}}) url = url_for_path(partnership_path) url = append_query_params(url, options) client.get(url, options) do |response| a_hash = parse(response) Resource::Page.from_coach a_hash, Resource::Partnership end end
[ "def", "partnerships", "(", "options", "=", "{", "query", ":", "{", "}", "}", ")", "url", "=", "url_for_path", "(", "partnership_path", ")", "url", "=", "append_query_params", "(", "url", ",", "options", ")", "client", ".", "get", "(", "url", ",", "options", ")", "do", "|", "response", "|", "a_hash", "=", "parse", "(", "response", ")", "Resource", "::", "Page", ".", "from_coach", "a_hash", ",", "Resource", "::", "Partnership", "end", "end" ]
Retrieves partnerships. @param [Hash] options @return [PageResource] ====Examples @example partnerships = @coach.partnerships @example partnerships = @coach.partnerships query: { start: 0, size: 10}
[ "Retrieves", "partnerships", "." ]
59105bfe45a0717e655e0deff4d1540d511f6b02
https://github.com/lexruee/coach4rb/blob/59105bfe45a0717e655e0deff4d1540d511f6b02/lib/coach4rb/coach.rb#L671-L678
train
NUBIC/aker
lib/aker/form/middleware/logout_responder.rb
Aker::Form::Middleware.LogoutResponder.call
def call(env) if env['REQUEST_METHOD'] == 'GET' && env['PATH_INFO'] == logout_path(env) ::Rack::Response.new(login_html(env, :logged_out => true)) do |resp| resp['Content-Type'] = 'text/html' end.finish else @app.call(env) end end
ruby
def call(env) if env['REQUEST_METHOD'] == 'GET' && env['PATH_INFO'] == logout_path(env) ::Rack::Response.new(login_html(env, :logged_out => true)) do |resp| resp['Content-Type'] = 'text/html' end.finish else @app.call(env) end end
[ "def", "call", "(", "env", ")", "if", "env", "[", "'REQUEST_METHOD'", "]", "==", "'GET'", "&&", "env", "[", "'PATH_INFO'", "]", "==", "logout_path", "(", "env", ")", "::", "Rack", "::", "Response", ".", "new", "(", "login_html", "(", "env", ",", ":logged_out", "=>", "true", ")", ")", "do", "|", "resp", "|", "resp", "[", "'Content-Type'", "]", "=", "'text/html'", "end", ".", "finish", "else", "@app", ".", "call", "(", "env", ")", "end", "end" ]
When given `GET` to the configured logout path, builds a Rack response containing the login form with a "you have been logged out" notification. Otherwise, passes the response on. @return a finished Rack response
[ "When", "given", "GET", "to", "the", "configured", "logout", "path", "builds", "a", "Rack", "response", "containing", "the", "login", "form", "with", "a", "you", "have", "been", "logged", "out", "notification", ".", "Otherwise", "passes", "the", "response", "on", "." ]
ff43606a8812e38f96bbe71b46e7f631cbeacf1c
https://github.com/NUBIC/aker/blob/ff43606a8812e38f96bbe71b46e7f631cbeacf1c/lib/aker/form/middleware/logout_responder.rb#L18-L26
train
visagio/render_super
lib/render_super.rb
RenderSuper.InstanceMethods.render_with_super
def render_with_super(*args, &block) if args.first == :super last_view = view_stack.last || {:view => instance_variable_get(:@virtual_path).split('/').last} options = args[1] || {} options[:locals] ||= {} options[:locals].reverse_merge!(last_view[:locals] || {}) if last_view[:templates].nil? last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals].keys) last_view[:templates].shift end options[:template] = last_view[:templates].shift view_stack << last_view result = render_without_super options view_stack.pop result else options = args.first if options.is_a?(Hash) current_view = {:view => options[:partial], :partial => true} if options[:partial] current_view = {:view => options[:template], :partial => false} if current_view.nil? && options[:template] current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals] view_stack << current_view if current_view.present? end result = render_without_super(*args, &block) view_stack.pop if current_view.present? result end end
ruby
def render_with_super(*args, &block) if args.first == :super last_view = view_stack.last || {:view => instance_variable_get(:@virtual_path).split('/').last} options = args[1] || {} options[:locals] ||= {} options[:locals].reverse_merge!(last_view[:locals] || {}) if last_view[:templates].nil? last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals].keys) last_view[:templates].shift end options[:template] = last_view[:templates].shift view_stack << last_view result = render_without_super options view_stack.pop result else options = args.first if options.is_a?(Hash) current_view = {:view => options[:partial], :partial => true} if options[:partial] current_view = {:view => options[:template], :partial => false} if current_view.nil? && options[:template] current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals] view_stack << current_view if current_view.present? end result = render_without_super(*args, &block) view_stack.pop if current_view.present? result end end
[ "def", "render_with_super", "(", "*", "args", ",", "&", "block", ")", "if", "args", ".", "first", "==", ":super", "last_view", "=", "view_stack", ".", "last", "||", "{", ":view", "=>", "instance_variable_get", "(", ":@virtual_path", ")", ".", "split", "(", "'/'", ")", ".", "last", "}", "options", "=", "args", "[", "1", "]", "||", "{", "}", "options", "[", ":locals", "]", "||=", "{", "}", "options", "[", ":locals", "]", ".", "reverse_merge!", "(", "last_view", "[", ":locals", "]", "||", "{", "}", ")", "if", "last_view", "[", ":templates", "]", ".", "nil?", "last_view", "[", ":templates", "]", "=", "lookup_context", ".", "find_all_templates", "(", "last_view", "[", ":view", "]", ",", "last_view", "[", ":partial", "]", ",", "options", "[", ":locals", "]", ".", "keys", ")", "last_view", "[", ":templates", "]", ".", "shift", "end", "options", "[", ":template", "]", "=", "last_view", "[", ":templates", "]", ".", "shift", "view_stack", "<<", "last_view", "result", "=", "render_without_super", "options", "view_stack", ".", "pop", "result", "else", "options", "=", "args", ".", "first", "if", "options", ".", "is_a?", "(", "Hash", ")", "current_view", "=", "{", ":view", "=>", "options", "[", ":partial", "]", ",", ":partial", "=>", "true", "}", "if", "options", "[", ":partial", "]", "current_view", "=", "{", ":view", "=>", "options", "[", ":template", "]", ",", ":partial", "=>", "false", "}", "if", "current_view", ".", "nil?", "&&", "options", "[", ":template", "]", "current_view", "[", ":locals", "]", "=", "options", "[", ":locals", "]", "if", "!", "current_view", ".", "nil?", "&&", "options", "[", ":locals", "]", "view_stack", "<<", "current_view", "if", "current_view", ".", "present?", "end", "result", "=", "render_without_super", "(", "args", ",", "block", ")", "view_stack", ".", "pop", "if", "current_view", ".", "present?", "result", "end", "end" ]
Adds rendering option. ==render :super This renders the "super" template, i.e. the one hidden by the plugin
[ "Adds", "rendering", "option", "." ]
680fdfda19233ca81ed851ae83a9eda99030a9a1
https://github.com/visagio/render_super/blob/680fdfda19233ca81ed851ae83a9eda99030a9a1/lib/render_super.rb#L42-L69
train
simonswine/php_fpm_docker
lib/php_fpm_docker/pool.rb
PhpFpmDocker.Pool.bind_mounts
def bind_mounts ret_val = @launcher.bind_mounts ret_val << File.dirname(@config['listen']) ret_val += valid_web_paths ret_val.uniq end
ruby
def bind_mounts ret_val = @launcher.bind_mounts ret_val << File.dirname(@config['listen']) ret_val += valid_web_paths ret_val.uniq end
[ "def", "bind_mounts", "ret_val", "=", "@launcher", ".", "bind_mounts", "ret_val", "<<", "File", ".", "dirname", "(", "@config", "[", "'listen'", "]", ")", "ret_val", "+=", "valid_web_paths", "ret_val", ".", "uniq", "end" ]
Find out bind mount paths
[ "Find", "out", "bind", "mount", "paths" ]
2d7ab79fb6394a6a3f90457f58fb584cd916ffcd
https://github.com/simonswine/php_fpm_docker/blob/2d7ab79fb6394a6a3f90457f58fb584cd916ffcd/lib/php_fpm_docker/pool.rb#L60-L65
train
simonswine/php_fpm_docker
lib/php_fpm_docker/pool.rb
PhpFpmDocker.Pool.spawn_command
def spawn_command [ @launcher.spawn_cmd_path, '-s', @config['listen'], '-U', listen_uid.to_s, '-G', listen_gid.to_s, '-M', '0660', '-u', uid.to_s, '-g', gid.to_s, '-C', '4', '-n' ] end
ruby
def spawn_command [ @launcher.spawn_cmd_path, '-s', @config['listen'], '-U', listen_uid.to_s, '-G', listen_gid.to_s, '-M', '0660', '-u', uid.to_s, '-g', gid.to_s, '-C', '4', '-n' ] end
[ "def", "spawn_command", "[", "@launcher", ".", "spawn_cmd_path", ",", "'-s'", ",", "@config", "[", "'listen'", "]", ",", "'-U'", ",", "listen_uid", ".", "to_s", ",", "'-G'", ",", "listen_gid", ".", "to_s", ",", "'-M'", ",", "'0660'", ",", "'-u'", ",", "uid", ".", "to_s", ",", "'-g'", ",", "gid", ".", "to_s", ",", "'-C'", ",", "'4'", ",", "'-n'", "]", "end" ]
Build the spawn command
[ "Build", "the", "spawn", "command" ]
2d7ab79fb6394a6a3f90457f58fb584cd916ffcd
https://github.com/simonswine/php_fpm_docker/blob/2d7ab79fb6394a6a3f90457f58fb584cd916ffcd/lib/php_fpm_docker/pool.rb#L104-L116
train
dannguyen/active_scraper
app/models/active_scraper/cached_request.rb
ActiveScraper.CachedRequest.to_uri
def to_uri h = self.attributes.symbolize_keys.slice(:scheme, :host, :path) h[:query] = self.unobfuscated_query || self.query return Addressable::URI.new(h) end
ruby
def to_uri h = self.attributes.symbolize_keys.slice(:scheme, :host, :path) h[:query] = self.unobfuscated_query || self.query return Addressable::URI.new(h) end
[ "def", "to_uri", "h", "=", "self", ".", "attributes", ".", "symbolize_keys", ".", "slice", "(", ":scheme", ",", ":host", ",", ":path", ")", "h", "[", ":query", "]", "=", "self", ".", "unobfuscated_query", "||", "self", ".", "query", "return", "Addressable", "::", "URI", ".", "new", "(", "h", ")", "end" ]
during a fresh query, we need to actually use the unobfuscated_query
[ "during", "a", "fresh", "query", "we", "need", "to", "actually", "use", "the", "unobfuscated_query" ]
f6d24ea99d4851f7bae69a2080863b58bb6b7266
https://github.com/dannguyen/active_scraper/blob/f6d24ea99d4851f7bae69a2080863b58bb6b7266/app/models/active_scraper/cached_request.rb#L68-L73
train
zaypay/zaypay_gem
lib/zaypay/price_setting.rb
Zaypay.PriceSetting.locale_string_for_ip
def locale_string_for_ip(ip) get "/#{ip}/pay/#{price_setting_id}/locale_for_ip" do |data| parts = data[:locale].split('-') Zaypay::Util.stringify_locale_hash({:country => parts[1], :language => parts[0]}) end end
ruby
def locale_string_for_ip(ip) get "/#{ip}/pay/#{price_setting_id}/locale_for_ip" do |data| parts = data[:locale].split('-') Zaypay::Util.stringify_locale_hash({:country => parts[1], :language => parts[0]}) end end
[ "def", "locale_string_for_ip", "(", "ip", ")", "get", "\"/#{ip}/pay/#{price_setting_id}/locale_for_ip\"", "do", "|", "data", "|", "parts", "=", "data", "[", ":locale", "]", ".", "split", "(", "'-'", ")", "Zaypay", "::", "Util", ".", "stringify_locale_hash", "(", "{", ":country", "=>", "parts", "[", "1", "]", ",", ":language", "=>", "parts", "[", "0", "]", "}", ")", "end", "end" ]
Returns the default locale as a string for a given ip_address, with the first part representing the language, the second part the country This method comes in handy when you want to preselect the language and country when your customer creates a payment on your website. = Example: # We take an ip-address from Great Britain for example: ip = "212.58.226.75" @price_setting.locale_string_for_ip(ip) => 'en-GB' Also see {#locale_for_ip} @param [String] ip an ip-address (e.g. from your site's visitors) @return [String] a string that represents the default locale for the given IP, in a language-country format.
[ "Returns", "the", "default", "locale", "as", "a", "string", "for", "a", "given", "ip_address", "with", "the", "first", "part", "representing", "the", "language", "the", "second", "part", "the", "country" ]
8001736687c8c7e98c6cbe7078194529ff02f6fb
https://github.com/zaypay/zaypay_gem/blob/8001736687c8c7e98c6cbe7078194529ff02f6fb/lib/zaypay/price_setting.rb#L56-L61
train
zaypay/zaypay_gem
lib/zaypay/price_setting.rb
Zaypay.PriceSetting.country_has_been_configured_for_ip
def country_has_been_configured_for_ip(ip, options={}) # options can take a :amount key locale = locale_for_ip(ip) country = list_countries(options).select{ |c| c.has_value? locale[:country] }.first {:country => country, :locale => locale} if country end
ruby
def country_has_been_configured_for_ip(ip, options={}) # options can take a :amount key locale = locale_for_ip(ip) country = list_countries(options).select{ |c| c.has_value? locale[:country] }.first {:country => country, :locale => locale} if country end
[ "def", "country_has_been_configured_for_ip", "(", "ip", ",", "options", "=", "{", "}", ")", "# options can take a :amount key", "locale", "=", "locale_for_ip", "(", "ip", ")", "country", "=", "list_countries", "(", "options", ")", ".", "select", "{", "|", "c", "|", "c", ".", "has_value?", "locale", "[", ":country", "]", "}", ".", "first", "{", ":country", "=>", "country", ",", ":locale", "=>", "locale", "}", "if", "country", "end" ]
Returns a country as a Hash, if the country of the given IP has been configured for your Price Setting. If the country of the given IP has been configured for this Price Setting, it returns a hash with *:country* and *:locale* subhashes, else it returns *nil*. @param [String] ip an ip-address (e.g. from your site's visitors) @return [Hash] a hash containing *:country* and *:locale* subhashes
[ "Returns", "a", "country", "as", "a", "Hash", "if", "the", "country", "of", "the", "given", "IP", "has", "been", "configured", "for", "your", "Price", "Setting", "." ]
8001736687c8c7e98c6cbe7078194529ff02f6fb
https://github.com/zaypay/zaypay_gem/blob/8001736687c8c7e98c6cbe7078194529ff02f6fb/lib/zaypay/price_setting.rb#L89-L94
train
zaypay/zaypay_gem
lib/zaypay/price_setting.rb
Zaypay.PriceSetting.list_payment_methods
def list_payment_methods(options={}) raise Zaypay::Error.new(:locale_not_set, "locale was not set for your price setting") if @locale.nil? get "/#{options[:amount]}/#{@locale}/pay/#{price_setting_id}/payments/new" do |data| Zaypay::Util.arrayify_if_not_an_array(data[:payment_methods][:payment_method]) end end
ruby
def list_payment_methods(options={}) raise Zaypay::Error.new(:locale_not_set, "locale was not set for your price setting") if @locale.nil? get "/#{options[:amount]}/#{@locale}/pay/#{price_setting_id}/payments/new" do |data| Zaypay::Util.arrayify_if_not_an_array(data[:payment_methods][:payment_method]) end end
[ "def", "list_payment_methods", "(", "options", "=", "{", "}", ")", "raise", "Zaypay", "::", "Error", ".", "new", "(", ":locale_not_set", ",", "\"locale was not set for your price setting\"", ")", "if", "@locale", ".", "nil?", "get", "\"/#{options[:amount]}/#{@locale}/pay/#{price_setting_id}/payments/new\"", "do", "|", "data", "|", "Zaypay", "::", "Util", ".", "arrayify_if_not_an_array", "(", "data", "[", ":payment_methods", "]", "[", ":payment_method", "]", ")", "end", "end" ]
Returns an array of payment methods that are available to your Price Setting with a given locale @param [Hash] options an options-hash that can take an *:amount* option, in case you want to use dynamic amounts @return [Array] an array of payment methods, each represented by a hash. @raise [Zaypay::Error] in case you call this method before setting a locale
[ "Returns", "an", "array", "of", "payment", "methods", "that", "are", "available", "to", "your", "Price", "Setting", "with", "a", "given", "locale" ]
8001736687c8c7e98c6cbe7078194529ff02f6fb
https://github.com/zaypay/zaypay_gem/blob/8001736687c8c7e98c6cbe7078194529ff02f6fb/lib/zaypay/price_setting.rb#L132-L137
train
zaypay/zaypay_gem
lib/zaypay/price_setting.rb
Zaypay.PriceSetting.create_payment
def create_payment(options={}) raise Zaypay::Error.new(:locale_not_set, "locale was not set for your price setting") if @locale.nil? raise Zaypay::Error.new(:payment_method_id_not_set, "payment_method_id was not set for your price setting") if @payment_method_id.nil? query = {:payment_method_id => payment_method_id} query.merge!(options) amount = query.delete(:amount) post "/#{amount}/#{@locale}/pay/#{price_setting_id}/payments", query do |data| payment_hash data end end
ruby
def create_payment(options={}) raise Zaypay::Error.new(:locale_not_set, "locale was not set for your price setting") if @locale.nil? raise Zaypay::Error.new(:payment_method_id_not_set, "payment_method_id was not set for your price setting") if @payment_method_id.nil? query = {:payment_method_id => payment_method_id} query.merge!(options) amount = query.delete(:amount) post "/#{amount}/#{@locale}/pay/#{price_setting_id}/payments", query do |data| payment_hash data end end
[ "def", "create_payment", "(", "options", "=", "{", "}", ")", "raise", "Zaypay", "::", "Error", ".", "new", "(", ":locale_not_set", ",", "\"locale was not set for your price setting\"", ")", "if", "@locale", ".", "nil?", "raise", "Zaypay", "::", "Error", ".", "new", "(", ":payment_method_id_not_set", ",", "\"payment_method_id was not set for your price setting\"", ")", "if", "@payment_method_id", ".", "nil?", "query", "=", "{", ":payment_method_id", "=>", "payment_method_id", "}", "query", ".", "merge!", "(", "options", ")", "amount", "=", "query", ".", "delete", "(", ":amount", ")", "post", "\"/#{amount}/#{@locale}/pay/#{price_setting_id}/payments\"", ",", "query", "do", "|", "data", "|", "payment_hash", "data", "end", "end" ]
Creates a payment on the Zaypay platform. You can provide an options-hash, which will add additional data to your payment. The following keys have special functionalities: :amount # Enables dynamic pricing. It must be an integer representing the price in cents. :payalogue_id # Adds the URL of the payalogue specified to your payment as :payalogue_url. Any other keys will be added to a key named :your_variables, which can be used for your future reference. Please check the {file:/README.rdoc README} for the structure of the payment returned. = Example: @price_setting.create_payment(:payalogue_id => payalogue_id, :amount => optional_amount, :my_variable_1 => "value_1", :my_variable_2 => "value_2") @param [Hash] options an options-hash that can take an *:amount*, *:payalogue_id* as options, and any other keys can be used as your custom variables for your own reference @return [Hash] a hash containing data of the payment you just created @raise [Zaypay::Error] in case you call this method before setting a *locale* or a *payment_method_id*
[ "Creates", "a", "payment", "on", "the", "Zaypay", "platform", "." ]
8001736687c8c7e98c6cbe7078194529ff02f6fb
https://github.com/zaypay/zaypay_gem/blob/8001736687c8c7e98c6cbe7078194529ff02f6fb/lib/zaypay/price_setting.rb#L154-L163
train
ryym/dio
lib/dio/injector.rb
Dio.Injector.register
def register(key, object = nil) assert_register_args_valid(object, block_given?) @container.register(key) do |*args| object = yield(*args) if block_given? injectable?(object) ? inject(object) : object end self end
ruby
def register(key, object = nil) assert_register_args_valid(object, block_given?) @container.register(key) do |*args| object = yield(*args) if block_given? injectable?(object) ? inject(object) : object end self end
[ "def", "register", "(", "key", ",", "object", "=", "nil", ")", "assert_register_args_valid", "(", "object", ",", "block_given?", ")", "@container", ".", "register", "(", "key", ")", "do", "|", "*", "args", "|", "object", "=", "yield", "(", "args", ")", "if", "block_given?", "injectable?", "(", "object", ")", "?", "inject", "(", "object", ")", ":", "object", "end", "self", "end" ]
Registers a new dependency with the given key. You can specify either an object or a factory block that creates an object. @param key [Object] Typically a class or a symbol. @param object [Object] @yield passed arguments when loading @return [Dio::Injector] self
[ "Registers", "a", "new", "dependency", "with", "the", "given", "key", ".", "You", "can", "specify", "either", "an", "object", "or", "a", "factory", "block", "that", "creates", "an", "object", "." ]
4547c3e75d43be7bd73335576e5e5dc3a8fa7efd
https://github.com/ryym/dio/blob/4547c3e75d43be7bd73335576e5e5dc3a8fa7efd/lib/dio/injector.rb#L43-L50
train
ryym/dio
lib/dio/injector.rb
Dio.Injector.inject
def inject(target) unless injectable?(target) raise ArgumentError, 'The given object does not include Dio module' end loader = @loader_factory.create(@container, target) target.__dio_inject__(loader) target end
ruby
def inject(target) unless injectable?(target) raise ArgumentError, 'The given object does not include Dio module' end loader = @loader_factory.create(@container, target) target.__dio_inject__(loader) target end
[ "def", "inject", "(", "target", ")", "unless", "injectable?", "(", "target", ")", "raise", "ArgumentError", ",", "'The given object does not include Dio module'", "end", "loader", "=", "@loader_factory", ".", "create", "(", "@container", ",", "target", ")", "target", ".", "__dio_inject__", "(", "loader", ")", "target", "end" ]
Inject dependencies to the given object. @param target [Object] @return target
[ "Inject", "dependencies", "to", "the", "given", "object", "." ]
4547c3e75d43be7bd73335576e5e5dc3a8fa7efd
https://github.com/ryym/dio/blob/4547c3e75d43be7bd73335576e5e5dc3a8fa7efd/lib/dio/injector.rb#L56-L63
train
ryym/dio
lib/dio/injector.rb
Dio.Injector.create
def create(clazz, *args) raise ArgumentError, "#{clazz} is not a class" unless clazz.is_a?(Class) inject(clazz.new(*args)) end
ruby
def create(clazz, *args) raise ArgumentError, "#{clazz} is not a class" unless clazz.is_a?(Class) inject(clazz.new(*args)) end
[ "def", "create", "(", "clazz", ",", "*", "args", ")", "raise", "ArgumentError", ",", "\"#{clazz} is not a class\"", "unless", "clazz", ".", "is_a?", "(", "Class", ")", "inject", "(", "clazz", ".", "new", "(", "args", ")", ")", "end" ]
Creates a new instance of the given class. Dio injects dependencies to the created instance. @param clazz [Class] @param args [Array] @return Instance of clazz
[ "Creates", "a", "new", "instance", "of", "the", "given", "class", ".", "Dio", "injects", "dependencies", "to", "the", "created", "instance", "." ]
4547c3e75d43be7bd73335576e5e5dc3a8fa7efd
https://github.com/ryym/dio/blob/4547c3e75d43be7bd73335576e5e5dc3a8fa7efd/lib/dio/injector.rb#L71-L74
train
ryanlchan/bitmask_attributes_helpers
lib/bitmask_attributes_helpers.rb
BitmaskAttributesHelpers.ClassMethods.bitmask_scopes
def bitmask_scopes(bitmask) send("values_for_#{bitmask}").each do |value| scope value, send("with_#{bitmask}", value) scope "not_#{value}", send("without_#{bitmask}", value) end end
ruby
def bitmask_scopes(bitmask) send("values_for_#{bitmask}").each do |value| scope value, send("with_#{bitmask}", value) scope "not_#{value}", send("without_#{bitmask}", value) end end
[ "def", "bitmask_scopes", "(", "bitmask", ")", "send", "(", "\"values_for_#{bitmask}\"", ")", ".", "each", "do", "|", "value", "|", "scope", "value", ",", "send", "(", "\"with_#{bitmask}\"", ",", "value", ")", "scope", "\"not_#{value}\"", ",", "send", "(", "\"without_#{bitmask}\"", ",", "value", ")", "end", "end" ]
Setup scopes for Bitmask attributes Scopes are setup with the same name as the value, and include both .value and .not_value versions @arg [Symbol] bitmask the name of the bitmask attribute
[ "Setup", "scopes", "for", "Bitmask", "attributes" ]
5601e97fcb823547118d41fd2a9022e387379533
https://github.com/ryanlchan/bitmask_attributes_helpers/blob/5601e97fcb823547118d41fd2a9022e387379533/lib/bitmask_attributes_helpers.rb#L25-L30
train
ryanlchan/bitmask_attributes_helpers
lib/bitmask_attributes_helpers.rb
BitmaskAttributesHelpers.ClassMethods.bitmask_virtual_attributes
def bitmask_virtual_attributes(bitmask) send("values_for_#{bitmask}").each do |value| define_method("#{value}") { send("#{bitmask}?", value) } define_method("#{value}=") { |arg| send("#{bitmask}=", arg.blank? || arg == "0" ? send("#{bitmask}") - [value] : send("#{bitmask}") << value) } end end
ruby
def bitmask_virtual_attributes(bitmask) send("values_for_#{bitmask}").each do |value| define_method("#{value}") { send("#{bitmask}?", value) } define_method("#{value}=") { |arg| send("#{bitmask}=", arg.blank? || arg == "0" ? send("#{bitmask}") - [value] : send("#{bitmask}") << value) } end end
[ "def", "bitmask_virtual_attributes", "(", "bitmask", ")", "send", "(", "\"values_for_#{bitmask}\"", ")", ".", "each", "do", "|", "value", "|", "define_method", "(", "\"#{value}\"", ")", "{", "send", "(", "\"#{bitmask}?\"", ",", "value", ")", "}", "define_method", "(", "\"#{value}=\"", ")", "{", "|", "arg", "|", "send", "(", "\"#{bitmask}=\"", ",", "arg", ".", "blank?", "||", "arg", "==", "\"0\"", "?", "send", "(", "\"#{bitmask}\"", ")", "-", "[", "value", "]", ":", "send", "(", "\"#{bitmask}\"", ")", "<<", "value", ")", "}", "end", "end" ]
Setup virtual attributes for Bitmask attributes Allows you to set and read Bitmask attributes using #value= and #value methods @arg [Symbol] bitmask the name of the bitmask attribute
[ "Setup", "virtual", "attributes", "for", "Bitmask", "attributes" ]
5601e97fcb823547118d41fd2a9022e387379533
https://github.com/ryanlchan/bitmask_attributes_helpers/blob/5601e97fcb823547118d41fd2a9022e387379533/lib/bitmask_attributes_helpers.rb#L37-L42
train
fkchang/awesome_print_lite
lib/awesome_print_lite/formatter.rb
AwesomePrintLite.Formatter.awesome_hash
def awesome_hash(h) return "{}" if h == {} keys = @options[:sort_keys] ? h.keys.sort { |a, b| a.to_s <=> b.to_s } : h.keys data = keys.map do |key| plain_single_line do [ @inspector.awesome(key), h[key] ] end end width = data.map { |key, | key.size }.max || 0 width += @indentation if @options[:indent] > 0 data = data.map do |key, value| indented do align(key, width) + colorize(" => ", :hash) + @inspector.awesome(value) end end data = limited(data, width, :hash => true) if should_be_limited? if @options[:multiline] "{\n" + data.join(",\n") + "\n#{outdent}}" else "{ #{data.join(', ')} }" end end
ruby
def awesome_hash(h) return "{}" if h == {} keys = @options[:sort_keys] ? h.keys.sort { |a, b| a.to_s <=> b.to_s } : h.keys data = keys.map do |key| plain_single_line do [ @inspector.awesome(key), h[key] ] end end width = data.map { |key, | key.size }.max || 0 width += @indentation if @options[:indent] > 0 data = data.map do |key, value| indented do align(key, width) + colorize(" => ", :hash) + @inspector.awesome(value) end end data = limited(data, width, :hash => true) if should_be_limited? if @options[:multiline] "{\n" + data.join(",\n") + "\n#{outdent}}" else "{ #{data.join(', ')} }" end end
[ "def", "awesome_hash", "(", "h", ")", "return", "\"{}\"", "if", "h", "==", "{", "}", "keys", "=", "@options", "[", ":sort_keys", "]", "?", "h", ".", "keys", ".", "sort", "{", "|", "a", ",", "b", "|", "a", ".", "to_s", "<=>", "b", ".", "to_s", "}", ":", "h", ".", "keys", "data", "=", "keys", ".", "map", "do", "|", "key", "|", "plain_single_line", "do", "[", "@inspector", ".", "awesome", "(", "key", ")", ",", "h", "[", "key", "]", "]", "end", "end", "width", "=", "data", ".", "map", "{", "|", "key", ",", "|", "key", ".", "size", "}", ".", "max", "||", "0", "width", "+=", "@indentation", "if", "@options", "[", ":indent", "]", ">", "0", "data", "=", "data", ".", "map", "do", "|", "key", ",", "value", "|", "indented", "do", "align", "(", "key", ",", "width", ")", "+", "colorize", "(", "\" => \"", ",", ":hash", ")", "+", "@inspector", ".", "awesome", "(", "value", ")", "end", "end", "data", "=", "limited", "(", "data", ",", "width", ",", ":hash", "=>", "true", ")", "if", "should_be_limited?", "if", "@options", "[", ":multiline", "]", "\"{\\n\"", "+", "data", ".", "join", "(", "\",\\n\"", ")", "+", "\"\\n#{outdent}}\"", "else", "\"{ #{data.join(', ')} }\"", "end", "end" ]
Format a hash. If @options[:indent] if negative left align hash keys. ------------------------------------------------------------------------------
[ "Format", "a", "hash", ".", "If" ]
68302eb197d95f85308afce69f7a24f31b9b7dfd
https://github.com/fkchang/awesome_print_lite/blob/68302eb197d95f85308afce69f7a24f31b9b7dfd/lib/awesome_print_lite/formatter.rb#L107-L132
train
giraffi/ruby-orchestrate.io
lib/orchestrate.io/client.rb
OrchestrateIo.Client.request
def request(http_method, uri, options={}) response = self.class.__send__(http_method, uri, options.merge(basic_auth)) # Add some logger.debug here ... response end
ruby
def request(http_method, uri, options={}) response = self.class.__send__(http_method, uri, options.merge(basic_auth)) # Add some logger.debug here ... response end
[ "def", "request", "(", "http_method", ",", "uri", ",", "options", "=", "{", "}", ")", "response", "=", "self", ".", "class", ".", "__send__", "(", "http_method", ",", "uri", ",", "options", ".", "merge", "(", "basic_auth", ")", ")", "# Add some logger.debug here ...", "response", "end" ]
Entry point to HTTP request Set the username of basic auth to the API Key attribute.
[ "Entry", "point", "to", "HTTP", "request", "Set", "the", "username", "of", "basic", "auth", "to", "the", "API", "Key", "attribute", "." ]
391b46b37c30728da106441f7f915ea7572634fc
https://github.com/giraffi/ruby-orchestrate.io/blob/391b46b37c30728da106441f7f915ea7572634fc/lib/orchestrate.io/client.rb#L43-L47
train
dgjnpr/Sloe
lib/sloe/ixia.rb
Sloe.Ixia.run_setup
def run_setup setup_tcl = File.open("/var/tmp/setup-#{@buildtime}", 'w') setup_tcl.write setup setup_tcl.close system "#@ixia_exe /var/tmp/setup-#{@buildtime}" File.delete setup_tcl end
ruby
def run_setup setup_tcl = File.open("/var/tmp/setup-#{@buildtime}", 'w') setup_tcl.write setup setup_tcl.close system "#@ixia_exe /var/tmp/setup-#{@buildtime}" File.delete setup_tcl end
[ "def", "run_setup", "setup_tcl", "=", "File", ".", "open", "(", "\"/var/tmp/setup-#{@buildtime}\"", ",", "'w'", ")", "setup_tcl", ".", "write", "setup", "setup_tcl", ".", "close", "system", "\"#@ixia_exe /var/tmp/setup-#{@buildtime}\"", "File", ".", "delete", "setup_tcl", "end" ]
Load IxN file, start all protocols and then start traffic
[ "Load", "IxN", "file", "start", "all", "protocols", "and", "then", "start", "traffic" ]
7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355
https://github.com/dgjnpr/Sloe/blob/7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355/lib/sloe/ixia.rb#L45-L51
train
dgjnpr/Sloe
lib/sloe/ixia.rb
Sloe.Ixia.clear_stats
def clear_stats clear_tcl = File.open("/var/tmp/clear-#{@buildtime}", 'w') clear_tcl.write clear_traffic_stats clear_tcl.close system "#{@ixia_exe} /var/tmp/clear-#{@buildtime}" File.delete clear_tcl end
ruby
def clear_stats clear_tcl = File.open("/var/tmp/clear-#{@buildtime}", 'w') clear_tcl.write clear_traffic_stats clear_tcl.close system "#{@ixia_exe} /var/tmp/clear-#{@buildtime}" File.delete clear_tcl end
[ "def", "clear_stats", "clear_tcl", "=", "File", ".", "open", "(", "\"/var/tmp/clear-#{@buildtime}\"", ",", "'w'", ")", "clear_tcl", ".", "write", "clear_traffic_stats", "clear_tcl", ".", "close", "system", "\"#{@ixia_exe} /var/tmp/clear-#{@buildtime}\"", "File", ".", "delete", "clear_tcl", "end" ]
Clear all Ixia stats. This removes "invalid" drops observed
[ "Clear", "all", "Ixia", "stats", ".", "This", "removes", "invalid", "drops", "observed" ]
7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355
https://github.com/dgjnpr/Sloe/blob/7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355/lib/sloe/ixia.rb#L54-L60
train
dgjnpr/Sloe
lib/sloe/ixia.rb
Sloe.Ixia.run_stats_gather
def run_stats_gather stats_tcl = File.open("/var/tmp/stats-#{@buildtime}", 'w') stats_tcl.write finish stats_tcl.close system "#@ixia_exe /var/tmp/stats-#{@buildtime}" File.delete stats_tcl ftp = Net::FTP.new(@host) ftp.login file = "#{@csv_file}.csv" Dir.chdir "#{$log_path}/ixia" do ftp.get "Reports/#{file}" end ftp.delete "Reports/#{file}" ftp.delete "Reports/#{file}.columns" ftp.close CSV.read("#{$log_path}/ixia/#{file}", headers: true) end
ruby
def run_stats_gather stats_tcl = File.open("/var/tmp/stats-#{@buildtime}", 'w') stats_tcl.write finish stats_tcl.close system "#@ixia_exe /var/tmp/stats-#{@buildtime}" File.delete stats_tcl ftp = Net::FTP.new(@host) ftp.login file = "#{@csv_file}.csv" Dir.chdir "#{$log_path}/ixia" do ftp.get "Reports/#{file}" end ftp.delete "Reports/#{file}" ftp.delete "Reports/#{file}.columns" ftp.close CSV.read("#{$log_path}/ixia/#{file}", headers: true) end
[ "def", "run_stats_gather", "stats_tcl", "=", "File", ".", "open", "(", "\"/var/tmp/stats-#{@buildtime}\"", ",", "'w'", ")", "stats_tcl", ".", "write", "finish", "stats_tcl", ".", "close", "system", "\"#@ixia_exe /var/tmp/stats-#{@buildtime}\"", "File", ".", "delete", "stats_tcl", "ftp", "=", "Net", "::", "FTP", ".", "new", "(", "@host", ")", "ftp", ".", "login", "file", "=", "\"#{@csv_file}.csv\"", "Dir", ".", "chdir", "\"#{$log_path}/ixia\"", "do", "ftp", ".", "get", "\"Reports/#{file}\"", "end", "ftp", ".", "delete", "\"Reports/#{file}\"", "ftp", ".", "delete", "\"Reports/#{file}.columns\"", "ftp", ".", "close", "CSV", ".", "read", "(", "\"#{$log_path}/ixia/#{file}\"", ",", "headers", ":", "true", ")", "end" ]
Stop Ixia traffic flows and gather Ixia stats
[ "Stop", "Ixia", "traffic", "flows", "and", "gather", "Ixia", "stats" ]
7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355
https://github.com/dgjnpr/Sloe/blob/7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355/lib/sloe/ixia.rb#L63-L79
train
dgjnpr/Sloe
lib/sloe/ixia.rb
Sloe.Ixia.run_protocols
def run_protocols run_proto = File.open("/var/tmp/run-proto-#{@buildtime}", 'w') tcl = connect tcl << load_config tcl << start_protocols tcl << disconnect run_proto.write tcl run_proto.close system "#{@ixia_exe} /var/tmp/run-proto-#{@buildtime}" File.delete run_proto end
ruby
def run_protocols run_proto = File.open("/var/tmp/run-proto-#{@buildtime}", 'w') tcl = connect tcl << load_config tcl << start_protocols tcl << disconnect run_proto.write tcl run_proto.close system "#{@ixia_exe} /var/tmp/run-proto-#{@buildtime}" File.delete run_proto end
[ "def", "run_protocols", "run_proto", "=", "File", ".", "open", "(", "\"/var/tmp/run-proto-#{@buildtime}\"", ",", "'w'", ")", "tcl", "=", "connect", "tcl", "<<", "load_config", "tcl", "<<", "start_protocols", "tcl", "<<", "disconnect", "run_proto", ".", "write", "tcl", "run_proto", ".", "close", "system", "\"#{@ixia_exe} /var/tmp/run-proto-#{@buildtime}\"", "File", ".", "delete", "run_proto", "end" ]
Just run protocols. Do not start traffic
[ "Just", "run", "protocols", ".", "Do", "not", "start", "traffic" ]
7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355
https://github.com/dgjnpr/Sloe/blob/7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355/lib/sloe/ixia.rb#L82-L92
train
levibostian/danger-ios_version_change
lib/ios_version_change/plugin.rb
Danger.DangerIosVersionChange.assert_version_changed
def assert_version_changed(info_plist_file_path) unless File.file?(info_plist_file_path) fail "Info.plist at path " + info_plist_file_path + " does not exist." return # rubocop:disable UnreachableCode end unless git.diff_for_file(info_plist_file_path) # No diff found for Info.plist file. fail "You did not edit your Info.plist file at all. Therefore, you did not change the iOS version." return # rubocop:disable UnreachableCode end git_diff_string = git.diff_for_file(info_plist_file_path).patch assert_version_changed_diff(git_diff_string) end
ruby
def assert_version_changed(info_plist_file_path) unless File.file?(info_plist_file_path) fail "Info.plist at path " + info_plist_file_path + " does not exist." return # rubocop:disable UnreachableCode end unless git.diff_for_file(info_plist_file_path) # No diff found for Info.plist file. fail "You did not edit your Info.plist file at all. Therefore, you did not change the iOS version." return # rubocop:disable UnreachableCode end git_diff_string = git.diff_for_file(info_plist_file_path).patch assert_version_changed_diff(git_diff_string) end
[ "def", "assert_version_changed", "(", "info_plist_file_path", ")", "unless", "File", ".", "file?", "(", "info_plist_file_path", ")", "fail", "\"Info.plist at path \"", "+", "info_plist_file_path", "+", "\" does not exist.\"", "return", "# rubocop:disable UnreachableCode", "end", "unless", "git", ".", "diff_for_file", "(", "info_plist_file_path", ")", "# No diff found for Info.plist file.", "fail", "\"You did not edit your Info.plist file at all. Therefore, you did not change the iOS version.\"", "return", "# rubocop:disable UnreachableCode", "end", "git_diff_string", "=", "git", ".", "diff_for_file", "(", "info_plist_file_path", ")", ".", "patch", "assert_version_changed_diff", "(", "git_diff_string", ")", "end" ]
Asserts the version string has been changed in your iOS XCode project. @example Assert the version string changed for your iOS project # Calls Danger `fail` if the version string not updated or nothing if it has changed. ios_version_change.assert_version_changed("ProjectName/Info.plist") @param [String] info_plist_file_path Path to Info.plist file for XCode project. @return [void]
[ "Asserts", "the", "version", "string", "has", "been", "changed", "in", "your", "iOS", "XCode", "project", "." ]
1a263e5eb188381dbdb92d76983c56d089736907
https://github.com/levibostian/danger-ios_version_change/blob/1a263e5eb188381dbdb92d76983c56d089736907/lib/ios_version_change/plugin.rb#L48-L61
train
payout/announcer
lib/announcer/event.rb
Announcer.Event._evaluate_params
def _evaluate_params(params) unless params.is_a?(Hash) raise ArgumentError, 'event parameters must be a hash' end params = params.dup @instance = params.delete(:instance) @params = _sanitize_params(params) end
ruby
def _evaluate_params(params) unless params.is_a?(Hash) raise ArgumentError, 'event parameters must be a hash' end params = params.dup @instance = params.delete(:instance) @params = _sanitize_params(params) end
[ "def", "_evaluate_params", "(", "params", ")", "unless", "params", ".", "is_a?", "(", "Hash", ")", "raise", "ArgumentError", ",", "'event parameters must be a hash'", "end", "params", "=", "params", ".", "dup", "@instance", "=", "params", ".", "delete", "(", ":instance", ")", "@params", "=", "_sanitize_params", "(", "params", ")", "end" ]
Parameter Evaluation Logic This evaluates the parameters passed to the initializer. Root evaluation method.
[ "Parameter", "Evaluation", "Logic" ]
2281360c368b5c024a00d447c0fc83af5f1b4ee1
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/event.rb#L54-L62
train
payout/announcer
lib/announcer/event.rb
Announcer.Event._sanitize_params
def _sanitize_params(params) Hash[params.map { |key, value| [key.to_sym, _sanitize_value(key, value)] }].freeze end
ruby
def _sanitize_params(params) Hash[params.map { |key, value| [key.to_sym, _sanitize_value(key, value)] }].freeze end
[ "def", "_sanitize_params", "(", "params", ")", "Hash", "[", "params", ".", "map", "{", "|", "key", ",", "value", "|", "[", "key", ".", "to_sym", ",", "_sanitize_value", "(", "key", ",", "value", ")", "]", "}", "]", ".", "freeze", "end" ]
Sanitize the event params. Prevents passing values that could cause errors later in Announcer.
[ "Sanitize", "the", "event", "params", ".", "Prevents", "passing", "values", "that", "could", "cause", "errors", "later", "in", "Announcer", "." ]
2281360c368b5c024a00d447c0fc83af5f1b4ee1
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/event.rb#L68-L70
train
payout/announcer
lib/announcer/event.rb
Announcer.Event._sanitize_array
def _sanitize_array(key, array) array.map { |value| _sanitize_value(key, value) }.freeze end
ruby
def _sanitize_array(key, array) array.map { |value| _sanitize_value(key, value) }.freeze end
[ "def", "_sanitize_array", "(", "key", ",", "array", ")", "array", ".", "map", "{", "|", "value", "|", "_sanitize_value", "(", "key", ",", "value", ")", "}", ".", "freeze", "end" ]
Sanitize an array.
[ "Sanitize", "an", "array", "." ]
2281360c368b5c024a00d447c0fc83af5f1b4ee1
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/event.rb#L73-L75
train
payout/announcer
lib/announcer/event.rb
Announcer.Event._sanitize_value
def _sanitize_value(key, value) case value when String value.dup.freeze when Symbol, Integer, Float, NilClass, TrueClass, FalseClass value when Array _sanitize_array(key, value) when Hash _sanitize_params(value) else raise Errors::UnsafeValueError.new(key, value) end end
ruby
def _sanitize_value(key, value) case value when String value.dup.freeze when Symbol, Integer, Float, NilClass, TrueClass, FalseClass value when Array _sanitize_array(key, value) when Hash _sanitize_params(value) else raise Errors::UnsafeValueError.new(key, value) end end
[ "def", "_sanitize_value", "(", "key", ",", "value", ")", "case", "value", "when", "String", "value", ".", "dup", ".", "freeze", "when", "Symbol", ",", "Integer", ",", "Float", ",", "NilClass", ",", "TrueClass", ",", "FalseClass", "value", "when", "Array", "_sanitize_array", "(", "key", ",", "value", ")", "when", "Hash", "_sanitize_params", "(", "value", ")", "else", "raise", "Errors", "::", "UnsafeValueError", ".", "new", "(", "key", ",", "value", ")", "end", "end" ]
Sanitize an individual value.
[ "Sanitize", "an", "individual", "value", "." ]
2281360c368b5c024a00d447c0fc83af5f1b4ee1
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/event.rb#L78-L91
train
patchapps/hash-that-tree
lib/hashit.rb
HashThatTree.HashIt.validate
def validate @folders.each do |item| if(item==nil) || (item=="") || !Dir.exists?(item) puts "a valid folder path is required as argument #{item}" exit end end end
ruby
def validate @folders.each do |item| if(item==nil) || (item=="") || !Dir.exists?(item) puts "a valid folder path is required as argument #{item}" exit end end end
[ "def", "validate", "@folders", ".", "each", "do", "|", "item", "|", "if", "(", "item", "==", "nil", ")", "||", "(", "item", "==", "\"\"", ")", "||", "!", "Dir", ".", "exists?", "(", "item", ")", "puts", "\"a valid folder path is required as argument #{item}\"", "exit", "end", "end", "end" ]
the container for the files that could not be processed initialize the class with the folders to be processed Validates the supplied folders ensuring they exist
[ "the", "container", "for", "the", "files", "that", "could", "not", "be", "processed", "initialize", "the", "class", "with", "the", "folders", "to", "be", "processed", "Validates", "the", "supplied", "folders", "ensuring", "they", "exist" ]
05a006389340d96d13613abc60a16f83b2bfd052
https://github.com/patchapps/hash-that-tree/blob/05a006389340d96d13613abc60a16f83b2bfd052/lib/hashit.rb#L26-L33
train
nolanw/mpq
lib/replay_file.rb
MPQ.SC2ReplayFile.attributes
def attributes return @attributes if defined? @attributes data = read_file "replay.attributes.events" data.slice! 0, (game_version[:build] < 17326 ? 4 : 5) @attributes = [] data.slice!(0, 4).unpack("V")[0].times do @attributes << Attribute.read(data.slice!(0, 13)) end @attributes end
ruby
def attributes return @attributes if defined? @attributes data = read_file "replay.attributes.events" data.slice! 0, (game_version[:build] < 17326 ? 4 : 5) @attributes = [] data.slice!(0, 4).unpack("V")[0].times do @attributes << Attribute.read(data.slice!(0, 13)) end @attributes end
[ "def", "attributes", "return", "@attributes", "if", "defined?", "@attributes", "data", "=", "read_file", "\"replay.attributes.events\"", "data", ".", "slice!", "0", ",", "(", "game_version", "[", ":build", "]", "<", "17326", "?", "4", ":", "5", ")", "@attributes", "=", "[", "]", "data", ".", "slice!", "(", "0", ",", "4", ")", ".", "unpack", "(", "\"V\"", ")", "[", "0", "]", ".", "times", "do", "@attributes", "<<", "Attribute", ".", "read", "(", "data", ".", "slice!", "(", "0", ",", "13", ")", ")", "end", "@attributes", "end" ]
`replay.attributes.events` has plenty of handy information. Here we simply deserialize all the attributes, taking into account a format change that took place in build 17326, for later processing.
[ "replay", ".", "attributes", ".", "events", "has", "plenty", "of", "handy", "information", ".", "Here", "we", "simply", "deserialize", "all", "the", "attributes", "taking", "into", "account", "a", "format", "change", "that", "took", "place", "in", "build", "17326", "for", "later", "processing", "." ]
4584611f6cede02807257fcf7defdf93b9b7f7db
https://github.com/nolanw/mpq/blob/4584611f6cede02807257fcf7defdf93b9b7f7db/lib/replay_file.rb#L123-L132
train
nolanw/mpq
lib/replay_file.rb
MPQ.SC2ReplayFile.parse_global_attributes
def parse_global_attributes attributes.each do |attr| case attr.id.to_i when 0x07d1 @game_type = attr.sval @game_type = @game_type == 'Cust' ? :custom : @game_type[1, 3].to_sym when 0x0bb8 @game_speed = ATTRIBUTES[:game_speed][attr.sval] when 0x0bc1 @category = ATTRIBUTES[:category][attr.sval] end end end
ruby
def parse_global_attributes attributes.each do |attr| case attr.id.to_i when 0x07d1 @game_type = attr.sval @game_type = @game_type == 'Cust' ? :custom : @game_type[1, 3].to_sym when 0x0bb8 @game_speed = ATTRIBUTES[:game_speed][attr.sval] when 0x0bc1 @category = ATTRIBUTES[:category][attr.sval] end end end
[ "def", "parse_global_attributes", "attributes", ".", "each", "do", "|", "attr", "|", "case", "attr", ".", "id", ".", "to_i", "when", "0x07d1", "@game_type", "=", "attr", ".", "sval", "@game_type", "=", "@game_type", "==", "'Cust'", "?", ":custom", ":", "@game_type", "[", "1", ",", "3", "]", ".", "to_sym", "when", "0x0bb8", "@game_speed", "=", "ATTRIBUTES", "[", ":game_speed", "]", "[", "attr", ".", "sval", "]", "when", "0x0bc1", "@category", "=", "ATTRIBUTES", "[", ":category", "]", "[", "attr", ".", "sval", "]", "end", "end", "end" ]
Several pieces of information come from `replay.attributes.events`, and finding one of them is about as hard as finding all of them, so we just find all of them here when asked.
[ "Several", "pieces", "of", "information", "come", "from", "replay", ".", "attributes", ".", "events", "and", "finding", "one", "of", "them", "is", "about", "as", "hard", "as", "finding", "all", "of", "them", "so", "we", "just", "find", "all", "of", "them", "here", "when", "asked", "." ]
4584611f6cede02807257fcf7defdf93b9b7f7db
https://github.com/nolanw/mpq/blob/4584611f6cede02807257fcf7defdf93b9b7f7db/lib/replay_file.rb#L150-L162
train
tether/actionpusher
lib/action_pusher/base.rb
ActionPusher.Base.push
def push(opts) tokens = [opts[:tokens] || opts[:token] || opts[:to]].flatten message = opts[:message] || '' data = opts[:data] || {} badge_count = opts[:badge_count] || 0 return self if message.blank? @_notifications = Array.new.tap do |notifications| tokens.each do |token| notifications << Houston::Notification.new(device: token).tap do |notification| notification.alert = message notification.badge = badge_count notification.custom_data = data end end end self end
ruby
def push(opts) tokens = [opts[:tokens] || opts[:token] || opts[:to]].flatten message = opts[:message] || '' data = opts[:data] || {} badge_count = opts[:badge_count] || 0 return self if message.blank? @_notifications = Array.new.tap do |notifications| tokens.each do |token| notifications << Houston::Notification.new(device: token).tap do |notification| notification.alert = message notification.badge = badge_count notification.custom_data = data end end end self end
[ "def", "push", "(", "opts", ")", "tokens", "=", "[", "opts", "[", ":tokens", "]", "||", "opts", "[", ":token", "]", "||", "opts", "[", ":to", "]", "]", ".", "flatten", "message", "=", "opts", "[", ":message", "]", "||", "''", "data", "=", "opts", "[", ":data", "]", "||", "{", "}", "badge_count", "=", "opts", "[", ":badge_count", "]", "||", "0", "return", "self", "if", "message", ".", "blank?", "@_notifications", "=", "Array", ".", "new", ".", "tap", "do", "|", "notifications", "|", "tokens", ".", "each", "do", "|", "token", "|", "notifications", "<<", "Houston", "::", "Notification", ".", "new", "(", "device", ":", "token", ")", ".", "tap", "do", "|", "notification", "|", "notification", ".", "alert", "=", "message", "notification", ".", "badge", "=", "badge_count", "notification", ".", "custom_data", "=", "data", "end", "end", "end", "self", "end" ]
Create apple push notifications to be sent out * *Args* - +tokens+ -> User's being sent to - +message+ -> Message sent to tokens - +data+ -> Custom data passed through the push notification - +badge_count+ -> Number to place in badge (default is 0)
[ "Create", "apple", "push", "notifications", "to", "be", "sent", "out" ]
0855a0bbe744fc87f555e49505adb49ce67f7516
https://github.com/tether/actionpusher/blob/0855a0bbe744fc87f555e49505adb49ce67f7516/lib/action_pusher/base.rb#L21-L40
train
tether/actionpusher
lib/action_pusher/base.rb
ActionPusher.Base.deliver
def deliver return self if @_push_was_called @_push_was_called = true apn = APNCertificate.instance @_notifications.each do |notification| apn.push(notification) end end
ruby
def deliver return self if @_push_was_called @_push_was_called = true apn = APNCertificate.instance @_notifications.each do |notification| apn.push(notification) end end
[ "def", "deliver", "return", "self", "if", "@_push_was_called", "@_push_was_called", "=", "true", "apn", "=", "APNCertificate", ".", "instance", "@_notifications", ".", "each", "do", "|", "notification", "|", "apn", ".", "push", "(", "notification", ")", "end", "end" ]
Send out the push notifications
[ "Send", "out", "the", "push", "notifications" ]
0855a0bbe744fc87f555e49505adb49ce67f7516
https://github.com/tether/actionpusher/blob/0855a0bbe744fc87f555e49505adb49ce67f7516/lib/action_pusher/base.rb#L48-L57
train
bdunn313/apexgen
lib/apexgen/object_factory.rb
Apexgen.ObjectFactory.generate
def generate create_header unless @fields.empty? @fields.each { |field| create_field(field) } end create_footer @dtd << Ox.dump(@doc).strip end
ruby
def generate create_header unless @fields.empty? @fields.each { |field| create_field(field) } end create_footer @dtd << Ox.dump(@doc).strip end
[ "def", "generate", "create_header", "unless", "@fields", ".", "empty?", "@fields", ".", "each", "{", "|", "field", "|", "create_field", "(", "field", ")", "}", "end", "create_footer", "@dtd", "<<", "Ox", ".", "dump", "(", "@doc", ")", ".", "strip", "end" ]
Initialization Create the XML and return XML string
[ "Initialization", "Create", "the", "XML", "and", "return", "XML", "string" ]
b993e54b6077b89f431baa938fdca556c50a677f
https://github.com/bdunn313/apexgen/blob/b993e54b6077b89f431baa938fdca556c50a677f/lib/apexgen/object_factory.rb#L21-L28
train
bdunn313/apexgen
lib/apexgen/object_factory.rb
Apexgen.ObjectFactory.make_node
def make_node(name, value=nil, attributes={}) node = Ox::Element.new(name) node << value unless value.nil? attributes.each { |att, val| node[att] = val } unless attributes.empty? node end
ruby
def make_node(name, value=nil, attributes={}) node = Ox::Element.new(name) node << value unless value.nil? attributes.each { |att, val| node[att] = val } unless attributes.empty? node end
[ "def", "make_node", "(", "name", ",", "value", "=", "nil", ",", "attributes", "=", "{", "}", ")", "node", "=", "Ox", "::", "Element", ".", "new", "(", "name", ")", "node", "<<", "value", "unless", "value", ".", "nil?", "attributes", ".", "each", "{", "|", "att", ",", "val", "|", "node", "[", "att", "]", "=", "val", "}", "unless", "attributes", ".", "empty?", "node", "end" ]
Make and return a single node
[ "Make", "and", "return", "a", "single", "node" ]
b993e54b6077b89f431baa938fdca556c50a677f
https://github.com/bdunn313/apexgen/blob/b993e54b6077b89f431baa938fdca556c50a677f/lib/apexgen/object_factory.rb#L31-L38
train
bdunn313/apexgen
lib/apexgen/object_factory.rb
Apexgen.ObjectFactory.make_nodes
def make_nodes(nodes, parent_node) nodes.each do |name, value| if value.kind_of?(Hash) node = Ox::Element.new(name.to_s) make_nodes(value, node) else node = make_node(name.to_s, value) end parent_node << node parent_node end end
ruby
def make_nodes(nodes, parent_node) nodes.each do |name, value| if value.kind_of?(Hash) node = Ox::Element.new(name.to_s) make_nodes(value, node) else node = make_node(name.to_s, value) end parent_node << node parent_node end end
[ "def", "make_nodes", "(", "nodes", ",", "parent_node", ")", "nodes", ".", "each", "do", "|", "name", ",", "value", "|", "if", "value", ".", "kind_of?", "(", "Hash", ")", "node", "=", "Ox", "::", "Element", ".", "new", "(", "name", ".", "to_s", ")", "make_nodes", "(", "value", ",", "node", ")", "else", "node", "=", "make_node", "(", "name", ".", "to_s", ",", "value", ")", "end", "parent_node", "<<", "node", "parent_node", "end", "end" ]
Make multiple nodes, appending to the parent passed to the method
[ "Make", "multiple", "nodes", "appending", "to", "the", "parent", "passed", "to", "the", "method" ]
b993e54b6077b89f431baa938fdca556c50a677f
https://github.com/bdunn313/apexgen/blob/b993e54b6077b89f431baa938fdca556c50a677f/lib/apexgen/object_factory.rb#L41-L52
train
bdunn313/apexgen
lib/apexgen/object_factory.rb
Apexgen.ObjectFactory.create_header
def create_header nodes = { deploymentStatus: 'Deployed', description: "A custom object named #{@name}", enableActivities: 'true', enableFeeds: 'false', enableHistory: 'true', enableReports: 'true' } make_nodes(nodes, @doc_root) end
ruby
def create_header nodes = { deploymentStatus: 'Deployed', description: "A custom object named #{@name}", enableActivities: 'true', enableFeeds: 'false', enableHistory: 'true', enableReports: 'true' } make_nodes(nodes, @doc_root) end
[ "def", "create_header", "nodes", "=", "{", "deploymentStatus", ":", "'Deployed'", ",", "description", ":", "\"A custom object named #{@name}\"", ",", "enableActivities", ":", "'true'", ",", "enableFeeds", ":", "'false'", ",", "enableHistory", ":", "'true'", ",", "enableReports", ":", "'true'", "}", "make_nodes", "(", "nodes", ",", "@doc_root", ")", "end" ]
Create the header for an object
[ "Create", "the", "header", "for", "an", "object" ]
b993e54b6077b89f431baa938fdca556c50a677f
https://github.com/bdunn313/apexgen/blob/b993e54b6077b89f431baa938fdca556c50a677f/lib/apexgen/object_factory.rb#L58-L68
train
waffleau/angular_rails_seo
lib/angular_rails_seo/view_helpers.rb
AngularRailsSeo.ViewHelpers.seo_data
def seo_data if @seo_data.nil? Rails.configuration.seo.each do |key, value| regex = Regexp.new(value["regex"]).match(request.path) unless regex.nil? data = Rails.configuration.seo[key] fallback = data["parent"].blank? ? seo_default : seo_default.merge(Rails.configuration.seo[data["parent"]]) unless data["model"].blank? response = seo_dynamic(data["model"], regex[1..(regex.size - 1)]) data = response.nil? ? {} : response end @seo_data = fallback.merge(data) end end end @seo_data ||= seo_default end
ruby
def seo_data if @seo_data.nil? Rails.configuration.seo.each do |key, value| regex = Regexp.new(value["regex"]).match(request.path) unless regex.nil? data = Rails.configuration.seo[key] fallback = data["parent"].blank? ? seo_default : seo_default.merge(Rails.configuration.seo[data["parent"]]) unless data["model"].blank? response = seo_dynamic(data["model"], regex[1..(regex.size - 1)]) data = response.nil? ? {} : response end @seo_data = fallback.merge(data) end end end @seo_data ||= seo_default end
[ "def", "seo_data", "if", "@seo_data", ".", "nil?", "Rails", ".", "configuration", ".", "seo", ".", "each", "do", "|", "key", ",", "value", "|", "regex", "=", "Regexp", ".", "new", "(", "value", "[", "\"regex\"", "]", ")", ".", "match", "(", "request", ".", "path", ")", "unless", "regex", ".", "nil?", "data", "=", "Rails", ".", "configuration", ".", "seo", "[", "key", "]", "fallback", "=", "data", "[", "\"parent\"", "]", ".", "blank?", "?", "seo_default", ":", "seo_default", ".", "merge", "(", "Rails", ".", "configuration", ".", "seo", "[", "data", "[", "\"parent\"", "]", "]", ")", "unless", "data", "[", "\"model\"", "]", ".", "blank?", "response", "=", "seo_dynamic", "(", "data", "[", "\"model\"", "]", ",", "regex", "[", "1", "..", "(", "regex", ".", "size", "-", "1", ")", "]", ")", "data", "=", "response", ".", "nil?", "?", "{", "}", ":", "response", "end", "@seo_data", "=", "fallback", ".", "merge", "(", "data", ")", "end", "end", "end", "@seo_data", "||=", "seo_default", "end" ]
Returns SEO data as defined in in seo.json
[ "Returns", "SEO", "data", "as", "defined", "in", "in", "seo", ".", "json" ]
3f8c766b1c9c09385e9af57c96cf714ca34b552f
https://github.com/waffleau/angular_rails_seo/blob/3f8c766b1c9c09385e9af57c96cf714ca34b552f/lib/angular_rails_seo/view_helpers.rb#L6-L26
train
jacquescrocker/viewfu
lib/view_fu/tag_helper.rb
ViewFu.TagHelper.add_class
def add_class(css_class, options = {}) return {} unless css_class attributes = {:class => css_class} if options.has_key?(:unless) return options[:unless] ? {} : attributes end if options.has_key?(:if) return options[:if] ? attributes : {} end attributes end
ruby
def add_class(css_class, options = {}) return {} unless css_class attributes = {:class => css_class} if options.has_key?(:unless) return options[:unless] ? {} : attributes end if options.has_key?(:if) return options[:if] ? attributes : {} end attributes end
[ "def", "add_class", "(", "css_class", ",", "options", "=", "{", "}", ")", "return", "{", "}", "unless", "css_class", "attributes", "=", "{", ":class", "=>", "css_class", "}", "if", "options", ".", "has_key?", "(", ":unless", ")", "return", "options", "[", ":unless", "]", "?", "{", "}", ":", "attributes", "end", "if", "options", ".", "has_key?", "(", ":if", ")", "return", "options", "[", ":if", "]", "?", "attributes", ":", "{", "}", "end", "attributes", "end" ]
provides a slick way to add classes inside haml attribute collections examples: %div{add_class("current")} #=> adds the "current" class to the div %div{add_class("current", :if => current?)} #=> adds the "current" class to the div if current? method %div{add_class("highlight", :unless => logged_in?)} #=> adds the "highlight" class to the div unless logged_in? method returns true
[ "provides", "a", "slick", "way", "to", "add", "classes", "inside", "haml", "attribute", "collections" ]
a21946e74553a1e83790ba7ea2a2ef4daa729458
https://github.com/jacquescrocker/viewfu/blob/a21946e74553a1e83790ba7ea2a2ef4daa729458/lib/view_fu/tag_helper.rb#L57-L71
train
jacquescrocker/viewfu
lib/view_fu/tag_helper.rb
ViewFu.TagHelper.delete_link
def delete_link(*args) options = {:method => :delete, :confirm => "Are you sure you want to delete this?"}.merge(extract_options_from_args!(args)||{}) args << options link_to(*args) end
ruby
def delete_link(*args) options = {:method => :delete, :confirm => "Are you sure you want to delete this?"}.merge(extract_options_from_args!(args)||{}) args << options link_to(*args) end
[ "def", "delete_link", "(", "*", "args", ")", "options", "=", "{", ":method", "=>", ":delete", ",", ":confirm", "=>", "\"Are you sure you want to delete this?\"", "}", ".", "merge", "(", "extract_options_from_args!", "(", "args", ")", "||", "{", "}", ")", "args", "<<", "options", "link_to", "(", "args", ")", "end" ]
Wrap a delete link
[ "Wrap", "a", "delete", "link" ]
a21946e74553a1e83790ba7ea2a2ef4daa729458
https://github.com/jacquescrocker/viewfu/blob/a21946e74553a1e83790ba7ea2a2ef4daa729458/lib/view_fu/tag_helper.rb#L112-L116
train
jonas-lantto/table_transform
lib/table_transform/table.rb
TableTransform.Table.metadata
def metadata warn 'metadata is deprecated. Use column_properties[] instead' @column_properties.inject({}){|res, (k, v)| res.merge!({k => v.to_h})} end
ruby
def metadata warn 'metadata is deprecated. Use column_properties[] instead' @column_properties.inject({}){|res, (k, v)| res.merge!({k => v.to_h})} end
[ "def", "metadata", "warn", "'metadata is deprecated. Use column_properties[] instead'", "@column_properties", ".", "inject", "(", "{", "}", ")", "{", "|", "res", ",", "(", "k", ",", "v", ")", "|", "res", ".", "merge!", "(", "{", "k", "=>", "v", ".", "to_h", "}", ")", "}", "end" ]
Returns meta data as Hash with header name as key
[ "Returns", "meta", "data", "as", "Hash", "with", "header", "name", "as", "key" ]
38d61dbda784210d918734231f26106cfcd9bc9c
https://github.com/jonas-lantto/table_transform/blob/38d61dbda784210d918734231f26106cfcd9bc9c/lib/table_transform/table.rb#L55-L58
train
jonas-lantto/table_transform
lib/table_transform/table.rb
TableTransform.Table.+
def +(table) t2 = table.to_a t2_header = t2.shift raise 'Tables cannot be added due to header mismatch' unless @column_properties.keys == t2_header raise 'Tables cannot be added due to column properties mismatch' unless column_properties_eql? table.column_properties raise 'Tables cannot be added due to table properties mismatch' unless @table_properties.to_h == table.table_properties.to_h TableTransform::Table.new(self.to_a + t2) end
ruby
def +(table) t2 = table.to_a t2_header = t2.shift raise 'Tables cannot be added due to header mismatch' unless @column_properties.keys == t2_header raise 'Tables cannot be added due to column properties mismatch' unless column_properties_eql? table.column_properties raise 'Tables cannot be added due to table properties mismatch' unless @table_properties.to_h == table.table_properties.to_h TableTransform::Table.new(self.to_a + t2) end
[ "def", "+", "(", "table", ")", "t2", "=", "table", ".", "to_a", "t2_header", "=", "t2", ".", "shift", "raise", "'Tables cannot be added due to header mismatch'", "unless", "@column_properties", ".", "keys", "==", "t2_header", "raise", "'Tables cannot be added due to column properties mismatch'", "unless", "column_properties_eql?", "table", ".", "column_properties", "raise", "'Tables cannot be added due to table properties mismatch'", "unless", "@table_properties", ".", "to_h", "==", "table", ".", "table_properties", ".", "to_h", "TableTransform", "::", "Table", ".", "new", "(", "self", ".", "to_a", "+", "t2", ")", "end" ]
Add two tables @throws if header or properties do not match
[ "Add", "two", "tables" ]
38d61dbda784210d918734231f26106cfcd9bc9c
https://github.com/jonas-lantto/table_transform/blob/38d61dbda784210d918734231f26106cfcd9bc9c/lib/table_transform/table.rb#L73-L80
train
jonas-lantto/table_transform
lib/table_transform/table.rb
TableTransform.Table.add_column
def add_column(name, column_properties = {}) validate_column_absence(name) create_column_properties(name, column_properties) @data_rows.each{|x| x << (yield Row.new(@column_indexes, x)) } @column_indexes[name] = @column_indexes.size self # enable chaining end
ruby
def add_column(name, column_properties = {}) validate_column_absence(name) create_column_properties(name, column_properties) @data_rows.each{|x| x << (yield Row.new(@column_indexes, x)) } @column_indexes[name] = @column_indexes.size self # enable chaining end
[ "def", "add_column", "(", "name", ",", "column_properties", "=", "{", "}", ")", "validate_column_absence", "(", "name", ")", "create_column_properties", "(", "name", ",", "column_properties", ")", "@data_rows", ".", "each", "{", "|", "x", "|", "x", "<<", "(", "yield", "Row", ".", "new", "(", "@column_indexes", ",", "x", ")", ")", "}", "@column_indexes", "[", "name", "]", "=", "@column_indexes", ".", "size", "self", "# enable chaining", "end" ]
adds a column with given name to the far right of the table @throws if given column name already exists
[ "adds", "a", "column", "with", "given", "name", "to", "the", "far", "right", "of", "the", "table" ]
38d61dbda784210d918734231f26106cfcd9bc9c
https://github.com/jonas-lantto/table_transform/blob/38d61dbda784210d918734231f26106cfcd9bc9c/lib/table_transform/table.rb#L116-L124
train
piedoom/clyp-ruby
lib/clyp/client.rb
Clyp.Client.upload
def upload track if track.playlist_id and track.playlist_token response = JSON.parse(RestClient.post(UPLOAD_BASE, audioFile: track.file, title: track.title, playlistId: track.playlist_id, playlistUploadToken: track.playlist_token, order: track.order, description: track.description, longitude: track.longitude, latitude: track.latitude)) else response = JSON.parse(RestClient.post(UPLOAD_BASE, audioFile: track.file, title: track.title, order: track.order, description: track.description, longitude: track.longitude, latitude: track.latitude)) end TrackUser.new(response) end
ruby
def upload track if track.playlist_id and track.playlist_token response = JSON.parse(RestClient.post(UPLOAD_BASE, audioFile: track.file, title: track.title, playlistId: track.playlist_id, playlistUploadToken: track.playlist_token, order: track.order, description: track.description, longitude: track.longitude, latitude: track.latitude)) else response = JSON.parse(RestClient.post(UPLOAD_BASE, audioFile: track.file, title: track.title, order: track.order, description: track.description, longitude: track.longitude, latitude: track.latitude)) end TrackUser.new(response) end
[ "def", "upload", "track", "if", "track", ".", "playlist_id", "and", "track", ".", "playlist_token", "response", "=", "JSON", ".", "parse", "(", "RestClient", ".", "post", "(", "UPLOAD_BASE", ",", "audioFile", ":", "track", ".", "file", ",", "title", ":", "track", ".", "title", ",", "playlistId", ":", "track", ".", "playlist_id", ",", "playlistUploadToken", ":", "track", ".", "playlist_token", ",", "order", ":", "track", ".", "order", ",", "description", ":", "track", ".", "description", ",", "longitude", ":", "track", ".", "longitude", ",", "latitude", ":", "track", ".", "latitude", ")", ")", "else", "response", "=", "JSON", ".", "parse", "(", "RestClient", ".", "post", "(", "UPLOAD_BASE", ",", "audioFile", ":", "track", ".", "file", ",", "title", ":", "track", ".", "title", ",", "order", ":", "track", ".", "order", ",", "description", ":", "track", ".", "description", ",", "longitude", ":", "track", ".", "longitude", ",", "latitude", ":", "track", ".", "latitude", ")", ")", "end", "TrackUser", ".", "new", "(", "response", ")", "end" ]
uploads a TrackUpload object, returns a TrackUser object
[ "uploads", "a", "TrackUpload", "object", "returns", "a", "TrackUser", "object" ]
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L9-L19
train
piedoom/clyp-ruby
lib/clyp/client.rb
Clyp.Client.get
def get (id:) response = Faraday.get("#{API_BASE}/#{id}") attributes = JSON.parse(response.body) Track.new(attributes) end
ruby
def get (id:) response = Faraday.get("#{API_BASE}/#{id}") attributes = JSON.parse(response.body) Track.new(attributes) end
[ "def", "get", "(", "id", ":", ")", "response", "=", "Faraday", ".", "get", "(", "\"#{API_BASE}/#{id}\"", ")", "attributes", "=", "JSON", ".", "parse", "(", "response", ".", "body", ")", "Track", ".", "new", "(", "attributes", ")", "end" ]
get song with specific id
[ "get", "song", "with", "specific", "id" ]
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L22-L26
train
piedoom/clyp-ruby
lib/clyp/client.rb
Clyp.Client.soundwave
def soundwave (id:) response = Faraday.get("#{API_BASE}/#{id}/soundwave") attributes = JSON.parse(response.body) Soundwave.new(attributes) end
ruby
def soundwave (id:) response = Faraday.get("#{API_BASE}/#{id}/soundwave") attributes = JSON.parse(response.body) Soundwave.new(attributes) end
[ "def", "soundwave", "(", "id", ":", ")", "response", "=", "Faraday", ".", "get", "(", "\"#{API_BASE}/#{id}/soundwave\"", ")", "attributes", "=", "JSON", ".", "parse", "(", "response", ".", "body", ")", "Soundwave", ".", "new", "(", "attributes", ")", "end" ]
returns a Soundwave object with peak data
[ "returns", "a", "Soundwave", "object", "with", "peak", "data" ]
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L29-L33
train
piedoom/clyp-ruby
lib/clyp/client.rb
Clyp.Client.category_list
def category_list response = Faraday.get("#{API_BASE}/categorylist") attributes = JSON.parse(response.body) result = Array.new attributes.each do |attrs| result << ListItem.new(attrs) end result end
ruby
def category_list response = Faraday.get("#{API_BASE}/categorylist") attributes = JSON.parse(response.body) result = Array.new attributes.each do |attrs| result << ListItem.new(attrs) end result end
[ "def", "category_list", "response", "=", "Faraday", ".", "get", "(", "\"#{API_BASE}/categorylist\"", ")", "attributes", "=", "JSON", ".", "parse", "(", "response", ".", "body", ")", "result", "=", "Array", ".", "new", "attributes", ".", "each", "do", "|", "attrs", "|", "result", "<<", "ListItem", ".", "new", "(", "attrs", ")", "end", "result", "end" ]
returns an array of ListItem objects of categories
[ "returns", "an", "array", "of", "ListItem", "objects", "of", "categories" ]
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L36-L44
train
piedoom/clyp-ruby
lib/clyp/client.rb
Clyp.Client.search
def search term response = Faraday.get("#{API_BASE}/categorylist/#{term}") attributes = JSON.parse(response.body) assemble_tracks attributes end
ruby
def search term response = Faraday.get("#{API_BASE}/categorylist/#{term}") attributes = JSON.parse(response.body) assemble_tracks attributes end
[ "def", "search", "term", "response", "=", "Faraday", ".", "get", "(", "\"#{API_BASE}/categorylist/#{term}\"", ")", "attributes", "=", "JSON", ".", "parse", "(", "response", ".", "body", ")", "assemble_tracks", "attributes", "end" ]
returns 20 tracks from a specified search in an array of Track objects
[ "returns", "20", "tracks", "from", "a", "specified", "search", "in", "an", "array", "of", "Track", "objects" ]
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L47-L51
train
piedoom/clyp-ruby
lib/clyp/client.rb
Clyp.Client.featured
def featured (count: 10) response = Faraday.get("#{API_BASE}/featuredlist/featured?count=#{count}") attributes = JSON.parse(response.body) assemble_tracks attributes end
ruby
def featured (count: 10) response = Faraday.get("#{API_BASE}/featuredlist/featured?count=#{count}") attributes = JSON.parse(response.body) assemble_tracks attributes end
[ "def", "featured", "(", "count", ":", "10", ")", "response", "=", "Faraday", ".", "get", "(", "\"#{API_BASE}/featuredlist/featured?count=#{count}\"", ")", "attributes", "=", "JSON", ".", "parse", "(", "response", ".", "body", ")", "assemble_tracks", "attributes", "end" ]
returns featured tracks in an array of Track objects
[ "returns", "featured", "tracks", "in", "an", "array", "of", "Track", "objects" ]
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L54-L58
train
michaelmior/mipper
lib/mipper/gurobi/model.rb
MIPPeR.GurobiModel.gurobi_status
def gurobi_status intptr = FFI::MemoryPointer.new :pointer ret = Gurobi.GRBgetintattr @ptr, Gurobi::GRB_INT_ATTR_STATUS, intptr fail if ret != 0 case intptr.read_int when Gurobi::GRB_OPTIMAL :optimized when Gurobi::GRB_INFEASIBLE, Gurobi::GRB_INF_OR_UNBD, Gurobi::GRB_UNBOUNDED :invalid else :unknown end end
ruby
def gurobi_status intptr = FFI::MemoryPointer.new :pointer ret = Gurobi.GRBgetintattr @ptr, Gurobi::GRB_INT_ATTR_STATUS, intptr fail if ret != 0 case intptr.read_int when Gurobi::GRB_OPTIMAL :optimized when Gurobi::GRB_INFEASIBLE, Gurobi::GRB_INF_OR_UNBD, Gurobi::GRB_UNBOUNDED :invalid else :unknown end end
[ "def", "gurobi_status", "intptr", "=", "FFI", "::", "MemoryPointer", ".", "new", ":pointer", "ret", "=", "Gurobi", ".", "GRBgetintattr", "@ptr", ",", "Gurobi", "::", "GRB_INT_ATTR_STATUS", ",", "intptr", "fail", "if", "ret", "!=", "0", "case", "intptr", ".", "read_int", "when", "Gurobi", "::", "GRB_OPTIMAL", ":optimized", "when", "Gurobi", "::", "GRB_INFEASIBLE", ",", "Gurobi", "::", "GRB_INF_OR_UNBD", ",", "Gurobi", "::", "GRB_UNBOUNDED", ":invalid", "else", ":unknown", "end", "end" ]
Get the status of the model
[ "Get", "the", "status", "of", "the", "model" ]
4ab7f8b32c27f33fc5121756554a0a28d2077e06
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L75-L89
train
michaelmior/mipper
lib/mipper/gurobi/model.rb
MIPPeR.GurobiModel.gurobi_objective
def gurobi_objective dblptr = FFI::MemoryPointer.new :pointer ret = Gurobi.GRBgetdblattr @ptr, Gurobi::GRB_DBL_ATTR_OBJVAL, dblptr fail if ret != 0 dblptr.read_double end
ruby
def gurobi_objective dblptr = FFI::MemoryPointer.new :pointer ret = Gurobi.GRBgetdblattr @ptr, Gurobi::GRB_DBL_ATTR_OBJVAL, dblptr fail if ret != 0 dblptr.read_double end
[ "def", "gurobi_objective", "dblptr", "=", "FFI", "::", "MemoryPointer", ".", "new", ":pointer", "ret", "=", "Gurobi", ".", "GRBgetdblattr", "@ptr", ",", "Gurobi", "::", "GRB_DBL_ATTR_OBJVAL", ",", "dblptr", "fail", "if", "ret", "!=", "0", "dblptr", ".", "read_double", "end" ]
The value of the objective function
[ "The", "value", "of", "the", "objective", "function" ]
4ab7f8b32c27f33fc5121756554a0a28d2077e06
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L92-L97
train
michaelmior/mipper
lib/mipper/gurobi/model.rb
MIPPeR.GurobiModel.add_variable
def add_variable(var) ret = Gurobi.GRBaddvar @ptr, 0, nil, nil, var.coefficient, var.lower_bound, var.upper_bound, gurobi_type(var.type), var.name fail if ret != 0 store_variable var end
ruby
def add_variable(var) ret = Gurobi.GRBaddvar @ptr, 0, nil, nil, var.coefficient, var.lower_bound, var.upper_bound, gurobi_type(var.type), var.name fail if ret != 0 store_variable var end
[ "def", "add_variable", "(", "var", ")", "ret", "=", "Gurobi", ".", "GRBaddvar", "@ptr", ",", "0", ",", "nil", ",", "nil", ",", "var", ".", "coefficient", ",", "var", ".", "lower_bound", ",", "var", ".", "upper_bound", ",", "gurobi_type", "(", "var", ".", "type", ")", ",", "var", ".", "name", "fail", "if", "ret", "!=", "0", "store_variable", "var", "end" ]
Add a new variable to the model
[ "Add", "a", "new", "variable", "to", "the", "model" ]
4ab7f8b32c27f33fc5121756554a0a28d2077e06
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L125-L132
train
michaelmior/mipper
lib/mipper/gurobi/model.rb
MIPPeR.GurobiModel.add_constraint
def add_constraint(constr) terms = constr.expression.terms indexes_buffer = build_pointer_array(terms.each_key.map do |var| var.index end, :int) values_buffer = build_pointer_array terms.values, :double ret = Gurobi.GRBaddconstr @ptr, terms.length, indexes_buffer, values_buffer, gurobi_sense(constr.sense), constr.rhs, constr.name fail if ret != 0 constr.model = self constr.index = @constraints.length constr.freeze @constraints << constr end
ruby
def add_constraint(constr) terms = constr.expression.terms indexes_buffer = build_pointer_array(terms.each_key.map do |var| var.index end, :int) values_buffer = build_pointer_array terms.values, :double ret = Gurobi.GRBaddconstr @ptr, terms.length, indexes_buffer, values_buffer, gurobi_sense(constr.sense), constr.rhs, constr.name fail if ret != 0 constr.model = self constr.index = @constraints.length constr.freeze @constraints << constr end
[ "def", "add_constraint", "(", "constr", ")", "terms", "=", "constr", ".", "expression", ".", "terms", "indexes_buffer", "=", "build_pointer_array", "(", "terms", ".", "each_key", ".", "map", "do", "|", "var", "|", "var", ".", "index", "end", ",", ":int", ")", "values_buffer", "=", "build_pointer_array", "terms", ".", "values", ",", ":double", "ret", "=", "Gurobi", ".", "GRBaddconstr", "@ptr", ",", "terms", ".", "length", ",", "indexes_buffer", ",", "values_buffer", ",", "gurobi_sense", "(", "constr", ".", "sense", ")", ",", "constr", ".", "rhs", ",", "constr", ".", "name", "fail", "if", "ret", "!=", "0", "constr", ".", "model", "=", "self", "constr", ".", "index", "=", "@constraints", ".", "length", "constr", ".", "freeze", "@constraints", "<<", "constr", "end" ]
Add a new constraint to the model
[ "Add", "a", "new", "constraint", "to", "the", "model" ]
4ab7f8b32c27f33fc5121756554a0a28d2077e06
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L163-L180
train
michaelmior/mipper
lib/mipper/gurobi/model.rb
MIPPeR.GurobiModel.build_constraint_matrix
def build_constraint_matrix(constrs) cbeg = [] cind = [] cval = [] constrs.each.map do |constr| cbeg << cind.length constr.expression.terms.each do |var, coeff| cind << var.index cval << coeff end end [cbeg, cind, cval] end
ruby
def build_constraint_matrix(constrs) cbeg = [] cind = [] cval = [] constrs.each.map do |constr| cbeg << cind.length constr.expression.terms.each do |var, coeff| cind << var.index cval << coeff end end [cbeg, cind, cval] end
[ "def", "build_constraint_matrix", "(", "constrs", ")", "cbeg", "=", "[", "]", "cind", "=", "[", "]", "cval", "=", "[", "]", "constrs", ".", "each", ".", "map", "do", "|", "constr", "|", "cbeg", "<<", "cind", ".", "length", "constr", ".", "expression", ".", "terms", ".", "each", "do", "|", "var", ",", "coeff", "|", "cind", "<<", "var", ".", "index", "cval", "<<", "coeff", "end", "end", "[", "cbeg", ",", "cind", ",", "cval", "]", "end" ]
Construct a matrix of values for the given list of constraints
[ "Construct", "a", "matrix", "of", "values", "for", "the", "given", "list", "of", "constraints" ]
4ab7f8b32c27f33fc5121756554a0a28d2077e06
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L190-L203
train
michaelmior/mipper
lib/mipper/gurobi/model.rb
MIPPeR.GurobiModel.array_to_pointers_to_names
def array_to_pointers_to_names(arr) arr.map do |obj| obj.name.nil? ? nil : FFI::MemoryPointer.from_string(obj.name) end end
ruby
def array_to_pointers_to_names(arr) arr.map do |obj| obj.name.nil? ? nil : FFI::MemoryPointer.from_string(obj.name) end end
[ "def", "array_to_pointers_to_names", "(", "arr", ")", "arr", ".", "map", "do", "|", "obj", "|", "obj", ".", "name", ".", "nil?", "?", "nil", ":", "FFI", "::", "MemoryPointer", ".", "from_string", "(", "obj", ".", "name", ")", "end", "end" ]
Convert an array of objects to an FFI array of memory pointers to the names of each object
[ "Convert", "an", "array", "of", "objects", "to", "an", "FFI", "array", "of", "memory", "pointers", "to", "the", "names", "of", "each", "object" ]
4ab7f8b32c27f33fc5121756554a0a28d2077e06
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L243-L247
train
ideonetwork/lato-blog
app/models/lato_blog/post/serializer_helpers.rb
LatoBlog.Post::SerializerHelpers.serialize
def serialize serialized = {} # set basic info serialized[:id] = id serialized[:title] = title serialized[:subtitle] = subtitle serialized[:excerpt] = excerpt serialized[:content] = content serialized[:seo_description] = seo_description serialized[:meta_language] = meta_language serialized[:meta_permalink] = meta_permalink serialized[:meta_status] = meta_status # add fields informations serialized[:fields] = serialize_fields # add categories informations serialized[:categories] = serialize_categories # add tags informations serialized[:tags] = serialize_tags # add post parent informations serialized[:other_informations] = serialize_other_informations # return serialized post serialized end
ruby
def serialize serialized = {} # set basic info serialized[:id] = id serialized[:title] = title serialized[:subtitle] = subtitle serialized[:excerpt] = excerpt serialized[:content] = content serialized[:seo_description] = seo_description serialized[:meta_language] = meta_language serialized[:meta_permalink] = meta_permalink serialized[:meta_status] = meta_status # add fields informations serialized[:fields] = serialize_fields # add categories informations serialized[:categories] = serialize_categories # add tags informations serialized[:tags] = serialize_tags # add post parent informations serialized[:other_informations] = serialize_other_informations # return serialized post serialized end
[ "def", "serialize", "serialized", "=", "{", "}", "# set basic info", "serialized", "[", ":id", "]", "=", "id", "serialized", "[", ":title", "]", "=", "title", "serialized", "[", ":subtitle", "]", "=", "subtitle", "serialized", "[", ":excerpt", "]", "=", "excerpt", "serialized", "[", ":content", "]", "=", "content", "serialized", "[", ":seo_description", "]", "=", "seo_description", "serialized", "[", ":meta_language", "]", "=", "meta_language", "serialized", "[", ":meta_permalink", "]", "=", "meta_permalink", "serialized", "[", ":meta_status", "]", "=", "meta_status", "# add fields informations", "serialized", "[", ":fields", "]", "=", "serialize_fields", "# add categories informations", "serialized", "[", ":categories", "]", "=", "serialize_categories", "# add tags informations", "serialized", "[", ":tags", "]", "=", "serialize_tags", "# add post parent informations", "serialized", "[", ":other_informations", "]", "=", "serialize_other_informations", "# return serialized post", "serialized", "end" ]
This function serializes a complete version of the post.
[ "This", "function", "serializes", "a", "complete", "version", "of", "the", "post", "." ]
a0d92de299a0e285851743b9d4a902f611187cba
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/post/serializer_helpers.rb#L5-L33
train
ideonetwork/lato-blog
app/models/lato_blog/post/serializer_helpers.rb
LatoBlog.Post::SerializerHelpers.serialize_fields
def serialize_fields serialized = {} post_fields.visibles.roots.order('position ASC').each do |post_field| serialized[post_field.key] = post_field.serialize_base end serialized end
ruby
def serialize_fields serialized = {} post_fields.visibles.roots.order('position ASC').each do |post_field| serialized[post_field.key] = post_field.serialize_base end serialized end
[ "def", "serialize_fields", "serialized", "=", "{", "}", "post_fields", ".", "visibles", ".", "roots", ".", "order", "(", "'position ASC'", ")", ".", "each", "do", "|", "post_field", "|", "serialized", "[", "post_field", ".", "key", "]", "=", "post_field", ".", "serialize_base", "end", "serialized", "end" ]
This function serializes the list of fields for the post.
[ "This", "function", "serializes", "the", "list", "of", "fields", "for", "the", "post", "." ]
a0d92de299a0e285851743b9d4a902f611187cba
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/post/serializer_helpers.rb#L53-L59
train
ideonetwork/lato-blog
app/models/lato_blog/post/serializer_helpers.rb
LatoBlog.Post::SerializerHelpers.serialize_categories
def serialize_categories serialized = {} categories.each do |category| serialized[category.id] = category.serialize_base end serialized end
ruby
def serialize_categories serialized = {} categories.each do |category| serialized[category.id] = category.serialize_base end serialized end
[ "def", "serialize_categories", "serialized", "=", "{", "}", "categories", ".", "each", "do", "|", "category", "|", "serialized", "[", "category", ".", "id", "]", "=", "category", ".", "serialize_base", "end", "serialized", "end" ]
This function serializes the list of categories for the post.
[ "This", "function", "serializes", "the", "list", "of", "categories", "for", "the", "post", "." ]
a0d92de299a0e285851743b9d4a902f611187cba
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/post/serializer_helpers.rb#L62-L68
train
ideonetwork/lato-blog
app/models/lato_blog/post/serializer_helpers.rb
LatoBlog.Post::SerializerHelpers.serialize_tags
def serialize_tags serialized = {} tags.each do |tag| serialized[tag.id] = tag.serialize_base end serialized end
ruby
def serialize_tags serialized = {} tags.each do |tag| serialized[tag.id] = tag.serialize_base end serialized end
[ "def", "serialize_tags", "serialized", "=", "{", "}", "tags", ".", "each", "do", "|", "tag", "|", "serialized", "[", "tag", ".", "id", "]", "=", "tag", ".", "serialize_base", "end", "serialized", "end" ]
This function serializes the list of tags for the post.
[ "This", "function", "serializes", "the", "list", "of", "tags", "for", "the", "post", "." ]
a0d92de299a0e285851743b9d4a902f611187cba
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/post/serializer_helpers.rb#L71-L77
train