repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
partition
stringclasses
1 value
cloudfoundry/cf-uaa-lib
lib/uaa/scim.rb
CF::UAA.Scim.add
def add(type, info) path, info = type_info(type, :path), force_case(info) reply = json_parse_reply(@key_style, *json_post(@target, path, info, headers)) fake_client_id(reply) if type == :client # hide client reply, not quite scim reply end
ruby
def add(type, info) path, info = type_info(type, :path), force_case(info) reply = json_parse_reply(@key_style, *json_post(@target, path, info, headers)) fake_client_id(reply) if type == :client # hide client reply, not quite scim reply end
[ "def", "add", "(", "type", ",", "info", ")", "path", ",", "info", "=", "type_info", "(", "type", ",", ":path", ")", ",", "force_case", "(", "info", ")", "reply", "=", "json_parse_reply", "(", "@key_style", ",", "*", "json_post", "(", "@target", ",", ...
Creates a SCIM resource. @param [Symbol] type can be :user, :group, :client, :user_id. @param [Hash] info converted to json and sent to the scim endpoint. For schema of each type of object see {Scim}. @return [Hash] contents of the object, including its +id+ and meta-data.
[ "Creates", "a", "SCIM", "resource", "." ]
e071d69ad5f16053321dfbb95835cf6a9b48227c
https://github.com/cloudfoundry/cf-uaa-lib/blob/e071d69ad5f16053321dfbb95835cf6a9b48227c/lib/uaa/scim.rb#L167-L173
train
cloudfoundry/cf-uaa-lib
lib/uaa/scim.rb
CF::UAA.Scim.put
def put(type, info) path, info = type_info(type, :path), force_case(info) ida = type == :client ? 'client_id' : 'id' raise ArgumentError, "info must include #{ida}" unless id = info[ida] hdrs = headers if info && info['meta'] && (etag = info['meta']['version']) hdrs.merge!('if-match' => etag) ...
ruby
def put(type, info) path, info = type_info(type, :path), force_case(info) ida = type == :client ? 'client_id' : 'id' raise ArgumentError, "info must include #{ida}" unless id = info[ida] hdrs = headers if info && info['meta'] && (etag = info['meta']['version']) hdrs.merge!('if-match' => etag) ...
[ "def", "put", "(", "type", ",", "info", ")", "path", ",", "info", "=", "type_info", "(", "type", ",", ":path", ")", ",", "force_case", "(", "info", ")", "ida", "=", "type", "==", ":client", "?", "'client_id'", ":", "'id'", "raise", "ArgumentError", "...
Replaces the contents of a SCIM object. @param (see #add) @return (see #add)
[ "Replaces", "the", "contents", "of", "a", "SCIM", "object", "." ]
e071d69ad5f16053321dfbb95835cf6a9b48227c
https://github.com/cloudfoundry/cf-uaa-lib/blob/e071d69ad5f16053321dfbb95835cf6a9b48227c/lib/uaa/scim.rb#L186-L199
train
cloudfoundry/cf-uaa-lib
lib/uaa/scim.rb
CF::UAA.Scim.query
def query(type, query = {}) query = force_case(query).reject {|k, v| v.nil? } if attrs = query['attributes'] attrs = Util.arglist(attrs).map {|a| force_attr(a)} query['attributes'] = Util.strlist(attrs, ",") end qstr = query.empty?? '': "?#{Util.encode_form(query)}" info = json_get(@targ...
ruby
def query(type, query = {}) query = force_case(query).reject {|k, v| v.nil? } if attrs = query['attributes'] attrs = Util.arglist(attrs).map {|a| force_attr(a)} query['attributes'] = Util.strlist(attrs, ",") end qstr = query.empty?? '': "?#{Util.encode_form(query)}" info = json_get(@targ...
[ "def", "query", "(", "type", ",", "query", "=", "{", "}", ")", "query", "=", "force_case", "(", "query", ")", ".", "reject", "{", "|", "k", ",", "v", "|", "v", ".", "nil?", "}", "if", "attrs", "=", "query", "[", "'attributes'", "]", "attrs", "=...
Gets a set of attributes for each object that matches a given filter. @param (see #add) @param [Hash] query may contain the following keys: * +attributes+: a comma or space separated list of attribute names to be returned for each object that matches the filter. If no attribute list is given, all attribu...
[ "Gets", "a", "set", "of", "attributes", "for", "each", "object", "that", "matches", "a", "given", "filter", "." ]
e071d69ad5f16053321dfbb95835cf6a9b48227c
https://github.com/cloudfoundry/cf-uaa-lib/blob/e071d69ad5f16053321dfbb95835cf6a9b48227c/lib/uaa/scim.rb#L231-L255
train
cloudfoundry/cf-uaa-lib
lib/uaa/scim.rb
CF::UAA.Scim.get
def get(type, id) info = json_get(@target, "#{type_info(type, :path)}/#{URI.encode(id)}", @key_style, headers) fake_client_id(info) if type == :client # hide client reply, not quite scim info end
ruby
def get(type, id) info = json_get(@target, "#{type_info(type, :path)}/#{URI.encode(id)}", @key_style, headers) fake_client_id(info) if type == :client # hide client reply, not quite scim info end
[ "def", "get", "(", "type", ",", "id", ")", "info", "=", "json_get", "(", "@target", ",", "\"#{type_info(type, :path)}/#{URI.encode(id)}\"", ",", "@key_style", ",", "headers", ")", "fake_client_id", "(", "info", ")", "if", "type", "==", ":client", "info", "end"...
Get information about a specific object. @param (see #delete) @return (see #add)
[ "Get", "information", "about", "a", "specific", "object", "." ]
e071d69ad5f16053321dfbb95835cf6a9b48227c
https://github.com/cloudfoundry/cf-uaa-lib/blob/e071d69ad5f16053321dfbb95835cf6a9b48227c/lib/uaa/scim.rb#L260-L266
train
cloudfoundry/cf-uaa-lib
lib/uaa/token_issuer.rb
CF::UAA.TokenIssuer.implicit_grant_with_creds
def implicit_grant_with_creds(credentials, scope = nil) # this manufactured redirect_uri is a convention here, not part of OAuth2 redir_uri = "https://uaa.cloudfoundry.com/redirect/#{@client_id}" response_type = "token" response_type = "#{response_type} id_token" if scope && (scope.include? "openid") ...
ruby
def implicit_grant_with_creds(credentials, scope = nil) # this manufactured redirect_uri is a convention here, not part of OAuth2 redir_uri = "https://uaa.cloudfoundry.com/redirect/#{@client_id}" response_type = "token" response_type = "#{response_type} id_token" if scope && (scope.include? "openid") ...
[ "def", "implicit_grant_with_creds", "(", "credentials", ",", "scope", "=", "nil", ")", "redir_uri", "=", "\"https://uaa.cloudfoundry.com/redirect/#{@client_id}\"", "response_type", "=", "\"token\"", "response_type", "=", "\"#{response_type} id_token\"", "if", "scope", "&&", ...
Gets an access token in a single call to the UAA with the user credentials used for authentication. @param credentials should be an object such as a hash that can be converted to a json representation of the credential name/value pairs corresponding to the keys retrieved by {#prompts}. @return [TokenInfo]
[ "Gets", "an", "access", "token", "in", "a", "single", "call", "to", "the", "UAA", "with", "the", "user", "credentials", "used", "for", "authentication", "." ]
e071d69ad5f16053321dfbb95835cf6a9b48227c
https://github.com/cloudfoundry/cf-uaa-lib/blob/e071d69ad5f16053321dfbb95835cf6a9b48227c/lib/uaa/token_issuer.rb#L131-L149
train
cloudfoundry/cf-uaa-lib
lib/uaa/token_issuer.rb
CF::UAA.TokenIssuer.implicit_uri
def implicit_uri(redirect_uri, scope = nil) response_type = "token" response_type = "#{response_type} id_token" if scope && (scope.include? "openid") @target + authorize_path_args(response_type, redirect_uri, scope) end
ruby
def implicit_uri(redirect_uri, scope = nil) response_type = "token" response_type = "#{response_type} id_token" if scope && (scope.include? "openid") @target + authorize_path_args(response_type, redirect_uri, scope) end
[ "def", "implicit_uri", "(", "redirect_uri", ",", "scope", "=", "nil", ")", "response_type", "=", "\"token\"", "response_type", "=", "\"#{response_type} id_token\"", "if", "scope", "&&", "(", "scope", ".", "include?", "\"openid\"", ")", "@target", "+", "authorize_p...
Constructs a uri that the client is to return to the browser to direct the user to the authorization server to get an authcode. @param [String] redirect_uri (see #authcode_uri) @return [String]
[ "Constructs", "a", "uri", "that", "the", "client", "is", "to", "return", "to", "the", "browser", "to", "direct", "the", "user", "to", "the", "authorization", "server", "to", "get", "an", "authcode", "." ]
e071d69ad5f16053321dfbb95835cf6a9b48227c
https://github.com/cloudfoundry/cf-uaa-lib/blob/e071d69ad5f16053321dfbb95835cf6a9b48227c/lib/uaa/token_issuer.rb#L155-L159
train
cloudfoundry/cf-uaa-lib
lib/uaa/token_issuer.rb
CF::UAA.TokenIssuer.implicit_grant
def implicit_grant(implicit_uri, callback_fragment) in_params = Util.decode_form(URI.parse(implicit_uri).query) unless in_params['state'] && in_params['redirect_uri'] raise ArgumentError, "redirect must happen before implicit grant" end parse_implicit_params(callback_fragment, in_params['state']) ...
ruby
def implicit_grant(implicit_uri, callback_fragment) in_params = Util.decode_form(URI.parse(implicit_uri).query) unless in_params['state'] && in_params['redirect_uri'] raise ArgumentError, "redirect must happen before implicit grant" end parse_implicit_params(callback_fragment, in_params['state']) ...
[ "def", "implicit_grant", "(", "implicit_uri", ",", "callback_fragment", ")", "in_params", "=", "Util", ".", "decode_form", "(", "URI", ".", "parse", "(", "implicit_uri", ")", ".", "query", ")", "unless", "in_params", "[", "'state'", "]", "&&", "in_params", "...
Gets a token via an implicit grant. @param [String] implicit_uri must be from a previous call to {#implicit_uri}, contains state used to validate the contents of the reply from the server. @param [String] callback_fragment must be the fragment portion of the URL received by the user's browser after the serve...
[ "Gets", "a", "token", "via", "an", "implicit", "grant", "." ]
e071d69ad5f16053321dfbb95835cf6a9b48227c
https://github.com/cloudfoundry/cf-uaa-lib/blob/e071d69ad5f16053321dfbb95835cf6a9b48227c/lib/uaa/token_issuer.rb#L172-L178
train
cloudfoundry/cf-uaa-lib
lib/uaa/token_issuer.rb
CF::UAA.TokenIssuer.autologin_uri
def autologin_uri(redirect_uri, credentials, scope = nil) headers = {'content-type' => FORM_UTF8, 'accept' => JSON_UTF8, 'authorization' => Http.basic_auth(@client_id, @client_secret) } body = Util.encode_form(credentials) reply = json_parse_reply(nil, *request(@target, :post, "/autologin", body, he...
ruby
def autologin_uri(redirect_uri, credentials, scope = nil) headers = {'content-type' => FORM_UTF8, 'accept' => JSON_UTF8, 'authorization' => Http.basic_auth(@client_id, @client_secret) } body = Util.encode_form(credentials) reply = json_parse_reply(nil, *request(@target, :post, "/autologin", body, he...
[ "def", "autologin_uri", "(", "redirect_uri", ",", "credentials", ",", "scope", "=", "nil", ")", "headers", "=", "{", "'content-type'", "=>", "FORM_UTF8", ",", "'accept'", "=>", "JSON_UTF8", ",", "'authorization'", "=>", "Http", ".", "basic_auth", "(", "@client...
A UAA extension to OAuth2 that allows a client to pre-authenticate a user at the start of an authorization code flow. By passing in the user's credentials the server can establish a session with the user's browser without reprompting for authentication. This is useful for user account management apps so that they c...
[ "A", "UAA", "extension", "to", "OAuth2", "that", "allows", "a", "client", "to", "pre", "-", "authenticate", "a", "user", "at", "the", "start", "of", "an", "authorization", "code", "flow", ".", "By", "passing", "in", "the", "user", "s", "credentials", "th...
e071d69ad5f16053321dfbb95835cf6a9b48227c
https://github.com/cloudfoundry/cf-uaa-lib/blob/e071d69ad5f16053321dfbb95835cf6a9b48227c/lib/uaa/token_issuer.rb#L190-L198
train
cloudfoundry/cf-uaa-lib
lib/uaa/token_issuer.rb
CF::UAA.TokenIssuer.authcode_grant
def authcode_grant(authcode_uri, callback_query) ac_params = Util.decode_form(URI.parse(authcode_uri).query) unless ac_params['state'] && ac_params['redirect_uri'] raise ArgumentError, "authcode redirect must happen before authcode grant" end begin params = Util.decode_form(callback_query) ...
ruby
def authcode_grant(authcode_uri, callback_query) ac_params = Util.decode_form(URI.parse(authcode_uri).query) unless ac_params['state'] && ac_params['redirect_uri'] raise ArgumentError, "authcode redirect must happen before authcode grant" end begin params = Util.decode_form(callback_query) ...
[ "def", "authcode_grant", "(", "authcode_uri", ",", "callback_query", ")", "ac_params", "=", "Util", ".", "decode_form", "(", "URI", ".", "parse", "(", "authcode_uri", ")", ".", "query", ")", "unless", "ac_params", "[", "'state'", "]", "&&", "ac_params", "[",...
Uses the instance client credentials in addition to +callback_query+ to get a token via the authorization code grant. @param [String] authcode_uri must be from a previous call to {#authcode_uri} and contains state used to validate the contents of the reply from the server. @param [String] callback_query must b...
[ "Uses", "the", "instance", "client", "credentials", "in", "addition", "to", "+", "callback_query", "+", "to", "get", "a", "token", "via", "the", "authorization", "code", "grant", "." ]
e071d69ad5f16053321dfbb95835cf6a9b48227c
https://github.com/cloudfoundry/cf-uaa-lib/blob/e071d69ad5f16053321dfbb95835cf6a9b48227c/lib/uaa/token_issuer.rb#L219-L233
train
piotrmurach/finite_machine
lib/finite_machine/events_map.rb
FiniteMachine.EventsMap.choice_transition?
def choice_transition?(name, from_state) find(name).select { |trans| trans.matches?(from_state) }.size > 1 end
ruby
def choice_transition?(name, from_state) find(name).select { |trans| trans.matches?(from_state) }.size > 1 end
[ "def", "choice_transition?", "(", "name", ",", "from_state", ")", "find", "(", "name", ")", ".", "select", "{", "|", "trans", "|", "trans", ".", "matches?", "(", "from_state", ")", "}", ".", "size", ">", "1", "end" ]
Check if event has branching choice transitions or not @example events_map.choice_transition?(:go, :green) # => true @param [Symbol] name the event name @param [Symbol] from_state the transition from state @return [Boolean] true if transition has any branches, false otherwise @api public
[ "Check", "if", "event", "has", "branching", "choice", "transitions", "or", "not" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/events_map.rb#L150-L152
train
piotrmurach/finite_machine
lib/finite_machine/events_map.rb
FiniteMachine.EventsMap.match_transition
def match_transition(name, from_state) find(name).find { |trans| trans.matches?(from_state) } end
ruby
def match_transition(name, from_state) find(name).find { |trans| trans.matches?(from_state) } end
[ "def", "match_transition", "(", "name", ",", "from_state", ")", "find", "(", "name", ")", ".", "find", "{", "|", "trans", "|", "trans", ".", "matches?", "(", "from_state", ")", "}", "end" ]
Find transition without checking conditions @param [Symbol] name the event name @param [Symbol] from_state the transition from state @return [Transition, nil] returns transition, nil otherwise @api private
[ "Find", "transition", "without", "checking", "conditions" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/events_map.rb#L166-L168
train
piotrmurach/finite_machine
lib/finite_machine/events_map.rb
FiniteMachine.EventsMap.match_transition_with
def match_transition_with(name, from_state, *conditions) find(name).find do |trans| trans.matches?(from_state) && trans.check_conditions(*conditions) end end
ruby
def match_transition_with(name, from_state, *conditions) find(name).find do |trans| trans.matches?(from_state) && trans.check_conditions(*conditions) end end
[ "def", "match_transition_with", "(", "name", ",", "from_state", ",", "*", "conditions", ")", "find", "(", "name", ")", ".", "find", "do", "|", "trans", "|", "trans", ".", "matches?", "(", "from_state", ")", "&&", "trans", ".", "check_conditions", "(", "*...
Examine transitions for event name that start in from state and find one matching condition. @param [Symbol] name the event name @param [Symbol] from_state the current context from_state @return [Transition] The choice transition that matches @api public
[ "Examine", "transitions", "for", "event", "name", "that", "start", "in", "from", "state", "and", "find", "one", "matching", "condition", "." ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/events_map.rb#L183-L188
train
piotrmurach/finite_machine
lib/finite_machine/events_map.rb
FiniteMachine.EventsMap.select_transition
def select_transition(name, from_state, *conditions) if choice_transition?(name, from_state) match_transition_with(name, from_state, *conditions) else match_transition(name, from_state) end end
ruby
def select_transition(name, from_state, *conditions) if choice_transition?(name, from_state) match_transition_with(name, from_state, *conditions) else match_transition(name, from_state) end end
[ "def", "select_transition", "(", "name", ",", "from_state", ",", "*", "conditions", ")", "if", "choice_transition?", "(", "name", ",", "from_state", ")", "match_transition_with", "(", "name", ",", "from_state", ",", "*", "conditions", ")", "else", "match_transit...
Select transition that matches conditions @param [Symbol] name the event name @param [Symbol] from_state the transition from state @param [Array[Object]] conditions the conditional data @return [Transition] @api public
[ "Select", "transition", "that", "matches", "conditions" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/events_map.rb#L202-L208
train
piotrmurach/finite_machine
lib/finite_machine/events_map.rb
FiniteMachine.EventsMap.move_to
def move_to(name, from_state, *conditions) transition = select_transition(name, from_state, *conditions) transition ||= UndefinedTransition.new(name) transition.to_state(from_state) end
ruby
def move_to(name, from_state, *conditions) transition = select_transition(name, from_state, *conditions) transition ||= UndefinedTransition.new(name) transition.to_state(from_state) end
[ "def", "move_to", "(", "name", ",", "from_state", ",", "*", "conditions", ")", "transition", "=", "select_transition", "(", "name", ",", "from_state", ",", "*", "conditions", ")", "transition", "||=", "UndefinedTransition", ".", "new", "(", "name", ")", "tra...
Find state that this machine can move to @example evenst_map.move_to(:go, :green) # => :red @param [Symbol] name the event name @param [Symbol] from_state the transition from state @param [Array] conditions the data associated with this transition @return [Symbol] the transition `to` state @a...
[ "Find", "state", "that", "this", "machine", "can", "move", "to" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/events_map.rb#L228-L232
train
piotrmurach/finite_machine
lib/finite_machine/events_map.rb
FiniteMachine.EventsMap.to_s
def to_s hash = {} @events_map.each_pair do |name, trans| hash[name] = trans end hash.to_s end
ruby
def to_s hash = {} @events_map.each_pair do |name, trans| hash[name] = trans end hash.to_s end
[ "def", "to_s", "hash", "=", "{", "}", "@events_map", ".", "each_pair", "do", "|", "name", ",", "trans", "|", "hash", "[", "name", "]", "=", "trans", "end", "hash", ".", "to_s", "end" ]
Return string representation of this map @return [String] @api public
[ "Return", "string", "representation", "of", "this", "map" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/events_map.rb#L249-L255
train
piotrmurach/finite_machine
lib/finite_machine/transition.rb
FiniteMachine.Transition.make_conditions
def make_conditions @if.map { |c| Callable.new(c) } + @unless.map { |c| Callable.new(c).invert } end
ruby
def make_conditions @if.map { |c| Callable.new(c) } + @unless.map { |c| Callable.new(c).invert } end
[ "def", "make_conditions", "@if", ".", "map", "{", "|", "c", "|", "Callable", ".", "new", "(", "c", ")", "}", "+", "@unless", ".", "map", "{", "|", "c", "|", "Callable", ".", "new", "(", "c", ")", ".", "invert", "}", "end" ]
Initialize a Transition @example attributes = {states: {green: :yellow}} Transition.new(context, :go, attributes) @param [Object] context the context this transition evaluets conditions in @param [Hash] attrs @return [Transition] @api public Reduce conditions @return [Array[Callable]] @api priva...
[ "Initialize", "a", "Transition" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/transition.rb#L63-L66
train
piotrmurach/finite_machine
lib/finite_machine/transition.rb
FiniteMachine.Transition.matches?
def matches?(from) states.keys.any? { |state| [ANY_STATE, from].include?(state) } end
ruby
def matches?(from) states.keys.any? { |state| [ANY_STATE, from].include?(state) } end
[ "def", "matches?", "(", "from", ")", "states", ".", "keys", ".", "any?", "{", "|", "state", "|", "[", "ANY_STATE", ",", "from", "]", ".", "include?", "(", "state", ")", "}", "end" ]
Check if this transition matches from state @param [Symbol] from the from state to match against @example transition = Transition.new(context, states: {:green => :red}) transition.matches?(:green) # => true @return [Boolean] Return true if match is found, false otherwise. @api public
[ "Check", "if", "this", "transition", "matches", "from", "state" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/transition.rb#L95-L97
train
piotrmurach/finite_machine
lib/finite_machine/choice_merger.rb
FiniteMachine.ChoiceMerger.choice
def choice(to, **conditions) transition_builder = TransitionBuilder.new(@machine, @name, @transitions.merge(conditions)) transition_builder.call(@transitions[:from] => to) end
ruby
def choice(to, **conditions) transition_builder = TransitionBuilder.new(@machine, @name, @transitions.merge(conditions)) transition_builder.call(@transitions[:from] => to) end
[ "def", "choice", "(", "to", ",", "**", "conditions", ")", "transition_builder", "=", "TransitionBuilder", ".", "new", "(", "@machine", ",", "@name", ",", "@transitions", ".", "merge", "(", "conditions", ")", ")", "transition_builder", ".", "call", "(", "@tra...
Initialize a ChoiceMerger @param [StateMachine] machine @param [String] name @param [Hash] transitions the transitions and attributes @api private Create choice transition @example event :stop, from: :green do choice :yellow end @param [Symbol] to the to state @param [Hash] conditions th...
[ "Initialize", "a", "ChoiceMerger" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/choice_merger.rb#L37-L41
train
piotrmurach/finite_machine
lib/finite_machine/state_definition.rb
FiniteMachine.StateDefinition.define_state_query_method
def define_state_query_method(state) return if machine.respond_to?("#{state}?") machine.send(:define_singleton_method, "#{state}?") do machine.is?(state.to_sym) end end
ruby
def define_state_query_method(state) return if machine.respond_to?("#{state}?") machine.send(:define_singleton_method, "#{state}?") do machine.is?(state.to_sym) end end
[ "def", "define_state_query_method", "(", "state", ")", "return", "if", "machine", ".", "respond_to?", "(", "\"#{state}?\"", ")", "machine", ".", "send", "(", ":define_singleton_method", ",", "\"#{state}?\"", ")", "do", "machine", ".", "is?", "(", "state", ".", ...
Define state helper method @param [Symbol] state the state to define helper for @api private
[ "Define", "state", "helper", "method" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_definition.rb#L57-L62
train
piotrmurach/finite_machine
lib/finite_machine/observer.rb
FiniteMachine.Observer.on
def on(hook_type, state_or_event_name = nil, async = nil, &callback) sync_exclusive do if state_or_event_name.nil? state_or_event_name = HookEvent.any_state_or_event(hook_type) end async = false if async.nil? ensure_valid_callback_name!(hook_type, state_or_event_name) ...
ruby
def on(hook_type, state_or_event_name = nil, async = nil, &callback) sync_exclusive do if state_or_event_name.nil? state_or_event_name = HookEvent.any_state_or_event(hook_type) end async = false if async.nil? ensure_valid_callback_name!(hook_type, state_or_event_name) ...
[ "def", "on", "(", "hook_type", ",", "state_or_event_name", "=", "nil", ",", "async", "=", "nil", ",", "&", "callback", ")", "sync_exclusive", "do", "if", "state_or_event_name", ".", "nil?", "state_or_event_name", "=", "HookEvent", ".", "any_state_or_event", "(",...
Register callback for a given hook type @param [HookEvent] hook_type @param [Symbol] state_or_event_name @param [Proc] callback @example observer.on HookEvent::Enter, :green @api public
[ "Register", "callback", "for", "a", "given", "hook", "type" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/observer.rb#L71-L81
train
piotrmurach/finite_machine
lib/finite_machine/observer.rb
FiniteMachine.Observer.off
def off(hook_type, name = ANY_STATE, &callback) sync_exclusive do hooks.unregister hook_type, name, callback end end
ruby
def off(hook_type, name = ANY_STATE, &callback) sync_exclusive do hooks.unregister hook_type, name, callback end end
[ "def", "off", "(", "hook_type", ",", "name", "=", "ANY_STATE", ",", "&", "callback", ")", "sync_exclusive", "do", "hooks", ".", "unregister", "hook_type", ",", "name", ",", "callback", "end", "end" ]
Unregister callback for a given event @api public
[ "Unregister", "callback", "for", "a", "given", "event" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/observer.rb#L86-L90
train
piotrmurach/finite_machine
lib/finite_machine/observer.rb
FiniteMachine.Observer.emit
def emit(event, *data) sync_exclusive do [event.type].each do |hook_type| any_state_or_event = HookEvent.any_state_or_event(hook_type) [any_state_or_event, event.name].each do |event_name| hooks[hook_type][event_name].each do |hook| handle_callback(hook, event...
ruby
def emit(event, *data) sync_exclusive do [event.type].each do |hook_type| any_state_or_event = HookEvent.any_state_or_event(hook_type) [any_state_or_event, event.name].each do |event_name| hooks[hook_type][event_name].each do |hook| handle_callback(hook, event...
[ "def", "emit", "(", "event", ",", "*", "data", ")", "sync_exclusive", "do", "[", "event", ".", "type", "]", ".", "each", "do", "|", "hook_type", "|", "any_state_or_event", "=", "HookEvent", ".", "any_state_or_event", "(", "hook_type", ")", "[", "any_state_...
Execute each of the hooks in order with supplied data @param [HookEvent] event the hook event @param [Array[Object]] data @return [nil] @api public
[ "Execute", "each", "of", "the", "hooks", "in", "order", "with", "supplied", "data" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/observer.rb#L146-L158
train
piotrmurach/finite_machine
lib/finite_machine/observer.rb
FiniteMachine.Observer.handle_callback
def handle_callback(hook, event, *data) to = machine.events_map.move_to(event.event_name, event.from, *data) trans_event = TransitionEvent.new(event.event_name, event.from, to) callable = create_callable(hook) if hook.is_a?(Async) defer(callable, trans_event, *data) else ...
ruby
def handle_callback(hook, event, *data) to = machine.events_map.move_to(event.event_name, event.from, *data) trans_event = TransitionEvent.new(event.event_name, event.from, to) callable = create_callable(hook) if hook.is_a?(Async) defer(callable, trans_event, *data) else ...
[ "def", "handle_callback", "(", "hook", ",", "event", ",", "*", "data", ")", "to", "=", "machine", ".", "events_map", ".", "move_to", "(", "event", ".", "event_name", ",", "event", ".", "from", ",", "*", "data", ")", "trans_event", "=", "TransitionEvent",...
Handle callback and decide if run synchronously or asynchronously @param [Proc] :hook The hook to evaluate @param [HookEvent] :event The event for which the hook is called @param [Array[Object]] :data @api private
[ "Handle", "callback", "and", "decide", "if", "run", "synchronously", "or", "asynchronously" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/observer.rb#L186-L196
train
piotrmurach/finite_machine
lib/finite_machine/observer.rb
FiniteMachine.Observer.defer
def defer(callable, trans_event, *data) async_call = AsyncCall.new(machine, callable, trans_event, *data) callback_queue.start unless callback_queue.running? callback_queue << async_call end
ruby
def defer(callable, trans_event, *data) async_call = AsyncCall.new(machine, callable, trans_event, *data) callback_queue.start unless callback_queue.running? callback_queue << async_call end
[ "def", "defer", "(", "callable", ",", "trans_event", ",", "*", "data", ")", "async_call", "=", "AsyncCall", ".", "new", "(", "machine", ",", "callable", ",", "trans_event", ",", "*", "data", ")", "callback_queue", ".", "start", "unless", "callback_queue", ...
Defer callback execution @api private
[ "Defer", "callback", "execution" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/observer.rb#L201-L205
train
piotrmurach/finite_machine
lib/finite_machine/observer.rb
FiniteMachine.Observer.create_callable
def create_callable(hook) callback = proc do |trans_event, *data| machine.instance_exec(trans_event, *data, &hook) end Callable.new(callback) end
ruby
def create_callable(hook) callback = proc do |trans_event, *data| machine.instance_exec(trans_event, *data, &hook) end Callable.new(callback) end
[ "def", "create_callable", "(", "hook", ")", "callback", "=", "proc", "do", "|", "trans_event", ",", "*", "data", "|", "machine", ".", "instance_exec", "(", "trans_event", ",", "*", "data", ",", "&", "hook", ")", "end", "Callable", ".", "new", "(", "cal...
Create callable instance @api private
[ "Create", "callable", "instance" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/observer.rb#L210-L215
train
piotrmurach/finite_machine
lib/finite_machine/hook_event.rb
FiniteMachine.HookEvent.notify
def notify(subscriber, *data) return unless subscriber.respond_to?(MESSAGE) subscriber.public_send(MESSAGE, self, *data) end
ruby
def notify(subscriber, *data) return unless subscriber.respond_to?(MESSAGE) subscriber.public_send(MESSAGE, self, *data) end
[ "def", "notify", "(", "subscriber", ",", "*", "data", ")", "return", "unless", "subscriber", ".", "respond_to?", "(", "MESSAGE", ")", "subscriber", ".", "public_send", "(", "MESSAGE", ",", "self", ",", "*", "data", ")", "end" ]
Instantiate a new HookEvent object @param [Symbol] name The action or state name @param [Symbol] event_name The event name associated with this hook event. @example HookEvent.new(:green, :move, :green) @return [self] @api public Notify subscriber about this event @param [Observer] subscriber th...
[ "Instantiate", "a", "new", "HookEvent", "object" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/hook_event.rb#L123-L127
train
piotrmurach/finite_machine
lib/finite_machine/event_definition.rb
FiniteMachine.EventDefinition.apply
def apply(event_name, silent = false) define_event_transition(event_name, silent) define_event_bang(event_name, silent) end
ruby
def apply(event_name, silent = false) define_event_transition(event_name, silent) define_event_bang(event_name, silent) end
[ "def", "apply", "(", "event_name", ",", "silent", "=", "false", ")", "define_event_transition", "(", "event_name", ",", "silent", ")", "define_event_bang", "(", "event_name", ",", "silent", ")", "end" ]
Initialize an EventDefinition @param [StateMachine] machine @api private Define transition event names as state machine events @param [Symbol] event_name the event name for which definition is created @return [nil] @api public
[ "Initialize", "an", "EventDefinition" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/event_definition.rb#L31-L34
train
piotrmurach/finite_machine
lib/finite_machine/event_definition.rb
FiniteMachine.EventDefinition.define_event_transition
def define_event_transition(event_name, silent) machine.send(:define_singleton_method, event_name) do |*data, &block| method = silent ? :transition : :trigger machine.public_send(method, event_name, *data, &block) end end
ruby
def define_event_transition(event_name, silent) machine.send(:define_singleton_method, event_name) do |*data, &block| method = silent ? :transition : :trigger machine.public_send(method, event_name, *data, &block) end end
[ "def", "define_event_transition", "(", "event_name", ",", "silent", ")", "machine", ".", "send", "(", ":define_singleton_method", ",", "event_name", ")", "do", "|", "*", "data", ",", "&", "block", "|", "method", "=", "silent", "?", ":transition", ":", ":trig...
Define transition event @param [Symbol] event_name the event name @param [Boolean] silent if true don't trigger callbacks, otherwise do @return [nil] @api private
[ "Define", "transition", "event" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/event_definition.rb#L49-L54
train
piotrmurach/finite_machine
lib/finite_machine/dsl.rb
FiniteMachine.DSL.initial
def initial(value, **options) state = (value && !value.is_a?(Hash)) ? value : raise_missing_state name, @defer_initial, @silent_initial = *parse_initial(options) @initial_event = name event(name, FiniteMachine::DEFAULT_STATE => state, silent: @silent_initial) end
ruby
def initial(value, **options) state = (value && !value.is_a?(Hash)) ? value : raise_missing_state name, @defer_initial, @silent_initial = *parse_initial(options) @initial_event = name event(name, FiniteMachine::DEFAULT_STATE => state, silent: @silent_initial) end
[ "def", "initial", "(", "value", ",", "**", "options", ")", "state", "=", "(", "value", "&&", "!", "value", ".", "is_a?", "(", "Hash", ")", ")", "?", "value", ":", "raise_missing_state", "name", ",", "@defer_initial", ",", "@silent_initial", "=", "*", "...
Initialize top level DSL @api public Define initial state @param [Symbol] value The initial state name. @param [Hash[Symbol]] options @option options [Symbol] :event The event name. @option options [Symbol] :defer Set to true to defer initial state transition. Default false. @option options [Symbol...
[ "Initialize", "top", "level", "DSL" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/dsl.rb#L99-L104
train
piotrmurach/finite_machine
lib/finite_machine/dsl.rb
FiniteMachine.DSL.event
def event(name, transitions = {}, &block) detect_event_conflict!(name) if machine.auto_methods? if block_given? merger = ChoiceMerger.new(machine, name, transitions) merger.instance_eval(&block) else transition_builder = TransitionBuilder.new(machine, name, transitions) ...
ruby
def event(name, transitions = {}, &block) detect_event_conflict!(name) if machine.auto_methods? if block_given? merger = ChoiceMerger.new(machine, name, transitions) merger.instance_eval(&block) else transition_builder = TransitionBuilder.new(machine, name, transitions) ...
[ "def", "event", "(", "name", ",", "transitions", "=", "{", "}", ",", "&", "block", ")", "detect_event_conflict!", "(", "name", ")", "if", "machine", ".", "auto_methods?", "if", "block_given?", "merger", "=", "ChoiceMerger", ".", "new", "(", "machine", ",",...
Create event and associate transition @example event :go, :green => :yellow event :go, :green => :yellow, if: :lights_on? @param [Symbol] name the event name @param [Hash] transitions the event transitions and conditions @return [Transition] @api public
[ "Create", "event", "and", "associate", "transition" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/dsl.rb#L142-L152
train
piotrmurach/finite_machine
lib/finite_machine/dsl.rb
FiniteMachine.DSL.parse_initial
def parse_initial(options) [options.fetch(:event) { FiniteMachine::DEFAULT_EVENT_NAME }, options.fetch(:defer) { false }, options.fetch(:silent) { true }] end
ruby
def parse_initial(options) [options.fetch(:event) { FiniteMachine::DEFAULT_EVENT_NAME }, options.fetch(:defer) { false }, options.fetch(:silent) { true }] end
[ "def", "parse_initial", "(", "options", ")", "[", "options", ".", "fetch", "(", ":event", ")", "{", "FiniteMachine", "::", "DEFAULT_EVENT_NAME", "}", ",", "options", ".", "fetch", "(", ":defer", ")", "{", "false", "}", ",", "options", ".", "fetch", "(", ...
Parse initial options @param [Hash] options the options to extract for initial state setup @return [Array[Symbol,String]] @api private
[ "Parse", "initial", "options" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/dsl.rb#L185-L189
train
piotrmurach/finite_machine
lib/finite_machine/state_machine.rb
FiniteMachine.StateMachine.is?
def is?(state) if state.is_a?(Array) state.include? current else state == current end end
ruby
def is?(state) if state.is_a?(Array) state.include? current else state == current end end
[ "def", "is?", "(", "state", ")", "if", "state", ".", "is_a?", "(", "Array", ")", "state", ".", "include?", "current", "else", "state", "==", "current", "end", "end" ]
Check if current state matches provided state @example fsm.is?(:green) # => true @param [String, Array[String]] state @return [Boolean] @api public
[ "Check", "if", "current", "state", "matches", "provided", "state" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_machine.rb#L158-L164
train
piotrmurach/finite_machine
lib/finite_machine/state_machine.rb
FiniteMachine.StateMachine.can?
def can?(*args) event_name = args.shift events_map.can_perform?(event_name, current, *args) end
ruby
def can?(*args) event_name = args.shift events_map.can_perform?(event_name, current, *args) end
[ "def", "can?", "(", "*", "args", ")", "event_name", "=", "args", ".", "shift", "events_map", ".", "can_perform?", "(", "event_name", ",", "current", ",", "*", "args", ")", "end" ]
Checks if event can be triggered @example fsm.can?(:go) # => true @example fsm.can?(:go, 'Piotr') # checks condition with parameter 'Piotr' @param [String] event @return [Boolean] @api public
[ "Checks", "if", "event", "can", "be", "triggered" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_machine.rb#L203-L206
train
piotrmurach/finite_machine
lib/finite_machine/state_machine.rb
FiniteMachine.StateMachine.valid_state?
def valid_state?(event_name) current_states = events_map.states_for(event_name) current_states.any? { |state| state == current || state == ANY_STATE } end
ruby
def valid_state?(event_name) current_states = events_map.states_for(event_name) current_states.any? { |state| state == current || state == ANY_STATE } end
[ "def", "valid_state?", "(", "event_name", ")", "current_states", "=", "events_map", ".", "states_for", "(", "event_name", ")", "current_states", ".", "any?", "{", "|", "state", "|", "state", "==", "current", "||", "state", "==", "ANY_STATE", "}", "end" ]
Check if state is reachable @param [Symbol] event_name the event name for all transitions @return [Boolean] @api private
[ "Check", "if", "state", "is", "reachable" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_machine.rb#L250-L253
train
piotrmurach/finite_machine
lib/finite_machine/state_machine.rb
FiniteMachine.StateMachine.notify
def notify(hook_event_type, event_name, from, *data) sync_shared do hook_event = hook_event_type.build(current, event_name, from) subscribers.visit(hook_event, *data) end end
ruby
def notify(hook_event_type, event_name, from, *data) sync_shared do hook_event = hook_event_type.build(current, event_name, from) subscribers.visit(hook_event, *data) end end
[ "def", "notify", "(", "hook_event_type", ",", "event_name", ",", "from", ",", "*", "data", ")", "sync_shared", "do", "hook_event", "=", "hook_event_type", ".", "build", "(", "current", ",", "event_name", ",", "from", ")", "subscribers", ".", "visit", "(", ...
Notify about event all the subscribers @param [HookEvent] :hook_event_type The hook event type. @param [FiniteMachine::Transition] :event_transition The event transition. @param [Array[Object]] :data The data associated with the hook event. @return [nil] @api private
[ "Notify", "about", "event", "all", "the", "subscribers" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_machine.rb#L267-L272
train
piotrmurach/finite_machine
lib/finite_machine/state_machine.rb
FiniteMachine.StateMachine.try_trigger
def try_trigger(event_name) if valid_state?(event_name) yield else exception = InvalidStateError catch_error(exception) || fail(exception, "inappropriate current state '#{current}'") false end end
ruby
def try_trigger(event_name) if valid_state?(event_name) yield else exception = InvalidStateError catch_error(exception) || fail(exception, "inappropriate current state '#{current}'") false end end
[ "def", "try_trigger", "(", "event_name", ")", "if", "valid_state?", "(", "event_name", ")", "yield", "else", "exception", "=", "InvalidStateError", "catch_error", "(", "exception", ")", "||", "fail", "(", "exception", ",", "\"inappropriate current state '#{current}'\"...
Attempt performing event trigger for valid state @return [Boolean] true is trigger successful, false otherwise @api private
[ "Attempt", "performing", "event", "trigger", "for", "valid", "state" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_machine.rb#L280-L290
train
piotrmurach/finite_machine
lib/finite_machine/state_machine.rb
FiniteMachine.StateMachine.trigger!
def trigger!(event_name, *data, &block) from = current # Save away current state sync_exclusive do notify HookEvent::Before, event_name, from, *data status = try_trigger(event_name) do if can?(event_name, *data) notify HookEvent::Exit, event_name, from, *data ...
ruby
def trigger!(event_name, *data, &block) from = current # Save away current state sync_exclusive do notify HookEvent::Before, event_name, from, *data status = try_trigger(event_name) do if can?(event_name, *data) notify HookEvent::Exit, event_name, from, *data ...
[ "def", "trigger!", "(", "event_name", ",", "*", "data", ",", "&", "block", ")", "from", "=", "current", "sync_exclusive", "do", "notify", "HookEvent", "::", "Before", ",", "event_name", ",", "from", ",", "*", "data", "status", "=", "try_trigger", "(", "e...
Trigger transition event with data @param [Symbol] event_name the event name @param [Array] data @return [Boolean] true when transition is successful, false otherwise @api public
[ "Trigger", "transition", "event", "with", "data" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_machine.rb#L302-L329
train
piotrmurach/finite_machine
lib/finite_machine/state_machine.rb
FiniteMachine.StateMachine.trigger
def trigger(event_name, *data, &block) trigger!(event_name, *data, &block) rescue InvalidStateError, TransitionError, CallbackError false end
ruby
def trigger(event_name, *data, &block) trigger!(event_name, *data, &block) rescue InvalidStateError, TransitionError, CallbackError false end
[ "def", "trigger", "(", "event_name", ",", "*", "data", ",", "&", "block", ")", "trigger!", "(", "event_name", ",", "*", "data", ",", "&", "block", ")", "rescue", "InvalidStateError", ",", "TransitionError", ",", "CallbackError", "false", "end" ]
Trigger transition event without raising any errors @param [Symbol] event_name @return [Boolean] true on successful transition, false otherwise @api public
[ "Trigger", "transition", "event", "without", "raising", "any", "errors" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_machine.rb#L339-L343
train
piotrmurach/finite_machine
lib/finite_machine/state_machine.rb
FiniteMachine.StateMachine.transition!
def transition!(event_name, *data, &block) from_state = current to_state = events_map.move_to(event_name, from_state, *data) block.call(from_state, to_state) if block if log_transitions Logger.report_transition(event_name, from_state, to_state, *data) end try_trigger(eve...
ruby
def transition!(event_name, *data, &block) from_state = current to_state = events_map.move_to(event_name, from_state, *data) block.call(from_state, to_state) if block if log_transitions Logger.report_transition(event_name, from_state, to_state, *data) end try_trigger(eve...
[ "def", "transition!", "(", "event_name", ",", "*", "data", ",", "&", "block", ")", "from_state", "=", "current", "to_state", "=", "events_map", ".", "move_to", "(", "event_name", ",", "from_state", ",", "*", "data", ")", "block", ".", "call", "(", "from_...
Find available state to transition to and transition @param [Symbol] event_name @api private
[ "Find", "available", "state", "to", "transition", "to", "and", "transition" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_machine.rb#L350-L361
train
piotrmurach/finite_machine
lib/finite_machine/state_machine.rb
FiniteMachine.StateMachine.transition_to!
def transition_to!(new_state) from_state = current self.state = new_state self.initial_state = new_state if from_state == DEFAULT_STATE true rescue Exception => e catch_error(e) || raise_transition_error(e) end
ruby
def transition_to!(new_state) from_state = current self.state = new_state self.initial_state = new_state if from_state == DEFAULT_STATE true rescue Exception => e catch_error(e) || raise_transition_error(e) end
[ "def", "transition_to!", "(", "new_state", ")", "from_state", "=", "current", "self", ".", "state", "=", "new_state", "self", ".", "initial_state", "=", "new_state", "if", "from_state", "==", "DEFAULT_STATE", "true", "rescue", "Exception", "=>", "e", "catch_erro...
Update this state machine state to new one @param [Symbol] new_state @raise [TransitionError] @api private
[ "Update", "this", "state", "machine", "state", "to", "new", "one" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_machine.rb#L376-L383
train
piotrmurach/finite_machine
lib/finite_machine/state_machine.rb
FiniteMachine.StateMachine.method_missing
def method_missing(method_name, *args, &block) if observer.respond_to?(method_name.to_sym) observer.public_send(method_name.to_sym, *args, &block) elsif env.aliases.include?(method_name.to_sym) env.send(:target, *args, &block) else super end end
ruby
def method_missing(method_name, *args, &block) if observer.respond_to?(method_name.to_sym) observer.public_send(method_name.to_sym, *args, &block) elsif env.aliases.include?(method_name.to_sym) env.send(:target, *args, &block) else super end end
[ "def", "method_missing", "(", "method_name", ",", "*", "args", ",", "&", "block", ")", "if", "observer", ".", "respond_to?", "(", "method_name", ".", "to_sym", ")", "observer", ".", "public_send", "(", "method_name", ".", "to_sym", ",", "*", "args", ",", ...
Forward the message to observer or self @param [String] method_name @param [Array] args @return [self] @api private
[ "Forward", "the", "message", "to", "observer", "or", "self" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_machine.rb#L421-L429
train
piotrmurach/finite_machine
lib/finite_machine/state_machine.rb
FiniteMachine.StateMachine.respond_to_missing?
def respond_to_missing?(method_name, include_private = false) observer.respond_to?(method_name.to_sym) || env.aliases.include?(method_name.to_sym) || super end
ruby
def respond_to_missing?(method_name, include_private = false) observer.respond_to?(method_name.to_sym) || env.aliases.include?(method_name.to_sym) || super end
[ "def", "respond_to_missing?", "(", "method_name", ",", "include_private", "=", "false", ")", "observer", ".", "respond_to?", "(", "method_name", ".", "to_sym", ")", "||", "env", ".", "aliases", ".", "include?", "(", "method_name", ".", "to_sym", ")", "||", "...
Test if a message can be handled by state machine @param [String] method_name @param [Boolean] include_private @return [Boolean] @api private
[ "Test", "if", "a", "message", "can", "be", "handled", "by", "state", "machine" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/state_machine.rb#L440-L443
train
piotrmurach/finite_machine
lib/finite_machine/safety.rb
FiniteMachine.Safety.detect_event_conflict!
def detect_event_conflict!(event_name, method_name = event_name) if method_already_implemented?(method_name) raise FiniteMachine::AlreadyDefinedError, EVENT_CONFLICT_MESSAGE % { name: event_name, type: :instance, method: method_name, source: 'FiniteMachine' ...
ruby
def detect_event_conflict!(event_name, method_name = event_name) if method_already_implemented?(method_name) raise FiniteMachine::AlreadyDefinedError, EVENT_CONFLICT_MESSAGE % { name: event_name, type: :instance, method: method_name, source: 'FiniteMachine' ...
[ "def", "detect_event_conflict!", "(", "event_name", ",", "method_name", "=", "event_name", ")", "if", "method_already_implemented?", "(", "method_name", ")", "raise", "FiniteMachine", "::", "AlreadyDefinedError", ",", "EVENT_CONFLICT_MESSAGE", "%", "{", "name", ":", "...
Raise error when the method is already defined @example detect_event_conflict!(:test, "test=") @raise [FiniteMachine::AlreadyDefinedError] @return [nil] @api public
[ "Raise", "error", "when", "the", "method", "is", "already", "defined" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/safety.rb#L36-L45
train
piotrmurach/finite_machine
lib/finite_machine/safety.rb
FiniteMachine.Safety.ensure_valid_callback_name!
def ensure_valid_callback_name!(event_type, name) message = if wrong_event_name?(name, event_type) EVENT_CALLBACK_CONFLICT_MESSAGE % { type: "on_#{event_type}", name: name } elsif wrong_state_name?(name, event_type) STATE_CALLBACK_CONFLICT_MESSAGE % { ty...
ruby
def ensure_valid_callback_name!(event_type, name) message = if wrong_event_name?(name, event_type) EVENT_CALLBACK_CONFLICT_MESSAGE % { type: "on_#{event_type}", name: name } elsif wrong_state_name?(name, event_type) STATE_CALLBACK_CONFLICT_MESSAGE % { ty...
[ "def", "ensure_valid_callback_name!", "(", "event_type", ",", "name", ")", "message", "=", "if", "wrong_event_name?", "(", "name", ",", "event_type", ")", "EVENT_CALLBACK_CONFLICT_MESSAGE", "%", "{", "type", ":", "\"on_#{event_type}\"", ",", "name", ":", "name", "...
Raise error when the callback name is not valid @example ensure_valid_callback_name!(HookEvent::Enter, ":state_name") @raise [FiniteMachine::InvalidCallbackNameError] @return [nil] @api public
[ "Raise", "error", "when", "the", "callback", "name", "is", "not", "valid" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/safety.rb#L57-L77
train
piotrmurach/finite_machine
lib/finite_machine/safety.rb
FiniteMachine.Safety.wrong_event_name?
def wrong_event_name?(name, event_type) machine.states.include?(name) && !machine.events.include?(name) && event_type < HookEvent::Anyaction end
ruby
def wrong_event_name?(name, event_type) machine.states.include?(name) && !machine.events.include?(name) && event_type < HookEvent::Anyaction end
[ "def", "wrong_event_name?", "(", "name", ",", "event_type", ")", "machine", ".", "states", ".", "include?", "(", "name", ")", "&&", "!", "machine", ".", "events", ".", "include?", "(", "name", ")", "&&", "event_type", "<", "HookEvent", "::", "Anyaction", ...
Check if event name exists @param [Symbol] name @param [FiniteMachine::HookEvent] event_type @return [Boolean] @api private
[ "Check", "if", "event", "name", "exists" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/safety.rb#L90-L94
train
piotrmurach/finite_machine
lib/finite_machine/safety.rb
FiniteMachine.Safety.wrong_state_name?
def wrong_state_name?(name, event_type) machine.events.include?(name) && !machine.states.include?(name) && event_type < HookEvent::Anystate end
ruby
def wrong_state_name?(name, event_type) machine.events.include?(name) && !machine.states.include?(name) && event_type < HookEvent::Anystate end
[ "def", "wrong_state_name?", "(", "name", ",", "event_type", ")", "machine", ".", "events", ".", "include?", "(", "name", ")", "&&", "!", "machine", ".", "states", ".", "include?", "(", "name", ")", "&&", "event_type", "<", "HookEvent", "::", "Anystate", ...
Check if state name exists @param [Symbol] name @param [FiniteMachine::HookEvent] event_type @return [Boolean] @api private
[ "Check", "if", "state", "name", "exists" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/safety.rb#L105-L109
train
piotrmurach/finite_machine
lib/finite_machine/message_queue.rb
FiniteMachine.MessageQueue.subscribe
def subscribe(*args, &block) @mutex.synchronize do listener = Listener.new(*args) listener.on_delivery(&block) @listeners << listener end end
ruby
def subscribe(*args, &block) @mutex.synchronize do listener = Listener.new(*args) listener.on_delivery(&block) @listeners << listener end end
[ "def", "subscribe", "(", "*", "args", ",", "&", "block", ")", "@mutex", ".", "synchronize", "do", "listener", "=", "Listener", ".", "new", "(", "*", "args", ")", "listener", ".", "on_delivery", "(", "&", "block", ")", "@listeners", "<<", "listener", "e...
Add listener to the queue to receive messages @api public
[ "Add", "listener", "to", "the", "queue", "to", "receive", "messages" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/message_queue.rb#L75-L81
train
piotrmurach/finite_machine
lib/finite_machine/message_queue.rb
FiniteMachine.MessageQueue.shutdown
def shutdown fail EventQueueDeadError, 'event queue already dead' if @dead queue = [] @mutex.synchronize do @dead = true @not_empty.broadcast queue = @queue @queue.clear end while !queue.empty? discard_message(queue.pop) end true en...
ruby
def shutdown fail EventQueueDeadError, 'event queue already dead' if @dead queue = [] @mutex.synchronize do @dead = true @not_empty.broadcast queue = @queue @queue.clear end while !queue.empty? discard_message(queue.pop) end true en...
[ "def", "shutdown", "fail", "EventQueueDeadError", ",", "'event queue already dead'", "if", "@dead", "queue", "=", "[", "]", "@mutex", ".", "synchronize", "do", "@dead", "=", "true", "@not_empty", ".", "broadcast", "queue", "=", "@queue", "@queue", ".", "clear", ...
Shut down this event queue and clean it up @example event_queue.shutdown @return [Boolean] @api public
[ "Shut", "down", "this", "event", "queue", "and", "clean", "it", "up" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/message_queue.rb#L128-L143
train
piotrmurach/finite_machine
lib/finite_machine/message_queue.rb
FiniteMachine.MessageQueue.process_events
def process_events until @dead @mutex.synchronize do while @queue.empty? break if @dead @not_empty.wait(@mutex) end event = @queue.pop break unless event notify_listeners(event) event.dispatch end end res...
ruby
def process_events until @dead @mutex.synchronize do while @queue.empty? break if @dead @not_empty.wait(@mutex) end event = @queue.pop break unless event notify_listeners(event) event.dispatch end end res...
[ "def", "process_events", "until", "@dead", "@mutex", ".", "synchronize", "do", "while", "@queue", ".", "empty?", "break", "if", "@dead", "@not_empty", ".", "wait", "(", "@mutex", ")", "end", "event", "=", "@queue", ".", "pop", "break", "unless", "event", "...
Process all the events @return [Thread] @api private
[ "Process", "all", "the", "events" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/message_queue.rb#L179-L194
train
piotrmurach/finite_machine
lib/finite_machine/subscribers.rb
FiniteMachine.Subscribers.visit
def visit(hook_event, *data) each { |subscriber| synchronize { hook_event.notify(subscriber, *data) } } end
ruby
def visit(hook_event, *data) each { |subscriber| synchronize { hook_event.notify(subscriber, *data) } } end
[ "def", "visit", "(", "hook_event", ",", "*", "data", ")", "each", "{", "|", "subscriber", "|", "synchronize", "{", "hook_event", ".", "notify", "(", "subscriber", ",", "*", "data", ")", "}", "}", "end" ]
Visit subscribers and notify @param [HookEvent] hook_event the callback event to notify about @return [undefined] @api public
[ "Visit", "subscribers", "and", "notify" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/subscribers.rb#L63-L67
train
piotrmurach/finite_machine
lib/finite_machine/transition_builder.rb
FiniteMachine.TransitionBuilder.call
def call(transitions) StateParser.parse(transitions) do |from, to| transition = Transition.new(@machine.env.target, @name, @attributes.merge(states: { from => to })) silent = @attributes.fetch(:silent, false) @machine.events_map.add(@name, transition) ...
ruby
def call(transitions) StateParser.parse(transitions) do |from, to| transition = Transition.new(@machine.env.target, @name, @attributes.merge(states: { from => to })) silent = @attributes.fetch(:silent, false) @machine.events_map.add(@name, transition) ...
[ "def", "call", "(", "transitions", ")", "StateParser", ".", "parse", "(", "transitions", ")", "do", "|", "from", ",", "to", "|", "transition", "=", "Transition", ".", "new", "(", "@machine", ".", "env", ".", "target", ",", "@name", ",", "@attributes", ...
Initialize a TransitionBuilder @example TransitionBuilder.new(machine, {}) @api public Converts user transitions into internal {Transition} representation @example transition_builder.call([:green, :yellow] => :red) @param [Hash[Symbol]] transitions The transitions to extract states from @return [sel...
[ "Initialize", "a", "TransitionBuilder" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/transition_builder.rb#L41-L55
train
piotrmurach/finite_machine
lib/finite_machine/catchable.rb
FiniteMachine.Catchable.handle
def handle(*exceptions, &block) options = exceptions.last.is_a?(Hash) ? exceptions.pop : {} unless options.key?(:with) if block_given? options[:with] = block else raise ArgumentError, 'Need to provide error handler.' end end evaluate_exceptions(except...
ruby
def handle(*exceptions, &block) options = exceptions.last.is_a?(Hash) ? exceptions.pop : {} unless options.key?(:with) if block_given? options[:with] = block else raise ArgumentError, 'Need to provide error handler.' end end evaluate_exceptions(except...
[ "def", "handle", "(", "*", "exceptions", ",", "&", "block", ")", "options", "=", "exceptions", ".", "last", ".", "is_a?", "(", "Hash", ")", "?", "exceptions", ".", "pop", ":", "{", "}", "unless", "options", ".", "key?", "(", ":with", ")", "if", "bl...
Rescue exception raised in state machine @param [Array[Exception]] exceptions @example handle TransitionError, with: :pretty_errors @example handle TransitionError do |exception| logger.info exception.message raise exception end @api public
[ "Rescue", "exception", "raised", "in", "state", "machine" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/catchable.rb#L29-L40
train
piotrmurach/finite_machine
lib/finite_machine/catchable.rb
FiniteMachine.Catchable.catch_error
def catch_error(exception) if handler = handler_for_error(exception) handler.arity.zero? ? handler.call : handler.call(exception) true end end
ruby
def catch_error(exception) if handler = handler_for_error(exception) handler.arity.zero? ? handler.call : handler.call(exception) true end end
[ "def", "catch_error", "(", "exception", ")", "if", "handler", "=", "handler_for_error", "(", "exception", ")", "handler", ".", "arity", ".", "zero?", "?", "handler", ".", "call", ":", "handler", ".", "call", "(", "exception", ")", "true", "end", "end" ]
Catches error and finds a handler @param [Exception] exception @return [Boolean] true if handler is found, nil otherwise @api public
[ "Catches", "error", "and", "finds", "a", "handler" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/catchable.rb#L50-L55
train
piotrmurach/finite_machine
lib/finite_machine/catchable.rb
FiniteMachine.Catchable.extract_const
def extract_const(class_name) class_name.split('::').reduce(FiniteMachine) do |constant, part| constant.const_get(part) end end
ruby
def extract_const(class_name) class_name.split('::').reduce(FiniteMachine) do |constant, part| constant.const_get(part) end end
[ "def", "extract_const", "(", "class_name", ")", "class_name", ".", "split", "(", "'::'", ")", ".", "reduce", "(", "FiniteMachine", ")", "do", "|", "constant", ",", "part", "|", "constant", ".", "const_get", "(", "part", ")", "end", "end" ]
Find constant in state machine namespace @param [String] class_name @api private
[ "Find", "constant", "in", "state", "machine", "namespace" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/catchable.rb#L73-L77
train
piotrmurach/finite_machine
lib/finite_machine/catchable.rb
FiniteMachine.Catchable.evaluate_handler
def evaluate_handler(handler) case handler when Symbol target.method(handler) when Proc if handler.arity.zero? proc { instance_exec(&handler) } else proc { |_exception| instance_exec(_exception, &handler) } end end end
ruby
def evaluate_handler(handler) case handler when Symbol target.method(handler) when Proc if handler.arity.zero? proc { instance_exec(&handler) } else proc { |_exception| instance_exec(_exception, &handler) } end end end
[ "def", "evaluate_handler", "(", "handler", ")", "case", "handler", "when", "Symbol", "target", ".", "method", "(", "handler", ")", "when", "Proc", "if", "handler", ".", "arity", ".", "zero?", "proc", "{", "instance_exec", "(", "&", "handler", ")", "}", "...
Executes given handler @api private
[ "Executes", "given", "handler" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/catchable.rb#L82-L93
train
piotrmurach/finite_machine
lib/finite_machine/catchable.rb
FiniteMachine.Catchable.evaluate_exceptions
def evaluate_exceptions(exceptions, options) exceptions.each do |exception| key = if exception.is_a?(Class) && exception <= Exception exception.name elsif exception.is_a?(String) exception else raise ArgumentError, "#{exception} isn't an Exception" end...
ruby
def evaluate_exceptions(exceptions, options) exceptions.each do |exception| key = if exception.is_a?(Class) && exception <= Exception exception.name elsif exception.is_a?(String) exception else raise ArgumentError, "#{exception} isn't an Exception" end...
[ "def", "evaluate_exceptions", "(", "exceptions", ",", "options", ")", "exceptions", ".", "each", "do", "|", "exception", "|", "key", "=", "if", "exception", ".", "is_a?", "(", "Class", ")", "&&", "exception", "<=", "Exception", "exception", ".", "name", "e...
Check if exception inherits from Exception class and add to error handlers @param [Array[Exception]] exceptions @param [Hash] options @api private
[ "Check", "if", "exception", "inherits", "from", "Exception", "class", "and", "add", "to", "error", "handlers" ]
e54b9397e74aabd502672afb838a5ceb2d3caa2f
https://github.com/piotrmurach/finite_machine/blob/e54b9397e74aabd502672afb838a5ceb2d3caa2f/lib/finite_machine/catchable.rb#L102-L114
train
PagerDuty/lita-github
lib/lita-github/org.rb
LitaGithub.Org.team_id_by_slug
def team_id_by_slug(slug, org) octo.organization_teams(org).each do |team| return team[:id] if team[:slug] == slug.downcase end nil end
ruby
def team_id_by_slug(slug, org) octo.organization_teams(org).each do |team| return team[:id] if team[:slug] == slug.downcase end nil end
[ "def", "team_id_by_slug", "(", "slug", ",", "org", ")", "octo", ".", "organization_teams", "(", "org", ")", ".", "each", "do", "|", "team", "|", "return", "team", "[", ":id", "]", "if", "team", "[", ":slug", "]", "==", "slug", ".", "downcase", "end",...
Get the Github team ID using its slug This depends on the `octo()` method from LitaGithub::Octo being within the same scope @author Tim Heckman <tim@pagerduty.com> @param slug [String] the slug of the team you're getting the ID for @param org [String] the organization this team should belong in @return [Nil] if ...
[ "Get", "the", "Github", "team", "ID", "using", "its", "slug" ]
3c3411e8daa4fbc3d5af506e159dd71c5ab6f48b
https://github.com/PagerDuty/lita-github/blob/3c3411e8daa4fbc3d5af506e159dd71c5ab6f48b/lib/lita-github/org.rb#L49-L54
train
PagerDuty/lita-github
lib/lita-github/org.rb
LitaGithub.Org.team_id
def team_id(team, org) /^\d+$/.match(team.to_s) ? team : team_id_by_slug(team, org) end
ruby
def team_id(team, org) /^\d+$/.match(team.to_s) ? team : team_id_by_slug(team, org) end
[ "def", "team_id", "(", "team", ",", "org", ")", "/", "\\d", "/", ".", "match", "(", "team", ".", "to_s", ")", "?", "team", ":", "team_id_by_slug", "(", "team", ",", "org", ")", "end" ]
Get the team id based on either the team slug or the team id @author Tim Heckman <tim@pagerduty.com> @param team [String,Integer] this is either the team's slug or the team's id @return [Integer] the team's id
[ "Get", "the", "team", "id", "based", "on", "either", "the", "team", "slug", "or", "the", "team", "id" ]
3c3411e8daa4fbc3d5af506e159dd71c5ab6f48b
https://github.com/PagerDuty/lita-github/blob/3c3411e8daa4fbc3d5af506e159dd71c5ab6f48b/lib/lita-github/org.rb#L61-L63
train
PagerDuty/lita-github
lib/lita-github/general.rb
LitaGithub.General.opts_parse
def opts_parse(cmd) o = {} cmd.scan(LitaGithub::R::OPT_REGEX).flatten.each do |opt| k, v = symbolize_opt_key(*opt.strip.split(':')) next if o.key?(k) # if it looks like we're using the extended option (first character is a " or '): # slice off the first and last character ...
ruby
def opts_parse(cmd) o = {} cmd.scan(LitaGithub::R::OPT_REGEX).flatten.each do |opt| k, v = symbolize_opt_key(*opt.strip.split(':')) next if o.key?(k) # if it looks like we're using the extended option (first character is a " or '): # slice off the first and last character ...
[ "def", "opts_parse", "(", "cmd", ")", "o", "=", "{", "}", "cmd", ".", "scan", "(", "LitaGithub", "::", "R", "::", "OPT_REGEX", ")", ".", "flatten", ".", "each", "do", "|", "opt", "|", "k", ",", "v", "=", "symbolize_opt_key", "(", "*", "opt", ".",...
Parse the options in the command using the option regex @author Tim Heckman <tim@pagerduty.com> @param cmd [String] the full command line provided to Lita @return [Hash] the key:value pairs that were in the command string
[ "Parse", "the", "options", "in", "the", "command", "using", "the", "option", "regex" ]
3c3411e8daa4fbc3d5af506e159dd71c5ab6f48b
https://github.com/PagerDuty/lita-github/blob/3c3411e8daa4fbc3d5af506e159dd71c5ab6f48b/lib/lita-github/general.rb#L50-L65
train
PagerDuty/lita-github
lib/lita-github/repo.rb
LitaGithub.Repo.repo_has_team?
def repo_has_team?(full_name, team_id) octo.repository_teams(full_name).each { |t| return true if t[:id] == team_id } false end
ruby
def repo_has_team?(full_name, team_id) octo.repository_teams(full_name).each { |t| return true if t[:id] == team_id } false end
[ "def", "repo_has_team?", "(", "full_name", ",", "team_id", ")", "octo", ".", "repository_teams", "(", "full_name", ")", ".", "each", "{", "|", "t", "|", "return", "true", "if", "t", "[", ":id", "]", "==", "team_id", "}", "false", "end" ]
Determine if the team is already on the repository @param full_name [String] the canonical name of the repository @param team_id [Integer] the id for the Github team @return [TrueClass] if the team is already on the repo @return [FalseClass] if the team is not on the repo
[ "Determine", "if", "the", "team", "is", "already", "on", "the", "repository" ]
3c3411e8daa4fbc3d5af506e159dd71c5ab6f48b
https://github.com/PagerDuty/lita-github/blob/3c3411e8daa4fbc3d5af506e159dd71c5ab6f48b/lib/lita-github/repo.rb#L58-L61
train
jpmckinney/tf-idf-similarity
lib/tf-idf-similarity/extras/tf_idf_model.rb
TfIdfSimilarity.TfIdfModel.probabilistic_inverse_document_frequency
def probabilistic_inverse_document_frequency(term) count = @model.document_count(term).to_f log((documents.size - count) / count) end
ruby
def probabilistic_inverse_document_frequency(term) count = @model.document_count(term).to_f log((documents.size - count) / count) end
[ "def", "probabilistic_inverse_document_frequency", "(", "term", ")", "count", "=", "@model", ".", "document_count", "(", "term", ")", ".", "to_f", "log", "(", "(", "documents", ".", "size", "-", "count", ")", "/", "count", ")", "end" ]
SMART p, Salton p, Chisholm IDFP
[ "SMART", "p", "Salton", "p", "Chisholm", "IDFP" ]
00777f8bee141aea3e22084c8257add7af0cbf5d
https://github.com/jpmckinney/tf-idf-similarity/blob/00777f8bee141aea3e22084c8257add7af0cbf5d/lib/tf-idf-similarity/extras/tf_idf_model.rb#L31-L34
train
jpmckinney/tf-idf-similarity
lib/tf-idf-similarity/extras/tf_idf_model.rb
TfIdfSimilarity.TfIdfModel.normalized_log_term_frequency
def normalized_log_term_frequency(document, term) count = document.term_count(term) if count > 0 (1 + log(count)) / (1 + log(document.average_term_count)) else 0 end end
ruby
def normalized_log_term_frequency(document, term) count = document.term_count(term) if count > 0 (1 + log(count)) / (1 + log(document.average_term_count)) else 0 end end
[ "def", "normalized_log_term_frequency", "(", "document", ",", "term", ")", "count", "=", "document", ".", "term_count", "(", "term", ")", "if", "count", ">", "0", "(", "1", "+", "log", "(", "count", ")", ")", "/", "(", "1", "+", "log", "(", "document...
SMART L, Chisholm LOGN
[ "SMART", "L", "Chisholm", "LOGN" ]
00777f8bee141aea3e22084c8257add7af0cbf5d
https://github.com/jpmckinney/tf-idf-similarity/blob/00777f8bee141aea3e22084c8257add7af0cbf5d/lib/tf-idf-similarity/extras/tf_idf_model.rb#L162-L169
train
jpmckinney/tf-idf-similarity
lib/tf-idf-similarity/document.rb
TfIdfSimilarity.Document.set_term_counts_and_size
def set_term_counts_and_size tokenize(text).each do |word| token = Token.new(word) if token.valid? term = token.lowercase_filter.classic_filter.to_s @term_counts[term] += 1 @size += 1 end end end
ruby
def set_term_counts_and_size tokenize(text).each do |word| token = Token.new(word) if token.valid? term = token.lowercase_filter.classic_filter.to_s @term_counts[term] += 1 @size += 1 end end end
[ "def", "set_term_counts_and_size", "tokenize", "(", "text", ")", ".", "each", "do", "|", "word", "|", "token", "=", "Token", ".", "new", "(", "word", ")", "if", "token", ".", "valid?", "term", "=", "token", ".", "lowercase_filter", ".", "classic_filter", ...
Tokenizes the text and counts terms and total tokens.
[ "Tokenizes", "the", "text", "and", "counts", "terms", "and", "total", "tokens", "." ]
00777f8bee141aea3e22084c8257add7af0cbf5d
https://github.com/jpmckinney/tf-idf-similarity/blob/00777f8bee141aea3e22084c8257add7af0cbf5d/lib/tf-idf-similarity/document.rb#L53-L62
train
jpmckinney/tf-idf-similarity
lib/tf-idf-similarity/bm25_model.rb
TfIdfSimilarity.BM25Model.inverse_document_frequency
def inverse_document_frequency(term) df = @model.document_count(term) log((documents.size - df + 0.5) / (df + 0.5)) end
ruby
def inverse_document_frequency(term) df = @model.document_count(term) log((documents.size - df + 0.5) / (df + 0.5)) end
[ "def", "inverse_document_frequency", "(", "term", ")", "df", "=", "@model", ".", "document_count", "(", "term", ")", "log", "(", "(", "documents", ".", "size", "-", "df", "+", "0.5", ")", "/", "(", "df", "+", "0.5", ")", ")", "end" ]
Return the term's inverse document frequency. @param [String] term a term @return [Float] the term's inverse document frequency
[ "Return", "the", "term", "s", "inverse", "document", "frequency", "." ]
00777f8bee141aea3e22084c8257add7af0cbf5d
https://github.com/jpmckinney/tf-idf-similarity/blob/00777f8bee141aea3e22084c8257add7af0cbf5d/lib/tf-idf-similarity/bm25_model.rb#L11-L14
train
jpmckinney/tf-idf-similarity
lib/tf-idf-similarity/bm25_model.rb
TfIdfSimilarity.BM25Model.term_frequency
def term_frequency(document, term) tf = document.term_count(term) (tf * 2.2) / (tf + 0.3 + 0.9 * documents.size / @model.average_document_size) end
ruby
def term_frequency(document, term) tf = document.term_count(term) (tf * 2.2) / (tf + 0.3 + 0.9 * documents.size / @model.average_document_size) end
[ "def", "term_frequency", "(", "document", ",", "term", ")", "tf", "=", "document", ".", "term_count", "(", "term", ")", "(", "tf", "*", "2.2", ")", "/", "(", "tf", "+", "0.3", "+", "0.9", "*", "documents", ".", "size", "/", "@model", ".", "average_...
Returns the term's frequency in the document. @param [Document] document a document @param [String] term a term @return [Float] the term's frequency in the document @note Like Lucene, we use a b value of 0.75 and a k1 value of 1.2.
[ "Returns", "the", "term", "s", "frequency", "in", "the", "document", "." ]
00777f8bee141aea3e22084c8257add7af0cbf5d
https://github.com/jpmckinney/tf-idf-similarity/blob/00777f8bee141aea3e22084c8257add7af0cbf5d/lib/tf-idf-similarity/bm25_model.rb#L24-L27
train
dry-rb/dry-view
lib/dry/view.rb
Dry.View.call
def call(format: config.default_format, context: config.default_context, **input) ensure_config env = self.class.render_env(format: format, context: context) template_env = self.class.template_env(format: format, context: context) locals = locals(template_env, input) output = env.templat...
ruby
def call(format: config.default_format, context: config.default_context, **input) ensure_config env = self.class.render_env(format: format, context: context) template_env = self.class.template_env(format: format, context: context) locals = locals(template_env, input) output = env.templat...
[ "def", "call", "(", "format", ":", "config", ".", "default_format", ",", "context", ":", "config", ".", "default_context", ",", "**", "input", ")", "ensure_config", "env", "=", "self", ".", "class", ".", "render_env", "(", "format", ":", "format", ",", "...
Render the view @param format [Symbol] template format to use @param context [Context] context object to use @param input input data for preparing exposure values @return [Rendered] rendered view object @api public
[ "Render", "the", "view" ]
477fe9e1f1f8e687c19d7c3a0ed15c0219a01821
https://github.com/dry-rb/dry-view/blob/477fe9e1f1f8e687c19d7c3a0ed15c0219a01821/lib/dry/view.rb#L459-L474
train
deep-cover/deep-cover
core_gem/spec/specs_tools.rb
DeepCover.CoveredCode.check_node_overlap!
def check_node_overlap! node_to_positions = {} each_node do |node| node.proper_range.each do |position| if node_to_positions[position] already = node_to_positions[position] puts "There is a proper_range overlap between #{node} and #{already}" puts "Overl...
ruby
def check_node_overlap! node_to_positions = {} each_node do |node| node.proper_range.each do |position| if node_to_positions[position] already = node_to_positions[position] puts "There is a proper_range overlap between #{node} and #{already}" puts "Overl...
[ "def", "check_node_overlap!", "node_to_positions", "=", "{", "}", "each_node", "do", "|", "node", "|", "node", ".", "proper_range", ".", "each", "do", "|", "position", "|", "if", "node_to_positions", "[", "position", "]", "already", "=", "node_to_positions", "...
For now, when an overlap is found, just open a binding.pry to make fixing it easier.
[ "For", "now", "when", "an", "overlap", "is", "found", "just", "open", "a", "binding", ".", "pry", "to", "make", "fixing", "it", "easier", "." ]
d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab
https://github.com/deep-cover/deep-cover/blob/d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab/core_gem/spec/specs_tools.rb#L82-L95
train
deep-cover/deep-cover
core_gem/lib/deep_cover/tools/content_tag.rb
DeepCover.Tools::ContentTag.content_tag
def content_tag(tag, content, **options) attrs = options.map { |kind, value| %{ #{kind}="#{value}"} }.join "<#{tag}#{attrs}>#{content}</#{tag}>" end
ruby
def content_tag(tag, content, **options) attrs = options.map { |kind, value| %{ #{kind}="#{value}"} }.join "<#{tag}#{attrs}>#{content}</#{tag}>" end
[ "def", "content_tag", "(", "tag", ",", "content", ",", "**", "options", ")", "attrs", "=", "options", ".", "map", "{", "|", "kind", ",", "value", "|", "%{ #{kind}=\"#{value}\"}", "}", ".", "join", "\"<#{tag}#{attrs}>#{content}</#{tag}>\"", "end" ]
Poor man's content_tag. No HTML escaping included
[ "Poor", "man", "s", "content_tag", ".", "No", "HTML", "escaping", "included" ]
d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab
https://github.com/deep-cover/deep-cover/blob/d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab/core_gem/lib/deep_cover/tools/content_tag.rb#L6-L9
train
deep-cover/deep-cover
core_gem/spec/analyser/node_spec.rb
DeepCover.IgnoreNodes.results
def results(analyser) r = analyser.results [0, nil].map do |val| r.select { |node, runs| runs == val } .keys .map(&:source) end end
ruby
def results(analyser) r = analyser.results [0, nil].map do |val| r.select { |node, runs| runs == val } .keys .map(&:source) end end
[ "def", "results", "(", "analyser", ")", "r", "=", "analyser", ".", "results", "[", "0", ",", "nil", "]", ".", "map", "do", "|", "val", "|", "r", ".", "select", "{", "|", "node", ",", "runs", "|", "runs", "==", "val", "}", ".", "keys", ".", "m...
returns not_covered, ignored
[ "returns", "not_covered", "ignored" ]
d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab
https://github.com/deep-cover/deep-cover/blob/d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab/core_gem/spec/analyser/node_spec.rb#L35-L42
train
deep-cover/deep-cover
core_gem/lib/deep_cover/node/base.rb
DeepCover.Node.find_all
def find_all(lookup) case lookup when ::Module each_node.grep(lookup) when ::Symbol each_node.find_all { |n| n.type == lookup } when ::String each_node.find_all { |n| n.source == lookup } when ::Regexp each_node.find_all { |n| n.source =~ lookup } else...
ruby
def find_all(lookup) case lookup when ::Module each_node.grep(lookup) when ::Symbol each_node.find_all { |n| n.type == lookup } when ::String each_node.find_all { |n| n.source == lookup } when ::Regexp each_node.find_all { |n| n.source =~ lookup } else...
[ "def", "find_all", "(", "lookup", ")", "case", "lookup", "when", "::", "Module", "each_node", ".", "grep", "(", "lookup", ")", "when", "::", "Symbol", "each_node", ".", "find_all", "{", "|", "n", "|", "n", ".", "type", "==", "lookup", "}", "when", ":...
Public API Search self and descendants for a particular Class or type
[ "Public", "API", "Search", "self", "and", "descendants", "for", "a", "particular", "Class", "or", "type" ]
d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab
https://github.com/deep-cover/deep-cover/blob/d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab/core_gem/lib/deep_cover/node/base.rb#L39-L52
train
deep-cover/deep-cover
core_gem/lib/deep_cover/node/base.rb
DeepCover.Node.[]
def [](lookup) if lookup.is_a?(Integer) children.fetch(lookup) else found = find_all(lookup) case found.size when 1 found.first when 0 raise "No children of type #{lookup}" else raise "Ambiguous lookup #{lookup}, found #{found}." ...
ruby
def [](lookup) if lookup.is_a?(Integer) children.fetch(lookup) else found = find_all(lookup) case found.size when 1 found.first when 0 raise "No children of type #{lookup}" else raise "Ambiguous lookup #{lookup}, found #{found}." ...
[ "def", "[]", "(", "lookup", ")", "if", "lookup", ".", "is_a?", "(", "Integer", ")", "children", ".", "fetch", "(", "lookup", ")", "else", "found", "=", "find_all", "(", "lookup", ")", "case", "found", ".", "size", "when", "1", "found", ".", "first", ...
Shortcut to access children
[ "Shortcut", "to", "access", "children" ]
d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab
https://github.com/deep-cover/deep-cover/blob/d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab/core_gem/lib/deep_cover/node/base.rb#L55-L69
train
deep-cover/deep-cover
core_gem/lib/deep_cover/node/base.rb
DeepCover.Node.each_node
def each_node(&block) return to_enum :each_node unless block_given? children_nodes.each do |child| child.each_node(&block) end yield self self end
ruby
def each_node(&block) return to_enum :each_node unless block_given? children_nodes.each do |child| child.each_node(&block) end yield self self end
[ "def", "each_node", "(", "&", "block", ")", "return", "to_enum", ":each_node", "unless", "block_given?", "children_nodes", ".", "each", "do", "|", "child", "|", "child", ".", "each_node", "(", "&", "block", ")", "end", "yield", "self", "self", "end" ]
Yields its children and itself
[ "Yields", "its", "children", "and", "itself" ]
d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab
https://github.com/deep-cover/deep-cover/blob/d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab/core_gem/lib/deep_cover/node/base.rb#L122-L129
train
deep-cover/deep-cover
core_gem/lib/deep_cover/coverage.rb
DeepCover.Coverage.add_missing_covered_codes
def add_missing_covered_codes top_level_path = DeepCover.config.paths.detect do |path| next unless path.is_a?(String) path = File.expand_path(path) File.dirname(path) == path end if top_level_path # One of the paths is a root path. # Either a mistake, or the use...
ruby
def add_missing_covered_codes top_level_path = DeepCover.config.paths.detect do |path| next unless path.is_a?(String) path = File.expand_path(path) File.dirname(path) == path end if top_level_path # One of the paths is a root path. # Either a mistake, or the use...
[ "def", "add_missing_covered_codes", "top_level_path", "=", "DeepCover", ".", "config", ".", "paths", ".", "detect", "do", "|", "path", "|", "next", "unless", "path", ".", "is_a?", "(", "String", ")", "path", "=", "File", ".", "expand_path", "(", "path", ")...
If a file wasn't required, it won't be in the trackers. This adds those mossing files
[ "If", "a", "file", "wasn", "t", "required", "it", "won", "t", "be", "in", "the", "trackers", ".", "This", "adds", "those", "mossing", "files" ]
d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab
https://github.com/deep-cover/deep-cover/blob/d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab/core_gem/lib/deep_cover/coverage.rb#L60-L84
train
deep-cover/deep-cover
core_gem/lib/deep_cover/persistence.rb
top_level_module::DeepCover.Persistence.load_trackers
def load_trackers tracker_hits_per_path_hashes = tracker_files.map do |full_path| JSON.parse(full_path.binread).transform_keys(&:to_sym).yield_self do |version:, tracker_hits_per_path:| raise "dump version mismatch: #{version}, currently #{VERSION}" unless version == VERSION tracker_hi...
ruby
def load_trackers tracker_hits_per_path_hashes = tracker_files.map do |full_path| JSON.parse(full_path.binread).transform_keys(&:to_sym).yield_self do |version:, tracker_hits_per_path:| raise "dump version mismatch: #{version}, currently #{VERSION}" unless version == VERSION tracker_hi...
[ "def", "load_trackers", "tracker_hits_per_path_hashes", "=", "tracker_files", ".", "map", "do", "|", "full_path", "|", "JSON", ".", "parse", "(", "full_path", ".", "binread", ")", ".", "transform_keys", "(", "&", ":to_sym", ")", ".", "yield_self", "do", "|", ...
returns a TrackerHitsPerPath
[ "returns", "a", "TrackerHitsPerPath" ]
d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab
https://github.com/deep-cover/deep-cover/blob/d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab/core_gem/lib/deep_cover/persistence.rb#L32-L41
train
deep-cover/deep-cover
core_gem/lib/deep_cover/autoload_tracker.rb
DeepCover.AutoloadTracker.initialize_autoloaded_paths
def initialize_autoloaded_paths(mods = ObjectSpace.each_object(Module)) # &do_autoload_block mods.each do |mod| # Module's constants are shared with Object. But if you set autoloads directly on Module, they # appear on multiple classes. So just skip, Object will take care of those. next if...
ruby
def initialize_autoloaded_paths(mods = ObjectSpace.each_object(Module)) # &do_autoload_block mods.each do |mod| # Module's constants are shared with Object. But if you set autoloads directly on Module, they # appear on multiple classes. So just skip, Object will take care of those. next if...
[ "def", "initialize_autoloaded_paths", "(", "mods", "=", "ObjectSpace", ".", "each_object", "(", "Module", ")", ")", "mods", ".", "each", "do", "|", "mod", "|", "next", "if", "mod", "==", "Module", "next", "unless", "mod", ".", "respond_to?", "(", ":constan...
In JRuby, ObjectSpace.each_object is allowed for Module and Class, so we are good.
[ "In", "JRuby", "ObjectSpace", ".", "each_object", "is", "allowed", "for", "Module", "and", "Class", "so", "we", "are", "good", "." ]
d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab
https://github.com/deep-cover/deep-cover/blob/d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab/core_gem/lib/deep_cover/autoload_tracker.rb#L79-L104
train
deep-cover/deep-cover
core_gem/lib/deep_cover/autoload_tracker.rb
DeepCover.AutoloadTracker.remove_interceptors
def remove_interceptors # &do_autoload_block @autoloads_by_basename.each do |basename, entries| entries.each do |entry| mod = entry.mod_if_available next unless mod # Module's constants are shared with Object. But if you set autoloads directly on Module, they # appe...
ruby
def remove_interceptors # &do_autoload_block @autoloads_by_basename.each do |basename, entries| entries.each do |entry| mod = entry.mod_if_available next unless mod # Module's constants are shared with Object. But if you set autoloads directly on Module, they # appe...
[ "def", "remove_interceptors", "@autoloads_by_basename", ".", "each", "do", "|", "basename", ",", "entries", "|", "entries", ".", "each", "do", "|", "entry", "|", "mod", "=", "entry", ".", "mod_if_available", "next", "unless", "mod", "next", "if", "mod", "=="...
We need to remove the interceptor hooks, otherwise, the problem if manually requiring something that is autoloaded will cause issues.
[ "We", "need", "to", "remove", "the", "interceptor", "hooks", "otherwise", "the", "problem", "if", "manually", "requiring", "something", "that", "is", "autoloaded", "will", "cause", "issues", "." ]
d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab
https://github.com/deep-cover/deep-cover/blob/d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab/core_gem/lib/deep_cover/autoload_tracker.rb#L108-L122
train
deep-cover/deep-cover
core_gem/lib/deep_cover/tools/execute_sample.rb
DeepCover.Tools::ExecuteSample.execute_sample
def execute_sample(to_execute, source: nil) # Disable some annoying warning by ruby. We are testing edge cases, so warnings are to be expected. Tools.silence_warnings do if to_execute.is_a?(CoveredCode) to_execute.execute_code else to_execute.call end end ...
ruby
def execute_sample(to_execute, source: nil) # Disable some annoying warning by ruby. We are testing edge cases, so warnings are to be expected. Tools.silence_warnings do if to_execute.is_a?(CoveredCode) to_execute.execute_code else to_execute.call end end ...
[ "def", "execute_sample", "(", "to_execute", ",", "source", ":", "nil", ")", "Tools", ".", "silence_warnings", "do", "if", "to_execute", ".", "is_a?", "(", "CoveredCode", ")", "to_execute", ".", "execute_code", "else", "to_execute", ".", "call", "end", "end", ...
Returns true if the code would have continued, false if the rescue was triggered.
[ "Returns", "true", "if", "the", "code", "would", "have", "continued", "false", "if", "the", "rescue", "was", "triggered", "." ]
d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab
https://github.com/deep-cover/deep-cover/blob/d83c0b9f8d3dd59a28cdf81cf3ea1848eac77dab/core_gem/lib/deep_cover/tools/execute_sample.rb#L9-L32
train
chef/mixlib-config
lib/mixlib/config.rb
Mixlib.Config.from_file
def from_file(filename) if %w{ .yml .yaml }.include?(File.extname(filename)) from_yaml(filename) elsif File.extname(filename) == ".json" from_json(filename) elsif File.extname(filename) == ".toml" from_toml(filename) else instance_eval(IO.read(filename), filename,...
ruby
def from_file(filename) if %w{ .yml .yaml }.include?(File.extname(filename)) from_yaml(filename) elsif File.extname(filename) == ".json" from_json(filename) elsif File.extname(filename) == ".toml" from_toml(filename) else instance_eval(IO.read(filename), filename,...
[ "def", "from_file", "(", "filename", ")", "if", "%w{", ".yml", ".yaml", "}", ".", "include?", "(", "File", ".", "extname", "(", "filename", ")", ")", "from_yaml", "(", "filename", ")", "elsif", "File", ".", "extname", "(", "filename", ")", "==", "\".js...
Loads a given ruby file, and runs instance_eval against it in the context of the current object. Raises an IOError if the file cannot be found, or is not readable. === Parameters filename<String>:: A filename to read from
[ "Loads", "a", "given", "ruby", "file", "and", "runs", "instance_eval", "against", "it", "in", "the", "context", "of", "the", "current", "object", "." ]
039024aa606d2346235bfbb1c482a95d53c792ac
https://github.com/chef/mixlib-config/blob/039024aa606d2346235bfbb1c482a95d53c792ac/lib/mixlib/config.rb#L55-L65
train
chef/mixlib-config
lib/mixlib/config.rb
Mixlib.Config.reset
def reset self.configuration = Hash.new config_contexts.values.each { |config_context| config_context.reset } end
ruby
def reset self.configuration = Hash.new config_contexts.values.each { |config_context| config_context.reset } end
[ "def", "reset", "self", ".", "configuration", "=", "Hash", ".", "new", "config_contexts", ".", "values", ".", "each", "{", "|", "config_context", "|", "config_context", ".", "reset", "}", "end" ]
Resets all config options to their defaults.
[ "Resets", "all", "config", "options", "to", "their", "defaults", "." ]
039024aa606d2346235bfbb1c482a95d53c792ac
https://github.com/chef/mixlib-config/blob/039024aa606d2346235bfbb1c482a95d53c792ac/lib/mixlib/config.rb#L167-L170
train
chef/mixlib-config
lib/mixlib/config.rb
Mixlib.Config.save
def save(include_defaults = false) result = configuration.dup if include_defaults (configurables.keys - result.keys).each do |missing_default| # Ask any configurables to save themselves into the result array if configurables[missing_default].has_default result[missing...
ruby
def save(include_defaults = false) result = configuration.dup if include_defaults (configurables.keys - result.keys).each do |missing_default| # Ask any configurables to save themselves into the result array if configurables[missing_default].has_default result[missing...
[ "def", "save", "(", "include_defaults", "=", "false", ")", "result", "=", "configuration", ".", "dup", "if", "include_defaults", "(", "configurables", ".", "keys", "-", "result", ".", "keys", ")", ".", "each", "do", "|", "missing_default", "|", "if", "conf...
Makes a copy of any non-default values. This returns a shallow copy of the hash; while the hash itself is duplicated a la dup, modifying data inside arrays and hashes may modify the original Config object. === Returns Hash of values the user has set. === Examples For example, this config class: class ...
[ "Makes", "a", "copy", "of", "any", "non", "-", "default", "values", "." ]
039024aa606d2346235bfbb1c482a95d53c792ac
https://github.com/chef/mixlib-config/blob/039024aa606d2346235bfbb1c482a95d53c792ac/lib/mixlib/config.rb#L215-L242
train
chef/mixlib-config
lib/mixlib/config.rb
Mixlib.Config.restore
def restore(hash) self.configuration = hash.reject { |key, value| config_contexts.key?(key) } config_contexts.each do |key, config_context| if hash.key?(key) config_context.restore(hash[key]) else config_context.reset end end config_context_lists.each ...
ruby
def restore(hash) self.configuration = hash.reject { |key, value| config_contexts.key?(key) } config_contexts.each do |key, config_context| if hash.key?(key) config_context.restore(hash[key]) else config_context.reset end end config_context_lists.each ...
[ "def", "restore", "(", "hash", ")", "self", ".", "configuration", "=", "hash", ".", "reject", "{", "|", "key", ",", "value", "|", "config_contexts", ".", "key?", "(", "key", ")", "}", "config_contexts", ".", "each", "do", "|", "key", ",", "config_conte...
Restore non-default values from the given hash. === Parameters hash<Hash>: a hash in the same format as output by save. === Returns self
[ "Restore", "non", "-", "default", "values", "from", "the", "given", "hash", "." ]
039024aa606d2346235bfbb1c482a95d53c792ac
https://github.com/chef/mixlib-config/blob/039024aa606d2346235bfbb1c482a95d53c792ac/lib/mixlib/config.rb#L252-L281
train
chef/mixlib-config
lib/mixlib/config.rb
Mixlib.Config.merge!
def merge!(hash) hash.each do |key, value| if config_contexts.key?(key) # Grab the config context and let internal_get cache it if so desired config_contexts[key].restore(value) else configuration[key] = value end end self end
ruby
def merge!(hash) hash.each do |key, value| if config_contexts.key?(key) # Grab the config context and let internal_get cache it if so desired config_contexts[key].restore(value) else configuration[key] = value end end self end
[ "def", "merge!", "(", "hash", ")", "hash", ".", "each", "do", "|", "key", ",", "value", "|", "if", "config_contexts", ".", "key?", "(", "key", ")", "config_contexts", "[", "key", "]", ".", "restore", "(", "value", ")", "else", "configuration", "[", "...
Merge an incoming hash with our config options === Parameters hash<Hash>: a hash in the same format as output by save. === Returns self
[ "Merge", "an", "incoming", "hash", "with", "our", "config", "options" ]
039024aa606d2346235bfbb1c482a95d53c792ac
https://github.com/chef/mixlib-config/blob/039024aa606d2346235bfbb1c482a95d53c792ac/lib/mixlib/config.rb#L290-L300
train
chef/mixlib-config
lib/mixlib/config.rb
Mixlib.Config.config_context
def config_context(symbol, &block) if configurables.key?(symbol) raise ReopenedConfigurableWithConfigContextError, "Cannot redefine config value #{symbol} with a config context" end if config_contexts.key?(symbol) context = config_contexts[symbol] else context = Class.ne...
ruby
def config_context(symbol, &block) if configurables.key?(symbol) raise ReopenedConfigurableWithConfigContextError, "Cannot redefine config value #{symbol} with a config context" end if config_contexts.key?(symbol) context = config_contexts[symbol] else context = Class.ne...
[ "def", "config_context", "(", "symbol", ",", "&", "block", ")", "if", "configurables", ".", "key?", "(", "symbol", ")", "raise", "ReopenedConfigurableWithConfigContextError", ",", "\"Cannot redefine config value #{symbol} with a config context\"", "end", "if", "config_conte...
Allows you to create a new config context where you can define new options with default values. This method allows you to open up the configurable more than once. For example: config_context :server_info do configurable(:url).defaults_to("http://localhost") end === Parameters symbol<Symbol>: the name of t...
[ "Allows", "you", "to", "create", "a", "new", "config", "context", "where", "you", "can", "define", "new", "options", "with", "default", "values", "." ]
039024aa606d2346235bfbb1c482a95d53c792ac
https://github.com/chef/mixlib-config/blob/039024aa606d2346235bfbb1c482a95d53c792ac/lib/mixlib/config.rb#L399-L419
train
chef/mixlib-config
lib/mixlib/config.rb
Mixlib.Config.config_context_list
def config_context_list(plural_symbol, singular_symbol, &block) if configurables.key?(plural_symbol) raise ReopenedConfigurableWithConfigContextError, "Cannot redefine config value #{plural_symbol} with a config context" end unless config_context_lists.key?(plural_symbol) config_conte...
ruby
def config_context_list(plural_symbol, singular_symbol, &block) if configurables.key?(plural_symbol) raise ReopenedConfigurableWithConfigContextError, "Cannot redefine config value #{plural_symbol} with a config context" end unless config_context_lists.key?(plural_symbol) config_conte...
[ "def", "config_context_list", "(", "plural_symbol", ",", "singular_symbol", ",", "&", "block", ")", "if", "configurables", ".", "key?", "(", "plural_symbol", ")", "raise", "ReopenedConfigurableWithConfigContextError", ",", "\"Cannot redefine config value #{plural_symbol} with...
Allows you to create a new list of config contexts where you can define new options with default values. This method allows you to open up the configurable more than once. For example: config_context_list :listeners, :listener do configurable(:url).defaults_to("http://localhost") end === Parameters symbol...
[ "Allows", "you", "to", "create", "a", "new", "list", "of", "config", "contexts", "where", "you", "can", "define", "new", "options", "with", "default", "values", "." ]
039024aa606d2346235bfbb1c482a95d53c792ac
https://github.com/chef/mixlib-config/blob/039024aa606d2346235bfbb1c482a95d53c792ac/lib/mixlib/config.rb#L437-L451
train
chef/mixlib-config
lib/mixlib/config.rb
Mixlib.Config.config_context_hash
def config_context_hash(plural_symbol, singular_symbol, &block) if configurables.key?(plural_symbol) raise ReopenedConfigurableWithConfigContextError, "Cannot redefine config value #{plural_symbol} with a config context" end unless config_context_hashes.key?(plural_symbol) config_cont...
ruby
def config_context_hash(plural_symbol, singular_symbol, &block) if configurables.key?(plural_symbol) raise ReopenedConfigurableWithConfigContextError, "Cannot redefine config value #{plural_symbol} with a config context" end unless config_context_hashes.key?(plural_symbol) config_cont...
[ "def", "config_context_hash", "(", "plural_symbol", ",", "singular_symbol", ",", "&", "block", ")", "if", "configurables", ".", "key?", "(", "plural_symbol", ")", "raise", "ReopenedConfigurableWithConfigContextError", ",", "\"Cannot redefine config value #{plural_symbol} with...
Allows you to create a new hash of config contexts where you can define new options with default values. This method allows you to open up the configurable more than once. For example: config_context_hash :listeners, :listener do configurable(:url).defaults_to("http://localhost") end === Parameters symbol...
[ "Allows", "you", "to", "create", "a", "new", "hash", "of", "config", "contexts", "where", "you", "can", "define", "new", "options", "with", "default", "values", "." ]
039024aa606d2346235bfbb1c482a95d53c792ac
https://github.com/chef/mixlib-config/blob/039024aa606d2346235bfbb1c482a95d53c792ac/lib/mixlib/config.rb#L469-L483
train
chef/mixlib-config
lib/mixlib/config.rb
Mixlib.Config.internal_set
def internal_set(symbol, value) if configurables.key?(symbol) configurables[symbol].set(configuration, value) elsif config_contexts.key?(symbol) config_contexts[symbol].restore(value.to_hash) else if config_strict_mode == :warn Chef::Log.warn("Setting unsupported conf...
ruby
def internal_set(symbol, value) if configurables.key?(symbol) configurables[symbol].set(configuration, value) elsif config_contexts.key?(symbol) config_contexts[symbol].restore(value.to_hash) else if config_strict_mode == :warn Chef::Log.warn("Setting unsupported conf...
[ "def", "internal_set", "(", "symbol", ",", "value", ")", "if", "configurables", ".", "key?", "(", "symbol", ")", "configurables", "[", "symbol", "]", ".", "set", "(", "configuration", ",", "value", ")", "elsif", "config_contexts", ".", "key?", "(", "symbol...
Internal dispatch setter for config values. === Parameters symbol<Symbol>:: Name of the method (variable setter) value<Object>:: Value to be set in config hash
[ "Internal", "dispatch", "setter", "for", "config", "values", "." ]
039024aa606d2346235bfbb1c482a95d53c792ac
https://github.com/chef/mixlib-config/blob/039024aa606d2346235bfbb1c482a95d53c792ac/lib/mixlib/config.rb#L606-L619
train
ryanb/nested_form
lib/nested_form/builder_mixin.rb
NestedForm.BuilderMixin.link_to_remove
def link_to_remove(*args, &block) options = args.extract_options!.symbolize_keys options[:class] = [options[:class], "remove_nested_fields"].compact.join(" ") # Extracting "milestones" from "...[milestones_attributes][...]" md = object_name.to_s.match /(\w+)_attributes\](?:\[[\w\d]+\])?$/ ...
ruby
def link_to_remove(*args, &block) options = args.extract_options!.symbolize_keys options[:class] = [options[:class], "remove_nested_fields"].compact.join(" ") # Extracting "milestones" from "...[milestones_attributes][...]" md = object_name.to_s.match /(\w+)_attributes\](?:\[[\w\d]+\])?$/ ...
[ "def", "link_to_remove", "(", "*", "args", ",", "&", "block", ")", "options", "=", "args", ".", "extract_options!", ".", "symbolize_keys", "options", "[", ":class", "]", "=", "[", "options", "[", ":class", "]", ",", "\"remove_nested_fields\"", "]", ".", "c...
Adds a link to remove the associated record. The first argment is the name of the link. f.link_to_remove("Remove Task") You can pass HTML options in a hash at the end and a block for the content. <%= f.link_to_remove(:class => "remove_task", :href => "#") do %> Remove Task <% end %> See the README f...
[ "Adds", "a", "link", "to", "remove", "the", "associated", "record", ".", "The", "first", "argment", "is", "the", "name", "of", "the", "link", "." ]
1b0689dfb4d230ceabd278eba159fcb02f23c68a
https://github.com/ryanb/nested_form/blob/1b0689dfb4d230ceabd278eba159fcb02f23c68a/lib/nested_form/builder_mixin.rb#L60-L72
train
noteflakes/lyp
lib/lyp/resolver.rb
Lyp.DependencyResolver.resolve_tree
def resolve_tree permutations = permutate_simplified_tree permutations = filter_invalid_permutations(permutations) # select highest versioned dependencies (for those specified by user) user_deps = tree.dependencies.keys result = select_highest_versioned_permutation(permutations, user_deps...
ruby
def resolve_tree permutations = permutate_simplified_tree permutations = filter_invalid_permutations(permutations) # select highest versioned dependencies (for those specified by user) user_deps = tree.dependencies.keys result = select_highest_versioned_permutation(permutations, user_deps...
[ "def", "resolve_tree", "permutations", "=", "permutate_simplified_tree", "permutations", "=", "filter_invalid_permutations", "(", "permutations", ")", "user_deps", "=", "tree", ".", "dependencies", ".", "keys", "result", "=", "select_highest_versioned_permutation", "(", "...
Resolve the given dependency tree and return a list of concrete packages that meet all dependency requirements. The following stages are involved: - Create permutations of possible version combinations for all dependencies - Remove invalid permutations - Select the permutation with the highest versions
[ "Resolve", "the", "given", "dependency", "tree", "and", "return", "a", "list", "of", "concrete", "packages", "that", "meet", "all", "dependency", "requirements", "." ]
cca29b702f65eb412cba50ba9d4e879e14930003
https://github.com/noteflakes/lyp/blob/cca29b702f65eb412cba50ba9d4e879e14930003/lib/lyp/resolver.rb#L108-L121
train
noteflakes/lyp
lib/lyp/resolver.rb
Lyp.DependencyResolver.dependencies_array
def dependencies_array(leaf, processed = {}) return processed[leaf] if processed[leaf] deps_array = [] processed[leaf] = deps_array leaf.each do |pack, versions| a = [] versions.each do |version, deps| perms = [] sub_perms = dependencies_array(deps, processe...
ruby
def dependencies_array(leaf, processed = {}) return processed[leaf] if processed[leaf] deps_array = [] processed[leaf] = deps_array leaf.each do |pack, versions| a = [] versions.each do |version, deps| perms = [] sub_perms = dependencies_array(deps, processe...
[ "def", "dependencies_array", "(", "leaf", ",", "processed", "=", "{", "}", ")", "return", "processed", "[", "leaf", "]", "if", "processed", "[", "leaf", "]", "deps_array", "=", "[", "]", "processed", "[", "leaf", "]", "=", "deps_array", "leaf", ".", "e...
Converts a simplified dependency tree into an array of dependencies, containing a sub-array for each top-level dependency. Each such sub-array contains, in its turn, version permutations for the top-level dependency and any transitive dependencies.
[ "Converts", "a", "simplified", "dependency", "tree", "into", "an", "array", "of", "dependencies", "containing", "a", "sub", "-", "array", "for", "each", "top", "-", "level", "dependency", ".", "Each", "such", "sub", "-", "array", "contains", "in", "its", "...
cca29b702f65eb412cba50ba9d4e879e14930003
https://github.com/noteflakes/lyp/blob/cca29b702f65eb412cba50ba9d4e879e14930003/lib/lyp/resolver.rb#L317-L341
train
noteflakes/lyp
lib/lyp/resolver.rb
Lyp.DependencyResolver.filter_invalid_permutations
def filter_invalid_permutations(permutations) valid = [] permutations.each do |perm| versions = {}; invalid = false perm.each do |ref| if ref =~ /(.+)@(.+)/ name, version = $1, $2 if versions[name] && versions[name] != version invalid = true ...
ruby
def filter_invalid_permutations(permutations) valid = [] permutations.each do |perm| versions = {}; invalid = false perm.each do |ref| if ref =~ /(.+)@(.+)/ name, version = $1, $2 if versions[name] && versions[name] != version invalid = true ...
[ "def", "filter_invalid_permutations", "(", "permutations", ")", "valid", "=", "[", "]", "permutations", ".", "each", "do", "|", "perm", "|", "versions", "=", "{", "}", ";", "invalid", "=", "false", "perm", ".", "each", "do", "|", "ref", "|", "if", "ref...
Remove invalid permutations, that is permutations that contain multiple versions of the same package, a scenario which could arrive in the case of circular dependencies, or when different dependencies rely on different versions of the same transitive dependency.
[ "Remove", "invalid", "permutations", "that", "is", "permutations", "that", "contain", "multiple", "versions", "of", "the", "same", "package", "a", "scenario", "which", "could", "arrive", "in", "the", "case", "of", "circular", "dependencies", "or", "when", "diffe...
cca29b702f65eb412cba50ba9d4e879e14930003
https://github.com/noteflakes/lyp/blob/cca29b702f65eb412cba50ba9d4e879e14930003/lib/lyp/resolver.rb#L347-L366
train
noteflakes/lyp
lib/lyp/resolver.rb
Lyp.DependencyResolver.select_highest_versioned_permutation
def select_highest_versioned_permutation(permutations, user_deps) sorted = sort_permutations(permutations, user_deps) sorted.empty? ? [] : sorted.last end
ruby
def select_highest_versioned_permutation(permutations, user_deps) sorted = sort_permutations(permutations, user_deps) sorted.empty? ? [] : sorted.last end
[ "def", "select_highest_versioned_permutation", "(", "permutations", ",", "user_deps", ")", "sorted", "=", "sort_permutations", "(", "permutations", ",", "user_deps", ")", "sorted", ".", "empty?", "?", "[", "]", ":", "sorted", ".", "last", "end" ]
Select the highest versioned permutation of package versions
[ "Select", "the", "highest", "versioned", "permutation", "of", "package", "versions" ]
cca29b702f65eb412cba50ba9d4e879e14930003
https://github.com/noteflakes/lyp/blob/cca29b702f65eb412cba50ba9d4e879e14930003/lib/lyp/resolver.rb#L369-L372
train
noteflakes/lyp
lib/lyp/resolver.rb
Lyp.DependencyResolver.sort_permutations
def sort_permutations(permutations, user_deps) # Cache for versions converted to Gem::Version instances versions = {} map = lambda do |m, p| if p =~ Lyp::PACKAGE_RE m[$1] = versions[p] ||= (Lyp.version($2 || '0.0') rescue nil) end m end compare = lambda ...
ruby
def sort_permutations(permutations, user_deps) # Cache for versions converted to Gem::Version instances versions = {} map = lambda do |m, p| if p =~ Lyp::PACKAGE_RE m[$1] = versions[p] ||= (Lyp.version($2 || '0.0') rescue nil) end m end compare = lambda ...
[ "def", "sort_permutations", "(", "permutations", ",", "user_deps", ")", "versions", "=", "{", "}", "map", "=", "lambda", "do", "|", "m", ",", "p", "|", "if", "p", "=~", "Lyp", "::", "PACKAGE_RE", "m", "[", "$1", "]", "=", "versions", "[", "p", "]",...
Sort permutations by version numbers
[ "Sort", "permutations", "by", "version", "numbers" ]
cca29b702f65eb412cba50ba9d4e879e14930003
https://github.com/noteflakes/lyp/blob/cca29b702f65eb412cba50ba9d4e879e14930003/lib/lyp/resolver.rb#L375-L405
train
noteflakes/lyp
lib/lyp/resolver.rb
Lyp.DependencyResolver.find_matching_packages
def find_matching_packages(req) return {} unless req =~ Lyp::PACKAGE_RE req_package = $1 req_version = $2 req = nil if @opts[:forced_package_paths] && @opts[:forced_package_paths][req_package] req_version = 'forced' end req = Lyp.version_req(req_version || '>=0') res...
ruby
def find_matching_packages(req) return {} unless req =~ Lyp::PACKAGE_RE req_package = $1 req_version = $2 req = nil if @opts[:forced_package_paths] && @opts[:forced_package_paths][req_package] req_version = 'forced' end req = Lyp.version_req(req_version || '>=0') res...
[ "def", "find_matching_packages", "(", "req", ")", "return", "{", "}", "unless", "req", "=~", "Lyp", "::", "PACKAGE_RE", "req_package", "=", "$1", "req_version", "=", "$2", "req", "=", "nil", "if", "@opts", "[", ":forced_package_paths", "]", "&&", "@opts", ...
Find packages meeting the version requirement
[ "Find", "packages", "meeting", "the", "version", "requirement" ]
cca29b702f65eb412cba50ba9d4e879e14930003
https://github.com/noteflakes/lyp/blob/cca29b702f65eb412cba50ba9d4e879e14930003/lib/lyp/resolver.rb#L438-L462
train
noteflakes/lyp
lib/lyp/resolver.rb
Lyp.DependencyResolver.find_package_versions
def find_package_versions(ref, leaf, location) return {} unless ref =~ Lyp::PACKAGE_RE ref_package = $1 version_clause = $2 matches = find_matching_packages(ref) # Raise if no match found and we're at top of the tree if matches.empty? && (leaf == tree) && !opts[:ignore_missing] ...
ruby
def find_package_versions(ref, leaf, location) return {} unless ref =~ Lyp::PACKAGE_RE ref_package = $1 version_clause = $2 matches = find_matching_packages(ref) # Raise if no match found and we're at top of the tree if matches.empty? && (leaf == tree) && !opts[:ignore_missing] ...
[ "def", "find_package_versions", "(", "ref", ",", "leaf", ",", "location", ")", "return", "{", "}", "unless", "ref", "=~", "Lyp", "::", "PACKAGE_RE", "ref_package", "=", "$1", "version_clause", "=", "$2", "matches", "=", "find_matching_packages", "(", "ref", ...
Find available packaging matching the package specifier, and queue them for processing any include files or transitive dependencies.
[ "Find", "available", "packaging", "matching", "the", "package", "specifier", "and", "queue", "them", "for", "processing", "any", "include", "files", "or", "transitive", "dependencies", "." ]
cca29b702f65eb412cba50ba9d4e879e14930003
https://github.com/noteflakes/lyp/blob/cca29b702f65eb412cba50ba9d4e879e14930003/lib/lyp/resolver.rb#L466-L487
train
noteflakes/lyp
lib/lyp/resolver.rb
Lyp.DependencyResolver.squash_old_versions
def squash_old_versions specifiers = map_specifiers_to_versions compare_versions = lambda do |x, y| v_x = x =~ Lyp::PACKAGE_RE && Lyp.version($2) v_y = y =~ Lyp::PACKAGE_RE && Lyp.version($2) x <=> y end specifiers.each do |package, clauses| # Remove old version...
ruby
def squash_old_versions specifiers = map_specifiers_to_versions compare_versions = lambda do |x, y| v_x = x =~ Lyp::PACKAGE_RE && Lyp.version($2) v_y = y =~ Lyp::PACKAGE_RE && Lyp.version($2) x <=> y end specifiers.each do |package, clauses| # Remove old version...
[ "def", "squash_old_versions", "specifiers", "=", "map_specifiers_to_versions", "compare_versions", "=", "lambda", "do", "|", "x", ",", "y", "|", "v_x", "=", "x", "=~", "Lyp", "::", "PACKAGE_RE", "&&", "Lyp", ".", "version", "(", "$2", ")", "v_y", "=", "y",...
Remove redundant older versions of dependencies by collating package versions by package specifiers, then removing older versions for any package for which a single package specifier exists.
[ "Remove", "redundant", "older", "versions", "of", "dependencies", "by", "collating", "package", "versions", "by", "package", "specifiers", "then", "removing", "older", "versions", "for", "any", "package", "for", "which", "a", "single", "package", "specifier", "exi...
cca29b702f65eb412cba50ba9d4e879e14930003
https://github.com/noteflakes/lyp/blob/cca29b702f65eb412cba50ba9d4e879e14930003/lib/lyp/resolver.rb#L492-L515
train
noteflakes/lyp
lib/lyp/resolver.rb
Lyp.DependencyResolver.map_specifiers_to_versions
def map_specifiers_to_versions specifiers = {} processed = {} l = lambda do |t| return if processed[t.object_id] processed[t.object_id] = true t.dependencies.each do |package, spec| specifiers[package] ||= {} specifiers[package][spec.clause] ||= [] ...
ruby
def map_specifiers_to_versions specifiers = {} processed = {} l = lambda do |t| return if processed[t.object_id] processed[t.object_id] = true t.dependencies.each do |package, spec| specifiers[package] ||= {} specifiers[package][spec.clause] ||= [] ...
[ "def", "map_specifiers_to_versions", "specifiers", "=", "{", "}", "processed", "=", "{", "}", "l", "=", "lambda", "do", "|", "t", "|", "return", "if", "processed", "[", "t", ".", "object_id", "]", "processed", "[", "t", ".", "object_id", "]", "=", "tru...
Return a hash mapping packages to package specifiers to spec objects, to be used to eliminate older versions from the dependency tree
[ "Return", "a", "hash", "mapping", "packages", "to", "package", "specifiers", "to", "spec", "objects", "to", "be", "used", "to", "eliminate", "older", "versions", "from", "the", "dependency", "tree" ]
cca29b702f65eb412cba50ba9d4e879e14930003
https://github.com/noteflakes/lyp/blob/cca29b702f65eb412cba50ba9d4e879e14930003/lib/lyp/resolver.rb#L519-L536
train
noteflakes/lyp
lib/lyp/resolver.rb
Lyp.DependencyResolver.remove_unfulfilled_dependencies
def remove_unfulfilled_dependencies(leaf, raise_on_missing = true, processed = {}) tree.dependencies.each do |package, dependency| dependency.versions.select! do |version, leaf| if processed[version] true else processed[version] = true # Remove unfu...
ruby
def remove_unfulfilled_dependencies(leaf, raise_on_missing = true, processed = {}) tree.dependencies.each do |package, dependency| dependency.versions.select! do |version, leaf| if processed[version] true else processed[version] = true # Remove unfu...
[ "def", "remove_unfulfilled_dependencies", "(", "leaf", ",", "raise_on_missing", "=", "true", ",", "processed", "=", "{", "}", ")", "tree", ".", "dependencies", ".", "each", "do", "|", "package", ",", "dependency", "|", "dependency", ".", "versions", ".", "se...
Recursively remove any dependency for which no version is locally available. If no version is found for any of the dependencies specified by the user, an error is raised. The processed hash is used for keeping track of dependencies that were already processed, and thus deal with circular dependencies.
[ "Recursively", "remove", "any", "dependency", "for", "which", "no", "version", "is", "locally", "available", ".", "If", "no", "version", "is", "found", "for", "any", "of", "the", "dependencies", "specified", "by", "the", "user", "an", "error", "is", "raised"...
cca29b702f65eb412cba50ba9d4e879e14930003
https://github.com/noteflakes/lyp/blob/cca29b702f65eb412cba50ba9d4e879e14930003/lib/lyp/resolver.rb#L544-L565
train
airbrake/airbrake-ruby
lib/airbrake-ruby/filter_chain.rb
Airbrake.FilterChain.add_filter
def add_filter(filter) @filters = (@filters << filter).sort_by do |f| f.respond_to?(:weight) ? f.weight : DEFAULT_WEIGHT end.reverse! end
ruby
def add_filter(filter) @filters = (@filters << filter).sort_by do |f| f.respond_to?(:weight) ? f.weight : DEFAULT_WEIGHT end.reverse! end
[ "def", "add_filter", "(", "filter", ")", "@filters", "=", "(", "@filters", "<<", "filter", ")", ".", "sort_by", "do", "|", "f", "|", "f", ".", "respond_to?", "(", ":weight", ")", "?", "f", ".", "weight", ":", "DEFAULT_WEIGHT", "end", ".", "reverse!", ...
Adds a filter to the filter chain. Sorts filters by weight. @param [#call] filter The filter object (proc, class, module, etc) @return [void]
[ "Adds", "a", "filter", "to", "the", "filter", "chain", ".", "Sorts", "filters", "by", "weight", "." ]
bb560edf03df57b559e1dee1d2e9ec6480a686b8
https://github.com/airbrake/airbrake-ruby/blob/bb560edf03df57b559e1dee1d2e9ec6480a686b8/lib/airbrake-ruby/filter_chain.rb#L48-L52
train
airbrake/airbrake-ruby
lib/airbrake-ruby/filter_chain.rb
Airbrake.FilterChain.delete_filter
def delete_filter(filter_class) index = @filters.index { |f| f.class.name == filter_class.name } @filters.delete_at(index) if index end
ruby
def delete_filter(filter_class) index = @filters.index { |f| f.class.name == filter_class.name } @filters.delete_at(index) if index end
[ "def", "delete_filter", "(", "filter_class", ")", "index", "=", "@filters", ".", "index", "{", "|", "f", "|", "f", ".", "class", ".", "name", "==", "filter_class", ".", "name", "}", "@filters", ".", "delete_at", "(", "index", ")", "if", "index", "end" ...
Deletes a filter from the the filter chain. @param [Class] filter_class The class of the filter you want to delete @return [void] @since v3.1.0
[ "Deletes", "a", "filter", "from", "the", "the", "filter", "chain", "." ]
bb560edf03df57b559e1dee1d2e9ec6480a686b8
https://github.com/airbrake/airbrake-ruby/blob/bb560edf03df57b559e1dee1d2e9ec6480a686b8/lib/airbrake-ruby/filter_chain.rb#L59-L62
train
airbrake/airbrake-ruby
lib/airbrake-ruby/truncator.rb
Airbrake.Truncator.replace_invalid_characters
def replace_invalid_characters(str) encoding = str.encoding utf8_string = (encoding == Encoding::UTF_8 || encoding == Encoding::ASCII) return str if utf8_string && str.valid_encoding? temp_str = str.dup temp_str.encode!(TEMP_ENCODING, ENCODING_OPTIONS) if utf8_string temp_str.encode...
ruby
def replace_invalid_characters(str) encoding = str.encoding utf8_string = (encoding == Encoding::UTF_8 || encoding == Encoding::ASCII) return str if utf8_string && str.valid_encoding? temp_str = str.dup temp_str.encode!(TEMP_ENCODING, ENCODING_OPTIONS) if utf8_string temp_str.encode...
[ "def", "replace_invalid_characters", "(", "str", ")", "encoding", "=", "str", ".", "encoding", "utf8_string", "=", "(", "encoding", "==", "Encoding", "::", "UTF_8", "||", "encoding", "==", "Encoding", "::", "ASCII", ")", "return", "str", "if", "utf8_string", ...
Replaces invalid characters in a string with arbitrary encoding. @param [String] str The string to replace characters @return [String] a UTF-8 encoded string @see https://github.com/flori/json/commit/3e158410e81f94dbbc3da6b7b35f4f64983aa4e3
[ "Replaces", "invalid", "characters", "in", "a", "string", "with", "arbitrary", "encoding", "." ]
bb560edf03df57b559e1dee1d2e9ec6480a686b8
https://github.com/airbrake/airbrake-ruby/blob/bb560edf03df57b559e1dee1d2e9ec6480a686b8/lib/airbrake-ruby/truncator.rb#L105-L113
train