id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
16,200
chef/knife-azure
lib/azure/resource_management/vnet_config.rb
Azure::ARM.VnetConfig.divide_network
def divide_network(address_prefix) network_address = IPAddress(address_prefix) prefix = nil case network_address.count when 4097..65536 prefix = "20" when 256..4096 prefix = "24" end ## if the given network is small then do not divide it else divide using ...
ruby
def divide_network(address_prefix) network_address = IPAddress(address_prefix) prefix = nil case network_address.count when 4097..65536 prefix = "20" when 256..4096 prefix = "24" end ## if the given network is small then do not divide it else divide using ...
[ "def", "divide_network", "(", "address_prefix", ")", "network_address", "=", "IPAddress", "(", "address_prefix", ")", "prefix", "=", "nil", "case", "network_address", ".", "count", "when", "4097", "..", "65536", "prefix", "=", "\"20\"", "when", "256", "..", "4...
when a address space in an existing virtual network is not used at all then divide the space into the number of subnets based on the total number of hosts that network supports
[ "when", "a", "address", "space", "in", "an", "existing", "virtual", "network", "is", "not", "used", "at", "all", "then", "divide", "the", "space", "into", "the", "number", "of", "subnets", "based", "on", "the", "total", "number", "of", "hosts", "that", "...
2cf998b286cd169478ba547057e6c5ca57217604
https://github.com/chef/knife-azure/blob/2cf998b286cd169478ba547057e6c5ca57217604/lib/azure/resource_management/vnet_config.rb#L111-L125
16,201
chef/knife-azure
lib/azure/resource_management/vnet_config.rb
Azure::ARM.VnetConfig.new_subnet_address_prefix
def new_subnet_address_prefix(vnet_address_prefix, subnets) if subnets.empty? ## no subnets exist in the given address space of the virtual network, so divide the network into smaller subnets (based on the network size) and allocate space for the new subnet to be added ## divide_network(vnet_address_prefi...
ruby
def new_subnet_address_prefix(vnet_address_prefix, subnets) if subnets.empty? ## no subnets exist in the given address space of the virtual network, so divide the network into smaller subnets (based on the network size) and allocate space for the new subnet to be added ## divide_network(vnet_address_prefi...
[ "def", "new_subnet_address_prefix", "(", "vnet_address_prefix", ",", "subnets", ")", "if", "subnets", ".", "empty?", "## no subnets exist in the given address space of the virtual network, so divide the network into smaller subnets (based on the network size) and allocate space for the new sub...
calculate and return address_prefix for the new subnet to be added in the existing virtual network
[ "calculate", "and", "return", "address_prefix", "for", "the", "new", "subnet", "to", "be", "added", "in", "the", "existing", "virtual", "network" ]
2cf998b286cd169478ba547057e6c5ca57217604
https://github.com/chef/knife-azure/blob/2cf998b286cd169478ba547057e6c5ca57217604/lib/azure/resource_management/vnet_config.rb#L135-L185
16,202
chef/knife-azure
lib/azure/resource_management/vnet_config.rb
Azure::ARM.VnetConfig.add_subnet
def add_subnet(subnet_name, vnet_config, subnets) new_subnet_prefix = nil vnet_address_prefix_count = 0 vnet_address_space = vnet_config[:addressPrefixes] ## search for space in all the address prefixes of the virtual network ## while new_subnet_prefix.nil? && vnet_address_space.length > ...
ruby
def add_subnet(subnet_name, vnet_config, subnets) new_subnet_prefix = nil vnet_address_prefix_count = 0 vnet_address_space = vnet_config[:addressPrefixes] ## search for space in all the address prefixes of the virtual network ## while new_subnet_prefix.nil? && vnet_address_space.length > ...
[ "def", "add_subnet", "(", "subnet_name", ",", "vnet_config", ",", "subnets", ")", "new_subnet_prefix", "=", "nil", "vnet_address_prefix_count", "=", "0", "vnet_address_space", "=", "vnet_config", "[", ":addressPrefixes", "]", "## search for space in all the address prefixes...
add new subnet into the existing virtual network
[ "add", "new", "subnet", "into", "the", "existing", "virtual", "network" ]
2cf998b286cd169478ba547057e6c5ca57217604
https://github.com/chef/knife-azure/blob/2cf998b286cd169478ba547057e6c5ca57217604/lib/azure/resource_management/vnet_config.rb#L188-L213
16,203
chef/knife-azure
lib/azure/resource_management/vnet_config.rb
Azure::ARM.VnetConfig.create_vnet_config
def create_vnet_config(resource_group_name, vnet_name, vnet_subnet_name) raise ArgumentError, "GatewaySubnet cannot be used as the name for --azure-vnet-subnet-name option. GatewaySubnet can only be used for virtual network gateways." if vnet_subnet_name == "GatewaySubnet" vnet_config = {} subnets = ...
ruby
def create_vnet_config(resource_group_name, vnet_name, vnet_subnet_name) raise ArgumentError, "GatewaySubnet cannot be used as the name for --azure-vnet-subnet-name option. GatewaySubnet can only be used for virtual network gateways." if vnet_subnet_name == "GatewaySubnet" vnet_config = {} subnets = ...
[ "def", "create_vnet_config", "(", "resource_group_name", ",", "vnet_name", ",", "vnet_subnet_name", ")", "raise", "ArgumentError", ",", "\"GatewaySubnet cannot be used as the name for --azure-vnet-subnet-name option. GatewaySubnet can only be used for virtual network gateways.\"", "if", ...
virtual network configuration creation for the new vnet creation or to handle existing vnet
[ "virtual", "network", "configuration", "creation", "for", "the", "new", "vnet", "creation", "or", "to", "handle", "existing", "vnet" ]
2cf998b286cd169478ba547057e6c5ca57217604
https://github.com/chef/knife-azure/blob/2cf998b286cd169478ba547057e6c5ca57217604/lib/azure/resource_management/vnet_config.rb#L217-L252
16,204
chef/knife-azure
lib/azure/service_management/host.rb
Azure.Hosts.fetch_from_cloud
def fetch_from_cloud(name) ret_val = @connection.query_azure("hostedservices/#{name}") error_code, error_message = error_from_response_xml(ret_val) if ret_val if ret_val.nil? || error_code.length > 0 Chef::Log.warn("Unable to find hosted(cloud) service:" + error_code + " : " + error_message) i...
ruby
def fetch_from_cloud(name) ret_val = @connection.query_azure("hostedservices/#{name}") error_code, error_message = error_from_response_xml(ret_val) if ret_val if ret_val.nil? || error_code.length > 0 Chef::Log.warn("Unable to find hosted(cloud) service:" + error_code + " : " + error_message) i...
[ "def", "fetch_from_cloud", "(", "name", ")", "ret_val", "=", "@connection", ".", "query_azure", "(", "\"hostedservices/#{name}\"", ")", "error_code", ",", "error_message", "=", "error_from_response_xml", "(", "ret_val", ")", "if", "ret_val", "if", "ret_val", ".", ...
Look up hosted service on cloud and not local cache
[ "Look", "up", "hosted", "service", "on", "cloud", "and", "not", "local", "cache" ]
2cf998b286cd169478ba547057e6c5ca57217604
https://github.com/chef/knife-azure/blob/2cf998b286cd169478ba547057e6c5ca57217604/lib/azure/service_management/host.rb#L73-L82
16,205
weppos/publicsuffix-ruby
lib/public_suffix/list.rb
PublicSuffix.List.each
def each(&block) Enumerator.new do |y| @rules.each do |key, node| y << entry_to_rule(node, key) end end.each(&block) end
ruby
def each(&block) Enumerator.new do |y| @rules.each do |key, node| y << entry_to_rule(node, key) end end.each(&block) end
[ "def", "each", "(", "&", "block", ")", "Enumerator", ".", "new", "do", "|", "y", "|", "@rules", ".", "each", "do", "|", "key", ",", "node", "|", "y", "<<", "entry_to_rule", "(", "node", ",", "key", ")", "end", "end", ".", "each", "(", "block", ...
Iterates each rule in the list.
[ "Iterates", "each", "rule", "in", "the", "list", "." ]
2803479f5a1eceec0f1416ea538aa0ca301b64e9
https://github.com/weppos/publicsuffix-ruby/blob/2803479f5a1eceec0f1416ea538aa0ca301b64e9/lib/public_suffix/list.rb#L126-L132
16,206
weppos/publicsuffix-ruby
lib/public_suffix/list.rb
PublicSuffix.List.find
def find(name, default: default_rule, **options) rule = select(name, **options).inject do |l, r| return r if r.class == Rule::Exception l.length > r.length ? l : r end rule || default end
ruby
def find(name, default: default_rule, **options) rule = select(name, **options).inject do |l, r| return r if r.class == Rule::Exception l.length > r.length ? l : r end rule || default end
[ "def", "find", "(", "name", ",", "default", ":", "default_rule", ",", "**", "options", ")", "rule", "=", "select", "(", "name", ",", "**", "options", ")", ".", "inject", "do", "|", "l", ",", "r", "|", "return", "r", "if", "r", ".", "class", "==",...
Finds and returns the rule corresponding to the longest public suffix for the hostname. @param name [#to_s] the hostname @param default [PublicSuffix::Rule::*] the default rule to return in case no rule matches @return [PublicSuffix::Rule::*]
[ "Finds", "and", "returns", "the", "rule", "corresponding", "to", "the", "longest", "public", "suffix", "for", "the", "hostname", "." ]
2803479f5a1eceec0f1416ea538aa0ca301b64e9
https://github.com/weppos/publicsuffix-ruby/blob/2803479f5a1eceec0f1416ea538aa0ca301b64e9/lib/public_suffix/list.rb#L172-L179
16,207
weppos/publicsuffix-ruby
lib/public_suffix/list.rb
PublicSuffix.List.select
def select(name, ignore_private: false) name = name.to_s parts = name.split(DOT).reverse! index = 0 query = parts[index] rules = [] loop do match = @rules[query] rules << entry_to_rule(match, query) if !match.nil? && (ignore_private == false || match.private == fals...
ruby
def select(name, ignore_private: false) name = name.to_s parts = name.split(DOT).reverse! index = 0 query = parts[index] rules = [] loop do match = @rules[query] rules << entry_to_rule(match, query) if !match.nil? && (ignore_private == false || match.private == fals...
[ "def", "select", "(", "name", ",", "ignore_private", ":", "false", ")", "name", "=", "name", ".", "to_s", "parts", "=", "name", ".", "split", "(", "DOT", ")", ".", "reverse!", "index", "=", "0", "query", "=", "parts", "[", "index", "]", "rules", "=...
Selects all the rules matching given hostame. If `ignore_private` is set to true, the algorithm will skip the rules that are flagged as private domain. Note that the rules will still be part of the loop. If you frequently need to access lists ignoring the private domains, you should create a list that doesn't incl...
[ "Selects", "all", "the", "rules", "matching", "given", "hostame", "." ]
2803479f5a1eceec0f1416ea538aa0ca301b64e9
https://github.com/weppos/publicsuffix-ruby/blob/2803479f5a1eceec0f1416ea538aa0ca301b64e9/lib/public_suffix/list.rb#L197-L216
16,208
jamesrwhite/minicron
server/lib/minicron/monitor.rb
Minicron.Monitor.start!
def start! # Activate the monitor @active = true # Connect to the database Minicron.establish_db_connection( Minicron.config['server']['database'], Minicron.config['verbose'] ) # Set the start time of the monitir @start_time = Time.now.utc # Start a thr...
ruby
def start! # Activate the monitor @active = true # Connect to the database Minicron.establish_db_connection( Minicron.config['server']['database'], Minicron.config['verbose'] ) # Set the start time of the monitir @start_time = Time.now.utc # Start a thr...
[ "def", "start!", "# Activate the monitor", "@active", "=", "true", "# Connect to the database", "Minicron", ".", "establish_db_connection", "(", "Minicron", ".", "config", "[", "'server'", "]", "[", "'database'", "]", ",", "Minicron", ".", "config", "[", "'verbose'"...
Starts the execution monitor in a new thread
[ "Starts", "the", "execution", "monitor", "in", "a", "new", "thread" ]
6b0a1330522a8aaabeb390d3530cab2fde5028b3
https://github.com/jamesrwhite/minicron/blob/6b0a1330522a8aaabeb390d3530cab2fde5028b3/server/lib/minicron/monitor.rb#L16-L52
16,209
jamesrwhite/minicron
server/lib/minicron/monitor.rb
Minicron.Monitor.monitor
def monitor(schedule) # Parse the cron expression cron = CronParser.new(schedule.formatted) # Find the time the cron was last expected to run with a 30 second pre buffer # and a 30 second post buffer (in addition to the 60 already in place) incase # jobs run early/late to allow for clock ...
ruby
def monitor(schedule) # Parse the cron expression cron = CronParser.new(schedule.formatted) # Find the time the cron was last expected to run with a 30 second pre buffer # and a 30 second post buffer (in addition to the 60 already in place) incase # jobs run early/late to allow for clock ...
[ "def", "monitor", "(", "schedule", ")", "# Parse the cron expression", "cron", "=", "CronParser", ".", "new", "(", "schedule", ".", "formatted", ")", "# Find the time the cron was last expected to run with a 30 second pre buffer", "# and a 30 second post buffer (in addition to the ...
Handle the monitoring of a cron schedule @param schedule [Minicron::Hub::Model::Schedule]
[ "Handle", "the", "monitoring", "of", "a", "cron", "schedule" ]
6b0a1330522a8aaabeb390d3530cab2fde5028b3
https://github.com/jamesrwhite/minicron/blob/6b0a1330522a8aaabeb390d3530cab2fde5028b3/server/lib/minicron/monitor.rb#L70-L103
16,210
jamesrwhite/minicron
server/lib/minicron/cron.rb
Minicron.Cron.build_crontab
def build_crontab(host) # You have been warned.. crontab = "#\n" crontab += "# This file was automatically generated by minicron at #{Time.now.utc}, DO NOT EDIT manually!\n" crontab += "#\n\n" # Set the path to something sensible by default, eventually this should be configurable cr...
ruby
def build_crontab(host) # You have been warned.. crontab = "#\n" crontab += "# This file was automatically generated by minicron at #{Time.now.utc}, DO NOT EDIT manually!\n" crontab += "#\n\n" # Set the path to something sensible by default, eventually this should be configurable cr...
[ "def", "build_crontab", "(", "host", ")", "# You have been warned..", "crontab", "=", "\"#\\n\"", "crontab", "+=", "\"# This file was automatically generated by minicron at #{Time.now.utc}, DO NOT EDIT manually!\\n\"", "crontab", "+=", "\"#\\n\\n\"", "# Set the path to something sensib...
Build the crontab multiline string that includes all the given jobs @param host [Minicron::Hub::Model::Host] a host instance with it's jobs and job schedules @return [String]
[ "Build", "the", "crontab", "multiline", "string", "that", "includes", "all", "the", "given", "jobs" ]
6b0a1330522a8aaabeb390d3530cab2fde5028b3
https://github.com/jamesrwhite/minicron/blob/6b0a1330522a8aaabeb390d3530cab2fde5028b3/server/lib/minicron/cron.rb#L21-L55
16,211
jaimeiniesta/metainspector
lib/meta_inspector/url.rb
MetaInspector.URL.with_default_scheme
def with_default_scheme(url) parsed(url) && parsed(url).scheme.nil? ? 'http://' + url : url end
ruby
def with_default_scheme(url) parsed(url) && parsed(url).scheme.nil? ? 'http://' + url : url end
[ "def", "with_default_scheme", "(", "url", ")", "parsed", "(", "url", ")", "&&", "parsed", "(", "url", ")", ".", "scheme", ".", "nil?", "?", "'http://'", "+", "url", ":", "url", "end" ]
Adds 'http' as default scheme, if there is none
[ "Adds", "http", "as", "default", "scheme", "if", "there", "is", "none" ]
540e2ee07ee697634d2a096dd1f010da79613313
https://github.com/jaimeiniesta/metainspector/blob/540e2ee07ee697634d2a096dd1f010da79613313/lib/meta_inspector/url.rb#L78-L80
16,212
jaimeiniesta/metainspector
lib/meta_inspector/url.rb
MetaInspector.URL.normalized
def normalized(url) Addressable::URI.parse(url).normalize.to_s rescue Addressable::URI::InvalidURIError => e raise MetaInspector::ParserError.new(e) end
ruby
def normalized(url) Addressable::URI.parse(url).normalize.to_s rescue Addressable::URI::InvalidURIError => e raise MetaInspector::ParserError.new(e) end
[ "def", "normalized", "(", "url", ")", "Addressable", "::", "URI", ".", "parse", "(", "url", ")", ".", "normalize", ".", "to_s", "rescue", "Addressable", "::", "URI", "::", "InvalidURIError", "=>", "e", "raise", "MetaInspector", "::", "ParserError", ".", "n...
Normalize url to deal with characters that should be encoded, add trailing slash, convert to downcase...
[ "Normalize", "url", "to", "deal", "with", "characters", "that", "should", "be", "encoded", "add", "trailing", "slash", "convert", "to", "downcase", "..." ]
540e2ee07ee697634d2a096dd1f010da79613313
https://github.com/jaimeiniesta/metainspector/blob/540e2ee07ee697634d2a096dd1f010da79613313/lib/meta_inspector/url.rb#L84-L88
16,213
jaimeiniesta/metainspector
lib/meta_inspector/document.rb
MetaInspector.Document.to_hash
def to_hash { 'url' => url, 'scheme' => scheme, 'host' => host, 'root_url' => root_url, 'title' => title, 'best_title' => best_title, 'author' => author, 'best_author' => best...
ruby
def to_hash { 'url' => url, 'scheme' => scheme, 'host' => host, 'root_url' => root_url, 'title' => title, 'best_title' => best_title, 'author' => author, 'best_author' => best...
[ "def", "to_hash", "{", "'url'", "=>", "url", ",", "'scheme'", "=>", "scheme", ",", "'host'", "=>", "host", ",", "'root_url'", "=>", "root_url", ",", "'title'", "=>", "title", ",", "'best_title'", "=>", "best_title", ",", "'author'", "=>", "author", ",", ...
Returns all document data as a nested Hash
[ "Returns", "all", "document", "data", "as", "a", "nested", "Hash" ]
540e2ee07ee697634d2a096dd1f010da79613313
https://github.com/jaimeiniesta/metainspector/blob/540e2ee07ee697634d2a096dd1f010da79613313/lib/meta_inspector/document.rb#L57-L79
16,214
davetron5000/gli
lib/gli/command.rb
GLI.Command.has_option?
def has_option?(option) #:nodoc: option = option.gsub(/^\-+/,'') ((flags.values.map { |_| [_.name,_.aliases] }) + (switches.values.map { |_| [_.name,_.aliases] })).flatten.map(&:to_s).include?(option) end
ruby
def has_option?(option) #:nodoc: option = option.gsub(/^\-+/,'') ((flags.values.map { |_| [_.name,_.aliases] }) + (switches.values.map { |_| [_.name,_.aliases] })).flatten.map(&:to_s).include?(option) end
[ "def", "has_option?", "(", "option", ")", "#:nodoc:", "option", "=", "option", ".", "gsub", "(", "/", "\\-", "/", ",", "''", ")", "(", "(", "flags", ".", "values", ".", "map", "{", "|", "_", "|", "[", "_", ".", "name", ",", "_", ".", "aliases",...
Returns true if this command has the given option defined
[ "Returns", "true", "if", "this", "command", "has", "the", "given", "option", "defined" ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/command.rb#L165-L169
16,215
davetron5000/gli
lib/gli/command.rb
GLI.Command.name_for_help
def name_for_help name_array = [name.to_s] command_parent = parent while(command_parent.is_a?(GLI::Command)) do name_array.unshift(command_parent.name.to_s) command_parent = command_parent.parent end name_array end
ruby
def name_for_help name_array = [name.to_s] command_parent = parent while(command_parent.is_a?(GLI::Command)) do name_array.unshift(command_parent.name.to_s) command_parent = command_parent.parent end name_array end
[ "def", "name_for_help", "name_array", "=", "[", "name", ".", "to_s", "]", "command_parent", "=", "parent", "while", "(", "command_parent", ".", "is_a?", "(", "GLI", "::", "Command", ")", ")", "do", "name_array", ".", "unshift", "(", "command_parent", ".", ...
Returns full name for help command including parents Example command :remote do |t| t.command :add do |global,options,args| end end @add_command.name_for_help # => ["remote", "add"]
[ "Returns", "full", "name", "for", "help", "command", "including", "parents" ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/command.rb#L182-L190
16,216
davetron5000/gli
lib/gli/app.rb
GLI.App.commands_from
def commands_from(path) if Pathname.new(path).absolute? and File.exist?(path) load_commands(path) else $LOAD_PATH.each do |load_path| commands_path = File.join(load_path,path) load_commands(commands_path) end end end
ruby
def commands_from(path) if Pathname.new(path).absolute? and File.exist?(path) load_commands(path) else $LOAD_PATH.each do |load_path| commands_path = File.join(load_path,path) load_commands(commands_path) end end end
[ "def", "commands_from", "(", "path", ")", "if", "Pathname", ".", "new", "(", "path", ")", ".", "absolute?", "and", "File", ".", "exist?", "(", "path", ")", "load_commands", "(", "path", ")", "else", "$LOAD_PATH", ".", "each", "do", "|", "load_path", "|...
Loads ruby files in the load path that start with +path+, which are presumed to be commands for your executable. This is useful for decomposing your bin file into different classes, but can also be used as a plugin mechanism, allowing users to provide additional commands for your app at runtime. All that being sai...
[ "Loads", "ruby", "files", "in", "the", "load", "path", "that", "start", "with", "+", "path", "+", "which", "are", "presumed", "to", "be", "commands", "for", "your", "executable", ".", "This", "is", "useful", "for", "decomposing", "your", "bin", "file", "...
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/app.rb#L32-L41
16,217
davetron5000/gli
lib/gli/app.rb
GLI.App.config_file
def config_file(filename) if filename =~ /^\// @config_file = filename else @config_file = File.join(File.expand_path(ENV['HOME']),filename) end commands[:initconfig] = InitConfig.new(@config_file,commands,flags,switches) @commands_declaration_order << commands[:initconfig]...
ruby
def config_file(filename) if filename =~ /^\// @config_file = filename else @config_file = File.join(File.expand_path(ENV['HOME']),filename) end commands[:initconfig] = InitConfig.new(@config_file,commands,flags,switches) @commands_declaration_order << commands[:initconfig]...
[ "def", "config_file", "(", "filename", ")", "if", "filename", "=~", "/", "\\/", "/", "@config_file", "=", "filename", "else", "@config_file", "=", "File", ".", "join", "(", "File", ".", "expand_path", "(", "ENV", "[", "'HOME'", "]", ")", ",", "filename",...
Sets that this app uses a config file as well as the name of the config file. +filename+:: A String representing the path to the file to use for the config file. If it's an absolute path, this is treated as the path to the file. If it's *not*, it's treated as relative to the user's home ...
[ "Sets", "that", "this", "app", "uses", "a", "config", "file", "as", "well", "as", "the", "name", "of", "the", "config", "file", "." ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/app.rb#L102-L111
16,218
davetron5000/gli
lib/gli/app_support.rb
GLI.AppSupport.reset
def reset # :nodoc: switches.clear flags.clear @commands = nil @commands_declaration_order = [] @flags_declaration_order = [] @switches_declaration_order = [] @version = nil @config_file = nil @use_openstruct = false @prog_desc = nil @error_block = false...
ruby
def reset # :nodoc: switches.clear flags.clear @commands = nil @commands_declaration_order = [] @flags_declaration_order = [] @switches_declaration_order = [] @version = nil @config_file = nil @use_openstruct = false @prog_desc = nil @error_block = false...
[ "def", "reset", "# :nodoc:", "switches", ".", "clear", "flags", ".", "clear", "@commands", "=", "nil", "@commands_declaration_order", "=", "[", "]", "@flags_declaration_order", "=", "[", "]", "@switches_declaration_order", "=", "[", "]", "@version", "=", "nil", ...
Reset the GLI module internal data structures; mostly useful for testing
[ "Reset", "the", "GLI", "module", "internal", "data", "structures", ";", "mostly", "useful", "for", "testing" ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/app_support.rb#L14-L34
16,219
davetron5000/gli
lib/gli/app_support.rb
GLI.AppSupport.run
def run(args) #:nodoc: args = args.dup if @preserve_argv the_command = nil begin override_defaults_based_on_config(parse_config) add_help_switch_if_needed(self) gli_option_parser = GLIOptionParser.new(commands, flags, ...
ruby
def run(args) #:nodoc: args = args.dup if @preserve_argv the_command = nil begin override_defaults_based_on_config(parse_config) add_help_switch_if_needed(self) gli_option_parser = GLIOptionParser.new(commands, flags, ...
[ "def", "run", "(", "args", ")", "#:nodoc:", "args", "=", "args", ".", "dup", "if", "@preserve_argv", "the_command", "=", "nil", "begin", "override_defaults_based_on_config", "(", "parse_config", ")", "add_help_switch_if_needed", "(", "self", ")", "gli_option_parser"...
Runs whatever command is needed based on the arguments. +args+:: the command line ARGV array Returns a number that would be a reasonable exit code
[ "Runs", "whatever", "command", "is", "needed", "based", "on", "the", "arguments", "." ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/app_support.rb#L60-L94
16,220
davetron5000/gli
lib/gli/app_support.rb
GLI.AppSupport.override_defaults_based_on_config
def override_defaults_based_on_config(config) override_default(flags,config) override_default(switches,config) override_command_defaults(commands,config) end
ruby
def override_defaults_based_on_config(config) override_default(flags,config) override_default(switches,config) override_command_defaults(commands,config) end
[ "def", "override_defaults_based_on_config", "(", "config", ")", "override_default", "(", "flags", ",", "config", ")", "override_default", "(", "switches", ",", "config", ")", "override_command_defaults", "(", "commands", ",", "config", ")", "end" ]
Sets the default values for flags based on the configuration
[ "Sets", "the", "default", "values", "for", "flags", "based", "on", "the", "configuration" ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/app_support.rb#L178-L183
16,221
davetron5000/gli
lib/gli/app_support.rb
GLI.AppSupport.proceed?
def proceed?(parsing_result) #:nodoc: if parsing_result.command && parsing_result.command.skips_pre true else pre_block.call(*parsing_result) end end
ruby
def proceed?(parsing_result) #:nodoc: if parsing_result.command && parsing_result.command.skips_pre true else pre_block.call(*parsing_result) end end
[ "def", "proceed?", "(", "parsing_result", ")", "#:nodoc:", "if", "parsing_result", ".", "command", "&&", "parsing_result", ".", "command", ".", "skips_pre", "true", "else", "pre_block", ".", "call", "(", "parsing_result", ")", "end", "end" ]
True if we should proceed with executing the command; this calls the pre block if it's defined
[ "True", "if", "we", "should", "proceed", "with", "executing", "the", "command", ";", "this", "calls", "the", "pre", "block", "if", "it", "s", "defined" ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/app_support.rb#L265-L271
16,222
davetron5000/gli
lib/gli/app_support.rb
GLI.AppSupport.regular_error_handling?
def regular_error_handling?(ex) #:nodoc: if @error_block return true if (ex.respond_to?(:exit_code) && ex.exit_code == 0) @error_block.call(ex) else true end end
ruby
def regular_error_handling?(ex) #:nodoc: if @error_block return true if (ex.respond_to?(:exit_code) && ex.exit_code == 0) @error_block.call(ex) else true end end
[ "def", "regular_error_handling?", "(", "ex", ")", "#:nodoc:", "if", "@error_block", "return", "true", "if", "(", "ex", ".", "respond_to?", "(", ":exit_code", ")", "&&", "ex", ".", "exit_code", "==", "0", ")", "@error_block", ".", "call", "(", "ex", ")", ...
Returns true if we should proceed with GLI's basic error handling. This calls the error block if the user provided one
[ "Returns", "true", "if", "we", "should", "proceed", "with", "GLI", "s", "basic", "error", "handling", ".", "This", "calls", "the", "error", "block", "if", "the", "user", "provided", "one" ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/app_support.rb#L275-L282
16,223
davetron5000/gli
lib/gli/dsl.rb
GLI.DSL.flag
def flag(*names) options = extract_options(names) names = [names].flatten verify_unused(names) flag = Flag.new(names,options) flags[flag.name] = flag clear_nexts flags_declaration_order << flag flag end
ruby
def flag(*names) options = extract_options(names) names = [names].flatten verify_unused(names) flag = Flag.new(names,options) flags[flag.name] = flag clear_nexts flags_declaration_order << flag flag end
[ "def", "flag", "(", "*", "names", ")", "options", "=", "extract_options", "(", "names", ")", "names", "=", "[", "names", "]", ".", "flatten", "verify_unused", "(", "names", ")", "flag", "=", "Flag", ".", "new", "(", "names", ",", "options", ")", "fla...
Create a flag, which is a switch that takes an argument +names+:: a String or Symbol, or an Array of String or Symbol that represent all the different names and aliases for this flag. The last element can be a hash of options: +:desc+:: the description, instead of using #desc +:long_...
[ "Create", "a", "flag", "which", "is", "a", "switch", "that", "takes", "an", "argument" ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/dsl.rb#L92-L103
16,224
davetron5000/gli
lib/gli/dsl.rb
GLI.DSL.verify_unused
def verify_unused(names) # :nodoc: names.each do |name| verify_unused_in_option(name,flags,"flag") verify_unused_in_option(name,switches,"switch") end end
ruby
def verify_unused(names) # :nodoc: names.each do |name| verify_unused_in_option(name,flags,"flag") verify_unused_in_option(name,switches,"switch") end end
[ "def", "verify_unused", "(", "names", ")", "# :nodoc:", "names", ".", "each", "do", "|", "name", "|", "verify_unused_in_option", "(", "name", ",", "flags", ",", "\"flag\"", ")", "verify_unused_in_option", "(", "name", ",", "switches", ",", "\"switch\"", ")", ...
Checks that the names passed in have not been used in another flag or option
[ "Checks", "that", "the", "names", "passed", "in", "have", "not", "been", "used", "in", "another", "flag", "or", "option" ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/dsl.rb#L218-L223
16,225
davetron5000/gli
lib/gli/gli_option_parser.rb
GLI.GLIOptionParser.parse_options
def parse_options(args) # :nodoc: option_parser_class = self.class.const_get("#{options[:subcommand_option_handling_strategy].to_s.capitalize}CommandOptionParser") OptionParsingResult.new.tap { |parsing_result| parsing_result.arguments = args parsing_result = @global_option_parser.parse!(par...
ruby
def parse_options(args) # :nodoc: option_parser_class = self.class.const_get("#{options[:subcommand_option_handling_strategy].to_s.capitalize}CommandOptionParser") OptionParsingResult.new.tap { |parsing_result| parsing_result.arguments = args parsing_result = @global_option_parser.parse!(par...
[ "def", "parse_options", "(", "args", ")", "# :nodoc:", "option_parser_class", "=", "self", ".", "class", ".", "const_get", "(", "\"#{options[:subcommand_option_handling_strategy].to_s.capitalize}CommandOptionParser\"", ")", "OptionParsingResult", ".", "new", ".", "tap", "{"...
Given the command-line argument array, returns an OptionParsingResult
[ "Given", "the", "command", "-", "line", "argument", "array", "returns", "an", "OptionParsingResult" ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/gli_option_parser.rb#L27-L34
16,226
davetron5000/gli
lib/gli/gli_option_block_parser.rb
GLI.GLIOptionBlockParser.parse!
def parse!(args) do_parse(args) rescue OptionParser::InvalidOption => ex @exception_handler.call("Unknown option #{ex.args.join(' ')}",@extra_error_context) rescue OptionParser::InvalidArgument => ex @exception_handler.call("#{ex.reason}: #{ex.args.join(' ')}",@extra_error_context) end
ruby
def parse!(args) do_parse(args) rescue OptionParser::InvalidOption => ex @exception_handler.call("Unknown option #{ex.args.join(' ')}",@extra_error_context) rescue OptionParser::InvalidArgument => ex @exception_handler.call("#{ex.reason}: #{ex.args.join(' ')}",@extra_error_context) end
[ "def", "parse!", "(", "args", ")", "do_parse", "(", "args", ")", "rescue", "OptionParser", "::", "InvalidOption", "=>", "ex", "@exception_handler", ".", "call", "(", "\"Unknown option #{ex.args.join(' ')}\"", ",", "@extra_error_context", ")", "rescue", "OptionParser",...
Create the parser using the given +OptionParser+ instance and exception handling strategy. option_parser_factory:: An +OptionParserFactory+ instance, configured to parse wherever you are on the command line exception_klass_or_block:: means of handling exceptions from +OptionParser+. One of: ...
[ "Create", "the", "parser", "using", "the", "given", "+", "OptionParser", "+", "instance", "and", "exception", "handling", "strategy", "." ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/gli_option_block_parser.rb#L32-L38
16,227
davetron5000/gli
lib/gli/command_line_token.rb
GLI.CommandLineToken.parse_names
def parse_names(names) # Allow strings; convert to symbols names = [names].flatten.map { |name| name.to_sym } names_hash = {} names.each do |name| raise ArgumentError.new("#{name} has spaces; they are not allowed") if name.to_s =~ /\s/ names_hash[self.class.name_as_string(name)...
ruby
def parse_names(names) # Allow strings; convert to symbols names = [names].flatten.map { |name| name.to_sym } names_hash = {} names.each do |name| raise ArgumentError.new("#{name} has spaces; they are not allowed") if name.to_s =~ /\s/ names_hash[self.class.name_as_string(name)...
[ "def", "parse_names", "(", "names", ")", "# Allow strings; convert to symbols", "names", "=", "[", "names", "]", ".", "flatten", ".", "map", "{", "|", "name", "|", "name", ".", "to_sym", "}", "names_hash", "=", "{", "}", "names", ".", "each", "do", "|", ...
Handles dealing with the "names" param, parsing it into the primary name and aliases list
[ "Handles", "dealing", "with", "the", "names", "param", "parsing", "it", "into", "the", "primary", "name", "and", "aliases", "list" ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/command_line_token.rb#L38-L49
16,228
davetron5000/gli
lib/gli/flag.rb
GLI.Flag.all_forms
def all_forms(joiner=', ') forms = all_forms_a string = forms.join(joiner) if forms[-1] =~ /^\-\-/ string += '=' else string += ' ' end string += @argument_name return string end
ruby
def all_forms(joiner=', ') forms = all_forms_a string = forms.join(joiner) if forms[-1] =~ /^\-\-/ string += '=' else string += ' ' end string += @argument_name return string end
[ "def", "all_forms", "(", "joiner", "=", "', '", ")", "forms", "=", "all_forms_a", "string", "=", "forms", ".", "join", "(", "joiner", ")", "if", "forms", "[", "-", "1", "]", "=~", "/", "\\-", "\\-", "/", "string", "+=", "'='", "else", "string", "+=...
Returns a string of all possible forms of this flag. Mostly intended for printing to the user.
[ "Returns", "a", "string", "of", "all", "possible", "forms", "of", "this", "flag", ".", "Mostly", "intended", "for", "printing", "to", "the", "user", "." ]
2a582cc04ae182ae29411ba888c23a91a6fe8d99
https://github.com/davetron5000/gli/blob/2a582cc04ae182ae29411ba888c23a91a6fe8d99/lib/gli/flag.rb#L85-L95
16,229
jamesotron/hamlbars
lib/hamlbars/template.rb
Hamlbars.Template.evaluate
def evaluate(scope, locals, &block) if @engine.respond_to?(:precompiled_method_return_value, true) super(scope, locals, &block) else @engine.render(scope, locals, &block) end end
ruby
def evaluate(scope, locals, &block) if @engine.respond_to?(:precompiled_method_return_value, true) super(scope, locals, &block) else @engine.render(scope, locals, &block) end end
[ "def", "evaluate", "(", "scope", ",", "locals", ",", "&", "block", ")", "if", "@engine", ".", "respond_to?", "(", ":precompiled_method_return_value", ",", "true", ")", "super", "(", "scope", ",", "locals", ",", "block", ")", "else", "@engine", ".", "render...
Uses Haml to render the template into an HTML string, then wraps it in the neccessary JavaScript to serve to the client.
[ "Uses", "Haml", "to", "render", "the", "template", "into", "an", "HTML", "string", "then", "wraps", "it", "in", "the", "neccessary", "JavaScript", "to", "serve", "to", "the", "client", "." ]
7f41686b28343ac68e7c90e04f481802e98f38d5
https://github.com/jamesotron/hamlbars/blob/7f41686b28343ac68e7c90e04f481802e98f38d5/lib/hamlbars/template.rb#L26-L32
16,230
vitalie/webshot
lib/webshot/screenshot.rb
Webshot.Screenshot.capture
def capture(url, path, opts = {}) begin # Default settings width = opts.fetch(:width, 120) height = opts.fetch(:height, 90) gravity = opts.fetch(:gravity, "north") quality = opts.fetch(:quality, 85) full = opts.fetch(:full, true) selector = opts.fetch(:se...
ruby
def capture(url, path, opts = {}) begin # Default settings width = opts.fetch(:width, 120) height = opts.fetch(:height, 90) gravity = opts.fetch(:gravity, "north") quality = opts.fetch(:quality, 85) full = opts.fetch(:full, true) selector = opts.fetch(:se...
[ "def", "capture", "(", "url", ",", "path", ",", "opts", "=", "{", "}", ")", "begin", "# Default settings", "width", "=", "opts", ".", "fetch", "(", ":width", ",", "120", ")", "height", "=", "opts", ".", "fetch", "(", ":height", ",", "90", ")", "gra...
Captures a screenshot of +url+ saving it to +path+.
[ "Captures", "a", "screenshot", "of", "+", "url", "+", "saving", "it", "to", "+", "path", "+", "." ]
2464ee47a34c6c7a8bade4686c7b179cd1c69e30
https://github.com/vitalie/webshot/blob/2464ee47a34c6c7a8bade4686c7b179cd1c69e30/lib/webshot/screenshot.rb#L36-L97
16,231
marinosoftware/active_storage_drag_and_drop
lib/active_storage_drag_and_drop/form_builder.rb
ActiveStorageDragAndDrop.FormBuilder.drag_and_drop_file_field
def drag_and_drop_file_field(method, content_or_options = nil, options = {}, &block) if block_given? options = content_or_options if content_or_options.is_a? Hash drag_and_drop_file_field_string(method, capture(&block), options) else drag_and_drop_file_field_string(method, content_or...
ruby
def drag_and_drop_file_field(method, content_or_options = nil, options = {}, &block) if block_given? options = content_or_options if content_or_options.is_a? Hash drag_and_drop_file_field_string(method, capture(&block), options) else drag_and_drop_file_field_string(method, content_or...
[ "def", "drag_and_drop_file_field", "(", "method", ",", "content_or_options", "=", "nil", ",", "options", "=", "{", "}", ",", "&", "block", ")", "if", "block_given?", "options", "=", "content_or_options", "if", "content_or_options", ".", "is_a?", "Hash", "drag_an...
Returns a file upload input tag wrapped in markup that allows dragging and dropping of files onto the element. @author Ian Grant @see file:README.md#Usage Usage section of the README @param [Symbol] method The attribute on the target model to attach the files to. @param [String] content The content to render ins...
[ "Returns", "a", "file", "upload", "input", "tag", "wrapped", "in", "markup", "that", "allows", "dragging", "and", "dropping", "of", "files", "onto", "the", "element", "." ]
c67e08709fdf31c13fed05db911e97cbaa1ebd42
https://github.com/marinosoftware/active_storage_drag_and_drop/blob/c67e08709fdf31c13fed05db911e97cbaa1ebd42/lib/active_storage_drag_and_drop/form_builder.rb#L44-L51
16,232
marinosoftware/active_storage_drag_and_drop
lib/active_storage_drag_and_drop/form_builder.rb
ActiveStorageDragAndDrop.FormBuilder.unpersisted_attachment_fields
def unpersisted_attachment_fields(method, multiple) unpersisted_attachments(method).map.with_index do |attachment, idx| hidden_field method, mutiple: multiple ? :multiple : false, value: attachment.signed_id, name: "#{object_name}[#{method}]#{'[]' if multiple}", ...
ruby
def unpersisted_attachment_fields(method, multiple) unpersisted_attachments(method).map.with_index do |attachment, idx| hidden_field method, mutiple: multiple ? :multiple : false, value: attachment.signed_id, name: "#{object_name}[#{method}]#{'[]' if multiple}", ...
[ "def", "unpersisted_attachment_fields", "(", "method", ",", "multiple", ")", "unpersisted_attachments", "(", "method", ")", ".", "map", ".", "with_index", "do", "|", "attachment", ",", "idx", "|", "hidden_field", "method", ",", "mutiple", ":", "multiple", "?", ...
returns an array of tags used to pre-populate the the dropzone with tags queueing unpersisted file attachments for attachment at the next form submission. @author Ian Grant @param [Symbol] method The attribute on the target model to attach the files to. @param [Boolean] multiple Whether the dropzone should accept ...
[ "returns", "an", "array", "of", "tags", "used", "to", "pre", "-", "populate", "the", "the", "dropzone", "with", "tags", "queueing", "unpersisted", "file", "attachments", "for", "attachment", "at", "the", "next", "form", "submission", "." ]
c67e08709fdf31c13fed05db911e97cbaa1ebd42
https://github.com/marinosoftware/active_storage_drag_and_drop/blob/c67e08709fdf31c13fed05db911e97cbaa1ebd42/lib/active_storage_drag_and_drop/form_builder.rb#L84-L95
16,233
marinosoftware/active_storage_drag_and_drop
lib/active_storage_drag_and_drop/form_builder.rb
ActiveStorageDragAndDrop.FormBuilder.default_file_field_options
def default_file_field_options(method) { multiple: @object.send(method).is_a?(ActiveStorage::Attached::Many), direct_upload: true, style: 'display:none;', data: { dnd: true, dnd_zone_id: "asdndz-#{object_name}_#{method}", icon_container_id: "asdndz-#{o...
ruby
def default_file_field_options(method) { multiple: @object.send(method).is_a?(ActiveStorage::Attached::Many), direct_upload: true, style: 'display:none;', data: { dnd: true, dnd_zone_id: "asdndz-#{object_name}_#{method}", icon_container_id: "asdndz-#{o...
[ "def", "default_file_field_options", "(", "method", ")", "{", "multiple", ":", "@object", ".", "send", "(", "method", ")", ".", "is_a?", "(", "ActiveStorage", "::", "Attached", "::", "Many", ")", ",", "direct_upload", ":", "true", ",", "style", ":", "'disp...
Generates a hash of default options for the embedded file input field. @author Ian Grant @param [Symbol] method The attribute on the target model to attach the files to. @return [Hash] The default options for the file field
[ "Generates", "a", "hash", "of", "default", "options", "for", "the", "embedded", "file", "input", "field", "." ]
c67e08709fdf31c13fed05db911e97cbaa1ebd42
https://github.com/marinosoftware/active_storage_drag_and_drop/blob/c67e08709fdf31c13fed05db911e97cbaa1ebd42/lib/active_storage_drag_and_drop/form_builder.rb#L120-L131
16,234
marinosoftware/active_storage_drag_and_drop
lib/active_storage_drag_and_drop/form_builder.rb
ActiveStorageDragAndDrop.FormBuilder.file_field_options
def file_field_options(method, custom_options) default_file_field_options(method).merge(custom_options) do |_key, default, custom| default.is_a?(Hash) && custom.is_a?(Hash) ? default.merge(custom) : custom end end
ruby
def file_field_options(method, custom_options) default_file_field_options(method).merge(custom_options) do |_key, default, custom| default.is_a?(Hash) && custom.is_a?(Hash) ? default.merge(custom) : custom end end
[ "def", "file_field_options", "(", "method", ",", "custom_options", ")", "default_file_field_options", "(", "method", ")", ".", "merge", "(", "custom_options", ")", "do", "|", "_key", ",", "default", ",", "custom", "|", "default", ".", "is_a?", "(", "Hash", "...
Merges the user provided options with the default options overwriting the defaults to generate the final options passed to the embedded file input field. @author Ian Grant @param [Symbol] method The attribute on the target model to attach the files to. @param [Hash] custom_options The user provided custom options ...
[ "Merges", "the", "user", "provided", "options", "with", "the", "default", "options", "overwriting", "the", "defaults", "to", "generate", "the", "final", "options", "passed", "to", "the", "embedded", "file", "input", "field", "." ]
c67e08709fdf31c13fed05db911e97cbaa1ebd42
https://github.com/marinosoftware/active_storage_drag_and_drop/blob/c67e08709fdf31c13fed05db911e97cbaa1ebd42/lib/active_storage_drag_and_drop/form_builder.rb#L150-L154
16,235
state-machines/state_machines
lib/state_machines/state.rb
StateMachines.State.value
def value(eval = true) if @value.is_a?(Proc) && eval if cache_value? @value = @value.call machine.states.update(self) @value else @value.call end else @value end end
ruby
def value(eval = true) if @value.is_a?(Proc) && eval if cache_value? @value = @value.call machine.states.update(self) @value else @value.call end else @value end end
[ "def", "value", "(", "eval", "=", "true", ")", "if", "@value", ".", "is_a?", "(", "Proc", ")", "&&", "eval", "if", "cache_value?", "@value", "=", "@value", ".", "call", "machine", ".", "states", ".", "update", "(", "self", ")", "@value", "else", "@va...
The value that represents this state. This will optionally evaluate the original block if it's a lambda block. Otherwise, the static value is returned. For example, State.new(machine, :parked, :value => 1).value # => 1 State.new(machine, :parked, :value => lambda {Time.now}).value ...
[ "The", "value", "that", "represents", "this", "state", ".", "This", "will", "optionally", "evaluate", "the", "original", "block", "if", "it", "s", "a", "lambda", "block", ".", "Otherwise", "the", "static", "value", "is", "returned", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/state.rb#L143-L155
16,236
state-machines/state_machines
lib/state_machines/state.rb
StateMachines.State.context_methods
def context_methods @context.instance_methods.inject({}) do |methods, name| methods.merge(name.to_sym => @context.instance_method(name)) end end
ruby
def context_methods @context.instance_methods.inject({}) do |methods, name| methods.merge(name.to_sym => @context.instance_method(name)) end end
[ "def", "context_methods", "@context", ".", "instance_methods", ".", "inject", "(", "{", "}", ")", "do", "|", "methods", ",", "name", "|", "methods", ".", "merge", "(", "name", ".", "to_sym", "=>", "@context", ".", "instance_method", "(", "name", ")", ")"...
The list of methods that have been defined in this state's context
[ "The", "list", "of", "methods", "that", "have", "been", "defined", "in", "this", "state", "s", "context" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/state.rb#L208-L212
16,237
state-machines/state_machines
lib/state_machines/state.rb
StateMachines.State.call
def call(object, method, *args, &block) options = args.last.is_a?(Hash) ? args.pop : {} options = {:method_name => method}.merge(options) state = machine.states.match!(object) if state == self && object.respond_to?(method) object.send(method, *args, &block) elsif method_missing = ...
ruby
def call(object, method, *args, &block) options = args.last.is_a?(Hash) ? args.pop : {} options = {:method_name => method}.merge(options) state = machine.states.match!(object) if state == self && object.respond_to?(method) object.send(method, *args, &block) elsif method_missing = ...
[ "def", "call", "(", "object", ",", "method", ",", "*", "args", ",", "&", "block", ")", "options", "=", "args", ".", "last", ".", "is_a?", "(", "Hash", ")", "?", "args", ".", "pop", ":", "{", "}", "options", "=", "{", ":method_name", "=>", "method...
Calls a method defined in this state's context on the given object. All arguments and any block will be passed into the method defined. If the method has never been defined for this state, then a NoMethodError will be raised.
[ "Calls", "a", "method", "defined", "in", "this", "state", "s", "context", "on", "the", "given", "object", ".", "All", "arguments", "and", "any", "block", "will", "be", "passed", "into", "the", "method", "defined", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/state.rb#L219-L240
16,238
state-machines/state_machines
lib/state_machines/state.rb
StateMachines.State.add_predicate
def add_predicate # Checks whether the current value matches this state machine.define_helper(:instance, "#{qualified_name}?") do |machine, object| machine.states.matches?(object, name) end end
ruby
def add_predicate # Checks whether the current value matches this state machine.define_helper(:instance, "#{qualified_name}?") do |machine, object| machine.states.matches?(object, name) end end
[ "def", "add_predicate", "# Checks whether the current value matches this state", "machine", ".", "define_helper", "(", ":instance", ",", "\"#{qualified_name}?\"", ")", "do", "|", "machine", ",", "object", "|", "machine", ".", "states", ".", "matches?", "(", "object", ...
Adds a predicate method to the owner class so long as a name has actually been configured for the state
[ "Adds", "a", "predicate", "method", "to", "the", "owner", "class", "so", "long", "as", "a", "name", "has", "actually", "been", "configured", "for", "the", "state" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/state.rb#L265-L270
16,239
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.initial_state=
def initial_state=(new_initial_state) @initial_state = new_initial_state add_states([@initial_state]) unless dynamic_initial_state? # Update all states to reflect the new initial state states.each { |state| state.initial = (state.name == @initial_state) } # Output a warning if there are ...
ruby
def initial_state=(new_initial_state) @initial_state = new_initial_state add_states([@initial_state]) unless dynamic_initial_state? # Update all states to reflect the new initial state states.each { |state| state.initial = (state.name == @initial_state) } # Output a warning if there are ...
[ "def", "initial_state", "=", "(", "new_initial_state", ")", "@initial_state", "=", "new_initial_state", "add_states", "(", "[", "@initial_state", "]", ")", "unless", "dynamic_initial_state?", "# Update all states to reflect the new initial state", "states", ".", "each", "{"...
Sets the initial state of the machine. This can be either the static name of a state or a lambda block which determines the initial state at creation time.
[ "Sets", "the", "initial", "state", "of", "the", "machine", ".", "This", "can", "be", "either", "the", "static", "name", "of", "a", "state", "or", "a", "lambda", "block", "which", "determines", "the", "initial", "state", "at", "creation", "time", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L593-L610
16,240
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.initialize_state
def initialize_state(object, options = {}) state = initial_state(object) if state && (options[:force] || initialize_state?(object)) value = state.value if hash = options[:to] hash[attribute.to_s] = value else write(object, :state, value) end end ...
ruby
def initialize_state(object, options = {}) state = initial_state(object) if state && (options[:force] || initialize_state?(object)) value = state.value if hash = options[:to] hash[attribute.to_s] = value else write(object, :state, value) end end ...
[ "def", "initialize_state", "(", "object", ",", "options", "=", "{", "}", ")", "state", "=", "initial_state", "(", "object", ")", "if", "state", "&&", "(", "options", "[", ":force", "]", "||", "initialize_state?", "(", "object", ")", ")", "value", "=", ...
Initializes the state on the given object. Initial values are only set if the machine's attribute hasn't been previously initialized. Configuration options: * <tt>:force</tt> - Whether to initialize the state regardless of its current value * <tt>:to</tt> - A hash to set the initial value in instead of writing...
[ "Initializes", "the", "state", "on", "the", "given", "object", ".", "Initial", "values", "are", "only", "set", "if", "the", "machine", "s", "attribute", "hasn", "t", "been", "previously", "initialized", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L663-L674
16,241
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.define_helper
def define_helper(scope, method, *args, &block) helper_module = @helper_modules.fetch(scope) if block_given? if !self.class.ignore_method_conflicts && conflicting_ancestor = owner_class_ancestor_has_method?(scope, method) ancestor_name = conflicting_ancestor.name && !conflicting_ancestor....
ruby
def define_helper(scope, method, *args, &block) helper_module = @helper_modules.fetch(scope) if block_given? if !self.class.ignore_method_conflicts && conflicting_ancestor = owner_class_ancestor_has_method?(scope, method) ancestor_name = conflicting_ancestor.name && !conflicting_ancestor....
[ "def", "define_helper", "(", "scope", ",", "method", ",", "*", "args", ",", "&", "block", ")", "helper_module", "=", "@helper_modules", ".", "fetch", "(", "scope", ")", "if", "block_given?", "if", "!", "self", ".", "class", ".", "ignore_method_conflicts", ...
Defines a new helper method in an instance or class scope with the given name. If the method is already defined in the scope, then this will not override it. If passing in a block, there are two side effects to be aware of 1. The method cannot be chained, meaning that the block cannot call +super+ 2. If the meth...
[ "Defines", "a", "new", "helper", "method", "in", "an", "instance", "or", "class", "scope", "with", "the", "given", "name", ".", "If", "the", "method", "is", "already", "defined", "in", "the", "scope", "then", "this", "will", "not", "override", "it", "." ...
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L718-L736
16,242
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.state
def state(*names, &block) options = names.last.is_a?(Hash) ? names.pop : {} options.assert_valid_keys(:value, :cache, :if, :human_name) # Store the context so that it can be used for / matched against any state # that gets added @states.context(names, &block) if block_given? if nam...
ruby
def state(*names, &block) options = names.last.is_a?(Hash) ? names.pop : {} options.assert_valid_keys(:value, :cache, :if, :human_name) # Store the context so that it can be used for / matched against any state # that gets added @states.context(names, &block) if block_given? if nam...
[ "def", "state", "(", "*", "names", ",", "&", "block", ")", "options", "=", "names", ".", "last", ".", "is_a?", "(", "Hash", ")", "?", "names", ".", "pop", ":", "{", "}", "options", ".", "assert_valid_keys", "(", ":value", ",", ":cache", ",", ":if",...
Customizes the definition of one or more states in the machine. Configuration options: * <tt>:value</tt> - The actual value to store when an object transitions to the state. Default is the name (stringified). * <tt>:cache</tt> - If a dynamic value (via a lambda block) is being used, then setting this to true...
[ "Customizes", "the", "definition", "of", "one", "or", "more", "states", "in", "the", "machine", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L1005-L1035
16,243
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.read
def read(object, attribute, ivar = false) attribute = self.attribute(attribute) if ivar object.instance_variable_defined?("@#{attribute}") ? object.instance_variable_get("@#{attribute}") : nil else object.send(attribute) end end
ruby
def read(object, attribute, ivar = false) attribute = self.attribute(attribute) if ivar object.instance_variable_defined?("@#{attribute}") ? object.instance_variable_get("@#{attribute}") : nil else object.send(attribute) end end
[ "def", "read", "(", "object", ",", "attribute", ",", "ivar", "=", "false", ")", "attribute", "=", "self", ".", "attribute", "(", "attribute", ")", "if", "ivar", "object", ".", "instance_variable_defined?", "(", "\"@#{attribute}\"", ")", "?", "object", ".", ...
Gets the current value stored in the given object's attribute. For example, class Vehicle state_machine :initial => :parked do ... end end vehicle = Vehicle.new # => #<Vehicle:0xb7d94ab0 @state="parked"> Vehicle.state_machine.read(vehicle, :state) # => "par...
[ "Gets", "the", "current", "value", "stored", "in", "the", "given", "object", "s", "attribute", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L1052-L1059
16,244
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.write
def write(object, attribute, value, ivar = false) attribute = self.attribute(attribute) ivar ? object.instance_variable_set("@#{attribute}", value) : object.send("#{attribute}=", value) end
ruby
def write(object, attribute, value, ivar = false) attribute = self.attribute(attribute) ivar ? object.instance_variable_set("@#{attribute}", value) : object.send("#{attribute}=", value) end
[ "def", "write", "(", "object", ",", "attribute", ",", "value", ",", "ivar", "=", "false", ")", "attribute", "=", "self", ".", "attribute", "(", "attribute", ")", "ivar", "?", "object", ".", "instance_variable_set", "(", "\"@#{attribute}\"", ",", "value", "...
Sets a new value in the given object's attribute. For example, class Vehicle state_machine :initial => :parked do ... end end vehicle = Vehicle.new # => #<Vehicle:0xb7d94ab0 @state="parked"> Vehicle.state_machine.write(vehicle, :state, 'idling') # => E...
[ "Sets", "a", "new", "value", "in", "the", "given", "object", "s", "attribute", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L1076-L1079
16,245
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.event
def event(*names, &block) options = names.last.is_a?(Hash) ? names.pop : {} options.assert_valid_keys(:human_name) # Store the context so that it can be used for / matched against any event # that gets added @events.context(names, &block) if block_given? if names.first.is_a?(Matche...
ruby
def event(*names, &block) options = names.last.is_a?(Hash) ? names.pop : {} options.assert_valid_keys(:human_name) # Store the context so that it can be used for / matched against any event # that gets added @events.context(names, &block) if block_given? if names.first.is_a?(Matche...
[ "def", "event", "(", "*", "names", ",", "&", "block", ")", "options", "=", "names", ".", "last", ".", "is_a?", "(", "Hash", ")", "?", "names", ".", "pop", ":", "{", "}", "options", ".", "assert_valid_keys", "(", ":human_name", ")", "# Store the context...
Defines one or more events for the machine and the transitions that can be performed when those events are run. This method is also aliased as +on+ for improved compatibility with using a domain-specific language. Configuration options: * <tt>:human_name</tt> - The human-readable version of this event's name. ...
[ "Defines", "one", "or", "more", "events", "for", "the", "machine", "and", "the", "transitions", "that", "can", "be", "performed", "when", "those", "events", "are", "run", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L1307-L1333
16,246
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.transition
def transition(options) raise ArgumentError, 'Must specify :on event' unless options[:on] branches = [] options = options.dup event(*Array(options.delete(:on))) { branches << transition(options) } branches.length == 1 ? branches.first : branches end
ruby
def transition(options) raise ArgumentError, 'Must specify :on event' unless options[:on] branches = [] options = options.dup event(*Array(options.delete(:on))) { branches << transition(options) } branches.length == 1 ? branches.first : branches end
[ "def", "transition", "(", "options", ")", "raise", "ArgumentError", ",", "'Must specify :on event'", "unless", "options", "[", ":on", "]", "branches", "=", "[", "]", "options", "=", "options", ".", "dup", "event", "(", "Array", "(", "options", ".", "delete",...
Creates a new transition that determines what to change the current state to when an event fires. == Defining transitions The options for a new transition uses the Hash syntax to map beginning states to ending states. For example, transition :parked => :idling, :idling => :first_gear, :on => :ignite In thi...
[ "Creates", "a", "new", "transition", "that", "determines", "what", "to", "change", "the", "current", "state", "to", "when", "an", "event", "fires", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L1426-L1434
16,247
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.generate_message
def generate_message(name, values = []) message = (@messages[name] || self.class.default_messages[name]) # Check whether there are actually any values to interpolate to avoid # any warnings if message.scan(/%./).any? { |match| match != '%%' } message % values.map { |value| value.last } ...
ruby
def generate_message(name, values = []) message = (@messages[name] || self.class.default_messages[name]) # Check whether there are actually any values to interpolate to avoid # any warnings if message.scan(/%./).any? { |match| match != '%%' } message % values.map { |value| value.last } ...
[ "def", "generate_message", "(", "name", ",", "values", "=", "[", "]", ")", "message", "=", "(", "@messages", "[", "name", "]", "||", "self", ".", "class", ".", "default_messages", "[", "name", "]", ")", "# Check whether there are actually any values to interpola...
Generates the message to use when invalidating the given object after failing to transition on a specific event
[ "Generates", "the", "message", "to", "use", "when", "invalidating", "the", "given", "object", "after", "failing", "to", "transition", "on", "a", "specific", "event" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L1849-L1859
16,248
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.action_hook?
def action_hook?(self_only = false) @action_hook_defined || !self_only && owner_class.state_machines.any? { |name, machine| machine.action == action && machine != self && machine.action_hook?(true) } end
ruby
def action_hook?(self_only = false) @action_hook_defined || !self_only && owner_class.state_machines.any? { |name, machine| machine.action == action && machine != self && machine.action_hook?(true) } end
[ "def", "action_hook?", "(", "self_only", "=", "false", ")", "@action_hook_defined", "||", "!", "self_only", "&&", "owner_class", ".", "state_machines", ".", "any?", "{", "|", "name", ",", "machine", "|", "machine", ".", "action", "==", "action", "&&", "machi...
Determines whether an action hook was defined for firing attribute-based event transitions when the configured action gets called.
[ "Determines", "whether", "an", "action", "hook", "was", "defined", "for", "firing", "attribute", "-", "based", "event", "transitions", "when", "the", "configured", "action", "gets", "called", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L1881-L1883
16,249
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.sibling_machines
def sibling_machines owner_class.state_machines.inject([]) do |machines, (name, machine)| if machine.attribute == attribute && machine != self machines << (owner_class.state_machine(name) {}) end machines end end
ruby
def sibling_machines owner_class.state_machines.inject([]) do |machines, (name, machine)| if machine.attribute == attribute && machine != self machines << (owner_class.state_machine(name) {}) end machines end end
[ "def", "sibling_machines", "owner_class", ".", "state_machines", ".", "inject", "(", "[", "]", ")", "do", "|", "machines", ",", "(", "name", ",", "machine", ")", "|", "if", "machine", ".", "attribute", "==", "attribute", "&&", "machine", "!=", "self", "m...
Looks up other machines that have been defined in the owner class and are targeting the same attribute as this machine. When accessing sibling machines, they will be automatically copied for the current class if they haven't been already. This ensures that any configuration changes made to the sibling machines on...
[ "Looks", "up", "other", "machines", "that", "have", "been", "defined", "in", "the", "owner", "class", "and", "are", "targeting", "the", "same", "attribute", "as", "this", "machine", ".", "When", "accessing", "sibling", "machines", "they", "will", "be", "auto...
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L1896-L1903
16,250
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.initialize_state?
def initialize_state?(object) value = read(object, :state) (value.nil? || value.respond_to?(:empty?) && value.empty?) && !states[value, :value] end
ruby
def initialize_state?(object) value = read(object, :state) (value.nil? || value.respond_to?(:empty?) && value.empty?) && !states[value, :value] end
[ "def", "initialize_state?", "(", "object", ")", "value", "=", "read", "(", "object", ",", ":state", ")", "(", "value", ".", "nil?", "||", "value", ".", "respond_to?", "(", ":empty?", ")", "&&", "value", ".", "empty?", ")", "&&", "!", "states", "[", "...
Determines if the machine's attribute needs to be initialized. This will only be true if the machine's attribute is blank.
[ "Determines", "if", "the", "machine", "s", "attribute", "needs", "to", "be", "initialized", ".", "This", "will", "only", "be", "true", "if", "the", "machine", "s", "attribute", "is", "blank", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L1907-L1910
16,251
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.define_path_helpers
def define_path_helpers # Gets the paths of transitions available to the current object define_helper(:instance, attribute(:paths)) do |machine, object, *args| machine.paths_for(object, *args) end end
ruby
def define_path_helpers # Gets the paths of transitions available to the current object define_helper(:instance, attribute(:paths)) do |machine, object, *args| machine.paths_for(object, *args) end end
[ "def", "define_path_helpers", "# Gets the paths of transitions available to the current object", "define_helper", "(", ":instance", ",", "attribute", "(", ":paths", ")", ")", "do", "|", "machine", ",", "object", ",", "*", "args", "|", "machine", ".", "paths_for", "(",...
Adds helper methods for getting information about this state machine's available transition paths
[ "Adds", "helper", "methods", "for", "getting", "information", "about", "this", "state", "machine", "s", "available", "transition", "paths" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L1997-L2002
16,252
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.define_action_helpers?
def define_action_helpers? action && !owner_class.state_machines.any? { |name, machine| machine.action == action && machine != self } end
ruby
def define_action_helpers? action && !owner_class.state_machines.any? { |name, machine| machine.action == action && machine != self } end
[ "def", "define_action_helpers?", "action", "&&", "!", "owner_class", ".", "state_machines", ".", "any?", "{", "|", "name", ",", "machine", "|", "machine", ".", "action", "==", "action", "&&", "machine", "!=", "self", "}", "end" ]
Determines whether action helpers should be defined for this machine. This is only true if there is an action configured and no other machines have process this same configuration already.
[ "Determines", "whether", "action", "helpers", "should", "be", "defined", "for", "this", "machine", ".", "This", "is", "only", "true", "if", "there", "is", "an", "action", "configured", "and", "no", "other", "machines", "have", "process", "this", "same", "con...
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L2007-L2009
16,253
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.owner_class_ancestor_has_method?
def owner_class_ancestor_has_method?(scope, method) return false unless owner_class_has_method?(scope, method) superclasses = owner_class.ancestors.select { |ancestor| ancestor.is_a?(Class) }[1..-1] if scope == :class current = owner_class.singleton_class superclass = superclasses.fi...
ruby
def owner_class_ancestor_has_method?(scope, method) return false unless owner_class_has_method?(scope, method) superclasses = owner_class.ancestors.select { |ancestor| ancestor.is_a?(Class) }[1..-1] if scope == :class current = owner_class.singleton_class superclass = superclasses.fi...
[ "def", "owner_class_ancestor_has_method?", "(", "scope", ",", "method", ")", "return", "false", "unless", "owner_class_has_method?", "(", "scope", ",", "method", ")", "superclasses", "=", "owner_class", ".", "ancestors", ".", "select", "{", "|", "ancestor", "|", ...
Determines whether there's already a helper method defined within the given scope. This is true only if one of the owner's ancestors defines the method and is further along in the ancestor chain than this machine's helper module.
[ "Determines", "whether", "there", "s", "already", "a", "helper", "method", "defined", "within", "the", "given", "scope", ".", "This", "is", "true", "only", "if", "one", "of", "the", "owner", "s", "ancestors", "defines", "the", "method", "and", "is", "furth...
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L2052-L2076
16,254
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.define_name_helpers
def define_name_helpers # Gets the humanized version of a state define_helper(:class, "human_#{attribute(:name)}") do |machine, klass, state| machine.states.fetch(state).human_name(klass) end # Gets the humanized version of an event define_helper(:class, "human_#{attribute(:event_...
ruby
def define_name_helpers # Gets the humanized version of a state define_helper(:class, "human_#{attribute(:name)}") do |machine, klass, state| machine.states.fetch(state).human_name(klass) end # Gets the humanized version of an event define_helper(:class, "human_#{attribute(:event_...
[ "def", "define_name_helpers", "# Gets the humanized version of a state", "define_helper", "(", ":class", ",", "\"human_#{attribute(:name)}\"", ")", "do", "|", "machine", ",", "klass", ",", "state", "|", "machine", ".", "states", ".", "fetch", "(", "state", ")", ".",...
Adds helper methods for accessing naming information about states and events on the owner class
[ "Adds", "helper", "methods", "for", "accessing", "naming", "information", "about", "states", "and", "events", "on", "the", "owner", "class" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L2085-L2105
16,255
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.run_scope
def run_scope(scope, machine, klass, states) values = states.flatten.map { |state| machine.states.fetch(state).value } scope.call(klass, values) end
ruby
def run_scope(scope, machine, klass, states) values = states.flatten.map { |state| machine.states.fetch(state).value } scope.call(klass, values) end
[ "def", "run_scope", "(", "scope", ",", "machine", ",", "klass", ",", "states", ")", "values", "=", "states", ".", "flatten", ".", "map", "{", "|", "state", "|", "machine", ".", "states", ".", "fetch", "(", "state", ")", ".", "value", "}", "scope", ...
Generates the results for the given scope based on one or more states to filter by
[ "Generates", "the", "results", "for", "the", "given", "scope", "based", "on", "one", "or", "more", "states", "to", "filter", "by" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L2132-L2135
16,256
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.add_sibling_machine_configs
def add_sibling_machine_configs # Add existing states sibling_machines.each do |machine| machine.states.each { |state| states << state unless states[state.name] } end end
ruby
def add_sibling_machine_configs # Add existing states sibling_machines.each do |machine| machine.states.each { |state| states << state unless states[state.name] } end end
[ "def", "add_sibling_machine_configs", "# Add existing states", "sibling_machines", ".", "each", "do", "|", "machine", "|", "machine", ".", "states", ".", "each", "{", "|", "state", "|", "states", "<<", "state", "unless", "states", "[", "state", ".", "name", "]...
Updates this machine based on the configuration of other machines in the owner class that share the same target attribute.
[ "Updates", "this", "machine", "based", "on", "the", "configuration", "of", "other", "machines", "in", "the", "owner", "class", "that", "share", "the", "same", "target", "attribute", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L2181-L2186
16,257
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.add_callback
def add_callback(type, options, &block) callbacks[type == :around ? :before : type] << callback = Callback.new(type, options, &block) add_states(callback.known_states) callback end
ruby
def add_callback(type, options, &block) callbacks[type == :around ? :before : type] << callback = Callback.new(type, options, &block) add_states(callback.known_states) callback end
[ "def", "add_callback", "(", "type", ",", "options", ",", "&", "block", ")", "callbacks", "[", "type", "==", ":around", "?", ":before", ":", "type", "]", "<<", "callback", "=", "Callback", ".", "new", "(", "type", ",", "options", ",", "block", ")", "a...
Adds a new transition callback of the given type.
[ "Adds", "a", "new", "transition", "callback", "of", "the", "given", "type", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L2189-L2193
16,258
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.add_states
def add_states(new_states) new_states.map do |new_state| # Check for other states that use a different class type for their name. # This typically prevents string / symbol misuse. if new_state && conflict = states.detect { |state| state.name && state.name.class != new_state.class } ...
ruby
def add_states(new_states) new_states.map do |new_state| # Check for other states that use a different class type for their name. # This typically prevents string / symbol misuse. if new_state && conflict = states.detect { |state| state.name && state.name.class != new_state.class } ...
[ "def", "add_states", "(", "new_states", ")", "new_states", ".", "map", "do", "|", "new_state", "|", "# Check for other states that use a different class type for their name.", "# This typically prevents string / symbol misuse.", "if", "new_state", "&&", "conflict", "=", "states...
Tracks the given set of states in the list of all known states for this machine
[ "Tracks", "the", "given", "set", "of", "states", "in", "the", "list", "of", "all", "known", "states", "for", "this", "machine" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L2197-L2214
16,259
state-machines/state_machines
lib/state_machines/machine.rb
StateMachines.Machine.add_events
def add_events(new_events) new_events.map do |new_event| # Check for other states that use a different class type for their name. # This typically prevents string / symbol misuse. if conflict = events.detect { |event| event.name.class != new_event.class } raise ArgumentError, "#{...
ruby
def add_events(new_events) new_events.map do |new_event| # Check for other states that use a different class type for their name. # This typically prevents string / symbol misuse. if conflict = events.detect { |event| event.name.class != new_event.class } raise ArgumentError, "#{...
[ "def", "add_events", "(", "new_events", ")", "new_events", ".", "map", "do", "|", "new_event", "|", "# Check for other states that use a different class type for their name.", "# This typically prevents string / symbol misuse.", "if", "conflict", "=", "events", ".", "detect", ...
Tracks the given set of events in the list of all known events for this machine
[ "Tracks", "the", "given", "set", "of", "events", "in", "the", "list", "of", "all", "known", "events", "for", "this", "machine" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine.rb#L2218-L2232
16,260
state-machines/state_machines
lib/state_machines/state_collection.rb
StateMachines.StateCollection.match
def match(object) value = machine.read(object, :state) self[value, :value] || detect { |state| state.matches?(value) } end
ruby
def match(object) value = machine.read(object, :state) self[value, :value] || detect { |state| state.matches?(value) } end
[ "def", "match", "(", "object", ")", "value", "=", "machine", ".", "read", "(", "object", ",", ":state", ")", "self", "[", "value", ",", ":value", "]", "||", "detect", "{", "|", "state", "|", "state", ".", "matches?", "(", "value", ")", "}", "end" ]
Determines the current state of the given object as configured by this state machine. This will attempt to find a known state that matches the value of the attribute on the object. == Examples class Vehicle state_machine :initial => :parked do other_states :idling end end states = Vehic...
[ "Determines", "the", "current", "state", "of", "the", "given", "object", "as", "configured", "by", "this", "state", "machine", ".", "This", "will", "attempt", "to", "find", "a", "known", "state", "that", "matches", "the", "value", "of", "the", "attribute", ...
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/state_collection.rb#L53-L56
16,261
state-machines/state_machines
lib/state_machines/branch.rb
StateMachines.Branch.build_matcher
def build_matcher(options, whitelist_option, blacklist_option) options.assert_exclusive_keys(whitelist_option, blacklist_option) if options.include?(whitelist_option) value = options[whitelist_option] value.is_a?(Matcher) ? value : WhitelistMatcher.new(options[whitelist_opti...
ruby
def build_matcher(options, whitelist_option, blacklist_option) options.assert_exclusive_keys(whitelist_option, blacklist_option) if options.include?(whitelist_option) value = options[whitelist_option] value.is_a?(Matcher) ? value : WhitelistMatcher.new(options[whitelist_opti...
[ "def", "build_matcher", "(", "options", ",", "whitelist_option", ",", "blacklist_option", ")", "options", ".", "assert_exclusive_keys", "(", "whitelist_option", ",", "blacklist_option", ")", "if", "options", ".", "include?", "(", "whitelist_option", ")", "value", "=...
Builds a matcher strategy to use for the given options. If neither a whitelist nor a blacklist option is specified, then an AllMatcher is built.
[ "Builds", "a", "matcher", "strategy", "to", "use", "for", "the", "given", "options", ".", "If", "neither", "a", "whitelist", "nor", "a", "blacklist", "option", "is", "specified", "then", "an", "AllMatcher", "is", "built", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/branch.rb#L130-L143
16,262
state-machines/state_machines
lib/state_machines/branch.rb
StateMachines.Branch.match_states
def match_states(query) state_requirements.detect do |state_requirement| [:from, :to].all? {|option| matches_requirement?(query, option, state_requirement[option])} end end
ruby
def match_states(query) state_requirements.detect do |state_requirement| [:from, :to].all? {|option| matches_requirement?(query, option, state_requirement[option])} end end
[ "def", "match_states", "(", "query", ")", "state_requirements", ".", "detect", "do", "|", "state_requirement", "|", "[", ":from", ",", ":to", "]", ".", "all?", "{", "|", "option", "|", "matches_requirement?", "(", "query", ",", "option", ",", "state_requirem...
Verifies that the state requirements match the given query. If a matching requirement is found, then it is returned.
[ "Verifies", "that", "the", "state", "requirements", "match", "the", "given", "query", ".", "If", "a", "matching", "requirement", "is", "found", "then", "it", "is", "returned", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/branch.rb#L163-L167
16,263
state-machines/state_machines
lib/state_machines/branch.rb
StateMachines.Branch.matches_requirement?
def matches_requirement?(query, option, requirement) !query.include?(option) || requirement.matches?(query[option], query) end
ruby
def matches_requirement?(query, option, requirement) !query.include?(option) || requirement.matches?(query[option], query) end
[ "def", "matches_requirement?", "(", "query", ",", "option", ",", "requirement", ")", "!", "query", ".", "include?", "(", "option", ")", "||", "requirement", ".", "matches?", "(", "query", "[", "option", "]", ",", "query", ")", "end" ]
Verifies that an option in the given query matches the values required for that option
[ "Verifies", "that", "an", "option", "in", "the", "given", "query", "matches", "the", "values", "required", "for", "that", "option" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/branch.rb#L171-L173
16,264
state-machines/state_machines
lib/state_machines/branch.rb
StateMachines.Branch.matches_conditions?
def matches_conditions?(object, query) query[:guard] == false || Array(if_condition).all? {|condition| evaluate_method(object, condition)} && !Array(unless_condition).any? {|condition| evaluate_method(object, condition)} end
ruby
def matches_conditions?(object, query) query[:guard] == false || Array(if_condition).all? {|condition| evaluate_method(object, condition)} && !Array(unless_condition).any? {|condition| evaluate_method(object, condition)} end
[ "def", "matches_conditions?", "(", "object", ",", "query", ")", "query", "[", ":guard", "]", "==", "false", "||", "Array", "(", "if_condition", ")", ".", "all?", "{", "|", "condition", "|", "evaluate_method", "(", "object", ",", "condition", ")", "}", "&...
Verifies that the conditionals for this branch evaluate to true for the given object
[ "Verifies", "that", "the", "conditionals", "for", "this", "branch", "evaluate", "to", "true", "for", "the", "given", "object" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/branch.rb#L177-L181
16,265
state-machines/state_machines
lib/state_machines/path_collection.rb
StateMachines.PathCollection.initial_paths
def initial_paths machine.events.transitions_for(object, :from => from_name, :guard => @guard).map do |transition| path = Path.new(object, machine, :target => to_name, :guard => @guard) path << transition path end end
ruby
def initial_paths machine.events.transitions_for(object, :from => from_name, :guard => @guard).map do |transition| path = Path.new(object, machine, :target => to_name, :guard => @guard) path << transition path end end
[ "def", "initial_paths", "machine", ".", "events", ".", "transitions_for", "(", "object", ",", ":from", "=>", "from_name", ",", ":guard", "=>", "@guard", ")", ".", "map", "do", "|", "transition", "|", "path", "=", "Path", ".", "new", "(", "object", ",", ...
Gets the initial set of paths to walk
[ "Gets", "the", "initial", "set", "of", "paths", "to", "walk" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/path_collection.rb#L73-L79
16,266
state-machines/state_machines
lib/state_machines/path_collection.rb
StateMachines.PathCollection.walk
def walk(path) self << path if path.complete? path.walk {|next_path| walk(next_path)} unless to_name && path.complete? && !@deep end
ruby
def walk(path) self << path if path.complete? path.walk {|next_path| walk(next_path)} unless to_name && path.complete? && !@deep end
[ "def", "walk", "(", "path", ")", "self", "<<", "path", "if", "path", ".", "complete?", "path", ".", "walk", "{", "|", "next_path", "|", "walk", "(", "next_path", ")", "}", "unless", "to_name", "&&", "path", ".", "complete?", "&&", "!", "@deep", "end"...
Walks down the given path. Each new path that matches the configured requirements will be added to this collection.
[ "Walks", "down", "the", "given", "path", ".", "Each", "new", "path", "that", "matches", "the", "configured", "requirements", "will", "be", "added", "to", "this", "collection", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/path_collection.rb#L83-L86
16,267
state-machines/state_machines
lib/state_machines/path.rb
StateMachines.Path.recently_walked?
def recently_walked?(transition) transitions = self if @target && @target != to_name && target_transition = detect {|t| t.to_name == @target} transitions = transitions[index(target_transition) + 1..-1] end transitions.include?(transition) end
ruby
def recently_walked?(transition) transitions = self if @target && @target != to_name && target_transition = detect {|t| t.to_name == @target} transitions = transitions[index(target_transition) + 1..-1] end transitions.include?(transition) end
[ "def", "recently_walked?", "(", "transition", ")", "transitions", "=", "self", "if", "@target", "&&", "@target", "!=", "to_name", "&&", "target_transition", "=", "detect", "{", "|", "t", "|", "t", ".", "to_name", "==", "@target", "}", "transitions", "=", "...
Determines whether the given transition has been recently walked down in this path. If a target is configured for this path, then this will only look at transitions walked down since the target was last reached.
[ "Determines", "whether", "the", "given", "transition", "has", "been", "recently", "walked", "down", "in", "this", "path", ".", "If", "a", "target", "is", "configured", "for", "this", "path", "then", "this", "will", "only", "look", "at", "transitions", "walke...
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/path.rb#L98-L104
16,268
state-machines/state_machines
lib/state_machines/path.rb
StateMachines.Path.transitions
def transitions @transitions ||= empty? ? [] : machine.events.transitions_for(object, :from => to_name, :guard => @guard).select {|transition| can_walk_to?(transition)} end
ruby
def transitions @transitions ||= empty? ? [] : machine.events.transitions_for(object, :from => to_name, :guard => @guard).select {|transition| can_walk_to?(transition)} end
[ "def", "transitions", "@transitions", "||=", "empty?", "?", "[", "]", ":", "machine", ".", "events", ".", "transitions_for", "(", "object", ",", ":from", "=>", "to_name", ",", ":guard", "=>", "@guard", ")", ".", "select", "{", "|", "transition", "|", "ca...
Get the next set of transitions that can be walked to starting from the end of this path
[ "Get", "the", "next", "set", "of", "transitions", "that", "can", "be", "walked", "to", "starting", "from", "the", "end", "of", "this", "path" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/path.rb#L116-L118
16,269
state-machines/state_machines
lib/state_machines/state_context.rb
StateMachines.StateContext.method_missing
def method_missing(*args, &block) # Get the configuration if args.last.is_a?(Hash) options = args.last else args << options = {} end # Get any existing condition that may need to be merged if_condition = options.delete(:if) unless_condition = options.dele...
ruby
def method_missing(*args, &block) # Get the configuration if args.last.is_a?(Hash) options = args.last else args << options = {} end # Get any existing condition that may need to be merged if_condition = options.delete(:if) unless_condition = options.dele...
[ "def", "method_missing", "(", "*", "args", ",", "&", "block", ")", "# Get the configuration", "if", "args", ".", "last", ".", "is_a?", "(", "Hash", ")", "options", "=", "args", ".", "last", "else", "args", "<<", "options", "=", "{", "}", "end", "# Get ...
Hooks in condition-merging to methods that don't exist in this module
[ "Hooks", "in", "condition", "-", "merging", "to", "methods", "that", "don", "t", "exist", "in", "this", "module" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/state_context.rb#L99-L131
16,270
state-machines/state_machines
lib/state_machines/event_collection.rb
StateMachines.EventCollection.valid_for
def valid_for(object, requirements = {}) match(requirements).select { |event| event.can_fire?(object, requirements) } end
ruby
def valid_for(object, requirements = {}) match(requirements).select { |event| event.can_fire?(object, requirements) } end
[ "def", "valid_for", "(", "object", ",", "requirements", "=", "{", "}", ")", "match", "(", "requirements", ")", ".", "select", "{", "|", "event", "|", "event", ".", "can_fire?", "(", "object", ",", "requirements", ")", "}", "end" ]
Gets the list of events that can be fired on the given object. Valid requirement options: * <tt>:from</tt> - One or more states being transitioned from. If none are specified, then this will be the object's current state. * <tt>:to</tt> - One or more states being transitioned to. If none are specified, then...
[ "Gets", "the", "list", "of", "events", "that", "can", "be", "fired", "on", "the", "given", "object", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/event_collection.rb#L41-L43
16,271
state-machines/state_machines
lib/state_machines/event_collection.rb
StateMachines.EventCollection.transitions_for
def transitions_for(object, requirements = {}) match(requirements).map { |event| event.transition_for(object, requirements) }.compact end
ruby
def transitions_for(object, requirements = {}) match(requirements).map { |event| event.transition_for(object, requirements) }.compact end
[ "def", "transitions_for", "(", "object", ",", "requirements", "=", "{", "}", ")", "match", "(", "requirements", ")", ".", "map", "{", "|", "event", "|", "event", ".", "transition_for", "(", "object", ",", "requirements", ")", "}", ".", "compact", "end" ]
Gets the list of transitions that can be run on the given object. Valid requirement options: * <tt>:from</tt> - One or more states being transitioned from. If none are specified, then this will be the object's current state. * <tt>:to</tt> - One or more states being transitioned to. If none are specified, t...
[ "Gets", "the", "list", "of", "transitions", "that", "can", "be", "run", "on", "the", "given", "object", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/event_collection.rb#L81-L83
16,272
state-machines/state_machines
lib/state_machines/event_collection.rb
StateMachines.EventCollection.attribute_transition_for
def attribute_transition_for(object, invalidate = false) return unless machine.action # TODO, simplify machine.read(object, :event_transition) || if event_name = machine.read(object, :event) if event = self[event_name.to_sym, :name] ...
ruby
def attribute_transition_for(object, invalidate = false) return unless machine.action # TODO, simplify machine.read(object, :event_transition) || if event_name = machine.read(object, :event) if event = self[event_name.to_sym, :name] ...
[ "def", "attribute_transition_for", "(", "object", ",", "invalidate", "=", "false", ")", "return", "unless", "machine", ".", "action", "# TODO, simplify", "machine", ".", "read", "(", "object", ",", ":event_transition", ")", "||", "if", "event_name", "=", "machin...
Gets the transition that should be performed for the event stored in the given object's event attribute. This also takes an additional parameter for automatically invalidating the object if the event or transition are invalid. By default, this is turned off. *Note* that if a transition has already been generated...
[ "Gets", "the", "transition", "that", "should", "be", "performed", "for", "the", "event", "stored", "in", "the", "given", "object", "s", "event", "attribute", ".", "This", "also", "takes", "an", "additional", "parameter", "for", "automatically", "invalidating", ...
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/event_collection.rb#L114-L132
16,273
state-machines/state_machines
lib/state_machines/event.rb
StateMachines.Event.transition_for
def transition_for(object, requirements = {}) requirements.assert_valid_keys(:from, :to, :guard) requirements[:from] = machine.states.match!(object).name unless custom_from_state = requirements.include?(:from) branches.each do |branch| if match = branch.match(object, requirements) #...
ruby
def transition_for(object, requirements = {}) requirements.assert_valid_keys(:from, :to, :guard) requirements[:from] = machine.states.match!(object).name unless custom_from_state = requirements.include?(:from) branches.each do |branch| if match = branch.match(object, requirements) #...
[ "def", "transition_for", "(", "object", ",", "requirements", "=", "{", "}", ")", "requirements", ".", "assert_valid_keys", "(", ":from", ",", ":to", ",", ":guard", ")", "requirements", "[", ":from", "]", "=", "machine", ".", "states", ".", "match!", "(", ...
Finds and builds the next transition that can be performed on the given object. If no transitions can be made, then this will return nil. Valid requirement options: * <tt>:from</tt> - One or more states being transitioned from. If none are specified, then this will be the object's current state. * <tt>:to</tt...
[ "Finds", "and", "builds", "the", "next", "transition", "that", "can", "be", "performed", "on", "the", "given", "object", ".", "If", "no", "transitions", "can", "be", "made", "then", "this", "will", "return", "nil", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/event.rb#L121-L143
16,274
state-machines/state_machines
lib/state_machines/event.rb
StateMachines.Event.fire
def fire(object, *args) machine.reset(object) if transition = transition_for(object) transition.perform(*args) else on_failure(object, *args) false end end
ruby
def fire(object, *args) machine.reset(object) if transition = transition_for(object) transition.perform(*args) else on_failure(object, *args) false end end
[ "def", "fire", "(", "object", ",", "*", "args", ")", "machine", ".", "reset", "(", "object", ")", "if", "transition", "=", "transition_for", "(", "object", ")", "transition", ".", "perform", "(", "args", ")", "else", "on_failure", "(", "object", ",", "...
Attempts to perform the next available transition on the given object. If no transitions can be made, then this will return false, otherwise true. Any additional arguments are passed to the StateMachines::Transition#perform instance method.
[ "Attempts", "to", "perform", "the", "next", "available", "transition", "on", "the", "given", "object", ".", "If", "no", "transitions", "can", "be", "made", "then", "this", "will", "return", "false", "otherwise", "true", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/event.rb#L151-L160
16,275
state-machines/state_machines
lib/state_machines/event.rb
StateMachines.Event.on_failure
def on_failure(object, *args) state = machine.states.match!(object) machine.invalidate(object, :state, :invalid_transition, [[:event, human_name(object.class)], [:state, state.human_name(object.class)]]) transition = Transition.new(object, machine, name, state.name, state.name) transition.args ...
ruby
def on_failure(object, *args) state = machine.states.match!(object) machine.invalidate(object, :state, :invalid_transition, [[:event, human_name(object.class)], [:state, state.human_name(object.class)]]) transition = Transition.new(object, machine, name, state.name, state.name) transition.args ...
[ "def", "on_failure", "(", "object", ",", "*", "args", ")", "state", "=", "machine", ".", "states", ".", "match!", "(", "object", ")", "machine", ".", "invalidate", "(", "object", ",", ":state", ",", ":invalid_transition", ",", "[", "[", ":event", ",", ...
Marks the object as invalid and runs any failure callbacks associated with this event. This should get called anytime this event fails to transition.
[ "Marks", "the", "object", "as", "invalid", "and", "runs", "any", "failure", "callbacks", "associated", "with", "this", "event", ".", "This", "should", "get", "called", "anytime", "this", "event", "fails", "to", "transition", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/event.rb#L164-L171
16,276
state-machines/state_machines
lib/state_machines/event.rb
StateMachines.Event.add_actions
def add_actions # Checks whether the event can be fired on the current object machine.define_helper(:instance, "can_#{qualified_name}?") do |machine, object, *args| machine.event(name).can_fire?(object, *args) end # Gets the next transition that would be performed if the event were ...
ruby
def add_actions # Checks whether the event can be fired on the current object machine.define_helper(:instance, "can_#{qualified_name}?") do |machine, object, *args| machine.event(name).can_fire?(object, *args) end # Gets the next transition that would be performed if the event were ...
[ "def", "add_actions", "# Checks whether the event can be fired on the current object", "machine", ".", "define_helper", "(", ":instance", ",", "\"can_#{qualified_name}?\"", ")", "do", "|", "machine", ",", "object", ",", "*", "args", "|", "machine", ".", "event", "(", ...
Add the various instance methods that can transition the object using the current event
[ "Add", "the", "various", "instance", "methods", "that", "can", "transition", "the", "object", "using", "the", "current", "event" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/event.rb#L207-L228
16,277
state-machines/state_machines
lib/state_machines/machine_collection.rb
StateMachines.MachineCollection.transitions
def transitions(object, action, options = {}) transitions = map do |name, machine| machine.events.attribute_transition_for(object, true) if machine.action == action end AttributeTransitionCollection.new(transitions.compact, {use_transactions: resolve_use_transactions}.merge(options)) end
ruby
def transitions(object, action, options = {}) transitions = map do |name, machine| machine.events.attribute_transition_for(object, true) if machine.action == action end AttributeTransitionCollection.new(transitions.compact, {use_transactions: resolve_use_transactions}.merge(options)) end
[ "def", "transitions", "(", "object", ",", "action", ",", "options", "=", "{", "}", ")", "transitions", "=", "map", "do", "|", "name", ",", "machine", "|", "machine", ".", "events", ".", "attribute_transition_for", "(", "object", ",", "true", ")", "if", ...
Builds the collection of transitions for all event attributes defined on the given object. This will only include events whose machine actions match the one specified. These should only be fired as a result of the action being run.
[ "Builds", "the", "collection", "of", "transitions", "for", "all", "event", "attributes", "defined", "on", "the", "given", "object", ".", "This", "will", "only", "include", "events", "whose", "machine", "actions", "match", "the", "one", "specified", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/machine_collection.rb#L76-L82
16,278
state-machines/state_machines
lib/state_machines/node_collection.rb
StateMachines.NodeCollection.<<
def <<(node) @nodes << node @index_names.each { |name| add_to_index(name, value(node, name), node) } @contexts.each { |context| eval_context(context, node) } self end
ruby
def <<(node) @nodes << node @index_names.each { |name| add_to_index(name, value(node, name), node) } @contexts.each { |context| eval_context(context, node) } self end
[ "def", "<<", "(", "node", ")", "@nodes", "<<", "node", "@index_names", ".", "each", "{", "|", "name", "|", "add_to_index", "(", "name", ",", "value", "(", "node", ",", "name", ")", ",", "node", ")", "}", "@contexts", ".", "each", "{", "|", "context...
Adds a new node to the collection. By doing so, this will also add it to the configured indices. This will also evaluate any existings contexts that match the new node.
[ "Adds", "a", "new", "node", "to", "the", "collection", ".", "By", "doing", "so", "this", "will", "also", "add", "it", "to", "the", "configured", "indices", ".", "This", "will", "also", "evaluate", "any", "existings", "contexts", "that", "match", "the", "...
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/node_collection.rb#L85-L90
16,279
state-machines/state_machines
lib/state_machines/node_collection.rb
StateMachines.NodeCollection.update_index
def update_index(name, node) index = self.index(name) old_key = index.key(node) new_key = value(node, name) # Only replace the key if it's changed if old_key != new_key remove_from_index(name, old_key) add_to_index(name, new_key, node) end end
ruby
def update_index(name, node) index = self.index(name) old_key = index.key(node) new_key = value(node, name) # Only replace the key if it's changed if old_key != new_key remove_from_index(name, old_key) add_to_index(name, new_key, node) end end
[ "def", "update_index", "(", "name", ",", "node", ")", "index", "=", "self", ".", "index", "(", "name", ")", "old_key", "=", "index", ".", "key", "(", "node", ")", "new_key", "=", "value", "(", "node", ",", "name", ")", "# Only replace the key if it's cha...
Updates the node for the given index, including the string and symbol versions of the index
[ "Updates", "the", "node", "for", "the", "given", "index", "including", "the", "string", "and", "symbol", "versions", "of", "the", "index" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/node_collection.rb#L196-L206
16,280
state-machines/state_machines
lib/state_machines/node_collection.rb
StateMachines.NodeCollection.eval_context
def eval_context(context, node) node.context(&context[:block]) if context[:nodes].matches?(node.name) end
ruby
def eval_context(context, node) node.context(&context[:block]) if context[:nodes].matches?(node.name) end
[ "def", "eval_context", "(", "context", ",", "node", ")", "node", ".", "context", "(", "context", "[", ":block", "]", ")", "if", "context", "[", ":nodes", "]", ".", "matches?", "(", "node", ".", "name", ")", "end" ]
Evaluates the given context for a particular node. This will only evaluate the context if the node matches.
[ "Evaluates", "the", "given", "context", "for", "a", "particular", "node", ".", "This", "will", "only", "evaluate", "the", "context", "if", "the", "node", "matches", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/node_collection.rb#L215-L217
16,281
state-machines/state_machines
lib/state_machines/transition.rb
StateMachines.Transition.pause
def pause raise ArgumentError, 'around_transition callbacks cannot be called in multiple execution contexts in java implementations of Ruby. Use before/after_transitions instead.' unless self.class.pause_supported? unless @resume_block require 'continuation' unless defined?(callcc) ...
ruby
def pause raise ArgumentError, 'around_transition callbacks cannot be called in multiple execution contexts in java implementations of Ruby. Use before/after_transitions instead.' unless self.class.pause_supported? unless @resume_block require 'continuation' unless defined?(callcc) ...
[ "def", "pause", "raise", "ArgumentError", ",", "'around_transition callbacks cannot be called in multiple execution contexts in java implementations of Ruby. Use before/after_transitions instead.'", "unless", "self", ".", "class", ".", "pause_supported?", "unless", "@resume_block", "requ...
Pauses the current callback execution. This should only occur within around callbacks when the remainder of the callback will be executed at a later point in time.
[ "Pauses", "the", "current", "callback", "execution", ".", "This", "should", "only", "occur", "within", "around", "callbacks", "when", "the", "remainder", "of", "the", "callback", "will", "be", "executed", "at", "a", "later", "point", "in", "time", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/transition.rb#L307-L317
16,282
state-machines/state_machines
lib/state_machines/transition.rb
StateMachines.Transition.resume
def resume if @paused_block halted, error = callcc do |block| @resume_block = block @paused_block.call end @resume_block = @paused_block = nil raise error if error !halted else true end ...
ruby
def resume if @paused_block halted, error = callcc do |block| @resume_block = block @paused_block.call end @resume_block = @paused_block = nil raise error if error !halted else true end ...
[ "def", "resume", "if", "@paused_block", "halted", ",", "error", "=", "callcc", "do", "|", "block", "|", "@resume_block", "=", "block", "@paused_block", ".", "call", "end", "@resume_block", "=", "@paused_block", "=", "nil", "raise", "error", "if", "error", "!...
Resumes the execution of a previously paused callback execution. Once the paused callbacks complete, the current execution will continue.
[ "Resumes", "the", "execution", "of", "a", "previously", "paused", "callback", "execution", ".", "Once", "the", "paused", "callbacks", "complete", "the", "current", "execution", "will", "continue", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/transition.rb#L321-L335
16,283
state-machines/state_machines
lib/state_machines/transition.rb
StateMachines.Transition.before
def before(complete = true, index = 0, &block) unless @before_run while callback = machine.callbacks[:before][index] index += 1 if callback.type == :around # Around callback: need to handle recursively. Execution only gets # paused if: ...
ruby
def before(complete = true, index = 0, &block) unless @before_run while callback = machine.callbacks[:before][index] index += 1 if callback.type == :around # Around callback: need to handle recursively. Execution only gets # paused if: ...
[ "def", "before", "(", "complete", "=", "true", ",", "index", "=", "0", ",", "&", "block", ")", "unless", "@before_run", "while", "callback", "=", "machine", ".", "callbacks", "[", ":before", "]", "[", "index", "]", "index", "+=", "1", "if", "callback",...
Runs the machine's +before+ callbacks for this transition. Only callbacks that are configured to match the event, from state, and to state will be invoked. Once the callbacks are run, they cannot be run again until this transition is reset.
[ "Runs", "the", "machine", "s", "+", "before", "+", "callbacks", "for", "this", "transition", ".", "Only", "callbacks", "that", "are", "configured", "to", "match", "the", "event", "from", "state", "and", "to", "state", "will", "be", "invoked", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/transition.rb#L343-L373
16,284
state-machines/state_machines
lib/state_machines/transition.rb
StateMachines.Transition.after
def after unless @after_run # First resume previously paused callbacks if resume catch(:halt) do type = @success ? :after : :failure machine.callbacks[type].each {|callback| callback.call(object, context, self)} end end ...
ruby
def after unless @after_run # First resume previously paused callbacks if resume catch(:halt) do type = @success ? :after : :failure machine.callbacks[type].each {|callback| callback.call(object, context, self)} end end ...
[ "def", "after", "unless", "@after_run", "# First resume previously paused callbacks", "if", "resume", "catch", "(", ":halt", ")", "do", "type", "=", "@success", "?", ":after", ":", ":failure", "machine", ".", "callbacks", "[", "type", "]", ".", "each", "{", "|...
Runs the machine's +after+ callbacks for this transition. Only callbacks that are configured to match the event, from state, and to state will be invoked. Once the callbacks are run, they cannot be run again until this transition is reset. == Halting If any callback throws a <tt>:halt</tt> exception, it will ...
[ "Runs", "the", "machine", "s", "+", "after", "+", "callbacks", "for", "this", "transition", ".", "Only", "callbacks", "that", "are", "configured", "to", "match", "the", "event", "from", "state", "and", "to", "state", "will", "be", "invoked", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/transition.rb#L388-L400
16,285
state-machines/state_machines
lib/state_machines/transition_collection.rb
StateMachines.TransitionCollection.run_callbacks
def run_callbacks(index = 0, &block) if transition = self[index] throw :halt unless transition.run_callbacks(:after => !skip_after) do run_callbacks(index + 1, &block) {:result => results[transition.action], :success => success?} end else persist ...
ruby
def run_callbacks(index = 0, &block) if transition = self[index] throw :halt unless transition.run_callbacks(:after => !skip_after) do run_callbacks(index + 1, &block) {:result => results[transition.action], :success => success?} end else persist ...
[ "def", "run_callbacks", "(", "index", "=", "0", ",", "&", "block", ")", "if", "transition", "=", "self", "[", "index", "]", "throw", ":halt", "unless", "transition", ".", "run_callbacks", "(", ":after", "=>", "!", "skip_after", ")", "do", "run_callbacks", ...
Runs each transition's callbacks recursively. Once all before callbacks have been executed, the transitions will then be persisted and the configured actions will be run. If any transition fails to run its callbacks, :halt will be thrown.
[ "Runs", "each", "transition", "s", "callbacks", "recursively", ".", "Once", "all", "before", "callbacks", "have", "been", "executed", "the", "transitions", "will", "then", "be", "persisted", "and", "the", "configured", "actions", "will", "be", "run", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/transition_collection.rb#L125-L135
16,286
state-machines/state_machines
lib/state_machines/transition_collection.rb
StateMachines.TransitionCollection.run_actions
def run_actions catch_exceptions do @success = if block_given? result = yield actions.each {|action| results[action] = result} !!result else actions.compact.each {|action| !skip_actions && results[action] = object.send(action)} resu...
ruby
def run_actions catch_exceptions do @success = if block_given? result = yield actions.each {|action| results[action] = result} !!result else actions.compact.each {|action| !skip_actions && results[action] = object.send(action)} resu...
[ "def", "run_actions", "catch_exceptions", "do", "@success", "=", "if", "block_given?", "result", "=", "yield", "actions", ".", "each", "{", "|", "action", "|", "results", "[", "action", "]", "=", "result", "}", "!", "!", "result", "else", "actions", ".", ...
Runs the actions for each transition. If a block is given method, then it will be called instead of invoking each transition's action. The results of the actions will be used to determine #success?.
[ "Runs", "the", "actions", "for", "each", "transition", ".", "If", "a", "block", "is", "given", "method", "then", "it", "will", "be", "called", "instead", "of", "invoking", "each", "transition", "s", "action", "." ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/transition_collection.rb#L147-L158
16,287
state-machines/state_machines
lib/state_machines/transition_collection.rb
StateMachines.AttributeTransitionCollection.rollback
def rollback super each {|transition| transition.machine.write(object, :event, transition.event) unless transition.transient?} end
ruby
def rollback super each {|transition| transition.machine.write(object, :event, transition.event) unless transition.transient?} end
[ "def", "rollback", "super", "each", "{", "|", "transition", "|", "transition", ".", "machine", ".", "write", "(", "object", ",", ":event", ",", "transition", ".", "event", ")", "unless", "transition", ".", "transient?", "}", "end" ]
Resets the event attribute so it can be re-evaluated if attempted again
[ "Resets", "the", "event", "attribute", "so", "it", "can", "be", "re", "-", "evaluated", "if", "attempted", "again" ]
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/transition_collection.rb#L241-L244
16,288
state-machines/state_machines
lib/state_machines/callback.rb
StateMachines.Callback.call
def call(object, context = {}, *args, &block) if @branch.matches?(object, context) run_methods(object, context, 0, *args, &block) true else false end end
ruby
def call(object, context = {}, *args, &block) if @branch.matches?(object, context) run_methods(object, context, 0, *args, &block) true else false end end
[ "def", "call", "(", "object", ",", "context", "=", "{", "}", ",", "*", "args", ",", "&", "block", ")", "if", "@branch", ".", "matches?", "(", "object", ",", "context", ")", "run_methods", "(", "object", ",", "context", ",", "0", ",", "args", ",", ...
Runs the callback as long as the transition context matches the branch requirements configured for this callback. If a block is provided, it will be called when the last method has run. If a terminator has been configured and it matches the result from the evaluated method, then the callback chain should be halte...
[ "Runs", "the", "callback", "as", "long", "as", "the", "transition", "context", "matches", "the", "branch", "requirements", "configured", "for", "this", "callback", ".", "If", "a", "block", "is", "provided", "it", "will", "be", "called", "when", "the", "last"...
10b03af5fc9245bcb09bbd9c40c58ffba9a85422
https://github.com/state-machines/state_machines/blob/10b03af5fc9245bcb09bbd9c40c58ffba9a85422/lib/state_machines/callback.rb#L157-L164
16,289
brianmario/yajl-ruby
lib/yajl/http_stream.rb
Yajl.HttpStream.get
def get(uri, opts = {}, &block) initialize_socket(uri, opts) HttpStream::get(uri, opts, &block) rescue IOError => e raise e unless @intentional_termination end
ruby
def get(uri, opts = {}, &block) initialize_socket(uri, opts) HttpStream::get(uri, opts, &block) rescue IOError => e raise e unless @intentional_termination end
[ "def", "get", "(", "uri", ",", "opts", "=", "{", "}", ",", "&", "block", ")", "initialize_socket", "(", "uri", ",", "opts", ")", "HttpStream", "::", "get", "(", "uri", ",", "opts", ",", "block", ")", "rescue", "IOError", "=>", "e", "raise", "e", ...
Makes a basic HTTP GET request to the URI provided allowing the user to terminate the connection
[ "Makes", "a", "basic", "HTTP", "GET", "request", "to", "the", "URI", "provided", "allowing", "the", "user", "to", "terminate", "the", "connection" ]
2f927c42bf4e1d766a1eb1f532d5924c3b61f588
https://github.com/brianmario/yajl-ruby/blob/2f927c42bf4e1d766a1eb1f532d5924c3b61f588/lib/yajl/http_stream.rb#L37-L42
16,290
brianmario/yajl-ruby
lib/yajl/http_stream.rb
Yajl.HttpStream.post
def post(uri, body, opts = {}, &block) initialize_socket(uri, opts) HttpStream::post(uri, body, opts, &block) rescue IOError => e raise e unless @intentional_termination end
ruby
def post(uri, body, opts = {}, &block) initialize_socket(uri, opts) HttpStream::post(uri, body, opts, &block) rescue IOError => e raise e unless @intentional_termination end
[ "def", "post", "(", "uri", ",", "body", ",", "opts", "=", "{", "}", ",", "&", "block", ")", "initialize_socket", "(", "uri", ",", "opts", ")", "HttpStream", "::", "post", "(", "uri", ",", "body", ",", "opts", ",", "block", ")", "rescue", "IOError",...
Makes a basic HTTP POST request to the URI provided allowing the user to terminate the connection
[ "Makes", "a", "basic", "HTTP", "POST", "request", "to", "the", "URI", "provided", "allowing", "the", "user", "to", "terminate", "the", "connection" ]
2f927c42bf4e1d766a1eb1f532d5924c3b61f588
https://github.com/brianmario/yajl-ruby/blob/2f927c42bf4e1d766a1eb1f532d5924c3b61f588/lib/yajl/http_stream.rb#L50-L55
16,291
brianmario/yajl-ruby
lib/yajl/http_stream.rb
Yajl.HttpStream.initialize_socket
def initialize_socket(uri, opts = {}) return if opts[:socket] @socket = TCPSocket.new(uri.host, uri.port) opts.merge!({:socket => @socket}) @intentional_termination = false end
ruby
def initialize_socket(uri, opts = {}) return if opts[:socket] @socket = TCPSocket.new(uri.host, uri.port) opts.merge!({:socket => @socket}) @intentional_termination = false end
[ "def", "initialize_socket", "(", "uri", ",", "opts", "=", "{", "}", ")", "return", "if", "opts", "[", ":socket", "]", "@socket", "=", "TCPSocket", ".", "new", "(", "uri", ".", "host", ",", "uri", ".", "port", ")", "opts", ".", "merge!", "(", "{", ...
Initialize socket and add it to the opts
[ "Initialize", "socket", "and", "add", "it", "to", "the", "opts" ]
2f927c42bf4e1d766a1eb1f532d5924c3b61f588
https://github.com/brianmario/yajl-ruby/blob/2f927c42bf4e1d766a1eb1f532d5924c3b61f588/lib/yajl/http_stream.rb#L205-L211
16,292
brentd/xray-rails
lib/xray/middleware.rb
Xray.Middleware.append_js!
def append_js!(html, after_script_name, script_name) html.sub!(script_matcher(after_script_name)) do "#{$~}\n" + helper.javascript_include_tag(script_name) end end
ruby
def append_js!(html, after_script_name, script_name) html.sub!(script_matcher(after_script_name)) do "#{$~}\n" + helper.javascript_include_tag(script_name) end end
[ "def", "append_js!", "(", "html", ",", "after_script_name", ",", "script_name", ")", "html", ".", "sub!", "(", "script_matcher", "(", "after_script_name", ")", ")", "do", "\"#{$~}\\n\"", "+", "helper", ".", "javascript_include_tag", "(", "script_name", ")", "end...
Appends the given `script_name` after the `after_script_name`.
[ "Appends", "the", "given", "script_name", "after", "the", "after_script_name", "." ]
ab86801b55285771c567352e1784ae4346dc06a4
https://github.com/brentd/xray-rails/blob/ab86801b55285771c567352e1784ae4346dc06a4/lib/xray/middleware.rb#L114-L118
16,293
plataformatec/has_scope
lib/has_scope.rb
HasScope.ClassMethods.has_scope
def has_scope(*scopes, &block) options = scopes.extract_options! options.symbolize_keys! options.assert_valid_keys(:type, :only, :except, :if, :unless, :default, :as, :using, :allow_blank, :in) if options.key?(:in) options[:as] = options[:in] options[:using] = scopes end ...
ruby
def has_scope(*scopes, &block) options = scopes.extract_options! options.symbolize_keys! options.assert_valid_keys(:type, :only, :except, :if, :unless, :default, :as, :using, :allow_blank, :in) if options.key?(:in) options[:as] = options[:in] options[:using] = scopes end ...
[ "def", "has_scope", "(", "*", "scopes", ",", "&", "block", ")", "options", "=", "scopes", ".", "extract_options!", "options", ".", "symbolize_keys!", "options", ".", "assert_valid_keys", "(", ":type", ",", ":only", ",", ":except", ",", ":if", ",", ":unless",...
Detects params from url and apply as scopes to your classes. == Options * <tt>:type</tt> - Checks the type of the parameter sent. If set to :boolean it just calls the named scope, without any argument. By default, it does not allow hashes or arrays to be given, except if type...
[ "Detects", "params", "from", "url", "and", "apply", "as", "scopes", "to", "your", "classes", "." ]
ac9f4e68ce14f3f4b94fd323d7b9a0acbab4cfb3
https://github.com/plataformatec/has_scope/blob/ac9f4e68ce14f3f4b94fd323d7b9a0acbab4cfb3/lib/has_scope.rb#L64-L93
16,294
ohler55/ox
lib/ox/element.rb
Ox.Element.attr_match
def attr_match(cond) cond.each_pair { |k,v| return false unless v == @attributes[k.to_sym] || v == @attributes[k.to_s] } true end
ruby
def attr_match(cond) cond.each_pair { |k,v| return false unless v == @attributes[k.to_sym] || v == @attributes[k.to_s] } true end
[ "def", "attr_match", "(", "cond", ")", "cond", ".", "each_pair", "{", "|", "k", ",", "v", "|", "return", "false", "unless", "v", "==", "@attributes", "[", "k", ".", "to_sym", "]", "||", "v", "==", "@attributes", "[", "k", ".", "to_s", "]", "}", "...
Return true if all the key-value pairs in the cond Hash match the @attributes key-values.
[ "Return", "true", "if", "all", "the", "key", "-", "value", "pairs", "in", "the", "cond", "Hash", "match", "the" ]
f5b618285a0b9c885aa86dd9d51188fce2d60856
https://github.com/ohler55/ox/blob/f5b618285a0b9c885aa86dd9d51188fce2d60856/lib/ox/element.rb#L106-L109
16,295
ohler55/ox
lib/ox/element.rb
Ox.Element.each
def each(cond=nil) if cond.nil? nodes.each { |n| yield(n) } else cond = cond.to_s if cond.is_a?(Symbol) if cond.is_a?(String) nodes.each { |n| yield(n) if n.is_a?(Element) && cond == n.name } elsif cond.is_a?(Hash) nodes.each { |n| yield(n) if n.is_a?(Elem...
ruby
def each(cond=nil) if cond.nil? nodes.each { |n| yield(n) } else cond = cond.to_s if cond.is_a?(Symbol) if cond.is_a?(String) nodes.each { |n| yield(n) if n.is_a?(Element) && cond == n.name } elsif cond.is_a?(Hash) nodes.each { |n| yield(n) if n.is_a?(Elem...
[ "def", "each", "(", "cond", "=", "nil", ")", "if", "cond", ".", "nil?", "nodes", ".", "each", "{", "|", "n", "|", "yield", "(", "n", ")", "}", "else", "cond", "=", "cond", ".", "to_s", "if", "cond", ".", "is_a?", "(", "Symbol", ")", "if", "co...
Iterate over each child of the instance yielding according to the cond argument value. If the cond argument is nil then all child nodes are yielded to. If cond is a string then only the child Elements with a matching name will be yielded to. If the cond is a Hash then the keys-value pairs in the cond must match the...
[ "Iterate", "over", "each", "child", "of", "the", "instance", "yielding", "according", "to", "the", "cond", "argument", "value", ".", "If", "the", "cond", "argument", "is", "nil", "then", "all", "child", "nodes", "are", "yielded", "to", ".", "If", "cond", ...
f5b618285a0b9c885aa86dd9d51188fce2d60856
https://github.com/ohler55/ox/blob/f5b618285a0b9c885aa86dd9d51188fce2d60856/lib/ox/element.rb#L117-L128
16,296
ohler55/ox
lib/ox/element.rb
Ox.Element.remove_children
def remove_children(*children) return self if children.compact.empty? recursive_children_removal(children.compact.map { |c| c.object_id }) self end
ruby
def remove_children(*children) return self if children.compact.empty? recursive_children_removal(children.compact.map { |c| c.object_id }) self end
[ "def", "remove_children", "(", "*", "children", ")", "return", "self", "if", "children", ".", "compact", ".", "empty?", "recursive_children_removal", "(", "children", ".", "compact", ".", "map", "{", "|", "c", "|", "c", ".", "object_id", "}", ")", "self", ...
Remove all the children matching the path provided Examples are: * <code>element.remove_children(Ox:Element)</code> removes the element passed as argument if child of the element. * <code>element.remove_children(Ox:Element, Ox:Element)</code> removes the list of elements passed as argument if children of the elemen...
[ "Remove", "all", "the", "children", "matching", "the", "path", "provided" ]
f5b618285a0b9c885aa86dd9d51188fce2d60856
https://github.com/ohler55/ox/blob/f5b618285a0b9c885aa86dd9d51188fce2d60856/lib/ox/element.rb#L192-L196
16,297
ohler55/ox
lib/ox/element.rb
Ox.Element.recursive_children_removal
def recursive_children_removal(found) return if found.empty? nodes.tap do |ns| # found.delete(n.object_id) stops looking for an already found object_id ns.delete_if { |n| found.include?(n.object_id) ? found.delete(n.object_id) : false } nodes.each do |n| n.send(:recursive_c...
ruby
def recursive_children_removal(found) return if found.empty? nodes.tap do |ns| # found.delete(n.object_id) stops looking for an already found object_id ns.delete_if { |n| found.include?(n.object_id) ? found.delete(n.object_id) : false } nodes.each do |n| n.send(:recursive_c...
[ "def", "recursive_children_removal", "(", "found", ")", "return", "if", "found", ".", "empty?", "nodes", ".", "tap", "do", "|", "ns", "|", "# found.delete(n.object_id) stops looking for an already found object_id", "ns", ".", "delete_if", "{", "|", "n", "|", "found"...
Removes recursively children for nodes and sub_nodes - +found+ [Array] An array of Ox::Element
[ "Removes", "recursively", "children", "for", "nodes", "and", "sub_nodes" ]
f5b618285a0b9c885aa86dd9d51188fce2d60856
https://github.com/ohler55/ox/blob/f5b618285a0b9c885aa86dd9d51188fce2d60856/lib/ox/element.rb#L418-L427
16,298
igor-makarov/xcake
lib/xcake/visitor.rb
Xcake.Visitor.visit
def visit(item) item_name = item_name(item) method = "visit_#{item_name}" send(method, item) if respond_to? method end
ruby
def visit(item) item_name = item_name(item) method = "visit_#{item_name}" send(method, item) if respond_to? method end
[ "def", "visit", "(", "item", ")", "item_name", "=", "item_name", "(", "item", ")", "method", "=", "\"visit_#{item_name}\"", "send", "(", "method", ",", "item", ")", "if", "respond_to?", "method", "end" ]
This is called when a visitor is visiting a visitable item. By default this method calls the method `visit_<visitable classname>` so make sure you've created a method for each visitable you intend to visit. @param [Visitable] visitable the visitable item the visitor is visiting
[ "This", "is", "called", "when", "a", "visitor", "is", "visiting", "a", "visitable", "item", "." ]
4a16d5cf2662cfe1dc521b6818e441748ba5a02a
https://github.com/igor-makarov/xcake/blob/4a16d5cf2662cfe1dc521b6818e441748ba5a02a/lib/xcake/visitor.rb#L41-L46
16,299
igor-makarov/xcake
lib/xcake/visitor.rb
Xcake.Visitor.leave
def leave(item) item_name = item_name(item) method = "leave_#{item_name}" send(method, item) if respond_to? method end
ruby
def leave(item) item_name = item_name(item) method = "leave_#{item_name}" send(method, item) if respond_to? method end
[ "def", "leave", "(", "item", ")", "item_name", "=", "item_name", "(", "item", ")", "method", "=", "\"leave_#{item_name}\"", "send", "(", "method", ",", "item", ")", "if", "respond_to?", "method", "end" ]
This is called when a visitor is leaving a visitable item. By default this method calls the method `leave_<visitable classname>` so make sure you've created a method for each visitable you intend to visit. @param [Visitable] visitable the visitable item the visitor has left
[ "This", "is", "called", "when", "a", "visitor", "is", "leaving", "a", "visitable", "item", "." ]
4a16d5cf2662cfe1dc521b6818e441748ba5a02a
https://github.com/igor-makarov/xcake/blob/4a16d5cf2662cfe1dc521b6818e441748ba5a02a/lib/xcake/visitor.rb#L59-L64