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
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
|
---|---|---|---|---|---|---|---|---|---|---|---|
2,900 | Yellowen/Faalis | app/models/faalis/user.rb | Faalis.User.join_guests | def join_guests
#::Faalis::Group.find_by(role: 'guest')
if groups.empty?
guest_group = ::Faalis::Group.find_or_create_by(name: 'Guest',
role: 'guest')
self.groups << guest_group
end
end | ruby | def join_guests
#::Faalis::Group.find_by(role: 'guest')
if groups.empty?
guest_group = ::Faalis::Group.find_or_create_by(name: 'Guest',
role: 'guest')
self.groups << guest_group
end
end | [
"def",
"join_guests",
"#::Faalis::Group.find_by(role: 'guest')",
"if",
"groups",
".",
"empty?",
"guest_group",
"=",
"::",
"Faalis",
"::",
"Group",
".",
"find_or_create_by",
"(",
"name",
":",
"'Guest'",
",",
"role",
":",
"'guest'",
")",
"self",
".",
"groups",
"<<",
"guest_group",
"end",
"end"
] | It's totally obviuse. Join the guest group if no group provided | [
"It",
"s",
"totally",
"obviuse",
".",
"Join",
"the",
"guest",
"group",
"if",
"no",
"group",
"provided"
] | d12abdb8559dabbf6b2044e3ba437038527039b2 | https://github.com/Yellowen/Faalis/blob/d12abdb8559dabbf6b2044e3ba437038527039b2/app/models/faalis/user.rb#L67-L74 |
2,901 | Yellowen/Faalis | lib/faalis/dashboard/dsl/base.rb | Faalis::Dashboard::DSL.Base.attributes | def attributes(*fields_name, **options, &block)
if options.include? :except
@fields = resolve_model_reflections.reject do |field|
options[:except].include? field.to_sym
end
elsif options.include? :append
@fields += options[:append]
else
# Check for valid field names
fields_name.each do |name|
unless @fields.include? name.to_s
raise ArgumentError, "can't find '#{name}' field for model '#{model}'."
end
end
# set new value for fields
@fields = fields_name.map(&:to_s) unless fields_name.empty?
end
@fields.concat(block.call.map(&:to_s)) if block_given?
end | ruby | def attributes(*fields_name, **options, &block)
if options.include? :except
@fields = resolve_model_reflections.reject do |field|
options[:except].include? field.to_sym
end
elsif options.include? :append
@fields += options[:append]
else
# Check for valid field names
fields_name.each do |name|
unless @fields.include? name.to_s
raise ArgumentError, "can't find '#{name}' field for model '#{model}'."
end
end
# set new value for fields
@fields = fields_name.map(&:to_s) unless fields_name.empty?
end
@fields.concat(block.call.map(&:to_s)) if block_given?
end | [
"def",
"attributes",
"(",
"*",
"fields_name",
",",
"**",
"options",
",",
"&",
"block",
")",
"if",
"options",
".",
"include?",
":except",
"@fields",
"=",
"resolve_model_reflections",
".",
"reject",
"do",
"|",
"field",
"|",
"options",
"[",
":except",
"]",
".",
"include?",
"field",
".",
"to_sym",
"end",
"elsif",
"options",
".",
"include?",
":append",
"@fields",
"+=",
"options",
"[",
":append",
"]",
"else",
"# Check for valid field names",
"fields_name",
".",
"each",
"do",
"|",
"name",
"|",
"unless",
"@fields",
".",
"include?",
"name",
".",
"to_s",
"raise",
"ArgumentError",
",",
"\"can't find '#{name}' field for model '#{model}'.\"",
"end",
"end",
"# set new value for fields",
"@fields",
"=",
"fields_name",
".",
"map",
"(",
":to_s",
")",
"unless",
"fields_name",
".",
"empty?",
"end",
"@fields",
".",
"concat",
"(",
"block",
".",
"call",
".",
"map",
"(",
":to_s",
")",
")",
"if",
"block_given?",
"end"
] | Base class for all the DSL property classes to be
used as the yielded object inside each section DSL
scope.
For example the below code will yield an instance of
one of this class children.
in_index do
# This will yield an instance of this class child
end
The most important note in this class is that all the public
methods that their name starts with an underscore (_) not meant to
be used as DSL.
Allow user to specify an array of model attributes to be used
in respected section. For example attributes to show as header
columns in index section | [
"Base",
"class",
"for",
"all",
"the",
"DSL",
"property",
"classes",
"to",
"be",
"used",
"as",
"the",
"yielded",
"object",
"inside",
"each",
"section",
"DSL",
"scope",
"."
] | d12abdb8559dabbf6b2044e3ba437038527039b2 | https://github.com/Yellowen/Faalis/blob/d12abdb8559dabbf6b2044e3ba437038527039b2/lib/faalis/dashboard/dsl/base.rb#L32-L53 |
2,902 | Yellowen/Faalis | lib/faalis/dashboard/dsl/base.rb | Faalis::Dashboard::DSL.Base.resolve_model_reflections | def resolve_model_reflections
# TODO: cach the result using and instance_var or something
reflections = model.reflections
columns = Set.new model.column_names
new_fields = Set.new
fields_to_remove = Set.new
reflections.each do |name, column|
has_many = ActiveRecord::Reflection::HasManyReflection
has_and_belongs_to_many = ActiveRecord::Reflection::HasAndBelongsToManyReflection
if !column.is_a?(has_many) && !column.is_a?(has_and_belongs_to_many)
new_fields << name.to_s
fields_to_remove << column.foreign_key.to_s
end
end
if model.respond_to? :attachment_definitions
# Paperclip is installed and model contains attachments
model.attachment_definitions.each do |name, _|
new_fields << name.to_s
["file_name", "content_type", "file_size", "updated_at"].each do |x|
fields_to_remove << "#{name}_#{x}"
end
end
end
columns.union(new_fields) - fields_to_remove
end | ruby | def resolve_model_reflections
# TODO: cach the result using and instance_var or something
reflections = model.reflections
columns = Set.new model.column_names
new_fields = Set.new
fields_to_remove = Set.new
reflections.each do |name, column|
has_many = ActiveRecord::Reflection::HasManyReflection
has_and_belongs_to_many = ActiveRecord::Reflection::HasAndBelongsToManyReflection
if !column.is_a?(has_many) && !column.is_a?(has_and_belongs_to_many)
new_fields << name.to_s
fields_to_remove << column.foreign_key.to_s
end
end
if model.respond_to? :attachment_definitions
# Paperclip is installed and model contains attachments
model.attachment_definitions.each do |name, _|
new_fields << name.to_s
["file_name", "content_type", "file_size", "updated_at"].each do |x|
fields_to_remove << "#{name}_#{x}"
end
end
end
columns.union(new_fields) - fields_to_remove
end | [
"def",
"resolve_model_reflections",
"# TODO: cach the result using and instance_var or something",
"reflections",
"=",
"model",
".",
"reflections",
"columns",
"=",
"Set",
".",
"new",
"model",
".",
"column_names",
"new_fields",
"=",
"Set",
".",
"new",
"fields_to_remove",
"=",
"Set",
".",
"new",
"reflections",
".",
"each",
"do",
"|",
"name",
",",
"column",
"|",
"has_many",
"=",
"ActiveRecord",
"::",
"Reflection",
"::",
"HasManyReflection",
"has_and_belongs_to_many",
"=",
"ActiveRecord",
"::",
"Reflection",
"::",
"HasAndBelongsToManyReflection",
"if",
"!",
"column",
".",
"is_a?",
"(",
"has_many",
")",
"&&",
"!",
"column",
".",
"is_a?",
"(",
"has_and_belongs_to_many",
")",
"new_fields",
"<<",
"name",
".",
"to_s",
"fields_to_remove",
"<<",
"column",
".",
"foreign_key",
".",
"to_s",
"end",
"end",
"if",
"model",
".",
"respond_to?",
":attachment_definitions",
"# Paperclip is installed and model contains attachments",
"model",
".",
"attachment_definitions",
".",
"each",
"do",
"|",
"name",
",",
"_",
"|",
"new_fields",
"<<",
"name",
".",
"to_s",
"[",
"\"file_name\"",
",",
"\"content_type\"",
",",
"\"file_size\"",
",",
"\"updated_at\"",
"]",
".",
"each",
"do",
"|",
"x",
"|",
"fields_to_remove",
"<<",
"\"#{name}_#{x}\"",
"end",
"end",
"end",
"columns",
".",
"union",
"(",
"new_fields",
")",
"-",
"fields_to_remove",
"end"
] | Replace foreign key names with their reflection names
and create an array of model fields | [
"Replace",
"foreign",
"key",
"names",
"with",
"their",
"reflection",
"names",
"and",
"create",
"an",
"array",
"of",
"model",
"fields"
] | d12abdb8559dabbf6b2044e3ba437038527039b2 | https://github.com/Yellowen/Faalis/blob/d12abdb8559dabbf6b2044e3ba437038527039b2/lib/faalis/dashboard/dsl/base.rb#L103-L131 |
2,903 | kjvarga/ajax | lib/ajax/application.rb | Ajax.Application.rails? | def rails?(*args)
version, comparator = args.pop, (args.pop || :==)
result =
if version.nil?
defined?(::Rails)
elsif defined?(::Rails)
if ::Rails.respond_to?(:version)
rails_version = Rails.version.to_f
rails_version = rails_version.floor if version.is_a?(Integer)
rails_version.send(comparator, version.to_f)
else
version.to_f <= 2.0
end
else
false
end
!!result
end | ruby | def rails?(*args)
version, comparator = args.pop, (args.pop || :==)
result =
if version.nil?
defined?(::Rails)
elsif defined?(::Rails)
if ::Rails.respond_to?(:version)
rails_version = Rails.version.to_f
rails_version = rails_version.floor if version.is_a?(Integer)
rails_version.send(comparator, version.to_f)
else
version.to_f <= 2.0
end
else
false
end
!!result
end | [
"def",
"rails?",
"(",
"*",
"args",
")",
"version",
",",
"comparator",
"=",
"args",
".",
"pop",
",",
"(",
"args",
".",
"pop",
"||",
":==",
")",
"result",
"=",
"if",
"version",
".",
"nil?",
"defined?",
"(",
"::",
"Rails",
")",
"elsif",
"defined?",
"(",
"::",
"Rails",
")",
"if",
"::",
"Rails",
".",
"respond_to?",
"(",
":version",
")",
"rails_version",
"=",
"Rails",
".",
"version",
".",
"to_f",
"rails_version",
"=",
"rails_version",
".",
"floor",
"if",
"version",
".",
"is_a?",
"(",
"Integer",
")",
"rails_version",
".",
"send",
"(",
"comparator",
",",
"version",
".",
"to_f",
")",
"else",
"version",
".",
"to_f",
"<=",
"2.0",
"end",
"else",
"false",
"end",
"!",
"!",
"result",
"end"
] | Return a boolean indicating whether the Rails constant is defined.
It cannot identify Rails < 2.1
Example:
rails?(3) => true if Rails major version is 3
rails?(3.0) => true if Rails major.minor version is 3.0
rails?(:>=, 3) => true if Rails major version is >= 3
rails?(:>=, 3.1) => true if Rails major.minor version is >= 3.1 | [
"Return",
"a",
"boolean",
"indicating",
"whether",
"the",
"Rails",
"constant",
"is",
"defined",
".",
"It",
"cannot",
"identify",
"Rails",
"<",
"2",
".",
"1"
] | e60acbc51855cd85b4907d509ea41fe0965ce72e | https://github.com/kjvarga/ajax/blob/e60acbc51855cd85b4907d509ea41fe0965ce72e/lib/ajax/application.rb#L15-L32 |
2,904 | kjvarga/ajax | lib/ajax/application.rb | Ajax.Application.init | def init
return unless rails?
if rails?(:>=, 3)
require 'ajax/railtie'
else
require 'ajax/action_controller'
require 'ajax/action_view'
Ajax.logger = ::Rails.logger
# Customize rendering. Include custom headers and don't render the layout for AJAX.
::ActionController::Base.send(:include, Ajax::ActionController)
# Insert the Rack::Ajax middleware to rewrite and handle requests
::ActionController::Dispatcher.middleware.insert_before(Rack::Head, Rack::Ajax)
# Add custom attributes to outgoing links
::ActionView::Base.send(:include, Ajax::ActionView)
end
end | ruby | def init
return unless rails?
if rails?(:>=, 3)
require 'ajax/railtie'
else
require 'ajax/action_controller'
require 'ajax/action_view'
Ajax.logger = ::Rails.logger
# Customize rendering. Include custom headers and don't render the layout for AJAX.
::ActionController::Base.send(:include, Ajax::ActionController)
# Insert the Rack::Ajax middleware to rewrite and handle requests
::ActionController::Dispatcher.middleware.insert_before(Rack::Head, Rack::Ajax)
# Add custom attributes to outgoing links
::ActionView::Base.send(:include, Ajax::ActionView)
end
end | [
"def",
"init",
"return",
"unless",
"rails?",
"if",
"rails?",
"(",
":>=",
",",
"3",
")",
"require",
"'ajax/railtie'",
"else",
"require",
"'ajax/action_controller'",
"require",
"'ajax/action_view'",
"Ajax",
".",
"logger",
"=",
"::",
"Rails",
".",
"logger",
"# Customize rendering. Include custom headers and don't render the layout for AJAX.",
"::",
"ActionController",
"::",
"Base",
".",
"send",
"(",
":include",
",",
"Ajax",
"::",
"ActionController",
")",
"# Insert the Rack::Ajax middleware to rewrite and handle requests",
"::",
"ActionController",
"::",
"Dispatcher",
".",
"middleware",
".",
"insert_before",
"(",
"Rack",
"::",
"Head",
",",
"Rack",
"::",
"Ajax",
")",
"# Add custom attributes to outgoing links",
"::",
"ActionView",
"::",
"Base",
".",
"send",
"(",
":include",
",",
"Ajax",
"::",
"ActionView",
")",
"end",
"end"
] | Include framework hooks for Rails
This method is called by <tt>init.rb</tt>, which is run by Rails on startup.
Customize rendering. Include custom headers and don't render the layout for AJAX.
Insert the Rack::Ajax middleware to rewrite and handle requests.
Add custom attributes to outgoing links.
Hooks for Rails 3 are installed using Railties. | [
"Include",
"framework",
"hooks",
"for",
"Rails"
] | e60acbc51855cd85b4907d509ea41fe0965ce72e | https://github.com/kjvarga/ajax/blob/e60acbc51855cd85b4907d509ea41fe0965ce72e/lib/ajax/application.rb#L47-L66 |
2,905 | opulent/opulent | lib/opulent/compiler/eval.rb | Opulent.Compiler.evaluate | def evaluate(node, indent)
# Check if this is a substructure of a control block and remove the last
# end evaluation if it is
if node[@value] =~ Settings::END_REMOVAL
@template.pop if @template[-1] == [:eval, 'end']
end
# Check for explicit end node
if node[@value] =~ Settings::END_EXPLICIT
Logger.error :compile, @template, :explicit_end, node
end
# Evaluate the current expression
buffer_eval node[@value]
# If the node has children, evaluate each one of them
node[@children].each do |child|
root child, indent + @settings[:indent]
end if node[@children]
# Check if the node is actually a block expression
buffer_eval 'end' if node[@value] =~ Settings::END_INSERTION
end | ruby | def evaluate(node, indent)
# Check if this is a substructure of a control block and remove the last
# end evaluation if it is
if node[@value] =~ Settings::END_REMOVAL
@template.pop if @template[-1] == [:eval, 'end']
end
# Check for explicit end node
if node[@value] =~ Settings::END_EXPLICIT
Logger.error :compile, @template, :explicit_end, node
end
# Evaluate the current expression
buffer_eval node[@value]
# If the node has children, evaluate each one of them
node[@children].each do |child|
root child, indent + @settings[:indent]
end if node[@children]
# Check if the node is actually a block expression
buffer_eval 'end' if node[@value] =~ Settings::END_INSERTION
end | [
"def",
"evaluate",
"(",
"node",
",",
"indent",
")",
"# Check if this is a substructure of a control block and remove the last",
"# end evaluation if it is",
"if",
"node",
"[",
"@value",
"]",
"=~",
"Settings",
"::",
"END_REMOVAL",
"@template",
".",
"pop",
"if",
"@template",
"[",
"-",
"1",
"]",
"==",
"[",
":eval",
",",
"'end'",
"]",
"end",
"# Check for explicit end node",
"if",
"node",
"[",
"@value",
"]",
"=~",
"Settings",
"::",
"END_EXPLICIT",
"Logger",
".",
"error",
":compile",
",",
"@template",
",",
":explicit_end",
",",
"node",
"end",
"# Evaluate the current expression",
"buffer_eval",
"node",
"[",
"@value",
"]",
"# If the node has children, evaluate each one of them",
"node",
"[",
"@children",
"]",
".",
"each",
"do",
"|",
"child",
"|",
"root",
"child",
",",
"indent",
"+",
"@settings",
"[",
":indent",
"]",
"end",
"if",
"node",
"[",
"@children",
"]",
"# Check if the node is actually a block expression",
"buffer_eval",
"'end'",
"if",
"node",
"[",
"@value",
"]",
"=~",
"Settings",
"::",
"END_INSERTION",
"end"
] | Evaluate the embedded ruby code using the current context
@param node [Array] Node code generation data
@param indent [Fixnum] Size of the indentation to be added | [
"Evaluate",
"the",
"embedded",
"ruby",
"code",
"using",
"the",
"current",
"context"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/compiler/eval.rb#L10-L32 |
2,906 | Yellowen/Faalis | lib/faalis/routes.rb | Faalis.RouteHelpers.localized_scope | def localized_scope
langs = ::I18n.available_locales.join('|')
scope '(:locale)', locale: Regexp.new(langs) do
yield
end
end | ruby | def localized_scope
langs = ::I18n.available_locales.join('|')
scope '(:locale)', locale: Regexp.new(langs) do
yield
end
end | [
"def",
"localized_scope",
"langs",
"=",
"::",
"I18n",
".",
"available_locales",
".",
"join",
"(",
"'|'",
")",
"scope",
"'(:locale)'",
",",
"locale",
":",
"Regexp",
".",
"new",
"(",
"langs",
")",
"do",
"yield",
"end",
"end"
] | Allow localized scope | [
"Allow",
"localized",
"scope"
] | d12abdb8559dabbf6b2044e3ba437038527039b2 | https://github.com/Yellowen/Faalis/blob/d12abdb8559dabbf6b2044e3ba437038527039b2/lib/faalis/routes.rb#L12-L17 |
2,907 | Yellowen/Faalis | lib/faalis/routes.rb | Faalis.RouteHelpers.api_routes | def api_routes(version: :v1)
# TODO: Add a dynamic solution for formats
namespace :api, defaults: { format: :json } do
namespace version do
# Call user given block to define user routes
# inside this namespace
yield if block_given?
end
end
scope 'module'.to_sym => 'faalis' do
#dashboard = Faalis::Engine.dashboard_namespace
#get "#{dashboard}/auth/groups/new", to: "#{dashboard}/groups#new"
get 'auth/profile/edit', to: "profile#edit"
post 'auth/profile/edit', to: "profile#update"
end
# TODO: Add a dynamic solution for formats
namespace :api, defaults: { format: :json } do
namespace version do
get 'permissions', to: 'permissions#index'
get 'permissions/user', to: 'permissions#user_permissions'
resources :groups, except: [:new]
resources :users, except: [:new]
resource :profile, except: [:new, :destroy]
get 'logs', to: 'logs#index'
end
end
end | ruby | def api_routes(version: :v1)
# TODO: Add a dynamic solution for formats
namespace :api, defaults: { format: :json } do
namespace version do
# Call user given block to define user routes
# inside this namespace
yield if block_given?
end
end
scope 'module'.to_sym => 'faalis' do
#dashboard = Faalis::Engine.dashboard_namespace
#get "#{dashboard}/auth/groups/new", to: "#{dashboard}/groups#new"
get 'auth/profile/edit', to: "profile#edit"
post 'auth/profile/edit', to: "profile#update"
end
# TODO: Add a dynamic solution for formats
namespace :api, defaults: { format: :json } do
namespace version do
get 'permissions', to: 'permissions#index'
get 'permissions/user', to: 'permissions#user_permissions'
resources :groups, except: [:new]
resources :users, except: [:new]
resource :profile, except: [:new, :destroy]
get 'logs', to: 'logs#index'
end
end
end | [
"def",
"api_routes",
"(",
"version",
":",
":v1",
")",
"# TODO: Add a dynamic solution for formats",
"namespace",
":api",
",",
"defaults",
":",
"{",
"format",
":",
":json",
"}",
"do",
"namespace",
"version",
"do",
"# Call user given block to define user routes",
"# inside this namespace",
"yield",
"if",
"block_given?",
"end",
"end",
"scope",
"'module'",
".",
"to_sym",
"=>",
"'faalis'",
"do",
"#dashboard = Faalis::Engine.dashboard_namespace",
"#get \"#{dashboard}/auth/groups/new\", to: \"#{dashboard}/groups#new\"",
"get",
"'auth/profile/edit'",
",",
"to",
":",
"\"profile#edit\"",
"post",
"'auth/profile/edit'",
",",
"to",
":",
"\"profile#update\"",
"end",
"# TODO: Add a dynamic solution for formats",
"namespace",
":api",
",",
"defaults",
":",
"{",
"format",
":",
":json",
"}",
"do",
"namespace",
"version",
"do",
"get",
"'permissions'",
",",
"to",
":",
"'permissions#index'",
"get",
"'permissions/user'",
",",
"to",
":",
"'permissions#user_permissions'",
"resources",
":groups",
",",
"except",
":",
"[",
":new",
"]",
"resources",
":users",
",",
"except",
":",
"[",
":new",
"]",
"resource",
":profile",
",",
"except",
":",
"[",
":new",
",",
":destroy",
"]",
"get",
"'logs'",
",",
"to",
":",
"'logs#index'",
"end",
"end",
"end"
] | This method allow user to define his routes in api
namespace | [
"This",
"method",
"allow",
"user",
"to",
"define",
"his",
"routes",
"in",
"api",
"namespace"
] | d12abdb8559dabbf6b2044e3ba437038527039b2 | https://github.com/Yellowen/Faalis/blob/d12abdb8559dabbf6b2044e3ba437038527039b2/lib/faalis/routes.rb#L21-L50 |
2,908 | beatrichartz/configurations | lib/configurations/configuration.rb | Configurations.Configuration.to_h | def to_h
@data.reduce({}) do |h, (k, v)|
h[k] = v.is_a?(__class__) ? v.to_h : v
h
end
end | ruby | def to_h
@data.reduce({}) do |h, (k, v)|
h[k] = v.is_a?(__class__) ? v.to_h : v
h
end
end | [
"def",
"to_h",
"@data",
".",
"reduce",
"(",
"{",
"}",
")",
"do",
"|",
"h",
",",
"(",
"k",
",",
"v",
")",
"|",
"h",
"[",
"k",
"]",
"=",
"v",
".",
"is_a?",
"(",
"__class__",
")",
"?",
"v",
".",
"to_h",
":",
"v",
"h",
"end",
"end"
] | A convenience accessor to get a hash representation of the
current state of the configuration
@return [Hash] the configuration in hash form | [
"A",
"convenience",
"accessor",
"to",
"get",
"a",
"hash",
"representation",
"of",
"the",
"current",
"state",
"of",
"the",
"configuration"
] | bd8ef480ca831e29b821ffc9ebeaed4ef46a9db2 | https://github.com/beatrichartz/configurations/blob/bd8ef480ca831e29b821ffc9ebeaed4ef46a9db2/lib/configurations/configuration.rb#L59-L65 |
2,909 | beatrichartz/configurations | lib/configurations/configuration.rb | Configurations.Configuration.from_h | def from_h(h)
@key_ambiguity_validator.validate!(h)
h.each do |property, value|
p = property.to_sym
if value.is_a?(::Hash) && __nested?(p)
@data[p].from_h(value)
elsif __configurable?(p)
__assign!(p, value)
end
end
self
end | ruby | def from_h(h)
@key_ambiguity_validator.validate!(h)
h.each do |property, value|
p = property.to_sym
if value.is_a?(::Hash) && __nested?(p)
@data[p].from_h(value)
elsif __configurable?(p)
__assign!(p, value)
end
end
self
end | [
"def",
"from_h",
"(",
"h",
")",
"@key_ambiguity_validator",
".",
"validate!",
"(",
"h",
")",
"h",
".",
"each",
"do",
"|",
"property",
",",
"value",
"|",
"p",
"=",
"property",
".",
"to_sym",
"if",
"value",
".",
"is_a?",
"(",
"::",
"Hash",
")",
"&&",
"__nested?",
"(",
"p",
")",
"@data",
"[",
"p",
"]",
".",
"from_h",
"(",
"value",
")",
"elsif",
"__configurable?",
"(",
"p",
")",
"__assign!",
"(",
"p",
",",
"value",
")",
"end",
"end",
"self",
"end"
] | A convenience accessor to instantiate a configuration from a hash
@param [Hash] h the hash to read into the configuration
@return [Configuration] the configuration with values assigned
@raise [ConfigurationError] if the given hash ambiguous values
- string and symbol keys with the same string value pointing to
different values | [
"A",
"convenience",
"accessor",
"to",
"instantiate",
"a",
"configuration",
"from",
"a",
"hash"
] | bd8ef480ca831e29b821ffc9ebeaed4ef46a9db2 | https://github.com/beatrichartz/configurations/blob/bd8ef480ca831e29b821ffc9ebeaed4ef46a9db2/lib/configurations/configuration.rb#L74-L87 |
2,910 | opulent/opulent | lib/opulent/compiler/control.rb | Opulent.Compiler.if_node | def if_node(node, indent)
# Check if we have any condition met, or an else branch
node[@value].each_with_index do |value, index|
# If we have a branch that meets the condition, generate code for the
# children related to that specific branch
case value
when node[@value].first then buffer_eval "if #{value}"
when node[@value].last then buffer_eval "else"
else buffer_eval "elsif #{value}"
end
# Evaluate child nodes
node[@children][index].each do |child|
root child, indent
end
end
# End
buffer_eval "end"
end | ruby | def if_node(node, indent)
# Check if we have any condition met, or an else branch
node[@value].each_with_index do |value, index|
# If we have a branch that meets the condition, generate code for the
# children related to that specific branch
case value
when node[@value].first then buffer_eval "if #{value}"
when node[@value].last then buffer_eval "else"
else buffer_eval "elsif #{value}"
end
# Evaluate child nodes
node[@children][index].each do |child|
root child, indent
end
end
# End
buffer_eval "end"
end | [
"def",
"if_node",
"(",
"node",
",",
"indent",
")",
"# Check if we have any condition met, or an else branch",
"node",
"[",
"@value",
"]",
".",
"each_with_index",
"do",
"|",
"value",
",",
"index",
"|",
"# If we have a branch that meets the condition, generate code for the",
"# children related to that specific branch",
"case",
"value",
"when",
"node",
"[",
"@value",
"]",
".",
"first",
"then",
"buffer_eval",
"\"if #{value}\"",
"when",
"node",
"[",
"@value",
"]",
".",
"last",
"then",
"buffer_eval",
"\"else\"",
"else",
"buffer_eval",
"\"elsif #{value}\"",
"end",
"# Evaluate child nodes",
"node",
"[",
"@children",
"]",
"[",
"index",
"]",
".",
"each",
"do",
"|",
"child",
"|",
"root",
"child",
",",
"indent",
"end",
"end",
"# End",
"buffer_eval",
"\"end\"",
"end"
] | Generate the code for a if-elsif-else control structure
@param node [Array] Node code generation data
@param indent [Fixnum] Size of the indentation to be added | [
"Generate",
"the",
"code",
"for",
"a",
"if",
"-",
"elsif",
"-",
"else",
"control",
"structure"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/compiler/control.rb#L10-L29 |
2,911 | opulent/opulent | lib/opulent/compiler/control.rb | Opulent.Compiler.unless_node | def unless_node(node, indent)
# Check if we have any condition met, or an else branch
node[@value].each_with_index do |value, index|
# If we have a branch that meets the condition, generate code for the
# children related to that specific branch
case value
when node[@value].first then buffer_eval "unless #{value}"
else buffer_eval "else"
end
# Evaluate child nodes
node[@children][index].each do |child|
root child, indent
end
end
# End
buffer_eval "end"
end | ruby | def unless_node(node, indent)
# Check if we have any condition met, or an else branch
node[@value].each_with_index do |value, index|
# If we have a branch that meets the condition, generate code for the
# children related to that specific branch
case value
when node[@value].first then buffer_eval "unless #{value}"
else buffer_eval "else"
end
# Evaluate child nodes
node[@children][index].each do |child|
root child, indent
end
end
# End
buffer_eval "end"
end | [
"def",
"unless_node",
"(",
"node",
",",
"indent",
")",
"# Check if we have any condition met, or an else branch",
"node",
"[",
"@value",
"]",
".",
"each_with_index",
"do",
"|",
"value",
",",
"index",
"|",
"# If we have a branch that meets the condition, generate code for the",
"# children related to that specific branch",
"case",
"value",
"when",
"node",
"[",
"@value",
"]",
".",
"first",
"then",
"buffer_eval",
"\"unless #{value}\"",
"else",
"buffer_eval",
"\"else\"",
"end",
"# Evaluate child nodes",
"node",
"[",
"@children",
"]",
"[",
"index",
"]",
".",
"each",
"do",
"|",
"child",
"|",
"root",
"child",
",",
"indent",
"end",
"end",
"# End",
"buffer_eval",
"\"end\"",
"end"
] | Generate the code for a unless-else control structure
@param node [Array] Node code generation data
@param indent [Fixnum] Size of the indentation to be added | [
"Generate",
"the",
"code",
"for",
"a",
"unless",
"-",
"else",
"control",
"structure"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/compiler/control.rb#L36-L54 |
2,912 | opulent/opulent | lib/opulent/compiler/control.rb | Opulent.Compiler.case_node | def case_node(node, indent)
# Evaluate the switching condition
buffer_eval "case #{node[@options][:condition]}"
# Check if we have any condition met, or an else branch
node[@value].each_with_index do |value, index|
# If we have a branch that meets the condition, generate code for the
# children related to that specific branch
case value
when node[@value].last then buffer_eval 'else'
else buffer_eval "when #{value}"
end
# Evaluate child nodes
node[@children][index].each do |child|
root child, indent
end
end
# End
buffer_eval 'end'
end | ruby | def case_node(node, indent)
# Evaluate the switching condition
buffer_eval "case #{node[@options][:condition]}"
# Check if we have any condition met, or an else branch
node[@value].each_with_index do |value, index|
# If we have a branch that meets the condition, generate code for the
# children related to that specific branch
case value
when node[@value].last then buffer_eval 'else'
else buffer_eval "when #{value}"
end
# Evaluate child nodes
node[@children][index].each do |child|
root child, indent
end
end
# End
buffer_eval 'end'
end | [
"def",
"case_node",
"(",
"node",
",",
"indent",
")",
"# Evaluate the switching condition",
"buffer_eval",
"\"case #{node[@options][:condition]}\"",
"# Check if we have any condition met, or an else branch",
"node",
"[",
"@value",
"]",
".",
"each_with_index",
"do",
"|",
"value",
",",
"index",
"|",
"# If we have a branch that meets the condition, generate code for the",
"# children related to that specific branch",
"case",
"value",
"when",
"node",
"[",
"@value",
"]",
".",
"last",
"then",
"buffer_eval",
"'else'",
"else",
"buffer_eval",
"\"when #{value}\"",
"end",
"# Evaluate child nodes",
"node",
"[",
"@children",
"]",
"[",
"index",
"]",
".",
"each",
"do",
"|",
"child",
"|",
"root",
"child",
",",
"indent",
"end",
"end",
"# End",
"buffer_eval",
"'end'",
"end"
] | Generate the code for a case-when-else control structure
@param node [Array] Node code generation data
@param indent [Fixnum] Size of the indentation to be added | [
"Generate",
"the",
"code",
"for",
"a",
"case",
"-",
"when",
"-",
"else",
"control",
"structure"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/compiler/control.rb#L61-L82 |
2,913 | mdub/representative | lib/representative/nokogiri.rb | Representative.Nokogiri.comment | def comment(text)
comment_node = ::Nokogiri::XML::Comment.new(doc, " #{text} ")
current_element.add_child(comment_node)
end | ruby | def comment(text)
comment_node = ::Nokogiri::XML::Comment.new(doc, " #{text} ")
current_element.add_child(comment_node)
end | [
"def",
"comment",
"(",
"text",
")",
"comment_node",
"=",
"::",
"Nokogiri",
"::",
"XML",
"::",
"Comment",
".",
"new",
"(",
"doc",
",",
"\" #{text} \"",
")",
"current_element",
".",
"add_child",
"(",
"comment_node",
")",
"end"
] | Generate a comment | [
"Generate",
"a",
"comment"
] | c60214e79d51581a1744ae2891094468416b88f9 | https://github.com/mdub/representative/blob/c60214e79d51581a1744ae2891094468416b88f9/lib/representative/nokogiri.rb#L33-L36 |
2,914 | opulent/opulent | lib/opulent/parser/node.rb | Opulent.Parser.node | def node(parent, indent = nil)
return unless (name = lookahead(:node_lookahead) ||
lookahead(:shorthand_lookahead))
# Skip node if it's a reserved keyword
return nil if KEYWORDS.include? name[0].to_sym
# Accept either explicit node_name or implicit :div node_name
# with shorthand attributes
if (node_name = accept :node)
node_name = node_name.to_sym
shorthand = shorthand_attributes
elsif (shorthand = shorthand_attributes)
node_name = :div
end
# Node creation options
options = {}
# Get leading whitespace
options[:recursive] = accept(:recursive)
# Get leading whitespace
options[:leading_whitespace] = accept_stripped(:leading_whitespace)
# Get trailing whitespace
options[:trailing_whitespace] = accept_stripped(:trailing_whitespace)
# Get wrapped node attributes
atts = attributes(shorthand) || {}
# Inherit attributes from definition
options[:extension] = extend_attributes
# Get unwrapped node attributes
options[:attributes] = attributes_assignments atts, false
# Create node
current_node = [:node, node_name, options, [], indent]
# Check for self enclosing tags and definitions
def_check = [email protected]?(node_name) &&
Settings::SELF_ENCLOSING.include?(node_name)
# Check if the node is explicitly self enclosing
if (close = accept_stripped :self_enclosing) || def_check
current_node[@options][:self_enclosing] = true
unless close.nil? || close.strip.empty?
undo close
Logger.error :parse, @code, @i, @j, :self_enclosing
end
end
# Check whether we have explicit inline elements and add them
# with increased base indentation
if accept :inline_child
# Inline node element
Logger.error :parse,
@code,
@i,
@j,
:inline_child unless node current_node, indent
elsif comment current_node, indent
# Accept same line comments
else
# Accept inline text element
text current_node, indent, false
end
# Add the current node to the root
root current_node, indent
# Add the parsed node to the parent
parent[@children] << current_node
end | ruby | def node(parent, indent = nil)
return unless (name = lookahead(:node_lookahead) ||
lookahead(:shorthand_lookahead))
# Skip node if it's a reserved keyword
return nil if KEYWORDS.include? name[0].to_sym
# Accept either explicit node_name or implicit :div node_name
# with shorthand attributes
if (node_name = accept :node)
node_name = node_name.to_sym
shorthand = shorthand_attributes
elsif (shorthand = shorthand_attributes)
node_name = :div
end
# Node creation options
options = {}
# Get leading whitespace
options[:recursive] = accept(:recursive)
# Get leading whitespace
options[:leading_whitespace] = accept_stripped(:leading_whitespace)
# Get trailing whitespace
options[:trailing_whitespace] = accept_stripped(:trailing_whitespace)
# Get wrapped node attributes
atts = attributes(shorthand) || {}
# Inherit attributes from definition
options[:extension] = extend_attributes
# Get unwrapped node attributes
options[:attributes] = attributes_assignments atts, false
# Create node
current_node = [:node, node_name, options, [], indent]
# Check for self enclosing tags and definitions
def_check = [email protected]?(node_name) &&
Settings::SELF_ENCLOSING.include?(node_name)
# Check if the node is explicitly self enclosing
if (close = accept_stripped :self_enclosing) || def_check
current_node[@options][:self_enclosing] = true
unless close.nil? || close.strip.empty?
undo close
Logger.error :parse, @code, @i, @j, :self_enclosing
end
end
# Check whether we have explicit inline elements and add them
# with increased base indentation
if accept :inline_child
# Inline node element
Logger.error :parse,
@code,
@i,
@j,
:inline_child unless node current_node, indent
elsif comment current_node, indent
# Accept same line comments
else
# Accept inline text element
text current_node, indent, false
end
# Add the current node to the root
root current_node, indent
# Add the parsed node to the parent
parent[@children] << current_node
end | [
"def",
"node",
"(",
"parent",
",",
"indent",
"=",
"nil",
")",
"return",
"unless",
"(",
"name",
"=",
"lookahead",
"(",
":node_lookahead",
")",
"||",
"lookahead",
"(",
":shorthand_lookahead",
")",
")",
"# Skip node if it's a reserved keyword",
"return",
"nil",
"if",
"KEYWORDS",
".",
"include?",
"name",
"[",
"0",
"]",
".",
"to_sym",
"# Accept either explicit node_name or implicit :div node_name",
"# with shorthand attributes",
"if",
"(",
"node_name",
"=",
"accept",
":node",
")",
"node_name",
"=",
"node_name",
".",
"to_sym",
"shorthand",
"=",
"shorthand_attributes",
"elsif",
"(",
"shorthand",
"=",
"shorthand_attributes",
")",
"node_name",
"=",
":div",
"end",
"# Node creation options",
"options",
"=",
"{",
"}",
"# Get leading whitespace",
"options",
"[",
":recursive",
"]",
"=",
"accept",
"(",
":recursive",
")",
"# Get leading whitespace",
"options",
"[",
":leading_whitespace",
"]",
"=",
"accept_stripped",
"(",
":leading_whitespace",
")",
"# Get trailing whitespace",
"options",
"[",
":trailing_whitespace",
"]",
"=",
"accept_stripped",
"(",
":trailing_whitespace",
")",
"# Get wrapped node attributes",
"atts",
"=",
"attributes",
"(",
"shorthand",
")",
"||",
"{",
"}",
"# Inherit attributes from definition",
"options",
"[",
":extension",
"]",
"=",
"extend_attributes",
"# Get unwrapped node attributes",
"options",
"[",
":attributes",
"]",
"=",
"attributes_assignments",
"atts",
",",
"false",
"# Create node",
"current_node",
"=",
"[",
":node",
",",
"node_name",
",",
"options",
",",
"[",
"]",
",",
"indent",
"]",
"# Check for self enclosing tags and definitions",
"def_check",
"=",
"!",
"@definitions",
".",
"keys",
".",
"include?",
"(",
"node_name",
")",
"&&",
"Settings",
"::",
"SELF_ENCLOSING",
".",
"include?",
"(",
"node_name",
")",
"# Check if the node is explicitly self enclosing",
"if",
"(",
"close",
"=",
"accept_stripped",
":self_enclosing",
")",
"||",
"def_check",
"current_node",
"[",
"@options",
"]",
"[",
":self_enclosing",
"]",
"=",
"true",
"unless",
"close",
".",
"nil?",
"||",
"close",
".",
"strip",
".",
"empty?",
"undo",
"close",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":self_enclosing",
"end",
"end",
"# Check whether we have explicit inline elements and add them",
"# with increased base indentation",
"if",
"accept",
":inline_child",
"# Inline node element",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":inline_child",
"unless",
"node",
"current_node",
",",
"indent",
"elsif",
"comment",
"current_node",
",",
"indent",
"# Accept same line comments",
"else",
"# Accept inline text element",
"text",
"current_node",
",",
"indent",
",",
"false",
"end",
"# Add the current node to the root",
"root",
"current_node",
",",
"indent",
"# Add the parsed node to the parent",
"parent",
"[",
"@children",
"]",
"<<",
"current_node",
"end"
] | Check if we match an node node with its attributes and possibly
inline text
node [ attributes ] Inline text
@param parent [Node] Parent node to which we append the node | [
"Check",
"if",
"we",
"match",
"an",
"node",
"node",
"with",
"its",
"attributes",
"and",
"possibly",
"inline",
"text"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/node.rb#L12-L87 |
2,915 | opulent/opulent | lib/opulent/parser/node.rb | Opulent.Parser.shorthand_attributes | def shorthand_attributes(atts = {})
while (key = accept :shorthand)
key = Settings::SHORTHAND[key.to_sym]
# Check whether the value is escaped or unescaped
escaped = accept(:unescaped_value) ? false : true
# Get the attribute value and process it
if (value = accept(:shorthand_node))
value = [:expression, value.inspect, { escaped: escaped }]
elsif (value = accept(:exp_string))
value = [:expression, value, { escaped: escaped }]
elsif (value = paranthesis)
value = [:expression, value, { escaped: escaped }]
else
Logger.error :parse, @code, @i, @j, :shorthand
end
# IDs are unique, the rest of the attributes turn into arrays in
# order to allow multiple values or identifiers
add_attribute(atts, key, value)
end
atts
end | ruby | def shorthand_attributes(atts = {})
while (key = accept :shorthand)
key = Settings::SHORTHAND[key.to_sym]
# Check whether the value is escaped or unescaped
escaped = accept(:unescaped_value) ? false : true
# Get the attribute value and process it
if (value = accept(:shorthand_node))
value = [:expression, value.inspect, { escaped: escaped }]
elsif (value = accept(:exp_string))
value = [:expression, value, { escaped: escaped }]
elsif (value = paranthesis)
value = [:expression, value, { escaped: escaped }]
else
Logger.error :parse, @code, @i, @j, :shorthand
end
# IDs are unique, the rest of the attributes turn into arrays in
# order to allow multiple values or identifiers
add_attribute(atts, key, value)
end
atts
end | [
"def",
"shorthand_attributes",
"(",
"atts",
"=",
"{",
"}",
")",
"while",
"(",
"key",
"=",
"accept",
":shorthand",
")",
"key",
"=",
"Settings",
"::",
"SHORTHAND",
"[",
"key",
".",
"to_sym",
"]",
"# Check whether the value is escaped or unescaped",
"escaped",
"=",
"accept",
"(",
":unescaped_value",
")",
"?",
"false",
":",
"true",
"# Get the attribute value and process it",
"if",
"(",
"value",
"=",
"accept",
"(",
":shorthand_node",
")",
")",
"value",
"=",
"[",
":expression",
",",
"value",
".",
"inspect",
",",
"{",
"escaped",
":",
"escaped",
"}",
"]",
"elsif",
"(",
"value",
"=",
"accept",
"(",
":exp_string",
")",
")",
"value",
"=",
"[",
":expression",
",",
"value",
",",
"{",
"escaped",
":",
"escaped",
"}",
"]",
"elsif",
"(",
"value",
"=",
"paranthesis",
")",
"value",
"=",
"[",
":expression",
",",
"value",
",",
"{",
"escaped",
":",
"escaped",
"}",
"]",
"else",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":shorthand",
"end",
"# IDs are unique, the rest of the attributes turn into arrays in",
"# order to allow multiple values or identifiers",
"add_attribute",
"(",
"atts",
",",
"key",
",",
"value",
")",
"end",
"atts",
"end"
] | Accept node shorthand attributes. Each shorthand attribute is directly
mapped to an attribute key
@param atts [Hash] Node attributes | [
"Accept",
"node",
"shorthand",
"attributes",
".",
"Each",
"shorthand",
"attribute",
"is",
"directly",
"mapped",
"to",
"an",
"attribute",
"key"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/node.rb#L164-L188 |
2,916 | opulent/opulent | lib/opulent/parser/node.rb | Opulent.Parser.attributes | def attributes(atts = {}, for_definition = false)
wrapped_attributes atts, for_definition
attributes_assignments atts, false, for_definition
atts
end | ruby | def attributes(atts = {}, for_definition = false)
wrapped_attributes atts, for_definition
attributes_assignments atts, false, for_definition
atts
end | [
"def",
"attributes",
"(",
"atts",
"=",
"{",
"}",
",",
"for_definition",
"=",
"false",
")",
"wrapped_attributes",
"atts",
",",
"for_definition",
"attributes_assignments",
"atts",
",",
"false",
",",
"for_definition",
"atts",
"end"
] | Get element attributes
@param atts [Hash] Accumulator for node attributes
@param for_definition [Boolean] Set default value in wrapped to nil | [
"Get",
"element",
"attributes"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/node.rb#L195-L199 |
2,917 | opulent/opulent | lib/opulent/parser/node.rb | Opulent.Parser.wrapped_attributes | def wrapped_attributes(list = {}, for_definition = false)
return unless (bracket = accept :brackets)
accept_newline
attributes_assignments list, true, for_definition
accept_newline
accept_stripped bracket.to_sym, :*
list
end | ruby | def wrapped_attributes(list = {}, for_definition = false)
return unless (bracket = accept :brackets)
accept_newline
attributes_assignments list, true, for_definition
accept_newline
accept_stripped bracket.to_sym, :*
list
end | [
"def",
"wrapped_attributes",
"(",
"list",
"=",
"{",
"}",
",",
"for_definition",
"=",
"false",
")",
"return",
"unless",
"(",
"bracket",
"=",
"accept",
":brackets",
")",
"accept_newline",
"attributes_assignments",
"list",
",",
"true",
",",
"for_definition",
"accept_newline",
"accept_stripped",
"bracket",
".",
"to_sym",
",",
":*",
"list",
"end"
] | Check if we match node attributes
[ assignments ]
@param as_parameters [Boolean] Accept or reject identifier nodes | [
"Check",
"if",
"we",
"match",
"node",
"attributes"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/node.rb#L207-L217 |
2,918 | opulent/opulent | lib/opulent/parser/node.rb | Opulent.Parser.attributes_assignments | def attributes_assignments(list, wrapped = true, for_definition = false)
if wrapped && lookahead(:exp_identifier_stripped_lookahead).nil? ||
!wrapped && lookahead(:assignment_lookahead).nil?
return list
end
return unless (argument = accept_stripped :node)
argument = argument.to_sym
if accept_stripped :assignment
# Check if we have an attribute escape or not
escaped = if accept :assignment_unescaped
false
else
true
end
# Get the argument value if we have an assignment
if (value = expression(false, wrapped))
value[@options][:escaped] = escaped
# IDs are unique, the rest of the attributes turn into arrays in
# order to allow multiple values or identifiers
add_attribute(list, argument, value)
else
Logger.error :parse, @code, @i, @j, :assignments_colon
end
else
unless list[argument]
default_value = for_definition ? 'nil' : 'true'
list[argument] = [:expression, default_value, { escaped: false }]
end
end
# If our attributes are wrapped, we allow method calls without
# paranthesis, ruby style, therefore we need a terminator to signify
# the expression end. If they are not wrapped (inline), we require
# paranthesis and allow inline calls
if wrapped
# Accept optional comma between attributes
accept_stripped :assignment_terminator
# Lookahead for attributes on the current line and the next one
if lookahead(:exp_identifier_stripped_lookahead)
attributes_assignments list, wrapped, for_definition
elsif lookahead_next_line(:exp_identifier_stripped_lookahead)
accept_newline
attributes_assignments list, wrapped, for_definition
end
elsif !wrapped && lookahead(:assignment_lookahead)
attributes_assignments list, wrapped, for_definition
end
list
end | ruby | def attributes_assignments(list, wrapped = true, for_definition = false)
if wrapped && lookahead(:exp_identifier_stripped_lookahead).nil? ||
!wrapped && lookahead(:assignment_lookahead).nil?
return list
end
return unless (argument = accept_stripped :node)
argument = argument.to_sym
if accept_stripped :assignment
# Check if we have an attribute escape or not
escaped = if accept :assignment_unescaped
false
else
true
end
# Get the argument value if we have an assignment
if (value = expression(false, wrapped))
value[@options][:escaped] = escaped
# IDs are unique, the rest of the attributes turn into arrays in
# order to allow multiple values or identifiers
add_attribute(list, argument, value)
else
Logger.error :parse, @code, @i, @j, :assignments_colon
end
else
unless list[argument]
default_value = for_definition ? 'nil' : 'true'
list[argument] = [:expression, default_value, { escaped: false }]
end
end
# If our attributes are wrapped, we allow method calls without
# paranthesis, ruby style, therefore we need a terminator to signify
# the expression end. If they are not wrapped (inline), we require
# paranthesis and allow inline calls
if wrapped
# Accept optional comma between attributes
accept_stripped :assignment_terminator
# Lookahead for attributes on the current line and the next one
if lookahead(:exp_identifier_stripped_lookahead)
attributes_assignments list, wrapped, for_definition
elsif lookahead_next_line(:exp_identifier_stripped_lookahead)
accept_newline
attributes_assignments list, wrapped, for_definition
end
elsif !wrapped && lookahead(:assignment_lookahead)
attributes_assignments list, wrapped, for_definition
end
list
end | [
"def",
"attributes_assignments",
"(",
"list",
",",
"wrapped",
"=",
"true",
",",
"for_definition",
"=",
"false",
")",
"if",
"wrapped",
"&&",
"lookahead",
"(",
":exp_identifier_stripped_lookahead",
")",
".",
"nil?",
"||",
"!",
"wrapped",
"&&",
"lookahead",
"(",
":assignment_lookahead",
")",
".",
"nil?",
"return",
"list",
"end",
"return",
"unless",
"(",
"argument",
"=",
"accept_stripped",
":node",
")",
"argument",
"=",
"argument",
".",
"to_sym",
"if",
"accept_stripped",
":assignment",
"# Check if we have an attribute escape or not",
"escaped",
"=",
"if",
"accept",
":assignment_unescaped",
"false",
"else",
"true",
"end",
"# Get the argument value if we have an assignment",
"if",
"(",
"value",
"=",
"expression",
"(",
"false",
",",
"wrapped",
")",
")",
"value",
"[",
"@options",
"]",
"[",
":escaped",
"]",
"=",
"escaped",
"# IDs are unique, the rest of the attributes turn into arrays in",
"# order to allow multiple values or identifiers",
"add_attribute",
"(",
"list",
",",
"argument",
",",
"value",
")",
"else",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":assignments_colon",
"end",
"else",
"unless",
"list",
"[",
"argument",
"]",
"default_value",
"=",
"for_definition",
"?",
"'nil'",
":",
"'true'",
"list",
"[",
"argument",
"]",
"=",
"[",
":expression",
",",
"default_value",
",",
"{",
"escaped",
":",
"false",
"}",
"]",
"end",
"end",
"# If our attributes are wrapped, we allow method calls without",
"# paranthesis, ruby style, therefore we need a terminator to signify",
"# the expression end. If they are not wrapped (inline), we require",
"# paranthesis and allow inline calls",
"if",
"wrapped",
"# Accept optional comma between attributes",
"accept_stripped",
":assignment_terminator",
"# Lookahead for attributes on the current line and the next one",
"if",
"lookahead",
"(",
":exp_identifier_stripped_lookahead",
")",
"attributes_assignments",
"list",
",",
"wrapped",
",",
"for_definition",
"elsif",
"lookahead_next_line",
"(",
":exp_identifier_stripped_lookahead",
")",
"accept_newline",
"attributes_assignments",
"list",
",",
"wrapped",
",",
"for_definition",
"end",
"elsif",
"!",
"wrapped",
"&&",
"lookahead",
"(",
":assignment_lookahead",
")",
"attributes_assignments",
"list",
",",
"wrapped",
",",
"for_definition",
"end",
"list",
"end"
] | Get all attribute assignments as key=value pairs or standalone keys
[ assignments ]
@param list [Hash] Parent to which we append nodes
@param as_parameters [Boolean] Accept or reject identifier nodes | [
"Get",
"all",
"attribute",
"assignments",
"as",
"key",
"=",
"value",
"pairs",
"or",
"standalone",
"keys"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/node.rb#L226-L281 |
2,919 | opulent/opulent | lib/opulent/parser/node.rb | Opulent.Parser.extend_attributes | def extend_attributes
return unless accept :extend_attributes
unescaped = accept :unescaped_value
extension = expression(false, false, false)
extension[@options][:escaped] = !unescaped
extension
end | ruby | def extend_attributes
return unless accept :extend_attributes
unescaped = accept :unescaped_value
extension = expression(false, false, false)
extension[@options][:escaped] = !unescaped
extension
end | [
"def",
"extend_attributes",
"return",
"unless",
"accept",
":extend_attributes",
"unescaped",
"=",
"accept",
":unescaped_value",
"extension",
"=",
"expression",
"(",
"false",
",",
"false",
",",
"false",
")",
"extension",
"[",
"@options",
"]",
"[",
":escaped",
"]",
"=",
"!",
"unescaped",
"extension",
"end"
] | Extend node attributes with hash from
+value
+{hash: "value"}
+(paranthesis) | [
"Extend",
"node",
"attributes",
"with",
"hash",
"from"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/node.rb#L289-L297 |
2,920 | opulent/opulent | lib/opulent/parser/root.rb | Opulent.Parser.root | def root(parent = @root, min_indent = -1)
while (@line = @code[(@i += 1)])
# Reset character position cursor
@j = 0
# Skip to next iteration if we have a blank line
next if @line =~ /\A\s*\Z/
# Reset the line offset
@offset = 0
# Parse the current line by trying to match each node type towards it
# Add current indentation to the indent stack
indent = accept(:indent).size
# Stop using the current parent as root if it does not match the
# minimum indentation includements
unless min_indent < indent
@i -= 1
break
end
# If last include path had a greater indentation, pop the last file path
@file.pop if @file[-1][1] >= indent
# Try the main Opulent node types and process each one of them using
# their matching evaluation procedure
current_node = node(parent, indent) ||
text(parent, indent) ||
comment(parent, indent) ||
define(parent, indent) ||
control(parent, indent) ||
evaluate(parent, indent) ||
filter(parent, indent) ||
block_yield(parent, indent) ||
include_file(parent, indent) ||
html_text(parent, indent) ||
doctype(parent, indent)
# Throw an error if we couldn't find any valid node
unless current_node
Logger.error :parse, @code, @i, @j, :unknown_node_type
end
end
parent
end | ruby | def root(parent = @root, min_indent = -1)
while (@line = @code[(@i += 1)])
# Reset character position cursor
@j = 0
# Skip to next iteration if we have a blank line
next if @line =~ /\A\s*\Z/
# Reset the line offset
@offset = 0
# Parse the current line by trying to match each node type towards it
# Add current indentation to the indent stack
indent = accept(:indent).size
# Stop using the current parent as root if it does not match the
# minimum indentation includements
unless min_indent < indent
@i -= 1
break
end
# If last include path had a greater indentation, pop the last file path
@file.pop if @file[-1][1] >= indent
# Try the main Opulent node types and process each one of them using
# their matching evaluation procedure
current_node = node(parent, indent) ||
text(parent, indent) ||
comment(parent, indent) ||
define(parent, indent) ||
control(parent, indent) ||
evaluate(parent, indent) ||
filter(parent, indent) ||
block_yield(parent, indent) ||
include_file(parent, indent) ||
html_text(parent, indent) ||
doctype(parent, indent)
# Throw an error if we couldn't find any valid node
unless current_node
Logger.error :parse, @code, @i, @j, :unknown_node_type
end
end
parent
end | [
"def",
"root",
"(",
"parent",
"=",
"@root",
",",
"min_indent",
"=",
"-",
"1",
")",
"while",
"(",
"@line",
"=",
"@code",
"[",
"(",
"@i",
"+=",
"1",
")",
"]",
")",
"# Reset character position cursor",
"@j",
"=",
"0",
"# Skip to next iteration if we have a blank line",
"next",
"if",
"@line",
"=~",
"/",
"\\A",
"\\s",
"\\Z",
"/",
"# Reset the line offset",
"@offset",
"=",
"0",
"# Parse the current line by trying to match each node type towards it",
"# Add current indentation to the indent stack",
"indent",
"=",
"accept",
"(",
":indent",
")",
".",
"size",
"# Stop using the current parent as root if it does not match the",
"# minimum indentation includements",
"unless",
"min_indent",
"<",
"indent",
"@i",
"-=",
"1",
"break",
"end",
"# If last include path had a greater indentation, pop the last file path",
"@file",
".",
"pop",
"if",
"@file",
"[",
"-",
"1",
"]",
"[",
"1",
"]",
">=",
"indent",
"# Try the main Opulent node types and process each one of them using",
"# their matching evaluation procedure",
"current_node",
"=",
"node",
"(",
"parent",
",",
"indent",
")",
"||",
"text",
"(",
"parent",
",",
"indent",
")",
"||",
"comment",
"(",
"parent",
",",
"indent",
")",
"||",
"define",
"(",
"parent",
",",
"indent",
")",
"||",
"control",
"(",
"parent",
",",
"indent",
")",
"||",
"evaluate",
"(",
"parent",
",",
"indent",
")",
"||",
"filter",
"(",
"parent",
",",
"indent",
")",
"||",
"block_yield",
"(",
"parent",
",",
"indent",
")",
"||",
"include_file",
"(",
"parent",
",",
"indent",
")",
"||",
"html_text",
"(",
"parent",
",",
"indent",
")",
"||",
"doctype",
"(",
"parent",
",",
"indent",
")",
"# Throw an error if we couldn't find any valid node",
"unless",
"current_node",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":unknown_node_type",
"end",
"end",
"parent",
"end"
] | Analyze the input code and check for matching tokens.
In case no match was found, throw an exception.
In special cases, modify the token hash.
@param parent [Array] Parent node to which we append to | [
"Analyze",
"the",
"input",
"code",
"and",
"check",
"for",
"matching",
"tokens",
".",
"In",
"case",
"no",
"match",
"was",
"found",
"throw",
"an",
"exception",
".",
"In",
"special",
"cases",
"modify",
"the",
"token",
"hash",
"."
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/root.rb#L11-L57 |
2,921 | opulent/opulent | lib/opulent/compiler/define.rb | Opulent.Compiler.define | def define(node)
# Write out def method_name
definition = "def _opulent_definition_#{node[@value].to_s.tr '-', '_'}"
# Node attributes
parameters = []
node[@options][:parameters].each do |key, value|
parameters << "#{key} = #{value[@value]}"
end
parameters << 'attributes = {}'
parameters << 'indent'
parameters << '&block'
definition += '(' + parameters.join(', ') + ')'
buffer_eval 'instance_eval do'
buffer_eval definition
@in_definition = true
node[@children].each do |child|
root child, 0
end
@in_definition = false
buffer_eval 'end'
buffer_eval 'end'
end | ruby | def define(node)
# Write out def method_name
definition = "def _opulent_definition_#{node[@value].to_s.tr '-', '_'}"
# Node attributes
parameters = []
node[@options][:parameters].each do |key, value|
parameters << "#{key} = #{value[@value]}"
end
parameters << 'attributes = {}'
parameters << 'indent'
parameters << '&block'
definition += '(' + parameters.join(', ') + ')'
buffer_eval 'instance_eval do'
buffer_eval definition
@in_definition = true
node[@children].each do |child|
root child, 0
end
@in_definition = false
buffer_eval 'end'
buffer_eval 'end'
end | [
"def",
"define",
"(",
"node",
")",
"# Write out def method_name",
"definition",
"=",
"\"def _opulent_definition_#{node[@value].to_s.tr '-', '_'}\"",
"# Node attributes",
"parameters",
"=",
"[",
"]",
"node",
"[",
"@options",
"]",
"[",
":parameters",
"]",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"parameters",
"<<",
"\"#{key} = #{value[@value]}\"",
"end",
"parameters",
"<<",
"'attributes = {}'",
"parameters",
"<<",
"'indent'",
"parameters",
"<<",
"'&block'",
"definition",
"+=",
"'('",
"+",
"parameters",
".",
"join",
"(",
"', '",
")",
"+",
"')'",
"buffer_eval",
"'instance_eval do'",
"buffer_eval",
"definition",
"@in_definition",
"=",
"true",
"node",
"[",
"@children",
"]",
".",
"each",
"do",
"|",
"child",
"|",
"root",
"child",
",",
"0",
"end",
"@in_definition",
"=",
"false",
"buffer_eval",
"'end'",
"buffer_eval",
"'end'",
"end"
] | Write out definition node using ruby def
@param node [Node] Current node data with options | [
"Write",
"out",
"definition",
"node",
"using",
"ruby",
"def"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/compiler/define.rb#L9-L34 |
2,922 | beatrichartz/configurations | lib/configurations/arbitrary.rb | Configurations.Arbitrary.respond_to_missing? | def respond_to_missing?(method, include_private = false)
__respond_to_writer?(method) ||
__respond_to_method_for_read?(method, *args, &block) ||
__respond_to_method_for_write?(method) ||
super
end | ruby | def respond_to_missing?(method, include_private = false)
__respond_to_writer?(method) ||
__respond_to_method_for_read?(method, *args, &block) ||
__respond_to_method_for_write?(method) ||
super
end | [
"def",
"respond_to_missing?",
"(",
"method",
",",
"include_private",
"=",
"false",
")",
"__respond_to_writer?",
"(",
"method",
")",
"||",
"__respond_to_method_for_read?",
"(",
"method",
",",
"args",
",",
"block",
")",
"||",
"__respond_to_method_for_write?",
"(",
"method",
")",
"||",
"super",
"end"
] | Respond to missing according to the method_missing implementation | [
"Respond",
"to",
"missing",
"according",
"to",
"the",
"method_missing",
"implementation"
] | bd8ef480ca831e29b821ffc9ebeaed4ef46a9db2 | https://github.com/beatrichartz/configurations/blob/bd8ef480ca831e29b821ffc9ebeaed4ef46a9db2/lib/configurations/arbitrary.rb#L43-L48 |
2,923 | opulent/opulent | lib/opulent/parser.rb | Opulent.Parser.apply_definitions | def apply_definitions(node)
# Apply definition check to all of the node's children
process_definitions = proc do |children|
children.each do |child|
# Check if we have a definition
is_definition = if child[@value] == @current_def
child[@options][:recursive]
else
@definitions.key?(child[@value])
end
# Set child as a defined node
child[@type] = :def if is_definition
# Recursively apply definitions to child nodes
apply_definitions child if child[@children]
end
end
# Apply definitions to each case of the control node
if [:if, :unless, :case].include? node[@type]
node[@children].each do |array|
process_definitions[array]
end
# Apply definition to all of the node's children
else
process_definitions[node[@children]]
end
end | ruby | def apply_definitions(node)
# Apply definition check to all of the node's children
process_definitions = proc do |children|
children.each do |child|
# Check if we have a definition
is_definition = if child[@value] == @current_def
child[@options][:recursive]
else
@definitions.key?(child[@value])
end
# Set child as a defined node
child[@type] = :def if is_definition
# Recursively apply definitions to child nodes
apply_definitions child if child[@children]
end
end
# Apply definitions to each case of the control node
if [:if, :unless, :case].include? node[@type]
node[@children].each do |array|
process_definitions[array]
end
# Apply definition to all of the node's children
else
process_definitions[node[@children]]
end
end | [
"def",
"apply_definitions",
"(",
"node",
")",
"# Apply definition check to all of the node's children",
"process_definitions",
"=",
"proc",
"do",
"|",
"children",
"|",
"children",
".",
"each",
"do",
"|",
"child",
"|",
"# Check if we have a definition",
"is_definition",
"=",
"if",
"child",
"[",
"@value",
"]",
"==",
"@current_def",
"child",
"[",
"@options",
"]",
"[",
":recursive",
"]",
"else",
"@definitions",
".",
"key?",
"(",
"child",
"[",
"@value",
"]",
")",
"end",
"# Set child as a defined node",
"child",
"[",
"@type",
"]",
"=",
":def",
"if",
"is_definition",
"# Recursively apply definitions to child nodes",
"apply_definitions",
"child",
"if",
"child",
"[",
"@children",
"]",
"end",
"end",
"# Apply definitions to each case of the control node",
"if",
"[",
":if",
",",
":unless",
",",
":case",
"]",
".",
"include?",
"node",
"[",
"@type",
"]",
"node",
"[",
"@children",
"]",
".",
"each",
"do",
"|",
"array",
"|",
"process_definitions",
"[",
"array",
"]",
"end",
"# Apply definition to all of the node's children",
"else",
"process_definitions",
"[",
"node",
"[",
"@children",
"]",
"]",
"end",
"end"
] | Set each node as a defined node if a definition exists with the given
node name, unless we're inside a definition with the same name as the node
because we want to avoid recursion.
@param node [Node] Input Node to checked for existence of definitions | [
"Set",
"each",
"node",
"as",
"a",
"defined",
"node",
"if",
"a",
"definition",
"exists",
"with",
"the",
"given",
"node",
"name",
"unless",
"we",
"re",
"inside",
"a",
"definition",
"with",
"the",
"same",
"name",
"as",
"the",
"node",
"because",
"we",
"want",
"to",
"avoid",
"recursion",
"."
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser.rb#L93-L121 |
2,924 | opulent/opulent | lib/opulent/parser.rb | Opulent.Parser.accept | def accept(token, required = false, strip = false)
# Consume leading whitespace if we want to ignore it
accept :whitespace if strip
# We reached the end of the parsing process and there are no more lines
# left to parse
return nil unless @line
# Match the token to the current line. If we find it, return the match.
# If it is required, signal an :expected error
if (match = @line[@offset..-1].match(Tokens[token]))
# Advance current offset with match length
@offset += match[0].size
@j += match[0].size
return match[0]
elsif required
Logger.error :parse, @code, @i, @j, :expected, token
end
end | ruby | def accept(token, required = false, strip = false)
# Consume leading whitespace if we want to ignore it
accept :whitespace if strip
# We reached the end of the parsing process and there are no more lines
# left to parse
return nil unless @line
# Match the token to the current line. If we find it, return the match.
# If it is required, signal an :expected error
if (match = @line[@offset..-1].match(Tokens[token]))
# Advance current offset with match length
@offset += match[0].size
@j += match[0].size
return match[0]
elsif required
Logger.error :parse, @code, @i, @j, :expected, token
end
end | [
"def",
"accept",
"(",
"token",
",",
"required",
"=",
"false",
",",
"strip",
"=",
"false",
")",
"# Consume leading whitespace if we want to ignore it",
"accept",
":whitespace",
"if",
"strip",
"# We reached the end of the parsing process and there are no more lines",
"# left to parse",
"return",
"nil",
"unless",
"@line",
"# Match the token to the current line. If we find it, return the match.",
"# If it is required, signal an :expected error",
"if",
"(",
"match",
"=",
"@line",
"[",
"@offset",
"..",
"-",
"1",
"]",
".",
"match",
"(",
"Tokens",
"[",
"token",
"]",
")",
")",
"# Advance current offset with match length",
"@offset",
"+=",
"match",
"[",
"0",
"]",
".",
"size",
"@j",
"+=",
"match",
"[",
"0",
"]",
".",
"size",
"return",
"match",
"[",
"0",
"]",
"elsif",
"required",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":expected",
",",
"token",
"end",
"end"
] | Check and accept or reject a given token as long as we have tokens
remaining. Shift the code with the match length plus any extra character
count around the capture group
@param token [RegEx] Token to be accepted by the parser
@param required [Boolean] Expect the given token syntax
@param strip [Boolean] Left strip the current code to remove whitespace | [
"Check",
"and",
"accept",
"or",
"reject",
"a",
"given",
"token",
"as",
"long",
"as",
"we",
"have",
"tokens",
"remaining",
".",
"Shift",
"the",
"code",
"with",
"the",
"match",
"length",
"plus",
"any",
"extra",
"character",
"count",
"around",
"the",
"capture",
"group"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser.rb#L131-L150 |
2,925 | opulent/opulent | lib/opulent/parser.rb | Opulent.Parser.indent_lines | def indent_lines(text, indent)
text ||= ''
text.lines.map { |line| indent + line }.join
end | ruby | def indent_lines(text, indent)
text ||= ''
text.lines.map { |line| indent + line }.join
end | [
"def",
"indent_lines",
"(",
"text",
",",
"indent",
")",
"text",
"||=",
"''",
"text",
".",
"lines",
".",
"map",
"{",
"|",
"line",
"|",
"indent",
"+",
"line",
"}",
".",
"join",
"end"
] | Indent all lines of the input text using give indentation
@param text [String] Input text to be indented
@param indent [String] Indentation string to be appended | [
"Indent",
"all",
"lines",
"of",
"the",
"input",
"text",
"using",
"give",
"indentation"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser.rb#L210-L213 |
2,926 | redbooth/redbooth-ruby | lib/redbooth-ruby/client.rb | RedboothRuby.Client.perform! | def perform!(resource_name, action, options = {})
ClientOperations::Perform.new(resource_name, action, session, options).perform!
end | ruby | def perform!(resource_name, action, options = {})
ClientOperations::Perform.new(resource_name, action, session, options).perform!
end | [
"def",
"perform!",
"(",
"resource_name",
",",
"action",
",",
"options",
"=",
"{",
"}",
")",
"ClientOperations",
"::",
"Perform",
".",
"new",
"(",
"resource_name",
",",
"action",
",",
"session",
",",
"options",
")",
".",
"perform!",
"end"
] | Executes block with the access token
@param [String||Symbol] resource_name name of the resource to execute over
@param [String||Symbol] action name of the action to execute over
@param [Hash] options for the execution
@return the execution return or nil | [
"Executes",
"block",
"with",
"the",
"access",
"token"
] | fb6bc228a9346d4db476032f0df16c9588fdfbe1 | https://github.com/redbooth/redbooth-ruby/blob/fb6bc228a9346d4db476032f0df16c9588fdfbe1/lib/redbooth-ruby/client.rb#L55-L57 |
2,927 | Yellowen/Faalis | app/models/faalis/concerns/user/auth_definitions.rb | Faalis.Concerns::User::AuthDefinitions.password_required? | def password_required?
# TODO: nil? is not suitable for here we should use empty? or blink?
if Devise.omniauth_configs.any?
return (provider.nil? || password.nil?) && super
else
password.nil? && super
end
end | ruby | def password_required?
# TODO: nil? is not suitable for here we should use empty? or blink?
if Devise.omniauth_configs.any?
return (provider.nil? || password.nil?) && super
else
password.nil? && super
end
end | [
"def",
"password_required?",
"# TODO: nil? is not suitable for here we should use empty? or blink?",
"if",
"Devise",
".",
"omniauth_configs",
".",
"any?",
"return",
"(",
"provider",
".",
"nil?",
"||",
"password",
".",
"nil?",
")",
"&&",
"super",
"else",
"password",
".",
"nil?",
"&&",
"super",
"end",
"end"
] | Omniauth users does not need password | [
"Omniauth",
"users",
"does",
"not",
"need",
"password"
] | d12abdb8559dabbf6b2044e3ba437038527039b2 | https://github.com/Yellowen/Faalis/blob/d12abdb8559dabbf6b2044e3ba437038527039b2/app/models/faalis/concerns/user/auth_definitions.rb#L51-L58 |
2,928 | redbooth/redbooth-ruby | lib/redbooth-ruby/file.rb | RedboothRuby.File.download | def download(style='original', path=nil)
options = { session: session }
options[:download_path] = path unless path.nil?
request = RedboothRuby.request(:download, nil, "files/#{id}/download/#{style}/#{name}", {}, options)
request.body
end | ruby | def download(style='original', path=nil)
options = { session: session }
options[:download_path] = path unless path.nil?
request = RedboothRuby.request(:download, nil, "files/#{id}/download/#{style}/#{name}", {}, options)
request.body
end | [
"def",
"download",
"(",
"style",
"=",
"'original'",
",",
"path",
"=",
"nil",
")",
"options",
"=",
"{",
"session",
":",
"session",
"}",
"options",
"[",
":download_path",
"]",
"=",
"path",
"unless",
"path",
".",
"nil?",
"request",
"=",
"RedboothRuby",
".",
"request",
"(",
":download",
",",
"nil",
",",
"\"files/#{id}/download/#{style}/#{name}\"",
",",
"{",
"}",
",",
"options",
")",
"request",
".",
"body",
"end"
] | Returns a blop with the file data
@param [String] style The style to use
@param [String] path The path to save the file to
@return [String] the object metadata | [
"Returns",
"a",
"blop",
"with",
"the",
"file",
"data"
] | fb6bc228a9346d4db476032f0df16c9588fdfbe1 | https://github.com/redbooth/redbooth-ruby/blob/fb6bc228a9346d4db476032f0df16c9588fdfbe1/lib/redbooth-ruby/file.rb#L32-L37 |
2,929 | opulent/opulent | lib/opulent/engine.rb | Opulent.Engine.render | def render(scope = Object.new, locals = {}, &block)
# Get opulent buffer value
if scope.instance_variable_defined?(:@_opulent_buffer)
initial_buffer = scope.instance_variable_get(:@_opulent_buffer)
else
initial_buffer = []
end
# If a layout is set, get the specific layout, otherwise, set the default
# one. If a layout is set to false, the page will be render as it is.
if scope.is_a? binding.class
scope_object = eval 'self', scope
scope = scope_object.instance_eval { binding } if block_given?
else
scope_object = scope
scope = scope_object.instance_eval { binding }
end
# Set input local variables in current scope
if scope.respond_to? :local_variable_set
locals.each do |key, value|
scope.local_variable_set key, value
end
else
locals.each do |key, value|
eval("#{key} = nil; lambda {|v| #{key} = v}", scope).call(value)
end
end
# Evaluate the template in the given scope (context)
begin
eval @src, scope
rescue ::SyntaxError => e
raise SyntaxError, e.message
ensure
# Get rid of the current buffer
scope_object.instance_variable_set :@_opulent_buffer, initial_buffer
end
end | ruby | def render(scope = Object.new, locals = {}, &block)
# Get opulent buffer value
if scope.instance_variable_defined?(:@_opulent_buffer)
initial_buffer = scope.instance_variable_get(:@_opulent_buffer)
else
initial_buffer = []
end
# If a layout is set, get the specific layout, otherwise, set the default
# one. If a layout is set to false, the page will be render as it is.
if scope.is_a? binding.class
scope_object = eval 'self', scope
scope = scope_object.instance_eval { binding } if block_given?
else
scope_object = scope
scope = scope_object.instance_eval { binding }
end
# Set input local variables in current scope
if scope.respond_to? :local_variable_set
locals.each do |key, value|
scope.local_variable_set key, value
end
else
locals.each do |key, value|
eval("#{key} = nil; lambda {|v| #{key} = v}", scope).call(value)
end
end
# Evaluate the template in the given scope (context)
begin
eval @src, scope
rescue ::SyntaxError => e
raise SyntaxError, e.message
ensure
# Get rid of the current buffer
scope_object.instance_variable_set :@_opulent_buffer, initial_buffer
end
end | [
"def",
"render",
"(",
"scope",
"=",
"Object",
".",
"new",
",",
"locals",
"=",
"{",
"}",
",",
"&",
"block",
")",
"# Get opulent buffer value",
"if",
"scope",
".",
"instance_variable_defined?",
"(",
":@_opulent_buffer",
")",
"initial_buffer",
"=",
"scope",
".",
"instance_variable_get",
"(",
":@_opulent_buffer",
")",
"else",
"initial_buffer",
"=",
"[",
"]",
"end",
"# If a layout is set, get the specific layout, otherwise, set the default",
"# one. If a layout is set to false, the page will be render as it is.",
"if",
"scope",
".",
"is_a?",
"binding",
".",
"class",
"scope_object",
"=",
"eval",
"'self'",
",",
"scope",
"scope",
"=",
"scope_object",
".",
"instance_eval",
"{",
"binding",
"}",
"if",
"block_given?",
"else",
"scope_object",
"=",
"scope",
"scope",
"=",
"scope_object",
".",
"instance_eval",
"{",
"binding",
"}",
"end",
"# Set input local variables in current scope",
"if",
"scope",
".",
"respond_to?",
":local_variable_set",
"locals",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"scope",
".",
"local_variable_set",
"key",
",",
"value",
"end",
"else",
"locals",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"eval",
"(",
"\"#{key} = nil; lambda {|v| #{key} = v}\"",
",",
"scope",
")",
".",
"call",
"(",
"value",
")",
"end",
"end",
"# Evaluate the template in the given scope (context)",
"begin",
"eval",
"@src",
",",
"scope",
"rescue",
"::",
"SyntaxError",
"=>",
"e",
"raise",
"SyntaxError",
",",
"e",
".",
"message",
"ensure",
"# Get rid of the current buffer",
"scope_object",
".",
"instance_variable_set",
":@_opulent_buffer",
",",
"initial_buffer",
"end",
"end"
] | Update render settings
@param input [Symbol/String] Input code or file
@param settings [Hash] Opulent settings override
Avoid code duplication when layouting is set. When we have a layout, look
in layouts/application by default.
@param scope [Object] Template evaluation context
@param locals [Hash] Render call local variables
@param block [Proc] Processing environment data | [
"Update",
"render",
"settings"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/engine.rb#L50-L88 |
2,930 | opulent/opulent | lib/opulent/engine.rb | Opulent.Engine.read | def read(input)
if input.is_a? Symbol
@file = File.expand_path get_eval_file input
File.read @file
else
@file = File.expand_path __FILE__
input
end
end | ruby | def read(input)
if input.is_a? Symbol
@file = File.expand_path get_eval_file input
File.read @file
else
@file = File.expand_path __FILE__
input
end
end | [
"def",
"read",
"(",
"input",
")",
"if",
"input",
".",
"is_a?",
"Symbol",
"@file",
"=",
"File",
".",
"expand_path",
"get_eval_file",
"input",
"File",
".",
"read",
"@file",
"else",
"@file",
"=",
"File",
".",
"expand_path",
"__FILE__",
"input",
"end",
"end"
] | Read input as file or string input
@param input [Object] | [
"Read",
"input",
"as",
"file",
"or",
"string",
"input"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/engine.rb#L96-L104 |
2,931 | opulent/opulent | lib/opulent/engine.rb | Opulent.Engine.get_eval_file | def get_eval_file(input)
input = input.to_s
unless File.extname(input) == Settings::FILE_EXTENSION
input += Settings::FILE_EXTENSION
end
input
end | ruby | def get_eval_file(input)
input = input.to_s
unless File.extname(input) == Settings::FILE_EXTENSION
input += Settings::FILE_EXTENSION
end
input
end | [
"def",
"get_eval_file",
"(",
"input",
")",
"input",
"=",
"input",
".",
"to_s",
"unless",
"File",
".",
"extname",
"(",
"input",
")",
"==",
"Settings",
"::",
"FILE_EXTENSION",
"input",
"+=",
"Settings",
"::",
"FILE_EXTENSION",
"end",
"input",
"end"
] | Add .op extension to input file if it isn't already set.
@param input [Symbol] Input file | [
"Add",
".",
"op",
"extension",
"to",
"input",
"file",
"if",
"it",
"isn",
"t",
"already",
"set",
"."
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/engine.rb#L110-L116 |
2,932 | opulent/opulent | lib/opulent/compiler/buffer.rb | Opulent.Compiler.buffer_attributes_to_hash | def buffer_attributes_to_hash(attributes)
'{' + attributes.inject([]) do |extend_map, (key, attribute)|
extend_map << (
":\"#{key}\" => " + if key == :class
'[' + attribute.map do |exp|
exp[@value]
end.join(', ') + ']'
else
attribute[@value]
end
)
end.join(', ') + '}'
end | ruby | def buffer_attributes_to_hash(attributes)
'{' + attributes.inject([]) do |extend_map, (key, attribute)|
extend_map << (
":\"#{key}\" => " + if key == :class
'[' + attribute.map do |exp|
exp[@value]
end.join(', ') + ']'
else
attribute[@value]
end
)
end.join(', ') + '}'
end | [
"def",
"buffer_attributes_to_hash",
"(",
"attributes",
")",
"'{'",
"+",
"attributes",
".",
"inject",
"(",
"[",
"]",
")",
"do",
"|",
"extend_map",
",",
"(",
"key",
",",
"attribute",
")",
"|",
"extend_map",
"<<",
"(",
"\":\\\"#{key}\\\" => \"",
"+",
"if",
"key",
"==",
":class",
"'['",
"+",
"attribute",
".",
"map",
"do",
"|",
"exp",
"|",
"exp",
"[",
"@value",
"]",
"end",
".",
"join",
"(",
"', '",
")",
"+",
"']'",
"else",
"attribute",
"[",
"@value",
"]",
"end",
")",
"end",
".",
"join",
"(",
"', '",
")",
"+",
"'}'",
"end"
] | Turn call node attributes into a hash string
@param attributes [Array] Array of node attributes | [
"Turn",
"call",
"node",
"attributes",
"into",
"a",
"hash",
"string"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/compiler/buffer.rb#L88-L100 |
2,933 | opulent/opulent | lib/opulent/compiler/buffer.rb | Opulent.Compiler.buffer_attributes | def buffer_attributes(attributes, extension)
# Proc for setting class attribute extension, used as DRY closure
#
buffer_class_attribute_type_check = proc do |variable, escape = true|
class_variable = buffer_set_variable :local, variable
# Check if we need to add the class attribute
buffer_eval "unless #{class_variable} and true === #{class_variable}"
# Check if class attribute has array value
buffer_eval "if Array === #{class_variable}"
ruby_code = "#{class_variable}.join ' '"
if escape
buffer_escape ruby_code
else
buffer ruby_code
end
# Check if class attribute has hash value
buffer_eval "elsif Hash === #{class_variable}"
ruby_code = "#{class_variable}.to_a.join ' '"
if escape
buffer_escape ruby_code
else
buffer ruby_code
end
# Other values
buffer_eval 'else'
ruby_code = "#{class_variable}"
if escape
buffer_escape ruby_code
else
buffer ruby_code
end
# End cases
buffer_eval 'end'
# End
buffer_eval 'end'
end
# Handle class attributes by checking if they're simple, noninterpolated
# strings or not and extend them if needed
#
buffer_class_attribute = proc do |attribute|
if attribute[@value] =~ Tokens[:exp_string_match]
buffer_split_by_interpolation attribute[@value][1..-2],
attribute[@options][:escaped]
else
buffer_class_attribute_type_check[
attribute[@value],
attribute[@options][:escaped]
]
end
end
# If we have class attributes, process each one and check if we have an
# extension for them
if attributes[:class]
buffer_freeze " class=\""
# Process every class attribute
attributes[:class].each do |node_class|
buffer_class_attribute[node_class]
buffer_freeze ' '
end
# Remove trailing whitespace from the buffer
buffer_remove_last_character
# Check for extension with :class key
if extension
buffer_eval "if #{extension[:name]}.has_key? :class"
buffer_freeze ' '
buffer_class_attribute_type_check[
"#{extension[:name]}.delete(:class)"
]
buffer_eval 'end'
end
buffer_freeze '"'
elsif extension
# If we do not have class attributes but we do have an extension, try to
# see if the extension contains a class attribute
buffer_eval "if #{extension[:name]}.has_key? :class"
buffer_freeze " class=\""
buffer_class_attribute_type_check["#{extension[:name]}.delete(:class)"]
buffer_freeze '"'
buffer_eval 'end'
end
# Proc for setting class attribute extension, used as DRY closure
#
buffer_data_attribute_type_check = proc do |key, variable, escape = true, dynamic = false|
# Check if variable is set
buffer_eval "if #{variable}"
# @Array
buffer_eval "if Array === #{variable}"
dynamic ? buffer("\" #{key}=\\\"\"") : buffer_freeze(" #{key}=\"")
ruby_code = "#{variable}.join '_'"
if escape
buffer_escape ruby_code
else
buffer ruby_code
end
buffer_freeze '"'
# @Hash
buffer_eval "elsif Hash === #{variable}"
buffer_eval "#{variable}.each do |#{OPULENT_KEY}, #{OPULENT_VALUE}|"
# key-hashkey
dynamic ? buffer("\" #{key}-\"") : buffer_freeze(" #{key}-")
buffer "#{OPULENT_KEY}.to_s"
#="value"
buffer_freeze "=\""
escape ? buffer_escape(OPULENT_VALUE) : buffer(OPULENT_VALUE)
buffer_freeze '"'
buffer_eval 'end'
# @TrueClass
buffer_eval "elsif true === #{variable}"
dynamic ? buffer("\" #{key}\"") : buffer_freeze(" #{key}")
# @Object
buffer_eval 'else'
dynamic ? buffer("\" #{key}=\\\"\"") : buffer_freeze(" #{key}=\"")
escape ? buffer_escape("#{variable}") : buffer("#{variable}")
buffer_freeze '"'
# End Cases
buffer_eval 'end'
# End
buffer_eval 'end'
end
# Handle data (normal) attributes by checking if they're simple, noninterpolated
# strings and extend them if needed
#
buffer_data_attribute = proc do |key, attribute|
# When we have an extension for our attributes, check current key.
# If it exists, check it's type and generate everything dynamically
if extension
buffer_eval "if #{extension[:name]}.has_key? :\"#{key}\""
variable = buffer_set_variable :local,
"#{extension[:name]}" \
".delete(:\"#{key}\")"
buffer_data_attribute_type_check[
key,
variable,
attribute[@options][:escaped]
]
buffer_eval 'else'
end
# Check if the set attribute is a simple string. If it is, freeze it or
# escape it. Otherwise, evaluate and initialize the type check.
if attribute[@value] =~ Tokens[:exp_string_match]
buffer_freeze " #{key}=\""
buffer_split_by_interpolation attribute[@value][1..-2],
attribute[@options][:escaped]
buffer_freeze "\""
else
# Evaluate and type check
variable = buffer_set_variable :local, attribute[@value]
buffer_data_attribute_type_check[
key,
variable,
attribute[@options][:escaped]
]
end
# Extension end
buffer_eval 'end' if extension
end
# Process the remaining, non-class related attributes
attributes.each do |key, attribute|
next if key == :class
buffer_data_attribute[key, attribute]
end
# Process remaining extension keys if there are any
return unless extension
buffer_eval "#{extension[:name]}.each do " \
"|ext#{OPULENT_KEY}, ext#{OPULENT_VALUE}|"
buffer_data_attribute_type_check[
"\#{ext#{OPULENT_KEY}}",
"ext#{OPULENT_VALUE}",
extension[:escaped],
true
]
buffer_eval 'end'
end | ruby | def buffer_attributes(attributes, extension)
# Proc for setting class attribute extension, used as DRY closure
#
buffer_class_attribute_type_check = proc do |variable, escape = true|
class_variable = buffer_set_variable :local, variable
# Check if we need to add the class attribute
buffer_eval "unless #{class_variable} and true === #{class_variable}"
# Check if class attribute has array value
buffer_eval "if Array === #{class_variable}"
ruby_code = "#{class_variable}.join ' '"
if escape
buffer_escape ruby_code
else
buffer ruby_code
end
# Check if class attribute has hash value
buffer_eval "elsif Hash === #{class_variable}"
ruby_code = "#{class_variable}.to_a.join ' '"
if escape
buffer_escape ruby_code
else
buffer ruby_code
end
# Other values
buffer_eval 'else'
ruby_code = "#{class_variable}"
if escape
buffer_escape ruby_code
else
buffer ruby_code
end
# End cases
buffer_eval 'end'
# End
buffer_eval 'end'
end
# Handle class attributes by checking if they're simple, noninterpolated
# strings or not and extend them if needed
#
buffer_class_attribute = proc do |attribute|
if attribute[@value] =~ Tokens[:exp_string_match]
buffer_split_by_interpolation attribute[@value][1..-2],
attribute[@options][:escaped]
else
buffer_class_attribute_type_check[
attribute[@value],
attribute[@options][:escaped]
]
end
end
# If we have class attributes, process each one and check if we have an
# extension for them
if attributes[:class]
buffer_freeze " class=\""
# Process every class attribute
attributes[:class].each do |node_class|
buffer_class_attribute[node_class]
buffer_freeze ' '
end
# Remove trailing whitespace from the buffer
buffer_remove_last_character
# Check for extension with :class key
if extension
buffer_eval "if #{extension[:name]}.has_key? :class"
buffer_freeze ' '
buffer_class_attribute_type_check[
"#{extension[:name]}.delete(:class)"
]
buffer_eval 'end'
end
buffer_freeze '"'
elsif extension
# If we do not have class attributes but we do have an extension, try to
# see if the extension contains a class attribute
buffer_eval "if #{extension[:name]}.has_key? :class"
buffer_freeze " class=\""
buffer_class_attribute_type_check["#{extension[:name]}.delete(:class)"]
buffer_freeze '"'
buffer_eval 'end'
end
# Proc for setting class attribute extension, used as DRY closure
#
buffer_data_attribute_type_check = proc do |key, variable, escape = true, dynamic = false|
# Check if variable is set
buffer_eval "if #{variable}"
# @Array
buffer_eval "if Array === #{variable}"
dynamic ? buffer("\" #{key}=\\\"\"") : buffer_freeze(" #{key}=\"")
ruby_code = "#{variable}.join '_'"
if escape
buffer_escape ruby_code
else
buffer ruby_code
end
buffer_freeze '"'
# @Hash
buffer_eval "elsif Hash === #{variable}"
buffer_eval "#{variable}.each do |#{OPULENT_KEY}, #{OPULENT_VALUE}|"
# key-hashkey
dynamic ? buffer("\" #{key}-\"") : buffer_freeze(" #{key}-")
buffer "#{OPULENT_KEY}.to_s"
#="value"
buffer_freeze "=\""
escape ? buffer_escape(OPULENT_VALUE) : buffer(OPULENT_VALUE)
buffer_freeze '"'
buffer_eval 'end'
# @TrueClass
buffer_eval "elsif true === #{variable}"
dynamic ? buffer("\" #{key}\"") : buffer_freeze(" #{key}")
# @Object
buffer_eval 'else'
dynamic ? buffer("\" #{key}=\\\"\"") : buffer_freeze(" #{key}=\"")
escape ? buffer_escape("#{variable}") : buffer("#{variable}")
buffer_freeze '"'
# End Cases
buffer_eval 'end'
# End
buffer_eval 'end'
end
# Handle data (normal) attributes by checking if they're simple, noninterpolated
# strings and extend them if needed
#
buffer_data_attribute = proc do |key, attribute|
# When we have an extension for our attributes, check current key.
# If it exists, check it's type and generate everything dynamically
if extension
buffer_eval "if #{extension[:name]}.has_key? :\"#{key}\""
variable = buffer_set_variable :local,
"#{extension[:name]}" \
".delete(:\"#{key}\")"
buffer_data_attribute_type_check[
key,
variable,
attribute[@options][:escaped]
]
buffer_eval 'else'
end
# Check if the set attribute is a simple string. If it is, freeze it or
# escape it. Otherwise, evaluate and initialize the type check.
if attribute[@value] =~ Tokens[:exp_string_match]
buffer_freeze " #{key}=\""
buffer_split_by_interpolation attribute[@value][1..-2],
attribute[@options][:escaped]
buffer_freeze "\""
else
# Evaluate and type check
variable = buffer_set_variable :local, attribute[@value]
buffer_data_attribute_type_check[
key,
variable,
attribute[@options][:escaped]
]
end
# Extension end
buffer_eval 'end' if extension
end
# Process the remaining, non-class related attributes
attributes.each do |key, attribute|
next if key == :class
buffer_data_attribute[key, attribute]
end
# Process remaining extension keys if there are any
return unless extension
buffer_eval "#{extension[:name]}.each do " \
"|ext#{OPULENT_KEY}, ext#{OPULENT_VALUE}|"
buffer_data_attribute_type_check[
"\#{ext#{OPULENT_KEY}}",
"ext#{OPULENT_VALUE}",
extension[:escaped],
true
]
buffer_eval 'end'
end | [
"def",
"buffer_attributes",
"(",
"attributes",
",",
"extension",
")",
"# Proc for setting class attribute extension, used as DRY closure",
"#",
"buffer_class_attribute_type_check",
"=",
"proc",
"do",
"|",
"variable",
",",
"escape",
"=",
"true",
"|",
"class_variable",
"=",
"buffer_set_variable",
":local",
",",
"variable",
"# Check if we need to add the class attribute",
"buffer_eval",
"\"unless #{class_variable} and true === #{class_variable}\"",
"# Check if class attribute has array value",
"buffer_eval",
"\"if Array === #{class_variable}\"",
"ruby_code",
"=",
"\"#{class_variable}.join ' '\"",
"if",
"escape",
"buffer_escape",
"ruby_code",
"else",
"buffer",
"ruby_code",
"end",
"# Check if class attribute has hash value",
"buffer_eval",
"\"elsif Hash === #{class_variable}\"",
"ruby_code",
"=",
"\"#{class_variable}.to_a.join ' '\"",
"if",
"escape",
"buffer_escape",
"ruby_code",
"else",
"buffer",
"ruby_code",
"end",
"# Other values",
"buffer_eval",
"'else'",
"ruby_code",
"=",
"\"#{class_variable}\"",
"if",
"escape",
"buffer_escape",
"ruby_code",
"else",
"buffer",
"ruby_code",
"end",
"# End cases",
"buffer_eval",
"'end'",
"# End",
"buffer_eval",
"'end'",
"end",
"# Handle class attributes by checking if they're simple, noninterpolated",
"# strings or not and extend them if needed",
"#",
"buffer_class_attribute",
"=",
"proc",
"do",
"|",
"attribute",
"|",
"if",
"attribute",
"[",
"@value",
"]",
"=~",
"Tokens",
"[",
":exp_string_match",
"]",
"buffer_split_by_interpolation",
"attribute",
"[",
"@value",
"]",
"[",
"1",
"..",
"-",
"2",
"]",
",",
"attribute",
"[",
"@options",
"]",
"[",
":escaped",
"]",
"else",
"buffer_class_attribute_type_check",
"[",
"attribute",
"[",
"@value",
"]",
",",
"attribute",
"[",
"@options",
"]",
"[",
":escaped",
"]",
"]",
"end",
"end",
"# If we have class attributes, process each one and check if we have an",
"# extension for them",
"if",
"attributes",
"[",
":class",
"]",
"buffer_freeze",
"\" class=\\\"\"",
"# Process every class attribute",
"attributes",
"[",
":class",
"]",
".",
"each",
"do",
"|",
"node_class",
"|",
"buffer_class_attribute",
"[",
"node_class",
"]",
"buffer_freeze",
"' '",
"end",
"# Remove trailing whitespace from the buffer",
"buffer_remove_last_character",
"# Check for extension with :class key",
"if",
"extension",
"buffer_eval",
"\"if #{extension[:name]}.has_key? :class\"",
"buffer_freeze",
"' '",
"buffer_class_attribute_type_check",
"[",
"\"#{extension[:name]}.delete(:class)\"",
"]",
"buffer_eval",
"'end'",
"end",
"buffer_freeze",
"'\"'",
"elsif",
"extension",
"# If we do not have class attributes but we do have an extension, try to",
"# see if the extension contains a class attribute",
"buffer_eval",
"\"if #{extension[:name]}.has_key? :class\"",
"buffer_freeze",
"\" class=\\\"\"",
"buffer_class_attribute_type_check",
"[",
"\"#{extension[:name]}.delete(:class)\"",
"]",
"buffer_freeze",
"'\"'",
"buffer_eval",
"'end'",
"end",
"# Proc for setting class attribute extension, used as DRY closure",
"#",
"buffer_data_attribute_type_check",
"=",
"proc",
"do",
"|",
"key",
",",
"variable",
",",
"escape",
"=",
"true",
",",
"dynamic",
"=",
"false",
"|",
"# Check if variable is set",
"buffer_eval",
"\"if #{variable}\"",
"# @Array",
"buffer_eval",
"\"if Array === #{variable}\"",
"dynamic",
"?",
"buffer",
"(",
"\"\\\" #{key}=\\\\\\\"\\\"\"",
")",
":",
"buffer_freeze",
"(",
"\" #{key}=\\\"\"",
")",
"ruby_code",
"=",
"\"#{variable}.join '_'\"",
"if",
"escape",
"buffer_escape",
"ruby_code",
"else",
"buffer",
"ruby_code",
"end",
"buffer_freeze",
"'\"'",
"# @Hash",
"buffer_eval",
"\"elsif Hash === #{variable}\"",
"buffer_eval",
"\"#{variable}.each do |#{OPULENT_KEY}, #{OPULENT_VALUE}|\"",
"# key-hashkey",
"dynamic",
"?",
"buffer",
"(",
"\"\\\" #{key}-\\\"\"",
")",
":",
"buffer_freeze",
"(",
"\" #{key}-\"",
")",
"buffer",
"\"#{OPULENT_KEY}.to_s\"",
"#=\"value\"",
"buffer_freeze",
"\"=\\\"\"",
"escape",
"?",
"buffer_escape",
"(",
"OPULENT_VALUE",
")",
":",
"buffer",
"(",
"OPULENT_VALUE",
")",
"buffer_freeze",
"'\"'",
"buffer_eval",
"'end'",
"# @TrueClass",
"buffer_eval",
"\"elsif true === #{variable}\"",
"dynamic",
"?",
"buffer",
"(",
"\"\\\" #{key}\\\"\"",
")",
":",
"buffer_freeze",
"(",
"\" #{key}\"",
")",
"# @Object",
"buffer_eval",
"'else'",
"dynamic",
"?",
"buffer",
"(",
"\"\\\" #{key}=\\\\\\\"\\\"\"",
")",
":",
"buffer_freeze",
"(",
"\" #{key}=\\\"\"",
")",
"escape",
"?",
"buffer_escape",
"(",
"\"#{variable}\"",
")",
":",
"buffer",
"(",
"\"#{variable}\"",
")",
"buffer_freeze",
"'\"'",
"# End Cases",
"buffer_eval",
"'end'",
"# End",
"buffer_eval",
"'end'",
"end",
"# Handle data (normal) attributes by checking if they're simple, noninterpolated",
"# strings and extend them if needed",
"#",
"buffer_data_attribute",
"=",
"proc",
"do",
"|",
"key",
",",
"attribute",
"|",
"# When we have an extension for our attributes, check current key.",
"# If it exists, check it's type and generate everything dynamically",
"if",
"extension",
"buffer_eval",
"\"if #{extension[:name]}.has_key? :\\\"#{key}\\\"\"",
"variable",
"=",
"buffer_set_variable",
":local",
",",
"\"#{extension[:name]}\"",
"\".delete(:\\\"#{key}\\\")\"",
"buffer_data_attribute_type_check",
"[",
"key",
",",
"variable",
",",
"attribute",
"[",
"@options",
"]",
"[",
":escaped",
"]",
"]",
"buffer_eval",
"'else'",
"end",
"# Check if the set attribute is a simple string. If it is, freeze it or",
"# escape it. Otherwise, evaluate and initialize the type check.",
"if",
"attribute",
"[",
"@value",
"]",
"=~",
"Tokens",
"[",
":exp_string_match",
"]",
"buffer_freeze",
"\" #{key}=\\\"\"",
"buffer_split_by_interpolation",
"attribute",
"[",
"@value",
"]",
"[",
"1",
"..",
"-",
"2",
"]",
",",
"attribute",
"[",
"@options",
"]",
"[",
":escaped",
"]",
"buffer_freeze",
"\"\\\"\"",
"else",
"# Evaluate and type check",
"variable",
"=",
"buffer_set_variable",
":local",
",",
"attribute",
"[",
"@value",
"]",
"buffer_data_attribute_type_check",
"[",
"key",
",",
"variable",
",",
"attribute",
"[",
"@options",
"]",
"[",
":escaped",
"]",
"]",
"end",
"# Extension end",
"buffer_eval",
"'end'",
"if",
"extension",
"end",
"# Process the remaining, non-class related attributes",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"attribute",
"|",
"next",
"if",
"key",
"==",
":class",
"buffer_data_attribute",
"[",
"key",
",",
"attribute",
"]",
"end",
"# Process remaining extension keys if there are any",
"return",
"unless",
"extension",
"buffer_eval",
"\"#{extension[:name]}.each do \"",
"\"|ext#{OPULENT_KEY}, ext#{OPULENT_VALUE}|\"",
"buffer_data_attribute_type_check",
"[",
"\"\\#{ext#{OPULENT_KEY}}\"",
",",
"\"ext#{OPULENT_VALUE}\"",
",",
"extension",
"[",
":escaped",
"]",
",",
"true",
"]",
"buffer_eval",
"'end'",
"end"
] | Go through the node attributes and apply extension where needed
@param attributes [Array] Array of node attributes, from parser
@param extension [String] Extension identifier | [
"Go",
"through",
"the",
"node",
"attributes",
"and",
"apply",
"extension",
"where",
"needed"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/compiler/buffer.rb#L107-L307 |
2,934 | opulent/opulent | lib/opulent/compiler/buffer.rb | Opulent.Compiler.buffer_split_by_interpolation | def buffer_split_by_interpolation(string, escape = true)
# Interpolate variables in text (#{variable}).
# Split the text into multiple dynamic and static parts.
begin
case string
when /\A\\\#\{/
# Escaped interpolation
buffer_freeze '#{'
string = $'
when /\A#\{((?>[^{}]|(\{(?>[^{}]|\g<1>)*\}))*)\}/
# Interpolation
string = $'
code = $1
# escape = code !~ /\A\{.*\}\Z/
if escape
buffer_escape code
else
buffer code
end
when /\A([\\#]?[^#\\]*([#\\][^\\#\{][^#\\]*)*)/
string_remaining = $'
string_current = $&
# Static text
if escape && string_current =~ Utils::ESCAPE_HTML_PATTERN
buffer_escape string_current.inspect
else
buffer_freeze string_current
end
string = string_remaining
end
end until string.empty?
end | ruby | def buffer_split_by_interpolation(string, escape = true)
# Interpolate variables in text (#{variable}).
# Split the text into multiple dynamic and static parts.
begin
case string
when /\A\\\#\{/
# Escaped interpolation
buffer_freeze '#{'
string = $'
when /\A#\{((?>[^{}]|(\{(?>[^{}]|\g<1>)*\}))*)\}/
# Interpolation
string = $'
code = $1
# escape = code !~ /\A\{.*\}\Z/
if escape
buffer_escape code
else
buffer code
end
when /\A([\\#]?[^#\\]*([#\\][^\\#\{][^#\\]*)*)/
string_remaining = $'
string_current = $&
# Static text
if escape && string_current =~ Utils::ESCAPE_HTML_PATTERN
buffer_escape string_current.inspect
else
buffer_freeze string_current
end
string = string_remaining
end
end until string.empty?
end | [
"def",
"buffer_split_by_interpolation",
"(",
"string",
",",
"escape",
"=",
"true",
")",
"# Interpolate variables in text (#{variable}).",
"# Split the text into multiple dynamic and static parts.",
"begin",
"case",
"string",
"when",
"/",
"\\A",
"\\\\",
"\\#",
"\\{",
"/",
"# Escaped interpolation",
"buffer_freeze",
"'#{'",
"string",
"=",
"$'",
"when",
"/",
"\\A",
"\\{",
"\\{",
"\\g",
"\\}",
"\\}",
"/",
"# Interpolation",
"string",
"=",
"$'",
"code",
"=",
"$1",
"# escape = code !~ /\\A\\{.*\\}\\Z/",
"if",
"escape",
"buffer_escape",
"code",
"else",
"buffer",
"code",
"end",
"when",
"/",
"\\A",
"\\\\",
"\\\\",
"\\\\",
"\\\\",
"\\{",
"\\\\",
"/",
"string_remaining",
"=",
"$'",
"string_current",
"=",
"$&",
"# Static text",
"if",
"escape",
"&&",
"string_current",
"=~",
"Utils",
"::",
"ESCAPE_HTML_PATTERN",
"buffer_escape",
"string_current",
".",
"inspect",
"else",
"buffer_freeze",
"string_current",
"end",
"string",
"=",
"string_remaining",
"end",
"end",
"until",
"string",
".",
"empty?",
"end"
] | Split a string by its interpolation, then check if it really needs to be
escaped or not. Huge performance boost!
@param string [String] Input string
@param escape [Boolean] Escape string
@ref slim-lang Thank you for the interpolation code | [
"Split",
"a",
"string",
"by",
"its",
"interpolation",
"then",
"check",
"if",
"it",
"really",
"needs",
"to",
"be",
"escaped",
"or",
"not",
".",
"Huge",
"performance",
"boost!"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/compiler/buffer.rb#L339-L373 |
2,935 | beatrichartz/configurations | lib/configurations/strict.rb | Configurations.Strict.__evaluate_configurable! | def __evaluate_configurable!
entries = @properties.entries_at(@path)
entries.each do |property, value|
if value.is_a?(Maps::Properties::Entry)
__install_property__(property)
else
__install_nested_getter__(property)
end
end
end | ruby | def __evaluate_configurable!
entries = @properties.entries_at(@path)
entries.each do |property, value|
if value.is_a?(Maps::Properties::Entry)
__install_property__(property)
else
__install_nested_getter__(property)
end
end
end | [
"def",
"__evaluate_configurable!",
"entries",
"=",
"@properties",
".",
"entries_at",
"(",
"@path",
")",
"entries",
".",
"each",
"do",
"|",
"property",
",",
"value",
"|",
"if",
"value",
".",
"is_a?",
"(",
"Maps",
"::",
"Properties",
"::",
"Entry",
")",
"__install_property__",
"(",
"property",
")",
"else",
"__install_nested_getter__",
"(",
"property",
")",
"end",
"end",
"end"
] | Evaluates configurable properties and passes eventual hashes
down to subconfigurations | [
"Evaluates",
"configurable",
"properties",
"and",
"passes",
"eventual",
"hashes",
"down",
"to",
"subconfigurations"
] | bd8ef480ca831e29b821ffc9ebeaed4ef46a9db2 | https://github.com/beatrichartz/configurations/blob/bd8ef480ca831e29b821ffc9ebeaed4ef46a9db2/lib/configurations/strict.rb#L36-L45 |
2,936 | beatrichartz/configurations | lib/configurations/strict.rb | Configurations.Strict.__assign! | def __assign!(property, value)
@types.test!(@path.add(property), value)
v = @blocks.evaluate!(@path.add(property), value)
value = v unless v.nil?
super(property, value)
end | ruby | def __assign!(property, value)
@types.test!(@path.add(property), value)
v = @blocks.evaluate!(@path.add(property), value)
value = v unless v.nil?
super(property, value)
end | [
"def",
"__assign!",
"(",
"property",
",",
"value",
")",
"@types",
".",
"test!",
"(",
"@path",
".",
"add",
"(",
"property",
")",
",",
"value",
")",
"v",
"=",
"@blocks",
".",
"evaluate!",
"(",
"@path",
".",
"add",
"(",
"property",
")",
",",
"value",
")",
"value",
"=",
"v",
"unless",
"v",
".",
"nil?",
"super",
"(",
"property",
",",
"value",
")",
"end"
] | Assigns a value after running the assertions
@param [Symbol] property the property to type test
@param [Any] value the given value | [
"Assigns",
"a",
"value",
"after",
"running",
"the",
"assertions"
] | bd8ef480ca831e29b821ffc9ebeaed4ef46a9db2 | https://github.com/beatrichartz/configurations/blob/bd8ef480ca831e29b821ffc9ebeaed4ef46a9db2/lib/configurations/strict.rb#L109-L115 |
2,937 | mdub/representative | lib/representative/abstract_xml.rb | Representative.AbstractXml.element | def element(name, *args, &block)
metadata = @inspector.get_metadata(current_subject, name)
attributes = args.extract_options!.merge(metadata)
subject_of_element = if args.empty?
@inspector.get_value(current_subject, name)
else
args.shift
end
raise ArgumentError, "too many arguments" unless args.empty?
representing(subject_of_element) do
resolved_attributes = resolve_attributes(attributes)
content_string = content_block = nil
unless current_subject.nil?
if block
unless block == Representative::EMPTY
content_block = Proc.new { block.call(current_subject) }
end
else
content_string = current_subject.to_s
end
end
generate_element(format_name(name), resolved_attributes, content_string, &content_block)
end
end | ruby | def element(name, *args, &block)
metadata = @inspector.get_metadata(current_subject, name)
attributes = args.extract_options!.merge(metadata)
subject_of_element = if args.empty?
@inspector.get_value(current_subject, name)
else
args.shift
end
raise ArgumentError, "too many arguments" unless args.empty?
representing(subject_of_element) do
resolved_attributes = resolve_attributes(attributes)
content_string = content_block = nil
unless current_subject.nil?
if block
unless block == Representative::EMPTY
content_block = Proc.new { block.call(current_subject) }
end
else
content_string = current_subject.to_s
end
end
generate_element(format_name(name), resolved_attributes, content_string, &content_block)
end
end | [
"def",
"element",
"(",
"name",
",",
"*",
"args",
",",
"&",
"block",
")",
"metadata",
"=",
"@inspector",
".",
"get_metadata",
"(",
"current_subject",
",",
"name",
")",
"attributes",
"=",
"args",
".",
"extract_options!",
".",
"merge",
"(",
"metadata",
")",
"subject_of_element",
"=",
"if",
"args",
".",
"empty?",
"@inspector",
".",
"get_value",
"(",
"current_subject",
",",
"name",
")",
"else",
"args",
".",
"shift",
"end",
"raise",
"ArgumentError",
",",
"\"too many arguments\"",
"unless",
"args",
".",
"empty?",
"representing",
"(",
"subject_of_element",
")",
"do",
"resolved_attributes",
"=",
"resolve_attributes",
"(",
"attributes",
")",
"content_string",
"=",
"content_block",
"=",
"nil",
"unless",
"current_subject",
".",
"nil?",
"if",
"block",
"unless",
"block",
"==",
"Representative",
"::",
"EMPTY",
"content_block",
"=",
"Proc",
".",
"new",
"{",
"block",
".",
"call",
"(",
"current_subject",
")",
"}",
"end",
"else",
"content_string",
"=",
"current_subject",
".",
"to_s",
"end",
"end",
"generate_element",
"(",
"format_name",
"(",
"name",
")",
",",
"resolved_attributes",
",",
"content_string",
",",
"content_block",
")",
"end",
"end"
] | Generate an element.
With two arguments, it generates an element with the specified text content.
r.element :size, 42
# => <size>42</size>
More commonly, though, the second argument is omitted, in which case the
element content is assumed to be the named property of the current #subject.
r.representing my_shoe do
r.element :size
end
# => <size>9</size>
If a block is attached, nested elements can be generated. The element "value"
(whether explicitly provided, or derived from the current subject) becomes the
subject during evaluation of the block.
r.element :book, book do
r.title
r.author
end
# => <book><title>Whatever</title><author>Whoever</author></book>
Providing a final Hash argument specifies element attributes.
r.element :size, :type => "integer"
# => <size type="integer">9</size> | [
"Generate",
"an",
"element",
"."
] | c60214e79d51581a1744ae2891094468416b88f9 | https://github.com/mdub/representative/blob/c60214e79d51581a1744ae2891094468416b88f9/lib/representative/abstract_xml.rb#L45-L77 |
2,938 | mdub/representative | lib/representative/abstract_xml.rb | Representative.AbstractXml.list_of | def list_of(name, *args, &block)
options = args.extract_options!
list_subject = args.empty? ? name : args.shift
raise ArgumentError, "too many arguments" unless args.empty?
list_attributes = options[:list_attributes] || {}
item_name = options[:item_name] || name.to_s.singularize
item_attributes = options[:item_attributes] || {}
items = resolve_value(list_subject)
element(name, items, list_attributes.merge(:type => proc{"array"})) do
items.each do |item|
element(item_name, item, item_attributes, &block)
end
end
end | ruby | def list_of(name, *args, &block)
options = args.extract_options!
list_subject = args.empty? ? name : args.shift
raise ArgumentError, "too many arguments" unless args.empty?
list_attributes = options[:list_attributes] || {}
item_name = options[:item_name] || name.to_s.singularize
item_attributes = options[:item_attributes] || {}
items = resolve_value(list_subject)
element(name, items, list_attributes.merge(:type => proc{"array"})) do
items.each do |item|
element(item_name, item, item_attributes, &block)
end
end
end | [
"def",
"list_of",
"(",
"name",
",",
"*",
"args",
",",
"&",
"block",
")",
"options",
"=",
"args",
".",
"extract_options!",
"list_subject",
"=",
"args",
".",
"empty?",
"?",
"name",
":",
"args",
".",
"shift",
"raise",
"ArgumentError",
",",
"\"too many arguments\"",
"unless",
"args",
".",
"empty?",
"list_attributes",
"=",
"options",
"[",
":list_attributes",
"]",
"||",
"{",
"}",
"item_name",
"=",
"options",
"[",
":item_name",
"]",
"||",
"name",
".",
"to_s",
".",
"singularize",
"item_attributes",
"=",
"options",
"[",
":item_attributes",
"]",
"||",
"{",
"}",
"items",
"=",
"resolve_value",
"(",
"list_subject",
")",
"element",
"(",
"name",
",",
"items",
",",
"list_attributes",
".",
"merge",
"(",
":type",
"=>",
"proc",
"{",
"\"array\"",
"}",
")",
")",
"do",
"items",
".",
"each",
"do",
"|",
"item",
"|",
"element",
"(",
"item_name",
",",
"item",
",",
"item_attributes",
",",
"block",
")",
"end",
"end",
"end"
] | Generate a list of elements from Enumerable data.
r.list_of :books, my_books do
r.element :title
end
# => <books type="array">
# <book><title>Sailing for old dogs</title></book>
# <book><title>On the horizon</title></book>
# <book><title>The Little Blue Book of VHS Programming</title></book>
# </books>
Like #element, the value can be explicit, but is more commonly extracted
by name from the current #subject. | [
"Generate",
"a",
"list",
"of",
"elements",
"from",
"Enumerable",
"data",
"."
] | c60214e79d51581a1744ae2891094468416b88f9 | https://github.com/mdub/representative/blob/c60214e79d51581a1744ae2891094468416b88f9/lib/representative/abstract_xml.rb#L93-L110 |
2,939 | opulent/opulent | lib/opulent/parser/expression.rb | Opulent.Parser.expression | def expression(allow_assignments = true, wrapped = true, whitespace = true)
buffer = ''
# Build a ruby expression out of accepted literals
while (term = (whitespace ? accept(:whitespace) : nil) ||
modifier ||
identifier ||
method_call ||
paranthesis ||
array ||
hash ||
symbol ||
percent ||
primary_term)
buffer += term
# Accept operations which have a right term and raise an error if
# we have an unfinished expression such as "a +", "b - 1 >" and other
# expressions following the same pattern
if wrapped && (op = operation ||
(allow_assignments ? accept_stripped(:exp_assignment) : nil))
buffer += op
if (right_term = expression(allow_assignments, wrapped)).nil?
Logger.error :parse, @code, @i, @j, :expression
else
buffer += right_term[@value]
end
elsif (op = array || op = method_call || op = ternary_operator(allow_assignments, wrapped))
buffer += op
end
# Do not continue if the expression has whitespace method calls in
# an unwrapped context because this will confuse the parser
unless buffer.strip.empty?
break if lookahead(:exp_identifier_lookahead).nil?
end
end
if buffer.strip.empty?
undo buffer
else
[:expression, buffer.strip, {}]
end
end | ruby | def expression(allow_assignments = true, wrapped = true, whitespace = true)
buffer = ''
# Build a ruby expression out of accepted literals
while (term = (whitespace ? accept(:whitespace) : nil) ||
modifier ||
identifier ||
method_call ||
paranthesis ||
array ||
hash ||
symbol ||
percent ||
primary_term)
buffer += term
# Accept operations which have a right term and raise an error if
# we have an unfinished expression such as "a +", "b - 1 >" and other
# expressions following the same pattern
if wrapped && (op = operation ||
(allow_assignments ? accept_stripped(:exp_assignment) : nil))
buffer += op
if (right_term = expression(allow_assignments, wrapped)).nil?
Logger.error :parse, @code, @i, @j, :expression
else
buffer += right_term[@value]
end
elsif (op = array || op = method_call || op = ternary_operator(allow_assignments, wrapped))
buffer += op
end
# Do not continue if the expression has whitespace method calls in
# an unwrapped context because this will confuse the parser
unless buffer.strip.empty?
break if lookahead(:exp_identifier_lookahead).nil?
end
end
if buffer.strip.empty?
undo buffer
else
[:expression, buffer.strip, {}]
end
end | [
"def",
"expression",
"(",
"allow_assignments",
"=",
"true",
",",
"wrapped",
"=",
"true",
",",
"whitespace",
"=",
"true",
")",
"buffer",
"=",
"''",
"# Build a ruby expression out of accepted literals",
"while",
"(",
"term",
"=",
"(",
"whitespace",
"?",
"accept",
"(",
":whitespace",
")",
":",
"nil",
")",
"||",
"modifier",
"||",
"identifier",
"||",
"method_call",
"||",
"paranthesis",
"||",
"array",
"||",
"hash",
"||",
"symbol",
"||",
"percent",
"||",
"primary_term",
")",
"buffer",
"+=",
"term",
"# Accept operations which have a right term and raise an error if",
"# we have an unfinished expression such as \"a +\", \"b - 1 >\" and other",
"# expressions following the same pattern",
"if",
"wrapped",
"&&",
"(",
"op",
"=",
"operation",
"||",
"(",
"allow_assignments",
"?",
"accept_stripped",
"(",
":exp_assignment",
")",
":",
"nil",
")",
")",
"buffer",
"+=",
"op",
"if",
"(",
"right_term",
"=",
"expression",
"(",
"allow_assignments",
",",
"wrapped",
")",
")",
".",
"nil?",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":expression",
"else",
"buffer",
"+=",
"right_term",
"[",
"@value",
"]",
"end",
"elsif",
"(",
"op",
"=",
"array",
"||",
"op",
"=",
"method_call",
"||",
"op",
"=",
"ternary_operator",
"(",
"allow_assignments",
",",
"wrapped",
")",
")",
"buffer",
"+=",
"op",
"end",
"# Do not continue if the expression has whitespace method calls in",
"# an unwrapped context because this will confuse the parser",
"unless",
"buffer",
".",
"strip",
".",
"empty?",
"break",
"if",
"lookahead",
"(",
":exp_identifier_lookahead",
")",
".",
"nil?",
"end",
"end",
"if",
"buffer",
".",
"strip",
".",
"empty?",
"undo",
"buffer",
"else",
"[",
":expression",
",",
"buffer",
".",
"strip",
",",
"{",
"}",
"]",
"end",
"end"
] | Check if the parser matches an expression node | [
"Check",
"if",
"the",
"parser",
"matches",
"an",
"expression",
"node"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/expression.rb#L7-L51 |
2,940 | opulent/opulent | lib/opulent/parser/expression.rb | Opulent.Parser.array_elements | def array_elements(buffer = '')
if (term = expression)
buffer += term[@value]
# If there is an array_terminator ",", recursively gather the next
# array element into the buffer
if (terminator = accept_stripped :comma)
accept_newline
buffer += array_elements terminator
end
end
# Array ended prematurely with a trailing comma, therefore the current
# parsing process will stop
error :array_elements_terminator if buffer.strip[-1] == ','
buffer
end | ruby | def array_elements(buffer = '')
if (term = expression)
buffer += term[@value]
# If there is an array_terminator ",", recursively gather the next
# array element into the buffer
if (terminator = accept_stripped :comma)
accept_newline
buffer += array_elements terminator
end
end
# Array ended prematurely with a trailing comma, therefore the current
# parsing process will stop
error :array_elements_terminator if buffer.strip[-1] == ','
buffer
end | [
"def",
"array_elements",
"(",
"buffer",
"=",
"''",
")",
"if",
"(",
"term",
"=",
"expression",
")",
"buffer",
"+=",
"term",
"[",
"@value",
"]",
"# If there is an array_terminator \",\", recursively gather the next",
"# array element into the buffer",
"if",
"(",
"terminator",
"=",
"accept_stripped",
":comma",
")",
"accept_newline",
"buffer",
"+=",
"array_elements",
"terminator",
"end",
"end",
"# Array ended prematurely with a trailing comma, therefore the current",
"# parsing process will stop",
"error",
":array_elements_terminator",
"if",
"buffer",
".",
"strip",
"[",
"-",
"1",
"]",
"==",
"','",
"buffer",
"end"
] | Recursively gather expressions separated by a comma and add them to the
expression buffer
experssion1, experssion2, experssion3
@param buffer [String] Accumulator for the array elements | [
"Recursively",
"gather",
"expressions",
"separated",
"by",
"a",
"comma",
"and",
"add",
"them",
"to",
"the",
"expression",
"buffer"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/expression.rb#L81-L97 |
2,941 | opulent/opulent | lib/opulent/parser/expression.rb | Opulent.Parser.method_call | def method_call
method_code = ''
while (method_start = accept(:exp_method_call))
method_code += method_start
argument = call
method_code += argument if argument
end
method_code == '' ? nil : method_code
end | ruby | def method_call
method_code = ''
while (method_start = accept(:exp_method_call))
method_code += method_start
argument = call
method_code += argument if argument
end
method_code == '' ? nil : method_code
end | [
"def",
"method_call",
"method_code",
"=",
"''",
"while",
"(",
"method_start",
"=",
"accept",
"(",
":exp_method_call",
")",
")",
"method_code",
"+=",
"method_start",
"argument",
"=",
"call",
"method_code",
"+=",
"argument",
"if",
"argument",
"end",
"method_code",
"==",
"''",
"?",
"nil",
":",
"method_code",
"end"
] | Accept a ruby method call modifier | [
"Accept",
"a",
"ruby",
"method",
"call",
"modifier"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/expression.rb#L185-L195 |
2,942 | opulent/opulent | lib/opulent/parser/expression.rb | Opulent.Parser.call_elements | def call_elements(buffer = '')
# Accept both shorthand and default ruby hash style. Following DRY
# principles, a Proc is used to assign the value to the current key
#
# key: value
# :key => value
# value
if (symbol = accept_stripped :hash_symbol)
buffer += symbol
# Get the value associated to the current hash key
if (exp = expression(true))
buffer += exp[@value]
else
error :call_elements
end
# If there is an comma ",", recursively gather the next
# array element into the buffer
if (terminator = accept_stripped :comma)
buffer += call_elements terminator
end
elsif (exp = expression(true))
buffer += exp[@value]
if (assign = accept_stripped :hash_assignment)
buffer += assign
# Get the value associated to the current hash key
if (exp = expression(true))
buffer += exp[@value]
else
error :call_elements
end
end
# If there is an comma ",", recursively gather the next
# array element into the buffer
if (terminator = accept_stripped :comma)
buffer += call_elements terminator
end
end
buffer
end | ruby | def call_elements(buffer = '')
# Accept both shorthand and default ruby hash style. Following DRY
# principles, a Proc is used to assign the value to the current key
#
# key: value
# :key => value
# value
if (symbol = accept_stripped :hash_symbol)
buffer += symbol
# Get the value associated to the current hash key
if (exp = expression(true))
buffer += exp[@value]
else
error :call_elements
end
# If there is an comma ",", recursively gather the next
# array element into the buffer
if (terminator = accept_stripped :comma)
buffer += call_elements terminator
end
elsif (exp = expression(true))
buffer += exp[@value]
if (assign = accept_stripped :hash_assignment)
buffer += assign
# Get the value associated to the current hash key
if (exp = expression(true))
buffer += exp[@value]
else
error :call_elements
end
end
# If there is an comma ",", recursively gather the next
# array element into the buffer
if (terminator = accept_stripped :comma)
buffer += call_elements terminator
end
end
buffer
end | [
"def",
"call_elements",
"(",
"buffer",
"=",
"''",
")",
"# Accept both shorthand and default ruby hash style. Following DRY",
"# principles, a Proc is used to assign the value to the current key",
"#",
"# key: value",
"# :key => value",
"# value",
"if",
"(",
"symbol",
"=",
"accept_stripped",
":hash_symbol",
")",
"buffer",
"+=",
"symbol",
"# Get the value associated to the current hash key",
"if",
"(",
"exp",
"=",
"expression",
"(",
"true",
")",
")",
"buffer",
"+=",
"exp",
"[",
"@value",
"]",
"else",
"error",
":call_elements",
"end",
"# If there is an comma \",\", recursively gather the next",
"# array element into the buffer",
"if",
"(",
"terminator",
"=",
"accept_stripped",
":comma",
")",
"buffer",
"+=",
"call_elements",
"terminator",
"end",
"elsif",
"(",
"exp",
"=",
"expression",
"(",
"true",
")",
")",
"buffer",
"+=",
"exp",
"[",
"@value",
"]",
"if",
"(",
"assign",
"=",
"accept_stripped",
":hash_assignment",
")",
"buffer",
"+=",
"assign",
"# Get the value associated to the current hash key",
"if",
"(",
"exp",
"=",
"expression",
"(",
"true",
")",
")",
"buffer",
"+=",
"exp",
"[",
"@value",
"]",
"else",
"error",
":call_elements",
"end",
"end",
"# If there is an comma \",\", recursively gather the next",
"# array element into the buffer",
"if",
"(",
"terminator",
"=",
"accept_stripped",
":comma",
")",
"buffer",
"+=",
"call_elements",
"terminator",
"end",
"end",
"buffer",
"end"
] | Recursively gather expression attributes separated by a comma and add
them to the expression buffer
expression1, a: expression2, expression3
@param buffer [String] Accumulator for the call elements | [
"Recursively",
"gather",
"expression",
"attributes",
"separated",
"by",
"a",
"comma",
"and",
"add",
"them",
"to",
"the",
"expression",
"buffer"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/expression.rb#L218-L262 |
2,943 | opulent/opulent | lib/opulent/parser/expression.rb | Opulent.Parser.symbol | def symbol
return unless (colon = accept :colon)
return undo colon if lookahead(:whitespace)
if (exp = expression).nil?
error :symbol
else
colon + exp[@value]
end
end | ruby | def symbol
return unless (colon = accept :colon)
return undo colon if lookahead(:whitespace)
if (exp = expression).nil?
error :symbol
else
colon + exp[@value]
end
end | [
"def",
"symbol",
"return",
"unless",
"(",
"colon",
"=",
"accept",
":colon",
")",
"return",
"undo",
"colon",
"if",
"lookahead",
"(",
":whitespace",
")",
"if",
"(",
"exp",
"=",
"expression",
")",
".",
"nil?",
"error",
":symbol",
"else",
"colon",
"+",
"exp",
"[",
"@value",
"]",
"end",
"end"
] | Accept a ruby symbol defined through a colon and a trailing expression
:'symbol'
:symbol | [
"Accept",
"a",
"ruby",
"symbol",
"defined",
"through",
"a",
"colon",
"and",
"a",
"trailing",
"expression"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/expression.rb#L269-L278 |
2,944 | opulent/opulent | lib/opulent/parser/expression.rb | Opulent.Parser.ternary_operator | def ternary_operator(allow_assignments, wrapped)
if (buffer = accept :exp_ternary)
buffer += expression(allow_assignments, wrapped)[@value]
if (else_branch = accept :exp_ternary_else)
buffer += else_branch
buffer += expression(allow_assignments, wrapped)[@value]
end
return buffer
end
end | ruby | def ternary_operator(allow_assignments, wrapped)
if (buffer = accept :exp_ternary)
buffer += expression(allow_assignments, wrapped)[@value]
if (else_branch = accept :exp_ternary_else)
buffer += else_branch
buffer += expression(allow_assignments, wrapped)[@value]
end
return buffer
end
end | [
"def",
"ternary_operator",
"(",
"allow_assignments",
",",
"wrapped",
")",
"if",
"(",
"buffer",
"=",
"accept",
":exp_ternary",
")",
"buffer",
"+=",
"expression",
"(",
"allow_assignments",
",",
"wrapped",
")",
"[",
"@value",
"]",
"if",
"(",
"else_branch",
"=",
"accept",
":exp_ternary_else",
")",
"buffer",
"+=",
"else_branch",
"buffer",
"+=",
"expression",
"(",
"allow_assignments",
",",
"wrapped",
")",
"[",
"@value",
"]",
"end",
"return",
"buffer",
"end",
"end"
] | Accept ternary operator syntax
condition ? expression1 : expression2 | [
"Accept",
"ternary",
"operator",
"syntax"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/expression.rb#L344-L353 |
2,945 | kjvarga/ajax | lib/ajax/action_controller.rb | Ajax.ActionController.serialize_ajax_info | def serialize_ajax_info
layout_name =
if Ajax.app.rails?(3)
if @_rendered_layout.is_a?(String)
@_rendered_layout =~ /.*\/([^\/]*)/ ? $1 : @_rendered_layout
elsif @_rendered_layout
@_rendered_layout.variable_name
end
else
active_layout
end
Ajax.set_header(response, :layout, layout_name)
Ajax.set_header(response, :controller, self.class.controller_name)
end | ruby | def serialize_ajax_info
layout_name =
if Ajax.app.rails?(3)
if @_rendered_layout.is_a?(String)
@_rendered_layout =~ /.*\/([^\/]*)/ ? $1 : @_rendered_layout
elsif @_rendered_layout
@_rendered_layout.variable_name
end
else
active_layout
end
Ajax.set_header(response, :layout, layout_name)
Ajax.set_header(response, :controller, self.class.controller_name)
end | [
"def",
"serialize_ajax_info",
"layout_name",
"=",
"if",
"Ajax",
".",
"app",
".",
"rails?",
"(",
"3",
")",
"if",
"@_rendered_layout",
".",
"is_a?",
"(",
"String",
")",
"@_rendered_layout",
"=~",
"/",
"\\/",
"\\/",
"/",
"?",
"$1",
":",
"@_rendered_layout",
"elsif",
"@_rendered_layout",
"@_rendered_layout",
".",
"variable_name",
"end",
"else",
"active_layout",
"end",
"Ajax",
".",
"set_header",
"(",
"response",
",",
":layout",
",",
"layout_name",
")",
"Ajax",
".",
"set_header",
"(",
"response",
",",
":controller",
",",
"self",
".",
"class",
".",
"controller_name",
")",
"end"
] | Convert the Ajax-Info hash to JSON before the request is sent.
Invoked as an after filter.
Adds the current +layout+ and +controller+ to the hash.
These values will be sent in future requests using the Ajax-Info header.
+controller+ is the result of calling ActionController#controller_name, so
if your controller is ApplicationController the value will be <tt>'application'</tt>.
+layout+ is the name of the layout without any path or extension. So for example if
layouts/simple.html.erb or layouts/ajax/simple.html.erb are rendered the
value of +layout+ would be <tt>'simple'</tt> in both cases. | [
"Convert",
"the",
"Ajax",
"-",
"Info",
"hash",
"to",
"JSON",
"before",
"the",
"request",
"is",
"sent",
".",
"Invoked",
"as",
"an",
"after",
"filter",
"."
] | e60acbc51855cd85b4907d509ea41fe0965ce72e | https://github.com/kjvarga/ajax/blob/e60acbc51855cd85b4907d509ea41fe0965ce72e/lib/ajax/action_controller.rb#L152-L165 |
2,946 | kjvarga/ajax | lib/ajax/action_controller.rb | Ajax.ActionController._layout_for_ajax | def _layout_for_ajax(default) #:nodoc:
ajax_layout = self.class.read_inheritable_attribute(:ajax_layout)
ajax_layout = if ajax_layout.nil? && default.nil?
nil
elsif ajax_layout.nil? && !default.nil? # look for one with the default name in layouts/ajax
if default =~ /^layouts\/ajax\//
default
elsif !(default =~ /^ajax\//)
"ajax/#{default.sub(/layouts(\/)?/, '')}"
else
default
end
elsif ajax_layout.include?(?/) # path to specific layout
ajax_layout
else # layout name, look in ajax/
"ajax/#{ajax_layout}"
end
ajax_layout = ajax_layout =~ /\blayouts/ ? ajax_layout : "layouts/#{ajax_layout}" if ajax_layout
ajax_layout
end | ruby | def _layout_for_ajax(default) #:nodoc:
ajax_layout = self.class.read_inheritable_attribute(:ajax_layout)
ajax_layout = if ajax_layout.nil? && default.nil?
nil
elsif ajax_layout.nil? && !default.nil? # look for one with the default name in layouts/ajax
if default =~ /^layouts\/ajax\//
default
elsif !(default =~ /^ajax\//)
"ajax/#{default.sub(/layouts(\/)?/, '')}"
else
default
end
elsif ajax_layout.include?(?/) # path to specific layout
ajax_layout
else # layout name, look in ajax/
"ajax/#{ajax_layout}"
end
ajax_layout = ajax_layout =~ /\blayouts/ ? ajax_layout : "layouts/#{ajax_layout}" if ajax_layout
ajax_layout
end | [
"def",
"_layout_for_ajax",
"(",
"default",
")",
"#:nodoc:",
"ajax_layout",
"=",
"self",
".",
"class",
".",
"read_inheritable_attribute",
"(",
":ajax_layout",
")",
"ajax_layout",
"=",
"if",
"ajax_layout",
".",
"nil?",
"&&",
"default",
".",
"nil?",
"nil",
"elsif",
"ajax_layout",
".",
"nil?",
"&&",
"!",
"default",
".",
"nil?",
"# look for one with the default name in layouts/ajax",
"if",
"default",
"=~",
"/",
"\\/",
"\\/",
"/",
"default",
"elsif",
"!",
"(",
"default",
"=~",
"/",
"\\/",
"/",
")",
"\"ajax/#{default.sub(/layouts(\\/)?/, '')}\"",
"else",
"default",
"end",
"elsif",
"ajax_layout",
".",
"include?",
"(",
"?/",
")",
"# path to specific layout",
"ajax_layout",
"else",
"# layout name, look in ajax/",
"\"ajax/#{ajax_layout}\"",
"end",
"ajax_layout",
"=",
"ajax_layout",
"=~",
"/",
"\\b",
"/",
"?",
"ajax_layout",
":",
"\"layouts/#{ajax_layout}\"",
"if",
"ajax_layout",
"ajax_layout",
"end"
] | Return the layout to use for an AJAX request, or nil if the default should be used.
If no ajax_layout is set, look for the default layout in <tt>layouts/ajax</tt>.
If the layout cannot be found, use the default. | [
"Return",
"the",
"layout",
"to",
"use",
"for",
"an",
"AJAX",
"request",
"or",
"nil",
"if",
"the",
"default",
"should",
"be",
"used",
"."
] | e60acbc51855cd85b4907d509ea41fe0965ce72e | https://github.com/kjvarga/ajax/blob/e60acbc51855cd85b4907d509ea41fe0965ce72e/lib/ajax/action_controller.rb#L258-L277 |
2,947 | opulent/opulent | lib/opulent/parser/filter.rb | Opulent.Parser.filter | def filter(parent, indent)
return unless (filter_name = accept :filter)
# Get element attributes
atts = attributes(shorthand_attributes) || {}
# Accept inline text or multiline text feed as first child
error :fiter unless accept(:line_feed).strip.empty?
# Get everything under the filter and set it as the node value
# and create a new node and set its extension
parent[@children] << [
:filter,
filter_name[1..-1].to_sym,
atts,
get_indented_lines(indent),
indent
]
end | ruby | def filter(parent, indent)
return unless (filter_name = accept :filter)
# Get element attributes
atts = attributes(shorthand_attributes) || {}
# Accept inline text or multiline text feed as first child
error :fiter unless accept(:line_feed).strip.empty?
# Get everything under the filter and set it as the node value
# and create a new node and set its extension
parent[@children] << [
:filter,
filter_name[1..-1].to_sym,
atts,
get_indented_lines(indent),
indent
]
end | [
"def",
"filter",
"(",
"parent",
",",
"indent",
")",
"return",
"unless",
"(",
"filter_name",
"=",
"accept",
":filter",
")",
"# Get element attributes",
"atts",
"=",
"attributes",
"(",
"shorthand_attributes",
")",
"||",
"{",
"}",
"# Accept inline text or multiline text feed as first child",
"error",
":fiter",
"unless",
"accept",
"(",
":line_feed",
")",
".",
"strip",
".",
"empty?",
"# Get everything under the filter and set it as the node value",
"# and create a new node and set its extension",
"parent",
"[",
"@children",
"]",
"<<",
"[",
":filter",
",",
"filter_name",
"[",
"1",
"..",
"-",
"1",
"]",
".",
"to_sym",
",",
"atts",
",",
"get_indented_lines",
"(",
"indent",
")",
",",
"indent",
"]",
"end"
] | Check if we match an compile time filter
:filter
@param parent [Node] Parent node to which we append the element | [
"Check",
"if",
"we",
"match",
"an",
"compile",
"time",
"filter"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/filter.rb#L11-L29 |
2,948 | opulent/opulent | lib/opulent/compiler/text.rb | Opulent.Compiler.plain | def plain(node, indent)
# Text value
value = node[@options][:value]
# Pretty print
if @settings[:pretty]
indentation = ' ' * indent
inline = @sibling_stack[-1][-1] &&
@sibling_stack[-1][-1][0] == :node &&
Settings::INLINE_NODE.include?(@sibling_stack[-1][-1][1])
# Add current node to the siblings stack
@sibling_stack[-1] << [node[@type], node[@value]]
# If we have a text on multiple lines and the text isn't supposed to be
# inline, indent all the lines of the text
if node[@value] == :text
if !inline
value.gsub!(/^(?!$)/, indentation)
else
buffer_remove_trailing_newline
value.strip!
end
else
buffer_freeze indentation
end
end
# Leading whitespace
buffer_freeze ' ' if node[@options][:leading_whitespace]
# Evaluate text node if it's marked as such and print nodes in the
# current context
if node[@value] == :text
buffer_split_by_interpolation value, node[@options][:escaped]
else
node[@options][:escaped] ? buffer_escape(value) : buffer(value)
end
# Trailing whitespace
buffer_freeze ' ' if node[@options][:trailing_whitespace]
# Pretty print
if @settings[:pretty]
buffer_freeze "\n" if !inline or node[@value] == :print
end
end | ruby | def plain(node, indent)
# Text value
value = node[@options][:value]
# Pretty print
if @settings[:pretty]
indentation = ' ' * indent
inline = @sibling_stack[-1][-1] &&
@sibling_stack[-1][-1][0] == :node &&
Settings::INLINE_NODE.include?(@sibling_stack[-1][-1][1])
# Add current node to the siblings stack
@sibling_stack[-1] << [node[@type], node[@value]]
# If we have a text on multiple lines and the text isn't supposed to be
# inline, indent all the lines of the text
if node[@value] == :text
if !inline
value.gsub!(/^(?!$)/, indentation)
else
buffer_remove_trailing_newline
value.strip!
end
else
buffer_freeze indentation
end
end
# Leading whitespace
buffer_freeze ' ' if node[@options][:leading_whitespace]
# Evaluate text node if it's marked as such and print nodes in the
# current context
if node[@value] == :text
buffer_split_by_interpolation value, node[@options][:escaped]
else
node[@options][:escaped] ? buffer_escape(value) : buffer(value)
end
# Trailing whitespace
buffer_freeze ' ' if node[@options][:trailing_whitespace]
# Pretty print
if @settings[:pretty]
buffer_freeze "\n" if !inline or node[@value] == :print
end
end | [
"def",
"plain",
"(",
"node",
",",
"indent",
")",
"# Text value",
"value",
"=",
"node",
"[",
"@options",
"]",
"[",
":value",
"]",
"# Pretty print",
"if",
"@settings",
"[",
":pretty",
"]",
"indentation",
"=",
"' '",
"*",
"indent",
"inline",
"=",
"@sibling_stack",
"[",
"-",
"1",
"]",
"[",
"-",
"1",
"]",
"&&",
"@sibling_stack",
"[",
"-",
"1",
"]",
"[",
"-",
"1",
"]",
"[",
"0",
"]",
"==",
":node",
"&&",
"Settings",
"::",
"INLINE_NODE",
".",
"include?",
"(",
"@sibling_stack",
"[",
"-",
"1",
"]",
"[",
"-",
"1",
"]",
"[",
"1",
"]",
")",
"# Add current node to the siblings stack",
"@sibling_stack",
"[",
"-",
"1",
"]",
"<<",
"[",
"node",
"[",
"@type",
"]",
",",
"node",
"[",
"@value",
"]",
"]",
"# If we have a text on multiple lines and the text isn't supposed to be",
"# inline, indent all the lines of the text",
"if",
"node",
"[",
"@value",
"]",
"==",
":text",
"if",
"!",
"inline",
"value",
".",
"gsub!",
"(",
"/",
"/",
",",
"indentation",
")",
"else",
"buffer_remove_trailing_newline",
"value",
".",
"strip!",
"end",
"else",
"buffer_freeze",
"indentation",
"end",
"end",
"# Leading whitespace",
"buffer_freeze",
"' '",
"if",
"node",
"[",
"@options",
"]",
"[",
":leading_whitespace",
"]",
"# Evaluate text node if it's marked as such and print nodes in the",
"# current context",
"if",
"node",
"[",
"@value",
"]",
"==",
":text",
"buffer_split_by_interpolation",
"value",
",",
"node",
"[",
"@options",
"]",
"[",
":escaped",
"]",
"else",
"node",
"[",
"@options",
"]",
"[",
":escaped",
"]",
"?",
"buffer_escape",
"(",
"value",
")",
":",
"buffer",
"(",
"value",
")",
"end",
"# Trailing whitespace",
"buffer_freeze",
"' '",
"if",
"node",
"[",
"@options",
"]",
"[",
":trailing_whitespace",
"]",
"# Pretty print",
"if",
"@settings",
"[",
":pretty",
"]",
"buffer_freeze",
"\"\\n\"",
"if",
"!",
"inline",
"or",
"node",
"[",
"@value",
"]",
"==",
":print",
"end",
"end"
] | Generate the code for a standard text node
@param node [Array] Node code generation data
@param indent [Fixnum] Size of the indentation to be added | [
"Generate",
"the",
"code",
"for",
"a",
"standard",
"text",
"node"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/compiler/text.rb#L10-L57 |
2,949 | opulent/opulent | lib/opulent/parser/include.rb | Opulent.Parser.include_file | def include_file(_parent, indent)
return unless accept :include
# Process data
name = accept :line_feed || ''
name.strip!
# Check if there is any string after the include input
Logger.error :parse, @code, @i, @j, :include_end if name.empty?
# Get the complete file path based on the current file being compiled
include_path = File.expand_path name, File.dirname(@file[-1][0])
# Try to see if it has any existing extension, otherwise add .op
include_path += Settings::FILE_EXTENSION if File.extname(name).empty?
# Throw an error if the file doesn't exist
unless Dir[include_path].any?
Logger.error :parse, @code, @i, @j, :include, name
end
# include entire directory tree
Dir[include_path].each do |file|
# Skip current file when including from same directory
next if file == @file[-1][0]
@file << [include_path, indent]
# Throw an error if the file doesn't exist
if File.directory? file
Logger.error :parse, @code, @i, @j, :include_dir, file
end
# Throw an error if the file doesn't exist
unless File.file? file
Logger.error :parse, @code, @i, @j, :include, file
end
# Indent all lines and prepare them for the parser
lines = indent_lines File.read(file), ' ' * indent
lines << ' '
# Indent all the output lines with the current indentation
@code.insert @i + 1, *lines.lines
end
true
end | ruby | def include_file(_parent, indent)
return unless accept :include
# Process data
name = accept :line_feed || ''
name.strip!
# Check if there is any string after the include input
Logger.error :parse, @code, @i, @j, :include_end if name.empty?
# Get the complete file path based on the current file being compiled
include_path = File.expand_path name, File.dirname(@file[-1][0])
# Try to see if it has any existing extension, otherwise add .op
include_path += Settings::FILE_EXTENSION if File.extname(name).empty?
# Throw an error if the file doesn't exist
unless Dir[include_path].any?
Logger.error :parse, @code, @i, @j, :include, name
end
# include entire directory tree
Dir[include_path].each do |file|
# Skip current file when including from same directory
next if file == @file[-1][0]
@file << [include_path, indent]
# Throw an error if the file doesn't exist
if File.directory? file
Logger.error :parse, @code, @i, @j, :include_dir, file
end
# Throw an error if the file doesn't exist
unless File.file? file
Logger.error :parse, @code, @i, @j, :include, file
end
# Indent all lines and prepare them for the parser
lines = indent_lines File.read(file), ' ' * indent
lines << ' '
# Indent all the output lines with the current indentation
@code.insert @i + 1, *lines.lines
end
true
end | [
"def",
"include_file",
"(",
"_parent",
",",
"indent",
")",
"return",
"unless",
"accept",
":include",
"# Process data",
"name",
"=",
"accept",
":line_feed",
"||",
"''",
"name",
".",
"strip!",
"# Check if there is any string after the include input",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":include_end",
"if",
"name",
".",
"empty?",
"# Get the complete file path based on the current file being compiled",
"include_path",
"=",
"File",
".",
"expand_path",
"name",
",",
"File",
".",
"dirname",
"(",
"@file",
"[",
"-",
"1",
"]",
"[",
"0",
"]",
")",
"# Try to see if it has any existing extension, otherwise add .op",
"include_path",
"+=",
"Settings",
"::",
"FILE_EXTENSION",
"if",
"File",
".",
"extname",
"(",
"name",
")",
".",
"empty?",
"# Throw an error if the file doesn't exist",
"unless",
"Dir",
"[",
"include_path",
"]",
".",
"any?",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":include",
",",
"name",
"end",
"# include entire directory tree",
"Dir",
"[",
"include_path",
"]",
".",
"each",
"do",
"|",
"file",
"|",
"# Skip current file when including from same directory",
"next",
"if",
"file",
"==",
"@file",
"[",
"-",
"1",
"]",
"[",
"0",
"]",
"@file",
"<<",
"[",
"include_path",
",",
"indent",
"]",
"# Throw an error if the file doesn't exist",
"if",
"File",
".",
"directory?",
"file",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":include_dir",
",",
"file",
"end",
"# Throw an error if the file doesn't exist",
"unless",
"File",
".",
"file?",
"file",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":include",
",",
"file",
"end",
"# Indent all lines and prepare them for the parser",
"lines",
"=",
"indent_lines",
"File",
".",
"read",
"(",
"file",
")",
",",
"' '",
"*",
"indent",
"lines",
"<<",
"' '",
"# Indent all the output lines with the current indentation",
"@code",
".",
"insert",
"@i",
"+",
"1",
",",
"lines",
".",
"lines",
"end",
"true",
"end"
] | Check if we have an include node, which will include a new file inside
of the current one to be parsed
@param parent [Array] Parent node to which we append to | [
"Check",
"if",
"we",
"have",
"an",
"include",
"node",
"which",
"will",
"include",
"a",
"new",
"file",
"inside",
"of",
"the",
"current",
"one",
"to",
"be",
"parsed"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/include.rb#L10-L57 |
2,950 | redbooth/redbooth-ruby | lib/redbooth-ruby/base.rb | RedboothRuby.Base.parse_timestamps | def parse_timestamps
@created_time = created_time.to_i if created_time.is_a? String
@created_time = Time.at(created_time) if created_time
end | ruby | def parse_timestamps
@created_time = created_time.to_i if created_time.is_a? String
@created_time = Time.at(created_time) if created_time
end | [
"def",
"parse_timestamps",
"@created_time",
"=",
"created_time",
".",
"to_i",
"if",
"created_time",
".",
"is_a?",
"String",
"@created_time",
"=",
"Time",
".",
"at",
"(",
"created_time",
")",
"if",
"created_time",
"end"
] | Parses UNIX timestamps and creates Time objects. | [
"Parses",
"UNIX",
"timestamps",
"and",
"creates",
"Time",
"objects",
"."
] | fb6bc228a9346d4db476032f0df16c9588fdfbe1 | https://github.com/redbooth/redbooth-ruby/blob/fb6bc228a9346d4db476032f0df16c9588fdfbe1/lib/redbooth-ruby/base.rb#L38-L41 |
2,951 | opulent/opulent | lib/opulent/compiler/node.rb | Opulent.Compiler.node | def node(node, indent)
# Pretty print
if @settings[:pretty]
indentation = ' ' * indent
inline = Settings::INLINE_NODE.include? node[@value]
indentate = proc do
if @in_definition
buffer "' ' * (indent + #{indent})"
else
buffer_freeze indentation
end
end
if inline
inline_last_sibling = @sibling_stack[-1][-1] ? Settings::INLINE_NODE.include?(@sibling_stack[-1][-1][1]) : true
if @sibling_stack[-1][-1] && @sibling_stack[-1][-1][0] == :plain
buffer_remove_trailing_newline
end
if @in_definition || @sibling_stack[-1].length == 1 || !inline_last_sibling
indentate[]
end
else
indentate[]
end
@sibling_stack[-1] << [node[@type], node[@value]]
@sibling_stack << [[node[@type], node[@value]]]
end
# Add the tag opening, with leading whitespace to the code buffer
buffer_freeze ' ' if node[@options][:leading_whitespace]
buffer_freeze "<#{node[@value]}"
# Evaluate node extension in the current context
if node[@options][:extension]
extension_name = buffer_set_variable :extension,
node[@options][:extension][@value]
extension = {
name: extension_name,
escaped: node[@options][:extension][@options][:escaped]
}
end
# Evaluate and generate node attributes, then process each one to
# by generating the required attribute code
buffer_attributes node[@options][:attributes],
extension
# Check if the current node is self enclosing. Self enclosing nodes
# do not have any child elements
if node[@options][:self_enclosing]
# If the tag is self enclosing, it cannot have any child elements.
buffer_freeze '>'
# Pretty print
buffer_freeze "\n" if @settings[:pretty]
# If we mistakenly add children to self enclosing nodes,
# process each child element as if it was correctly indented
# node[@children].each do |child|
# root child, indent + @settings[:indent]
# end
else
# Set tag ending code
buffer_freeze '>'
# Pretty print
if @settings[:pretty]
if node[@children].length > 0
buffer_freeze "\n" unless inline
end
# @sibling_stack << [[node[@type], node[@value]]]
end
# Process each child element recursively, increasing indentation
node[@children].each do |child|
root child, indent + @settings[:indent]
end
inline_last_child = @sibling_stack[-1][-2] &&
(@sibling_stack[-1][-2][0] == :plain ||
Settings::INLINE_NODE.include?(@sibling_stack[-1][-2][1]))
# Pretty print
if @settings[:pretty]
if node[@children].length > 1 && inline_last_child
buffer_freeze "\n"
end
if node[@children].size > 0 && !inline
indentate[]
end
end
# Set tag closing code
buffer_freeze "</#{node[@value]}>"
buffer_freeze ' ' if node[@options][:trailing_whitespace]
# Pretty print
if @settings[:pretty]
buffer_freeze "\n" if !inline || @in_definition
end
end
if @settings[:pretty]
@sibling_stack.pop
end
end | ruby | def node(node, indent)
# Pretty print
if @settings[:pretty]
indentation = ' ' * indent
inline = Settings::INLINE_NODE.include? node[@value]
indentate = proc do
if @in_definition
buffer "' ' * (indent + #{indent})"
else
buffer_freeze indentation
end
end
if inline
inline_last_sibling = @sibling_stack[-1][-1] ? Settings::INLINE_NODE.include?(@sibling_stack[-1][-1][1]) : true
if @sibling_stack[-1][-1] && @sibling_stack[-1][-1][0] == :plain
buffer_remove_trailing_newline
end
if @in_definition || @sibling_stack[-1].length == 1 || !inline_last_sibling
indentate[]
end
else
indentate[]
end
@sibling_stack[-1] << [node[@type], node[@value]]
@sibling_stack << [[node[@type], node[@value]]]
end
# Add the tag opening, with leading whitespace to the code buffer
buffer_freeze ' ' if node[@options][:leading_whitespace]
buffer_freeze "<#{node[@value]}"
# Evaluate node extension in the current context
if node[@options][:extension]
extension_name = buffer_set_variable :extension,
node[@options][:extension][@value]
extension = {
name: extension_name,
escaped: node[@options][:extension][@options][:escaped]
}
end
# Evaluate and generate node attributes, then process each one to
# by generating the required attribute code
buffer_attributes node[@options][:attributes],
extension
# Check if the current node is self enclosing. Self enclosing nodes
# do not have any child elements
if node[@options][:self_enclosing]
# If the tag is self enclosing, it cannot have any child elements.
buffer_freeze '>'
# Pretty print
buffer_freeze "\n" if @settings[:pretty]
# If we mistakenly add children to self enclosing nodes,
# process each child element as if it was correctly indented
# node[@children].each do |child|
# root child, indent + @settings[:indent]
# end
else
# Set tag ending code
buffer_freeze '>'
# Pretty print
if @settings[:pretty]
if node[@children].length > 0
buffer_freeze "\n" unless inline
end
# @sibling_stack << [[node[@type], node[@value]]]
end
# Process each child element recursively, increasing indentation
node[@children].each do |child|
root child, indent + @settings[:indent]
end
inline_last_child = @sibling_stack[-1][-2] &&
(@sibling_stack[-1][-2][0] == :plain ||
Settings::INLINE_NODE.include?(@sibling_stack[-1][-2][1]))
# Pretty print
if @settings[:pretty]
if node[@children].length > 1 && inline_last_child
buffer_freeze "\n"
end
if node[@children].size > 0 && !inline
indentate[]
end
end
# Set tag closing code
buffer_freeze "</#{node[@value]}>"
buffer_freeze ' ' if node[@options][:trailing_whitespace]
# Pretty print
if @settings[:pretty]
buffer_freeze "\n" if !inline || @in_definition
end
end
if @settings[:pretty]
@sibling_stack.pop
end
end | [
"def",
"node",
"(",
"node",
",",
"indent",
")",
"# Pretty print",
"if",
"@settings",
"[",
":pretty",
"]",
"indentation",
"=",
"' '",
"*",
"indent",
"inline",
"=",
"Settings",
"::",
"INLINE_NODE",
".",
"include?",
"node",
"[",
"@value",
"]",
"indentate",
"=",
"proc",
"do",
"if",
"@in_definition",
"buffer",
"\"' ' * (indent + #{indent})\"",
"else",
"buffer_freeze",
"indentation",
"end",
"end",
"if",
"inline",
"inline_last_sibling",
"=",
"@sibling_stack",
"[",
"-",
"1",
"]",
"[",
"-",
"1",
"]",
"?",
"Settings",
"::",
"INLINE_NODE",
".",
"include?",
"(",
"@sibling_stack",
"[",
"-",
"1",
"]",
"[",
"-",
"1",
"]",
"[",
"1",
"]",
")",
":",
"true",
"if",
"@sibling_stack",
"[",
"-",
"1",
"]",
"[",
"-",
"1",
"]",
"&&",
"@sibling_stack",
"[",
"-",
"1",
"]",
"[",
"-",
"1",
"]",
"[",
"0",
"]",
"==",
":plain",
"buffer_remove_trailing_newline",
"end",
"if",
"@in_definition",
"||",
"@sibling_stack",
"[",
"-",
"1",
"]",
".",
"length",
"==",
"1",
"||",
"!",
"inline_last_sibling",
"indentate",
"[",
"]",
"end",
"else",
"indentate",
"[",
"]",
"end",
"@sibling_stack",
"[",
"-",
"1",
"]",
"<<",
"[",
"node",
"[",
"@type",
"]",
",",
"node",
"[",
"@value",
"]",
"]",
"@sibling_stack",
"<<",
"[",
"[",
"node",
"[",
"@type",
"]",
",",
"node",
"[",
"@value",
"]",
"]",
"]",
"end",
"# Add the tag opening, with leading whitespace to the code buffer",
"buffer_freeze",
"' '",
"if",
"node",
"[",
"@options",
"]",
"[",
":leading_whitespace",
"]",
"buffer_freeze",
"\"<#{node[@value]}\"",
"# Evaluate node extension in the current context",
"if",
"node",
"[",
"@options",
"]",
"[",
":extension",
"]",
"extension_name",
"=",
"buffer_set_variable",
":extension",
",",
"node",
"[",
"@options",
"]",
"[",
":extension",
"]",
"[",
"@value",
"]",
"extension",
"=",
"{",
"name",
":",
"extension_name",
",",
"escaped",
":",
"node",
"[",
"@options",
"]",
"[",
":extension",
"]",
"[",
"@options",
"]",
"[",
":escaped",
"]",
"}",
"end",
"# Evaluate and generate node attributes, then process each one to",
"# by generating the required attribute code",
"buffer_attributes",
"node",
"[",
"@options",
"]",
"[",
":attributes",
"]",
",",
"extension",
"# Check if the current node is self enclosing. Self enclosing nodes",
"# do not have any child elements",
"if",
"node",
"[",
"@options",
"]",
"[",
":self_enclosing",
"]",
"# If the tag is self enclosing, it cannot have any child elements.",
"buffer_freeze",
"'>'",
"# Pretty print",
"buffer_freeze",
"\"\\n\"",
"if",
"@settings",
"[",
":pretty",
"]",
"# If we mistakenly add children to self enclosing nodes,",
"# process each child element as if it was correctly indented",
"# node[@children].each do |child|",
"# root child, indent + @settings[:indent]",
"# end",
"else",
"# Set tag ending code",
"buffer_freeze",
"'>'",
"# Pretty print",
"if",
"@settings",
"[",
":pretty",
"]",
"if",
"node",
"[",
"@children",
"]",
".",
"length",
">",
"0",
"buffer_freeze",
"\"\\n\"",
"unless",
"inline",
"end",
"# @sibling_stack << [[node[@type], node[@value]]]",
"end",
"# Process each child element recursively, increasing indentation",
"node",
"[",
"@children",
"]",
".",
"each",
"do",
"|",
"child",
"|",
"root",
"child",
",",
"indent",
"+",
"@settings",
"[",
":indent",
"]",
"end",
"inline_last_child",
"=",
"@sibling_stack",
"[",
"-",
"1",
"]",
"[",
"-",
"2",
"]",
"&&",
"(",
"@sibling_stack",
"[",
"-",
"1",
"]",
"[",
"-",
"2",
"]",
"[",
"0",
"]",
"==",
":plain",
"||",
"Settings",
"::",
"INLINE_NODE",
".",
"include?",
"(",
"@sibling_stack",
"[",
"-",
"1",
"]",
"[",
"-",
"2",
"]",
"[",
"1",
"]",
")",
")",
"# Pretty print",
"if",
"@settings",
"[",
":pretty",
"]",
"if",
"node",
"[",
"@children",
"]",
".",
"length",
">",
"1",
"&&",
"inline_last_child",
"buffer_freeze",
"\"\\n\"",
"end",
"if",
"node",
"[",
"@children",
"]",
".",
"size",
">",
"0",
"&&",
"!",
"inline",
"indentate",
"[",
"]",
"end",
"end",
"# Set tag closing code",
"buffer_freeze",
"\"</#{node[@value]}>\"",
"buffer_freeze",
"' '",
"if",
"node",
"[",
"@options",
"]",
"[",
":trailing_whitespace",
"]",
"# Pretty print",
"if",
"@settings",
"[",
":pretty",
"]",
"buffer_freeze",
"\"\\n\"",
"if",
"!",
"inline",
"||",
"@in_definition",
"end",
"end",
"if",
"@settings",
"[",
":pretty",
"]",
"@sibling_stack",
".",
"pop",
"end",
"end"
] | Generate the code for a standard node element, with closing tags or
self enclosing elements
@param node [Array] Node code generation data
@param indent [Fixnum] Size of the indentation to be added | [
"Generate",
"the",
"code",
"for",
"a",
"standard",
"node",
"element",
"with",
"closing",
"tags",
"or",
"self",
"enclosing",
"elements"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/compiler/node.rb#L11-L123 |
2,952 | ageweke/flex_columns | lib/flex_columns/has_flex_columns.rb | FlexColumns.HasFlexColumns._flex_columns_before_save! | def _flex_columns_before_save!
self.class._all_flex_column_names.each do |flex_column_name|
klass = self.class._flex_column_class_for(flex_column_name)
if klass.requires_serialization_on_save?(self)
_flex_column_object_for(flex_column_name).before_save!
end
end
end | ruby | def _flex_columns_before_save!
self.class._all_flex_column_names.each do |flex_column_name|
klass = self.class._flex_column_class_for(flex_column_name)
if klass.requires_serialization_on_save?(self)
_flex_column_object_for(flex_column_name).before_save!
end
end
end | [
"def",
"_flex_columns_before_save!",
"self",
".",
"class",
".",
"_all_flex_column_names",
".",
"each",
"do",
"|",
"flex_column_name",
"|",
"klass",
"=",
"self",
".",
"class",
".",
"_flex_column_class_for",
"(",
"flex_column_name",
")",
"if",
"klass",
".",
"requires_serialization_on_save?",
"(",
"self",
")",
"_flex_column_object_for",
"(",
"flex_column_name",
")",
".",
"before_save!",
"end",
"end",
"end"
] | Before we save this model, make sure each flex column has a chance to serialize itself up and assign itself
properly to this model object. Note that we only need to call through to flex-column objects that have actually
been instantiated, since, by definition, there's no way the contents of any other flex columns could possibly
have been changed. | [
"Before",
"we",
"save",
"this",
"model",
"make",
"sure",
"each",
"flex",
"column",
"has",
"a",
"chance",
"to",
"serialize",
"itself",
"up",
"and",
"assign",
"itself",
"properly",
"to",
"this",
"model",
"object",
".",
"Note",
"that",
"we",
"only",
"need",
"to",
"call",
"through",
"to",
"flex",
"-",
"column",
"objects",
"that",
"have",
"actually",
"been",
"instantiated",
"since",
"by",
"definition",
"there",
"s",
"no",
"way",
"the",
"contents",
"of",
"any",
"other",
"flex",
"columns",
"could",
"possibly",
"have",
"been",
"changed",
"."
] | 3870086352ac1a0342e96e86c403c4870fea9d6f | https://github.com/ageweke/flex_columns/blob/3870086352ac1a0342e96e86c403c4870fea9d6f/lib/flex_columns/has_flex_columns.rb#L30-L37 |
2,953 | ageweke/flex_columns | lib/flex_columns/has_flex_columns.rb | FlexColumns.HasFlexColumns._flex_column_owned_object_for | def _flex_column_owned_object_for(column_name, create_if_needed = true)
column_name = self.class._flex_column_normalize_name(column_name)
out = _flex_column_objects[column_name]
if (! out) && create_if_needed
out = _flex_column_objects[column_name] = self.class._flex_column_class_for(column_name).new(self)
end
out
end | ruby | def _flex_column_owned_object_for(column_name, create_if_needed = true)
column_name = self.class._flex_column_normalize_name(column_name)
out = _flex_column_objects[column_name]
if (! out) && create_if_needed
out = _flex_column_objects[column_name] = self.class._flex_column_class_for(column_name).new(self)
end
out
end | [
"def",
"_flex_column_owned_object_for",
"(",
"column_name",
",",
"create_if_needed",
"=",
"true",
")",
"column_name",
"=",
"self",
".",
"class",
".",
"_flex_column_normalize_name",
"(",
"column_name",
")",
"out",
"=",
"_flex_column_objects",
"[",
"column_name",
"]",
"if",
"(",
"!",
"out",
")",
"&&",
"create_if_needed",
"out",
"=",
"_flex_column_objects",
"[",
"column_name",
"]",
"=",
"self",
".",
"class",
".",
"_flex_column_class_for",
"(",
"column_name",
")",
".",
"new",
"(",
"self",
")",
"end",
"out",
"end"
] | Returns the correct flex-column object for the given column name. This simply creates an instance of the
appropriate flex-column class, and saves it away so it will be returned again if someone requests the object for
the same column later.
This method almost never gets invoked directly; instead, everything calls it via
FlexColumns::ActiveRecord::Base#_flex_column_object_for. | [
"Returns",
"the",
"correct",
"flex",
"-",
"column",
"object",
"for",
"the",
"given",
"column",
"name",
".",
"This",
"simply",
"creates",
"an",
"instance",
"of",
"the",
"appropriate",
"flex",
"-",
"column",
"class",
"and",
"saves",
"it",
"away",
"so",
"it",
"will",
"be",
"returned",
"again",
"if",
"someone",
"requests",
"the",
"object",
"for",
"the",
"same",
"column",
"later",
"."
] | 3870086352ac1a0342e96e86c403c4870fea9d6f | https://github.com/ageweke/flex_columns/blob/3870086352ac1a0342e96e86c403c4870fea9d6f/lib/flex_columns/has_flex_columns.rb#L55-L63 |
2,954 | opulent/opulent | lib/opulent/parser/define.rb | Opulent.Parser.define | def define(parent, indent)
return unless accept(:def)
# Definition parent check
Logger.error :parse, @code, @i, @j, :definition if parent[@type] != :root
# Process data
name = accept(:node, :*).to_sym
# Create node
definition = [
:def,
name,
{ parameters: attributes({}, true) },
[],
indent
]
# Set definition as root node and let the parser know that we're inside
# a definition. This is used because inside definitions we do not
# process nodes (we do not check if they are have a definition or not).
root definition, indent
# Add to parent
@definitions[name] = definition
end | ruby | def define(parent, indent)
return unless accept(:def)
# Definition parent check
Logger.error :parse, @code, @i, @j, :definition if parent[@type] != :root
# Process data
name = accept(:node, :*).to_sym
# Create node
definition = [
:def,
name,
{ parameters: attributes({}, true) },
[],
indent
]
# Set definition as root node and let the parser know that we're inside
# a definition. This is used because inside definitions we do not
# process nodes (we do not check if they are have a definition or not).
root definition, indent
# Add to parent
@definitions[name] = definition
end | [
"def",
"define",
"(",
"parent",
",",
"indent",
")",
"return",
"unless",
"accept",
"(",
":def",
")",
"# Definition parent check",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":definition",
"if",
"parent",
"[",
"@type",
"]",
"!=",
":root",
"# Process data",
"name",
"=",
"accept",
"(",
":node",
",",
":*",
")",
".",
"to_sym",
"# Create node",
"definition",
"=",
"[",
":def",
",",
"name",
",",
"{",
"parameters",
":",
"attributes",
"(",
"{",
"}",
",",
"true",
")",
"}",
",",
"[",
"]",
",",
"indent",
"]",
"# Set definition as root node and let the parser know that we're inside",
"# a definition. This is used because inside definitions we do not",
"# process nodes (we do not check if they are have a definition or not).",
"root",
"definition",
",",
"indent",
"# Add to parent",
"@definitions",
"[",
"name",
"]",
"=",
"definition",
"end"
] | Check if we match a new node definition to use within our page.
Definitions will not be recursive because, by the time we parse
the definition children, the definition itself is not in the
knowledgebase yet.
However, we may use previously defined nodes inside new definitions,
due to the fact that they are known at parse time.
@param nodes [Array] Parent node to which we append to | [
"Check",
"if",
"we",
"match",
"a",
"new",
"node",
"definition",
"to",
"use",
"within",
"our",
"page",
"."
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/define.rb#L16-L41 |
2,955 | kjvarga/ajax | lib/rack-ajax.rb | Rack.Ajax.encode_env | def encode_env(env)
env = env.dup
env.keep_if { |k, v| k =~ /[A-Z]/ }
env.to_yaml(:Encoding => :Utf8)
end | ruby | def encode_env(env)
env = env.dup
env.keep_if { |k, v| k =~ /[A-Z]/ }
env.to_yaml(:Encoding => :Utf8)
end | [
"def",
"encode_env",
"(",
"env",
")",
"env",
"=",
"env",
".",
"dup",
"env",
".",
"keep_if",
"{",
"|",
"k",
",",
"v",
"|",
"k",
"=~",
"/",
"/",
"}",
"env",
".",
"to_yaml",
"(",
":Encoding",
"=>",
":Utf8",
")",
"end"
] | Convert the environment hash to yaml so it can be unserialized later | [
"Convert",
"the",
"environment",
"hash",
"to",
"yaml",
"so",
"it",
"can",
"be",
"unserialized",
"later"
] | e60acbc51855cd85b4907d509ea41fe0965ce72e | https://github.com/kjvarga/ajax/blob/e60acbc51855cd85b4907d509ea41fe0965ce72e/lib/rack-ajax.rb#L63-L67 |
2,956 | cottonwoodcoding/repack | lib/repack/helper.rb | Repack.Helper.webpack_asset_paths | def webpack_asset_paths(source, extension: nil)
return "" unless source.present?
paths = Repack::Manifest.asset_paths(source)
paths = paths.select {|p| p.ends_with? ".#{extension}" } if extension
host = ::Rails.configuration.repack.dev_server.host
port = ::Rails.configuration.repack.dev_server.port
if ::Rails.configuration.repack.dev_server.enabled
paths.map! do |p|
"//#{host}:#{port}#{p}"
end
end
paths
end | ruby | def webpack_asset_paths(source, extension: nil)
return "" unless source.present?
paths = Repack::Manifest.asset_paths(source)
paths = paths.select {|p| p.ends_with? ".#{extension}" } if extension
host = ::Rails.configuration.repack.dev_server.host
port = ::Rails.configuration.repack.dev_server.port
if ::Rails.configuration.repack.dev_server.enabled
paths.map! do |p|
"//#{host}:#{port}#{p}"
end
end
paths
end | [
"def",
"webpack_asset_paths",
"(",
"source",
",",
"extension",
":",
"nil",
")",
"return",
"\"\"",
"unless",
"source",
".",
"present?",
"paths",
"=",
"Repack",
"::",
"Manifest",
".",
"asset_paths",
"(",
"source",
")",
"paths",
"=",
"paths",
".",
"select",
"{",
"|",
"p",
"|",
"p",
".",
"ends_with?",
"\".#{extension}\"",
"}",
"if",
"extension",
"host",
"=",
"::",
"Rails",
".",
"configuration",
".",
"repack",
".",
"dev_server",
".",
"host",
"port",
"=",
"::",
"Rails",
".",
"configuration",
".",
"repack",
".",
"dev_server",
".",
"port",
"if",
"::",
"Rails",
".",
"configuration",
".",
"repack",
".",
"dev_server",
".",
"enabled",
"paths",
".",
"map!",
"do",
"|",
"p",
"|",
"\"//#{host}:#{port}#{p}\"",
"end",
"end",
"paths",
"end"
] | Return asset paths for a particular webpack entry point.
Response may either be full URLs (eg http://localhost/...) if the dev server
is in use or a host-relative URl (eg /webpack/...) if assets are precompiled.
Will raise an error if our manifest can't be found or the entry point does
not exist. | [
"Return",
"asset",
"paths",
"for",
"a",
"particular",
"webpack",
"entry",
"point",
"."
] | a1d05799502779afdc97970cc6e79a2b2e8695fd | https://github.com/cottonwoodcoding/repack/blob/a1d05799502779afdc97970cc6e79a2b2e8695fd/lib/repack/helper.rb#L14-L30 |
2,957 | 3ofcoins/chef-helpers | lib/chef-helpers/has_source.rb | ChefHelpers.HasSource.has_source? | def has_source?(source, segment, cookbook=nil)
cookbook ||= cookbook_name
begin
run_context.cookbook_collection[cookbook].
send(:find_preferred_manifest_record, run_context.node, segment, source)
rescue Chef::Exceptions::FileNotFound
nil
end
end | ruby | def has_source?(source, segment, cookbook=nil)
cookbook ||= cookbook_name
begin
run_context.cookbook_collection[cookbook].
send(:find_preferred_manifest_record, run_context.node, segment, source)
rescue Chef::Exceptions::FileNotFound
nil
end
end | [
"def",
"has_source?",
"(",
"source",
",",
"segment",
",",
"cookbook",
"=",
"nil",
")",
"cookbook",
"||=",
"cookbook_name",
"begin",
"run_context",
".",
"cookbook_collection",
"[",
"cookbook",
"]",
".",
"send",
"(",
":find_preferred_manifest_record",
",",
"run_context",
".",
"node",
",",
"segment",
",",
"source",
")",
"rescue",
"Chef",
"::",
"Exceptions",
"::",
"FileNotFound",
"nil",
"end",
"end"
] | Checks for existence of a cookbook file or template source in a cookbook.
@param [String] source name of the desired template or cookbook file source
@param [Symbol] segment `:files` or `:templates`
@param [String, nil] cookbook to look in, defaults to current cookbook
@return [String, nil] full path to the source or `nil` if it doesn't exist
@example
has_source?("foo.erb", :templates)
has_source?("bar.conf", :files, "a_cookbook") | [
"Checks",
"for",
"existence",
"of",
"a",
"cookbook",
"file",
"or",
"template",
"source",
"in",
"a",
"cookbook",
"."
] | 6d784d53751528c28b8c6e5c69c206740d22ada0 | https://github.com/3ofcoins/chef-helpers/blob/6d784d53751528c28b8c6e5c69c206740d22ada0/lib/chef-helpers/has_source.rb#L16-L24 |
2,958 | chadrem/tribe | lib/tribe/actable.rb | Tribe.Actable.process_events | def process_events
while (event = @_actable.mailbox.obtain_and_shift)
event_handler(event)
end
rescue Exception => exception
cleanup_handler(exception)
exception_handler(exception)
ensure
@_actable.mailbox.release do
process_events
end
nil
end | ruby | def process_events
while (event = @_actable.mailbox.obtain_and_shift)
event_handler(event)
end
rescue Exception => exception
cleanup_handler(exception)
exception_handler(exception)
ensure
@_actable.mailbox.release do
process_events
end
nil
end | [
"def",
"process_events",
"while",
"(",
"event",
"=",
"@_actable",
".",
"mailbox",
".",
"obtain_and_shift",
")",
"event_handler",
"(",
"event",
")",
"end",
"rescue",
"Exception",
"=>",
"exception",
"cleanup_handler",
"(",
"exception",
")",
"exception_handler",
"(",
"exception",
")",
"ensure",
"@_actable",
".",
"mailbox",
".",
"release",
"do",
"process_events",
"end",
"nil",
"end"
] | All system commands are prefixed with an underscore. | [
"All",
"system",
"commands",
"are",
"prefixed",
"with",
"an",
"underscore",
"."
] | 7cca0c3f66c710b4f361f8a371b6d126b22d7f6a | https://github.com/chadrem/tribe/blob/7cca0c3f66c710b4f361f8a371b6d126b22d7f6a/lib/tribe/actable.rb#L157-L171 |
2,959 | opulent/opulent | lib/opulent/context.rb | Opulent.Context.evaluate | def evaluate(code, &block)
begin
eval code, @binding, &block
rescue NameError => variable
Compiler.error :binding, variable, code
end
end | ruby | def evaluate(code, &block)
begin
eval code, @binding, &block
rescue NameError => variable
Compiler.error :binding, variable, code
end
end | [
"def",
"evaluate",
"(",
"code",
",",
"&",
"block",
")",
"begin",
"eval",
"code",
",",
"@binding",
",",
"block",
"rescue",
"NameError",
"=>",
"variable",
"Compiler",
".",
"error",
":binding",
",",
"variable",
",",
"code",
"end",
"end"
] | Create a context from the environment binding, extended with the locals
given as arguments
@param locals [Hash] Binding extension
@param block [Binding] Call environment block
@param content [Binding] Content yielding
Evaluate ruby code in current context
@param code [String] Code to be evaluated | [
"Create",
"a",
"context",
"from",
"the",
"environment",
"binding",
"extended",
"with",
"the",
"locals",
"given",
"as",
"arguments"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/context.rb#L36-L42 |
2,960 | opulent/opulent | lib/opulent/context.rb | Opulent.Context.extend_locals | def extend_locals(locals)
# Create new local variables from the input hash
locals.each do |key, value|
begin
@binding.local_variable_set key.to_sym, value
rescue NameError => variable
Compiler.error :variable_name, variable, key
end
end
end | ruby | def extend_locals(locals)
# Create new local variables from the input hash
locals.each do |key, value|
begin
@binding.local_variable_set key.to_sym, value
rescue NameError => variable
Compiler.error :variable_name, variable, key
end
end
end | [
"def",
"extend_locals",
"(",
"locals",
")",
"# Create new local variables from the input hash",
"locals",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"begin",
"@binding",
".",
"local_variable_set",
"key",
".",
"to_sym",
",",
"value",
"rescue",
"NameError",
"=>",
"variable",
"Compiler",
".",
"error",
":variable_name",
",",
"variable",
",",
"key",
"end",
"end",
"end"
] | Extend the call context with a Hash, String or other Object
@param context [Object] Extension object | [
"Extend",
"the",
"call",
"context",
"with",
"a",
"Hash",
"String",
"or",
"other",
"Object"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/context.rb#L54-L63 |
2,961 | opulent/opulent | lib/opulent/context.rb | Opulent.Context.extend_nonlocals | def extend_nonlocals(bind)
bind.eval('instance_variables').each do |var|
@binding.eval('self').instance_variable_set var, bind.eval(var.to_s)
end
bind.eval('self.class.class_variables').each do |var|
@binding.eval('self').class_variable_set var, bind.eval(var.to_s)
end
end | ruby | def extend_nonlocals(bind)
bind.eval('instance_variables').each do |var|
@binding.eval('self').instance_variable_set var, bind.eval(var.to_s)
end
bind.eval('self.class.class_variables').each do |var|
@binding.eval('self').class_variable_set var, bind.eval(var.to_s)
end
end | [
"def",
"extend_nonlocals",
"(",
"bind",
")",
"bind",
".",
"eval",
"(",
"'instance_variables'",
")",
".",
"each",
"do",
"|",
"var",
"|",
"@binding",
".",
"eval",
"(",
"'self'",
")",
".",
"instance_variable_set",
"var",
",",
"bind",
".",
"eval",
"(",
"var",
".",
"to_s",
")",
"end",
"bind",
".",
"eval",
"(",
"'self.class.class_variables'",
")",
".",
"each",
"do",
"|",
"var",
"|",
"@binding",
".",
"eval",
"(",
"'self'",
")",
".",
"class_variable_set",
"var",
",",
"bind",
".",
"eval",
"(",
"var",
".",
"to_s",
")",
"end",
"end"
] | Extend instance, class and global variables for use in definitions
@param bind [Binding] Binding to extend current context binding | [
"Extend",
"instance",
"class",
"and",
"global",
"variables",
"for",
"use",
"in",
"definitions"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/context.rb#L69-L77 |
2,962 | Yellowen/Faalis | lib/faalis/dashboard/dsl/index.rb | Faalis::Dashboard::DSL.Index.attributes | def attributes(*fields_name, **options, &block)
if options.include? :except
@fields = resolve_model_reflections.reject do |field|
options[:except].include? field.to_sym
end
elsif options.include? :append
@fields += options[:append]
else
# set new value for fields
@fields = fields_name.map(&:to_s) unless fields_name.empty?
end
@fields.concat(block.call.map(&:to_s)) if block_given?
end | ruby | def attributes(*fields_name, **options, &block)
if options.include? :except
@fields = resolve_model_reflections.reject do |field|
options[:except].include? field.to_sym
end
elsif options.include? :append
@fields += options[:append]
else
# set new value for fields
@fields = fields_name.map(&:to_s) unless fields_name.empty?
end
@fields.concat(block.call.map(&:to_s)) if block_given?
end | [
"def",
"attributes",
"(",
"*",
"fields_name",
",",
"**",
"options",
",",
"&",
"block",
")",
"if",
"options",
".",
"include?",
":except",
"@fields",
"=",
"resolve_model_reflections",
".",
"reject",
"do",
"|",
"field",
"|",
"options",
"[",
":except",
"]",
".",
"include?",
"field",
".",
"to_sym",
"end",
"elsif",
"options",
".",
"include?",
":append",
"@fields",
"+=",
"options",
"[",
":append",
"]",
"else",
"# set new value for fields",
"@fields",
"=",
"fields_name",
".",
"map",
"(",
":to_s",
")",
"unless",
"fields_name",
".",
"empty?",
"end",
"@fields",
".",
"concat",
"(",
"block",
".",
"call",
".",
"map",
"(",
":to_s",
")",
")",
"if",
"block_given?",
"end"
] | Allow user to specify an array of model attributes to be used
in respected section. For example attributes to show as header
columns in index section | [
"Allow",
"user",
"to",
"specify",
"an",
"array",
"of",
"model",
"attributes",
"to",
"be",
"used",
"in",
"respected",
"section",
".",
"For",
"example",
"attributes",
"to",
"show",
"as",
"header",
"columns",
"in",
"index",
"section"
] | d12abdb8559dabbf6b2044e3ba437038527039b2 | https://github.com/Yellowen/Faalis/blob/d12abdb8559dabbf6b2044e3ba437038527039b2/lib/faalis/dashboard/dsl/index.rb#L10-L23 |
2,963 | Yellowen/Faalis | lib/faalis/dashboard/sections/resources_index.rb | Faalis::Dashboard::Sections.ResourcesIndex.fetch_index_objects | def fetch_index_objects
scope = index_properties.default_scope
puts "<<<<<<<" * 100, scope
if !scope.nil?
# If user provided an scope for `index` section.
if scope.respond_to? :call
# If scope provided by a block
scope = scope.call
else
# If scope provided by a symbol
# which should be a method name
scope = self.send(scope)
end
else
scope = model.all
#scope = ApplicationPolicy::Scope.new(current_user, model.all).resolve
end
scope = scope.order('created_at DESC').page(params[:page])
policy_scope(scope)
end | ruby | def fetch_index_objects
scope = index_properties.default_scope
puts "<<<<<<<" * 100, scope
if !scope.nil?
# If user provided an scope for `index` section.
if scope.respond_to? :call
# If scope provided by a block
scope = scope.call
else
# If scope provided by a symbol
# which should be a method name
scope = self.send(scope)
end
else
scope = model.all
#scope = ApplicationPolicy::Scope.new(current_user, model.all).resolve
end
scope = scope.order('created_at DESC').page(params[:page])
policy_scope(scope)
end | [
"def",
"fetch_index_objects",
"scope",
"=",
"index_properties",
".",
"default_scope",
"puts",
"\"<<<<<<<\"",
"*",
"100",
",",
"scope",
"if",
"!",
"scope",
".",
"nil?",
"# If user provided an scope for `index` section.",
"if",
"scope",
".",
"respond_to?",
":call",
"# If scope provided by a block",
"scope",
"=",
"scope",
".",
"call",
"else",
"# If scope provided by a symbol",
"# which should be a method name",
"scope",
"=",
"self",
".",
"send",
"(",
"scope",
")",
"end",
"else",
"scope",
"=",
"model",
".",
"all",
"#scope = ApplicationPolicy::Scope.new(current_user, model.all).resolve",
"end",
"scope",
"=",
"scope",
".",
"order",
"(",
"'created_at DESC'",
")",
".",
"page",
"(",
"params",
"[",
":page",
"]",
")",
"policy_scope",
"(",
"scope",
")",
"end"
] | Fetch all or part of the corresponding resource
from data base with respect to `scope` DSL.
The important thing here is that by using `scope`
DSL this method will chain the resulted scope
with other scopes like `page` and `policy_scope` | [
"Fetch",
"all",
"or",
"part",
"of",
"the",
"corresponding",
"resource",
"from",
"data",
"base",
"with",
"respect",
"to",
"scope",
"DSL",
"."
] | d12abdb8559dabbf6b2044e3ba437038527039b2 | https://github.com/Yellowen/Faalis/blob/d12abdb8559dabbf6b2044e3ba437038527039b2/lib/faalis/dashboard/sections/resources_index.rb#L29-L53 |
2,964 | vjt/sanitize-rails | lib/sanitize/rails/matchers.rb | Sanitize::Rails::Matchers.SanitizeFieldsMatcher.matches? | def matches?(instance)
self.instance = instance
# assign invalid value to each field
fields.each { |field| instance.send("#{field}=", invalid_value) }
# sanitize the object calling the method
instance.send(sanitizer) rescue nil
# check expectation on results
fields.all? { |field| valid_value == instance.send(field) }
end | ruby | def matches?(instance)
self.instance = instance
# assign invalid value to each field
fields.each { |field| instance.send("#{field}=", invalid_value) }
# sanitize the object calling the method
instance.send(sanitizer) rescue nil
# check expectation on results
fields.all? { |field| valid_value == instance.send(field) }
end | [
"def",
"matches?",
"(",
"instance",
")",
"self",
".",
"instance",
"=",
"instance",
"# assign invalid value to each field",
"fields",
".",
"each",
"{",
"|",
"field",
"|",
"instance",
".",
"send",
"(",
"\"#{field}=\"",
",",
"invalid_value",
")",
"}",
"# sanitize the object calling the method",
"instance",
".",
"send",
"(",
"sanitizer",
")",
"rescue",
"nil",
"# check expectation on results",
"fields",
".",
"all?",
"{",
"|",
"field",
"|",
"valid_value",
"==",
"instance",
".",
"send",
"(",
"field",
")",
"}",
"end"
] | Actual match code | [
"Actual",
"match",
"code"
] | 85541b447427347b59f1c3b584cffcecbc884476 | https://github.com/vjt/sanitize-rails/blob/85541b447427347b59f1c3b584cffcecbc884476/lib/sanitize/rails/matchers.rb#L84-L92 |
2,965 | opulent/opulent | lib/opulent/parser/control.rb | Opulent.Parser.control | def control(parent, indent)
# Accept eval or multiline eval syntax and return a new node,
return unless (structure = accept(:control))
structure = structure.to_sym
# Handle each and the other control structures
condition = accept(:line_feed).strip
# Process each control structure condition
if structure == :each
# Check if arguments provided correctly
unless condition.match Tokens[:each_pattern]
Logger.error :parse, @code, @i, @j, :each_arguments
end
# Conditions for each iterator
condition = [
Regexp.last_match[1].split(' '),
Regexp.last_match[2].split(/,(.+)$/).map(&:strip).map(&:to_sym)
]
# Array loop as default
condition[0].unshift '{}' if condition[0].length == 1
end
# Else and default structures are not allowed to have any condition
# set and the other control structures require a condition
if structure == :else
unless condition.empty?
Logger.error :parse, @code, @i, @j, :condition_exists
end
else
if condition.empty?
Logger.error :parse, @code, @i, @j, :condition_missing
end
end
# Add the condition and create a new child to the control parent.
# The control parent keeps condition -> children matches for our
# document's content
# add_options = proc do |control_parent|
# control_parent.value << condition
# control_parent.children << []
#
# root control_parent
# end
# If the current control structure is a parent which allows multiple
# branches, such as an if or case, we create an array of conditions
# which can be matched and an array of children belonging to each
# conditional branch
if [:if, :unless].include? structure
# Create the control structure and get its child nodes
control_structure = [structure, [condition], {}, [], indent]
root control_structure, indent
# Turn children into an array because we allow multiple branches
control_structure[@children] = [control_structure[@children]]
# Add it to the parent node
parent[@children] << control_structure
elsif structure == :case
# Create the control structure and get its child nodes
control_structure = [
structure,
[],
{ condition: condition },
[],
indent
]
# Add it to the parent node
parent[@children] << control_structure
# If the control structure is a child structure, we need to find the
# node it belongs to amont the current parent. Search from end to
# beginning until we find the node parent
elsif control_child structure
# During the search, we try to find the matching parent type
unless control_parent(structure).include? parent[@children][-1][@type]
Logger.error :parse,
@code,
@i,
@j,
:control_child,
control_parent(structure)
end
# Gather child elements for current structure
control_structure = [structure, [condition], {}, [], indent]
root control_structure, indent
# Add the new condition and children to our parent structure
parent[@children][-1][@value] << condition
parent[@children][-1][@children] << control_structure[@children]
# When our control structure isn't a complex composite, we create
# it the same way as a normal node
else
control_structure = [structure, condition, {}, [], indent]
root control_structure, indent
parent[@children] << control_structure
end
end | ruby | def control(parent, indent)
# Accept eval or multiline eval syntax and return a new node,
return unless (structure = accept(:control))
structure = structure.to_sym
# Handle each and the other control structures
condition = accept(:line_feed).strip
# Process each control structure condition
if structure == :each
# Check if arguments provided correctly
unless condition.match Tokens[:each_pattern]
Logger.error :parse, @code, @i, @j, :each_arguments
end
# Conditions for each iterator
condition = [
Regexp.last_match[1].split(' '),
Regexp.last_match[2].split(/,(.+)$/).map(&:strip).map(&:to_sym)
]
# Array loop as default
condition[0].unshift '{}' if condition[0].length == 1
end
# Else and default structures are not allowed to have any condition
# set and the other control structures require a condition
if structure == :else
unless condition.empty?
Logger.error :parse, @code, @i, @j, :condition_exists
end
else
if condition.empty?
Logger.error :parse, @code, @i, @j, :condition_missing
end
end
# Add the condition and create a new child to the control parent.
# The control parent keeps condition -> children matches for our
# document's content
# add_options = proc do |control_parent|
# control_parent.value << condition
# control_parent.children << []
#
# root control_parent
# end
# If the current control structure is a parent which allows multiple
# branches, such as an if or case, we create an array of conditions
# which can be matched and an array of children belonging to each
# conditional branch
if [:if, :unless].include? structure
# Create the control structure and get its child nodes
control_structure = [structure, [condition], {}, [], indent]
root control_structure, indent
# Turn children into an array because we allow multiple branches
control_structure[@children] = [control_structure[@children]]
# Add it to the parent node
parent[@children] << control_structure
elsif structure == :case
# Create the control structure and get its child nodes
control_structure = [
structure,
[],
{ condition: condition },
[],
indent
]
# Add it to the parent node
parent[@children] << control_structure
# If the control structure is a child structure, we need to find the
# node it belongs to amont the current parent. Search from end to
# beginning until we find the node parent
elsif control_child structure
# During the search, we try to find the matching parent type
unless control_parent(structure).include? parent[@children][-1][@type]
Logger.error :parse,
@code,
@i,
@j,
:control_child,
control_parent(structure)
end
# Gather child elements for current structure
control_structure = [structure, [condition], {}, [], indent]
root control_structure, indent
# Add the new condition and children to our parent structure
parent[@children][-1][@value] << condition
parent[@children][-1][@children] << control_structure[@children]
# When our control structure isn't a complex composite, we create
# it the same way as a normal node
else
control_structure = [structure, condition, {}, [], indent]
root control_structure, indent
parent[@children] << control_structure
end
end | [
"def",
"control",
"(",
"parent",
",",
"indent",
")",
"# Accept eval or multiline eval syntax and return a new node,",
"return",
"unless",
"(",
"structure",
"=",
"accept",
"(",
":control",
")",
")",
"structure",
"=",
"structure",
".",
"to_sym",
"# Handle each and the other control structures",
"condition",
"=",
"accept",
"(",
":line_feed",
")",
".",
"strip",
"# Process each control structure condition",
"if",
"structure",
"==",
":each",
"# Check if arguments provided correctly",
"unless",
"condition",
".",
"match",
"Tokens",
"[",
":each_pattern",
"]",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":each_arguments",
"end",
"# Conditions for each iterator",
"condition",
"=",
"[",
"Regexp",
".",
"last_match",
"[",
"1",
"]",
".",
"split",
"(",
"' '",
")",
",",
"Regexp",
".",
"last_match",
"[",
"2",
"]",
".",
"split",
"(",
"/",
"/",
")",
".",
"map",
"(",
":strip",
")",
".",
"map",
"(",
":to_sym",
")",
"]",
"# Array loop as default",
"condition",
"[",
"0",
"]",
".",
"unshift",
"'{}'",
"if",
"condition",
"[",
"0",
"]",
".",
"length",
"==",
"1",
"end",
"# Else and default structures are not allowed to have any condition",
"# set and the other control structures require a condition",
"if",
"structure",
"==",
":else",
"unless",
"condition",
".",
"empty?",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":condition_exists",
"end",
"else",
"if",
"condition",
".",
"empty?",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":condition_missing",
"end",
"end",
"# Add the condition and create a new child to the control parent.",
"# The control parent keeps condition -> children matches for our",
"# document's content",
"# add_options = proc do |control_parent|",
"# control_parent.value << condition",
"# control_parent.children << []",
"#",
"# root control_parent",
"# end",
"# If the current control structure is a parent which allows multiple",
"# branches, such as an if or case, we create an array of conditions",
"# which can be matched and an array of children belonging to each",
"# conditional branch",
"if",
"[",
":if",
",",
":unless",
"]",
".",
"include?",
"structure",
"# Create the control structure and get its child nodes",
"control_structure",
"=",
"[",
"structure",
",",
"[",
"condition",
"]",
",",
"{",
"}",
",",
"[",
"]",
",",
"indent",
"]",
"root",
"control_structure",
",",
"indent",
"# Turn children into an array because we allow multiple branches",
"control_structure",
"[",
"@children",
"]",
"=",
"[",
"control_structure",
"[",
"@children",
"]",
"]",
"# Add it to the parent node",
"parent",
"[",
"@children",
"]",
"<<",
"control_structure",
"elsif",
"structure",
"==",
":case",
"# Create the control structure and get its child nodes",
"control_structure",
"=",
"[",
"structure",
",",
"[",
"]",
",",
"{",
"condition",
":",
"condition",
"}",
",",
"[",
"]",
",",
"indent",
"]",
"# Add it to the parent node",
"parent",
"[",
"@children",
"]",
"<<",
"control_structure",
"# If the control structure is a child structure, we need to find the",
"# node it belongs to amont the current parent. Search from end to",
"# beginning until we find the node parent",
"elsif",
"control_child",
"structure",
"# During the search, we try to find the matching parent type",
"unless",
"control_parent",
"(",
"structure",
")",
".",
"include?",
"parent",
"[",
"@children",
"]",
"[",
"-",
"1",
"]",
"[",
"@type",
"]",
"Logger",
".",
"error",
":parse",
",",
"@code",
",",
"@i",
",",
"@j",
",",
":control_child",
",",
"control_parent",
"(",
"structure",
")",
"end",
"# Gather child elements for current structure",
"control_structure",
"=",
"[",
"structure",
",",
"[",
"condition",
"]",
",",
"{",
"}",
",",
"[",
"]",
",",
"indent",
"]",
"root",
"control_structure",
",",
"indent",
"# Add the new condition and children to our parent structure",
"parent",
"[",
"@children",
"]",
"[",
"-",
"1",
"]",
"[",
"@value",
"]",
"<<",
"condition",
"parent",
"[",
"@children",
"]",
"[",
"-",
"1",
"]",
"[",
"@children",
"]",
"<<",
"control_structure",
"[",
"@children",
"]",
"# When our control structure isn't a complex composite, we create",
"# it the same way as a normal node",
"else",
"control_structure",
"=",
"[",
"structure",
",",
"condition",
",",
"{",
"}",
",",
"[",
"]",
",",
"indent",
"]",
"root",
"control_structure",
",",
"indent",
"parent",
"[",
"@children",
"]",
"<<",
"control_structure",
"end",
"end"
] | Match an if-else control structure | [
"Match",
"an",
"if",
"-",
"else",
"control",
"structure"
] | 7b219bd4f54b404e8f43955b8e70925a01814b59 | https://github.com/opulent/opulent/blob/7b219bd4f54b404e8f43955b8e70925a01814b59/lib/opulent/parser/control.rb#L7-L112 |
2,966 | taganaka/polipus | lib/polipus/robotex.rb | Polipus.Robotex.delay! | def delay!(uri)
delay = delay(uri)
sleep delay - (Time.now - @last_accessed) if delay
@last_accessed = Time.now
end | ruby | def delay!(uri)
delay = delay(uri)
sleep delay - (Time.now - @last_accessed) if delay
@last_accessed = Time.now
end | [
"def",
"delay!",
"(",
"uri",
")",
"delay",
"=",
"delay",
"(",
"uri",
")",
"sleep",
"delay",
"-",
"(",
"Time",
".",
"now",
"-",
"@last_accessed",
")",
"if",
"delay",
"@last_accessed",
"=",
"Time",
".",
"now",
"end"
] | Sleep for the amount of time necessary to obey the Crawl-Delay specified by the server | [
"Sleep",
"for",
"the",
"amount",
"of",
"time",
"necessary",
"to",
"obey",
"the",
"Crawl",
"-",
"Delay",
"specified",
"by",
"the",
"server"
] | 8917a37c151a8e36fcc49fb5461aaeaf97f1f5a6 | https://github.com/taganaka/polipus/blob/8917a37c151a8e36fcc49fb5461aaeaf97f1f5a6/lib/polipus/robotex.rb#L139-L143 |
2,967 | Yellowen/Faalis | app/helpers/faalis/dashboard_helper.rb | Faalis.DashboardHelper.get_url | def get_url(route_name, id = nil, engine = Rails.application)
return route_name.call if id.nil?
return route_name.call(id) unless id.nil?
end | ruby | def get_url(route_name, id = nil, engine = Rails.application)
return route_name.call if id.nil?
return route_name.call(id) unless id.nil?
end | [
"def",
"get_url",
"(",
"route_name",
",",
"id",
"=",
"nil",
",",
"engine",
"=",
"Rails",
".",
"application",
")",
"return",
"route_name",
".",
"call",
"if",
"id",
".",
"nil?",
"return",
"route_name",
".",
"call",
"(",
"id",
")",
"unless",
"id",
".",
"nil?",
"end"
] | Translate route name to url dynamically | [
"Translate",
"route",
"name",
"to",
"url",
"dynamically"
] | d12abdb8559dabbf6b2044e3ba437038527039b2 | https://github.com/Yellowen/Faalis/blob/d12abdb8559dabbf6b2044e3ba437038527039b2/app/helpers/faalis/dashboard_helper.rb#L59-L62 |
2,968 | hassox/warden_strategies | lib/warden_strategies/simple.rb | WardenStrategies.Simple.authenticate! | def authenticate!
if u = user_class.send(config[:authenticate_method], *required_param_values)
success!(u)
else
fail!(config[:error_message])
end
end | ruby | def authenticate!
if u = user_class.send(config[:authenticate_method], *required_param_values)
success!(u)
else
fail!(config[:error_message])
end
end | [
"def",
"authenticate!",
"if",
"u",
"=",
"user_class",
".",
"send",
"(",
"config",
"[",
":authenticate_method",
"]",
",",
"required_param_values",
")",
"success!",
"(",
"u",
")",
"else",
"fail!",
"(",
"config",
"[",
":error_message",
"]",
")",
"end",
"end"
] | The workhorse. Will pass all requred_param_values to the configured authenticate_method
@see WardenStrategies::Simple.config
@see Warden::Strategy::Base#authenticate!
@api private | [
"The",
"workhorse",
".",
"Will",
"pass",
"all",
"requred_param_values",
"to",
"the",
"configured",
"authenticate_method"
] | 8d249132c56d519c19adc92fbac0553456375cc9 | https://github.com/hassox/warden_strategies/blob/8d249132c56d519c19adc92fbac0553456375cc9/lib/warden_strategies/simple.rb#L101-L107 |
2,969 | myfreecomm/charging-client-ruby | lib/charging/invoice.rb | Charging.Invoice.create! | def create!
super do
raise 'can not create without a domain' if invalid_domain?
raise 'can not create wihtout a charge account' if invalid_charge_account?
Invoice.post_charge_accounts_invoices(domain, charge_account, attributes)
end
reload_attributes!(Helpers.extract_uuid(last_response.headers[:location]) || uuid)
end | ruby | def create!
super do
raise 'can not create without a domain' if invalid_domain?
raise 'can not create wihtout a charge account' if invalid_charge_account?
Invoice.post_charge_accounts_invoices(domain, charge_account, attributes)
end
reload_attributes!(Helpers.extract_uuid(last_response.headers[:location]) || uuid)
end | [
"def",
"create!",
"super",
"do",
"raise",
"'can not create without a domain'",
"if",
"invalid_domain?",
"raise",
"'can not create wihtout a charge account'",
"if",
"invalid_charge_account?",
"Invoice",
".",
"post_charge_accounts_invoices",
"(",
"domain",
",",
"charge_account",
",",
"attributes",
")",
"end",
"reload_attributes!",
"(",
"Helpers",
".",
"extract_uuid",
"(",
"last_response",
".",
"headers",
"[",
":location",
"]",
")",
"||",
"uuid",
")",
"end"
] | Creates current invoice at API.
API method: <tt>POST /charge-accounts/:uuid/invoices/</tt>
API documentation: https://charging.financeconnect.com.br/static/docs/charges.html#post-charge-accounts-uuid-invoices | [
"Creates",
"current",
"invoice",
"at",
"API",
"."
] | d2b164a3536a8c5faa8656c8477b399b22181e7f | https://github.com/myfreecomm/charging-client-ruby/blob/d2b164a3536a8c5faa8656c8477b399b22181e7f/lib/charging/invoice.rb#L28-L37 |
2,970 | myfreecomm/charging-client-ruby | lib/charging/invoice.rb | Charging.Invoice.payments | def payments
reset_errors!
response = Http.get("/invoices/#{uuid}/payments/", domain.token)
return [] if response.code != 200
MultiJson.decode(response.body)
end | ruby | def payments
reset_errors!
response = Http.get("/invoices/#{uuid}/payments/", domain.token)
return [] if response.code != 200
MultiJson.decode(response.body)
end | [
"def",
"payments",
"reset_errors!",
"response",
"=",
"Http",
".",
"get",
"(",
"\"/invoices/#{uuid}/payments/\"",
",",
"domain",
".",
"token",
")",
"return",
"[",
"]",
"if",
"response",
".",
"code",
"!=",
"200",
"MultiJson",
".",
"decode",
"(",
"response",
".",
"body",
")",
"end"
] | List all payments for an invoice
API method: <tt>GET /invoices/:uuid/payments/</tt>
API documentation: https://charging.financeconnect.com.br/static/docs/charges.html#get-invoices-uuid-payments | [
"List",
"all",
"payments",
"for",
"an",
"invoice"
] | d2b164a3536a8c5faa8656c8477b399b22181e7f | https://github.com/myfreecomm/charging-client-ruby/blob/d2b164a3536a8c5faa8656c8477b399b22181e7f/lib/charging/invoice.rb#L84-L92 |
2,971 | myfreecomm/charging-client-ruby | lib/charging/invoice.rb | Charging.Invoice.billet_url | def billet_url
return if unpersisted?
response = Http.get("/invoices/#{uuid}/billet/", domain.token)
return if response.code != 200
MultiJson.decode(response.body)["billet"]
rescue
nil
end | ruby | def billet_url
return if unpersisted?
response = Http.get("/invoices/#{uuid}/billet/", domain.token)
return if response.code != 200
MultiJson.decode(response.body)["billet"]
rescue
nil
end | [
"def",
"billet_url",
"return",
"if",
"unpersisted?",
"response",
"=",
"Http",
".",
"get",
"(",
"\"/invoices/#{uuid}/billet/\"",
",",
"domain",
".",
"token",
")",
"return",
"if",
"response",
".",
"code",
"!=",
"200",
"MultiJson",
".",
"decode",
"(",
"response",
".",
"body",
")",
"[",
"\"billet\"",
"]",
"rescue",
"nil",
"end"
] | Returns a String with the temporary URL for print current invoice.
API method: <tt>GET /invoices/:uuid/billet/</tt>
API documentation: https://charging.financeconnect.com.br/static/docs/charges.html#get-invoices-uuid-billet | [
"Returns",
"a",
"String",
"with",
"the",
"temporary",
"URL",
"for",
"print",
"current",
"invoice",
"."
] | d2b164a3536a8c5faa8656c8477b399b22181e7f | https://github.com/myfreecomm/charging-client-ruby/blob/d2b164a3536a8c5faa8656c8477b399b22181e7f/lib/charging/invoice.rb#L99-L109 |
2,972 | myfreecomm/rexpense-client-ruby | lib/rexpense/resources/nested_endpoints/participant.rb | Rexpense::Resources.Participant.participants | def participants(resource_id)
http.get(participants_endpoint(resource_id)) do |response|
Rexpense::Entities::UserCollection.build response
end
end | ruby | def participants(resource_id)
http.get(participants_endpoint(resource_id)) do |response|
Rexpense::Entities::UserCollection.build response
end
end | [
"def",
"participants",
"(",
"resource_id",
")",
"http",
".",
"get",
"(",
"participants_endpoint",
"(",
"resource_id",
")",
")",
"do",
"|",
"response",
"|",
"Rexpense",
"::",
"Entities",
"::",
"UserCollection",
".",
"build",
"response",
"end",
"end"
] | Get resource participants tags
[API]
Method: <tt>GET /api/v1/reimbursements/:id/participants</tt>
Method: <tt>GET /api/v1/expenses/:id/participants</tt>
Method: <tt>GET /api/v1/advancements/:id/participants</tt>
Documentation: http://developers.rexpense.com/api/participants#index
Documentation: http://developers.rexpense.com/api/expense_participants#index
Documentation: http://developers.rexpense.com/api/reimbursement_participants#index | [
"Get",
"resource",
"participants",
"tags"
] | c3a36440876dda29e0747d45807e70b246e99945 | https://github.com/myfreecomm/rexpense-client-ruby/blob/c3a36440876dda29e0747d45807e70b246e99945/lib/rexpense/resources/nested_endpoints/participant.rb#L14-L18 |
2,973 | myfreecomm/charging-client-ruby | lib/charging/charge_account.rb | Charging.ChargeAccount.update_attribute! | def update_attribute!(attribute, value, should_reload_attributes = true)
execute_and_capture_raises_at_errors(204) do
@last_response = Http.patch("/charge-accounts/#{uuid}/", domain.token, etag, attribute => value)
end
reload_attributes! if should_reload_attributes
end | ruby | def update_attribute!(attribute, value, should_reload_attributes = true)
execute_and_capture_raises_at_errors(204) do
@last_response = Http.patch("/charge-accounts/#{uuid}/", domain.token, etag, attribute => value)
end
reload_attributes! if should_reload_attributes
end | [
"def",
"update_attribute!",
"(",
"attribute",
",",
"value",
",",
"should_reload_attributes",
"=",
"true",
")",
"execute_and_capture_raises_at_errors",
"(",
"204",
")",
"do",
"@last_response",
"=",
"Http",
".",
"patch",
"(",
"\"/charge-accounts/#{uuid}/\"",
",",
"domain",
".",
"token",
",",
"etag",
",",
"attribute",
"=>",
"value",
")",
"end",
"reload_attributes!",
"if",
"should_reload_attributes",
"end"
] | Update an attribute on charge account at API.
API method: <tt>PATCH /charge-accounts/:uuid/</tt>
API documentation: https://charging.financeconnect.com.br/static/docs/charges.html#patch-charge-accounts-uuid | [
"Update",
"an",
"attribute",
"on",
"charge",
"account",
"at",
"API",
"."
] | d2b164a3536a8c5faa8656c8477b399b22181e7f | https://github.com/myfreecomm/charging-client-ruby/blob/d2b164a3536a8c5faa8656c8477b399b22181e7f/lib/charging/charge_account.rb#L56-L62 |
2,974 | myfreecomm/rexpense-client-ruby | lib/rexpense/resources/nested_endpoints/membership.rb | Rexpense::Resources.Membership.memberships | def memberships(organization_id)
http.get(membership_endpoint(organization_id)) do |response|
Rexpense::Entities::MembershipCollection.build response
end
end | ruby | def memberships(organization_id)
http.get(membership_endpoint(organization_id)) do |response|
Rexpense::Entities::MembershipCollection.build response
end
end | [
"def",
"memberships",
"(",
"organization_id",
")",
"http",
".",
"get",
"(",
"membership_endpoint",
"(",
"organization_id",
")",
")",
"do",
"|",
"response",
"|",
"Rexpense",
"::",
"Entities",
"::",
"MembershipCollection",
".",
"build",
"response",
"end",
"end"
] | Get organization memberships
[API]
Method: <tt>GET /api/v1/organizations/:id/memberships</tt>
Documentation: http://developers.rexpense.com/api/memberships#index | [
"Get",
"organization",
"memberships"
] | c3a36440876dda29e0747d45807e70b246e99945 | https://github.com/myfreecomm/rexpense-client-ruby/blob/c3a36440876dda29e0747d45807e70b246e99945/lib/rexpense/resources/nested_endpoints/membership.rb#L10-L14 |
2,975 | myfreecomm/rexpense-client-ruby | lib/rexpense/resources/nested_endpoints/membership.rb | Rexpense::Resources.Membership.create_membership | def create_membership(organization_id, params)
http.post(membership_endpoint(organization_id), body: params) do |response|
response.parsed_body
end
end | ruby | def create_membership(organization_id, params)
http.post(membership_endpoint(organization_id), body: params) do |response|
response.parsed_body
end
end | [
"def",
"create_membership",
"(",
"organization_id",
",",
"params",
")",
"http",
".",
"post",
"(",
"membership_endpoint",
"(",
"organization_id",
")",
",",
"body",
":",
"params",
")",
"do",
"|",
"response",
"|",
"response",
".",
"parsed_body",
"end",
"end"
] | Create organization membership
[API]
Method: <tt>POST /api/v1/organizations/:id/memberships</tt>
Documentation: http://developers.rexpense.com/api/memberships#create | [
"Create",
"organization",
"membership"
] | c3a36440876dda29e0747d45807e70b246e99945 | https://github.com/myfreecomm/rexpense-client-ruby/blob/c3a36440876dda29e0747d45807e70b246e99945/lib/rexpense/resources/nested_endpoints/membership.rb#L36-L40 |
2,976 | myfreecomm/rexpense-client-ruby | lib/rexpense/resources/nested_endpoints/membership.rb | Rexpense::Resources.Membership.update_membership | def update_membership(organization_id, membership_id, params)
http.put("#{membership_endpoint(organization_id)}/#{membership_id}", body: params) do |response|
Rexpense::Entities::Membership.new response.parsed_body
end
end | ruby | def update_membership(organization_id, membership_id, params)
http.put("#{membership_endpoint(organization_id)}/#{membership_id}", body: params) do |response|
Rexpense::Entities::Membership.new response.parsed_body
end
end | [
"def",
"update_membership",
"(",
"organization_id",
",",
"membership_id",
",",
"params",
")",
"http",
".",
"put",
"(",
"\"#{membership_endpoint(organization_id)}/#{membership_id}\"",
",",
"body",
":",
"params",
")",
"do",
"|",
"response",
"|",
"Rexpense",
"::",
"Entities",
"::",
"Membership",
".",
"new",
"response",
".",
"parsed_body",
"end",
"end"
] | Update organization membership
[API]
Method: <tt>PUT /api/v1/organizations/:id/memberships/:membership_id</tt>
Documentation: http://developers.rexpense.com/api/memberships#update | [
"Update",
"organization",
"membership"
] | c3a36440876dda29e0747d45807e70b246e99945 | https://github.com/myfreecomm/rexpense-client-ruby/blob/c3a36440876dda29e0747d45807e70b246e99945/lib/rexpense/resources/nested_endpoints/membership.rb#L49-L53 |
2,977 | myfreecomm/rexpense-client-ruby | lib/rexpense/resources/nested_endpoints/attachment.rb | Rexpense::Resources.Attachment.attachments | def attachments(resource_id)
http.get(attachment_endpoint(resource_id)) do |response|
Rexpense::Entities::AttachmentCollection.build response
end
end | ruby | def attachments(resource_id)
http.get(attachment_endpoint(resource_id)) do |response|
Rexpense::Entities::AttachmentCollection.build response
end
end | [
"def",
"attachments",
"(",
"resource_id",
")",
"http",
".",
"get",
"(",
"attachment_endpoint",
"(",
"resource_id",
")",
")",
"do",
"|",
"response",
"|",
"Rexpense",
"::",
"Entities",
"::",
"AttachmentCollection",
".",
"build",
"response",
"end",
"end"
] | Get resource attachments
[API]
Method: <tt>GET /api/v1/expenses/:id/attachments</tt>
Documentation: http://developers.rexpense.com/api/attachments#index | [
"Get",
"resource",
"attachments"
] | c3a36440876dda29e0747d45807e70b246e99945 | https://github.com/myfreecomm/rexpense-client-ruby/blob/c3a36440876dda29e0747d45807e70b246e99945/lib/rexpense/resources/nested_endpoints/attachment.rb#L10-L14 |
2,978 | myfreecomm/rexpense-client-ruby | lib/rexpense/resources/nested_endpoints/attachment.rb | Rexpense::Resources.Attachment.find_attachment | def find_attachment(resource_id, attachment_id)
http.get("#{attachment_endpoint(resource_id)}/#{attachment_id}") do |response|
Rexpense::Entities::Attachment.new response.parsed_body
end
end | ruby | def find_attachment(resource_id, attachment_id)
http.get("#{attachment_endpoint(resource_id)}/#{attachment_id}") do |response|
Rexpense::Entities::Attachment.new response.parsed_body
end
end | [
"def",
"find_attachment",
"(",
"resource_id",
",",
"attachment_id",
")",
"http",
".",
"get",
"(",
"\"#{attachment_endpoint(resource_id)}/#{attachment_id}\"",
")",
"do",
"|",
"response",
"|",
"Rexpense",
"::",
"Entities",
"::",
"Attachment",
".",
"new",
"response",
".",
"parsed_body",
"end",
"end"
] | Get resource attachment
[API]
Method: <tt>GET /api/v1/expenses/:id/attachments/:id</tt>
Documentation: http://developers.rexpense.com/api/attachments#show | [
"Get",
"resource",
"attachment"
] | c3a36440876dda29e0747d45807e70b246e99945 | https://github.com/myfreecomm/rexpense-client-ruby/blob/c3a36440876dda29e0747d45807e70b246e99945/lib/rexpense/resources/nested_endpoints/attachment.rb#L23-L27 |
2,979 | myfreecomm/rexpense-client-ruby | lib/rexpense/resources/nested_endpoints/comment.rb | Rexpense::Resources.Comment.comments | def comments(resource_id)
http.get(comment_endpoint(resource_id)) do |response|
Rexpense::Entities::CommentCollection.build response
end
end | ruby | def comments(resource_id)
http.get(comment_endpoint(resource_id)) do |response|
Rexpense::Entities::CommentCollection.build response
end
end | [
"def",
"comments",
"(",
"resource_id",
")",
"http",
".",
"get",
"(",
"comment_endpoint",
"(",
"resource_id",
")",
")",
"do",
"|",
"response",
"|",
"Rexpense",
"::",
"Entities",
"::",
"CommentCollection",
".",
"build",
"response",
"end",
"end"
] | Get resource comments
[API]
Method: <tt>GET /api/v1/reimbursements/:id/comments</tt>
Method: <tt>GET /api/v1/expenses/:id/comments</tt>
Method: <tt>GET /api/v1/advancements/:id/comments</tt>
Documentation: http://developers.rexpense.com/api/comments#index | [
"Get",
"resource",
"comments"
] | c3a36440876dda29e0747d45807e70b246e99945 | https://github.com/myfreecomm/rexpense-client-ruby/blob/c3a36440876dda29e0747d45807e70b246e99945/lib/rexpense/resources/nested_endpoints/comment.rb#L12-L16 |
2,980 | myfreecomm/rexpense-client-ruby | lib/rexpense/resources/nested_endpoints/comment.rb | Rexpense::Resources.Comment.find_comment | def find_comment(resource_id, comment_id)
http.get("#{comment_endpoint(resource_id)}/#{comment_id}") do |response|
Rexpense::Entities::Comment.new response.parsed_body
end
end | ruby | def find_comment(resource_id, comment_id)
http.get("#{comment_endpoint(resource_id)}/#{comment_id}") do |response|
Rexpense::Entities::Comment.new response.parsed_body
end
end | [
"def",
"find_comment",
"(",
"resource_id",
",",
"comment_id",
")",
"http",
".",
"get",
"(",
"\"#{comment_endpoint(resource_id)}/#{comment_id}\"",
")",
"do",
"|",
"response",
"|",
"Rexpense",
"::",
"Entities",
"::",
"Comment",
".",
"new",
"response",
".",
"parsed_body",
"end",
"end"
] | Get resource comment
[API]
Method: <tt>GET /api/v1/reimbursements/:id/comments/:comment_id</tt>
Method: <tt>GET /api/v1/expenses/:id/comments/:comment_id</tt>
Method: <tt>GET /api/v1/advancements/:id/comments/:comment_id</tt>
Documentation: http://developers.rexpense.com/api/comments#show | [
"Get",
"resource",
"comment"
] | c3a36440876dda29e0747d45807e70b246e99945 | https://github.com/myfreecomm/rexpense-client-ruby/blob/c3a36440876dda29e0747d45807e70b246e99945/lib/rexpense/resources/nested_endpoints/comment.rb#L27-L31 |
2,981 | myfreecomm/rexpense-client-ruby | lib/rexpense/resources/nested_endpoints/comment.rb | Rexpense::Resources.Comment.create_comment | def create_comment(resource_id, params)
http.post(comment_endpoint(resource_id), body: params) do |response|
Rexpense::Entities::Comment.new response.parsed_body
end
end | ruby | def create_comment(resource_id, params)
http.post(comment_endpoint(resource_id), body: params) do |response|
Rexpense::Entities::Comment.new response.parsed_body
end
end | [
"def",
"create_comment",
"(",
"resource_id",
",",
"params",
")",
"http",
".",
"post",
"(",
"comment_endpoint",
"(",
"resource_id",
")",
",",
"body",
":",
"params",
")",
"do",
"|",
"response",
"|",
"Rexpense",
"::",
"Entities",
"::",
"Comment",
".",
"new",
"response",
".",
"parsed_body",
"end",
"end"
] | Create resource comment
[API]
Method: <tt>POST /api/v1/reimbursements/:id/comments</tt>
Method: <tt>POST /api/v1/expenses/:id/comments</tt>
Method: <tt>POST /api/v1/advancements/:id/comments</tt>
Documentation: http://developers.rexpense.com/api/comments#create | [
"Create",
"resource",
"comment"
] | c3a36440876dda29e0747d45807e70b246e99945 | https://github.com/myfreecomm/rexpense-client-ruby/blob/c3a36440876dda29e0747d45807e70b246e99945/lib/rexpense/resources/nested_endpoints/comment.rb#L42-L46 |
2,982 | myfreecomm/rexpense-client-ruby | lib/rexpense/resources/nested_endpoints/comment.rb | Rexpense::Resources.Comment.update_comment | def update_comment(resource_id, comment_id, params)
http.put("#{comment_endpoint(resource_id)}/#{comment_id}", body: params) do |response|
Rexpense::Entities::Comment.new response.parsed_body
end
end | ruby | def update_comment(resource_id, comment_id, params)
http.put("#{comment_endpoint(resource_id)}/#{comment_id}", body: params) do |response|
Rexpense::Entities::Comment.new response.parsed_body
end
end | [
"def",
"update_comment",
"(",
"resource_id",
",",
"comment_id",
",",
"params",
")",
"http",
".",
"put",
"(",
"\"#{comment_endpoint(resource_id)}/#{comment_id}\"",
",",
"body",
":",
"params",
")",
"do",
"|",
"response",
"|",
"Rexpense",
"::",
"Entities",
"::",
"Comment",
".",
"new",
"response",
".",
"parsed_body",
"end",
"end"
] | Update resource comment
[API]
Method: <tt>PUT /api/v1/reimbursements/:id/comments/:comment_id</tt>
Method: <tt>PUT /api/v1/expenses/:id/comments/:comment_id</tt>
Method: <tt>PUT /api/v1/advancements/:id/comments/:comment_id</tt>
Documentation: http://developers.rexpense.com/api/comments#update | [
"Update",
"resource",
"comment"
] | c3a36440876dda29e0747d45807e70b246e99945 | https://github.com/myfreecomm/rexpense-client-ruby/blob/c3a36440876dda29e0747d45807e70b246e99945/lib/rexpense/resources/nested_endpoints/comment.rb#L57-L61 |
2,983 | bensie/enom | lib/enom/domain.rb | Enom.Domain.sync_auth_info | def sync_auth_info(options = {})
opts = {
"RunSynchAutoInfo" => 'True',
"EmailEPP" => 'True'
}
opts["EmailEPP"] = 'True' if options[:email]
Client.request({"Command" => "SynchAuthInfo", "SLD" => sld, "TLD" => tld}.merge(opts))
return self
end | ruby | def sync_auth_info(options = {})
opts = {
"RunSynchAutoInfo" => 'True',
"EmailEPP" => 'True'
}
opts["EmailEPP"] = 'True' if options[:email]
Client.request({"Command" => "SynchAuthInfo", "SLD" => sld, "TLD" => tld}.merge(opts))
return self
end | [
"def",
"sync_auth_info",
"(",
"options",
"=",
"{",
"}",
")",
"opts",
"=",
"{",
"\"RunSynchAutoInfo\"",
"=>",
"'True'",
",",
"\"EmailEPP\"",
"=>",
"'True'",
"}",
"opts",
"[",
"\"EmailEPP\"",
"]",
"=",
"'True'",
"if",
"options",
"[",
":email",
"]",
"Client",
".",
"request",
"(",
"{",
"\"Command\"",
"=>",
"\"SynchAuthInfo\"",
",",
"\"SLD\"",
"=>",
"sld",
",",
"\"TLD\"",
"=>",
"tld",
"}",
".",
"merge",
"(",
"opts",
")",
")",
"return",
"self",
"end"
] | synchronize EPP key with Registry, and optionally email it to owner | [
"synchronize",
"EPP",
"key",
"with",
"Registry",
"and",
"optionally",
"email",
"it",
"to",
"owner"
] | a5f493a61422ea8da5d327d541c300c8756aed1e | https://github.com/bensie/enom/blob/a5f493a61422ea8da5d327d541c300c8756aed1e/lib/enom/domain.rb#L212-L222 |
2,984 | bensie/enom | lib/enom/domain.rb | Enom.Domain.get_extended_domain_attributes | def get_extended_domain_attributes
sld, tld = name.split(".")
attributes = Client.request("Command" => "GetDomainInfo", "SLD" => sld, "TLD" => tld)["interface_response"]["GetDomainInfo"]
set_extended_domain_attributes(attributes)
end | ruby | def get_extended_domain_attributes
sld, tld = name.split(".")
attributes = Client.request("Command" => "GetDomainInfo", "SLD" => sld, "TLD" => tld)["interface_response"]["GetDomainInfo"]
set_extended_domain_attributes(attributes)
end | [
"def",
"get_extended_domain_attributes",
"sld",
",",
"tld",
"=",
"name",
".",
"split",
"(",
"\".\"",
")",
"attributes",
"=",
"Client",
".",
"request",
"(",
"\"Command\"",
"=>",
"\"GetDomainInfo\"",
",",
"\"SLD\"",
"=>",
"sld",
",",
"\"TLD\"",
"=>",
"tld",
")",
"[",
"\"interface_response\"",
"]",
"[",
"\"GetDomainInfo\"",
"]",
"set_extended_domain_attributes",
"(",
"attributes",
")",
"end"
] | Make another API call to get all domain info. Often necessary when domains are
found using Domain.all instead of Domain.find. | [
"Make",
"another",
"API",
"call",
"to",
"get",
"all",
"domain",
"info",
".",
"Often",
"necessary",
"when",
"domains",
"are",
"found",
"using",
"Domain",
".",
"all",
"instead",
"of",
"Domain",
".",
"find",
"."
] | a5f493a61422ea8da5d327d541c300c8756aed1e | https://github.com/bensie/enom/blob/a5f493a61422ea8da5d327d541c300c8756aed1e/lib/enom/domain.rb#L292-L296 |
2,985 | bdurand/acts_as_revisionable | lib/acts_as_revisionable/revision_record.rb | ActsAsRevisionable.RevisionRecord.restore | def restore
restore_class = self.revisionable_type.constantize
# Check if we have a type field, if yes, assume single table inheritance and restore the actual class instead of the stored base class
sti_type = self.revision_attributes[restore_class.inheritance_column]
if sti_type
begin
if !restore_class.store_full_sti_class && !sti_type.start_with?("::")
sti_type = "#{restore_class.parent.name}::#{sti_type}"
end
restore_class = sti_type.constantize
rescue NameError => e
raise e
# Seems our assumption was wrong and we have no STI
end
end
record = restore_class.new
restore_record(record, revision_attributes)
return record
end | ruby | def restore
restore_class = self.revisionable_type.constantize
# Check if we have a type field, if yes, assume single table inheritance and restore the actual class instead of the stored base class
sti_type = self.revision_attributes[restore_class.inheritance_column]
if sti_type
begin
if !restore_class.store_full_sti_class && !sti_type.start_with?("::")
sti_type = "#{restore_class.parent.name}::#{sti_type}"
end
restore_class = sti_type.constantize
rescue NameError => e
raise e
# Seems our assumption was wrong and we have no STI
end
end
record = restore_class.new
restore_record(record, revision_attributes)
return record
end | [
"def",
"restore",
"restore_class",
"=",
"self",
".",
"revisionable_type",
".",
"constantize",
"# Check if we have a type field, if yes, assume single table inheritance and restore the actual class instead of the stored base class",
"sti_type",
"=",
"self",
".",
"revision_attributes",
"[",
"restore_class",
".",
"inheritance_column",
"]",
"if",
"sti_type",
"begin",
"if",
"!",
"restore_class",
".",
"store_full_sti_class",
"&&",
"!",
"sti_type",
".",
"start_with?",
"(",
"\"::\"",
")",
"sti_type",
"=",
"\"#{restore_class.parent.name}::#{sti_type}\"",
"end",
"restore_class",
"=",
"sti_type",
".",
"constantize",
"rescue",
"NameError",
"=>",
"e",
"raise",
"e",
"# Seems our assumption was wrong and we have no STI",
"end",
"end",
"record",
"=",
"restore_class",
".",
"new",
"restore_record",
"(",
"record",
",",
"revision_attributes",
")",
"return",
"record",
"end"
] | Restore the revision to the original record. If any errors are encountered restoring attributes, they
will be added to the errors object of the restored record. | [
"Restore",
"the",
"revision",
"to",
"the",
"original",
"record",
".",
"If",
"any",
"errors",
"are",
"encountered",
"restoring",
"attributes",
"they",
"will",
"be",
"added",
"to",
"the",
"errors",
"object",
"of",
"the",
"restored",
"record",
"."
] | cabc9b9e35b58463d2a942f6cd2b4ab3d4fe64fc | https://github.com/bdurand/acts_as_revisionable/blob/cabc9b9e35b58463d2a942f6cd2b4ab3d4fe64fc/lib/acts_as_revisionable/revision_record.rb#L95-L115 |
2,986 | bdurand/acts_as_revisionable | lib/acts_as_revisionable/revision_record.rb | ActsAsRevisionable.RevisionRecord.restore_record | def restore_record(record, attributes)
primary_key = record.class.primary_key
primary_key = [primary_key].compact unless primary_key.is_a?(Array)
primary_key.each do |key|
record.send("#{key.to_s}=", attributes[key.to_s])
end
attrs, association_attrs = attributes_and_associations(record.class, attributes)
attrs.each_pair do |key, value|
begin
record.send("#{key}=", value)
rescue
record.errors.add(key.to_sym, "could not be restored to #{value.inspect}")
end
end
association_attrs.each_pair do |key, values|
restore_association(record, key, values) if values
end
# Check if the record already exists in the database and restore its state.
# This must be done last because otherwise associations on an existing record
# can be deleted when a revision is restored to memory.
exists = record.class.find(record.send(record.class.primary_key)) rescue nil
if exists
record.instance_variable_set(:@new_record, nil) if record.instance_variable_defined?(:@new_record)
# ActiveRecord 3.0.2 and 3.0.3 used @persisted instead of @new_record
record.instance_variable_set(:@persisted, true) if record.instance_variable_defined?(:@persisted)
end
end | ruby | def restore_record(record, attributes)
primary_key = record.class.primary_key
primary_key = [primary_key].compact unless primary_key.is_a?(Array)
primary_key.each do |key|
record.send("#{key.to_s}=", attributes[key.to_s])
end
attrs, association_attrs = attributes_and_associations(record.class, attributes)
attrs.each_pair do |key, value|
begin
record.send("#{key}=", value)
rescue
record.errors.add(key.to_sym, "could not be restored to #{value.inspect}")
end
end
association_attrs.each_pair do |key, values|
restore_association(record, key, values) if values
end
# Check if the record already exists in the database and restore its state.
# This must be done last because otherwise associations on an existing record
# can be deleted when a revision is restored to memory.
exists = record.class.find(record.send(record.class.primary_key)) rescue nil
if exists
record.instance_variable_set(:@new_record, nil) if record.instance_variable_defined?(:@new_record)
# ActiveRecord 3.0.2 and 3.0.3 used @persisted instead of @new_record
record.instance_variable_set(:@persisted, true) if record.instance_variable_defined?(:@persisted)
end
end | [
"def",
"restore_record",
"(",
"record",
",",
"attributes",
")",
"primary_key",
"=",
"record",
".",
"class",
".",
"primary_key",
"primary_key",
"=",
"[",
"primary_key",
"]",
".",
"compact",
"unless",
"primary_key",
".",
"is_a?",
"(",
"Array",
")",
"primary_key",
".",
"each",
"do",
"|",
"key",
"|",
"record",
".",
"send",
"(",
"\"#{key.to_s}=\"",
",",
"attributes",
"[",
"key",
".",
"to_s",
"]",
")",
"end",
"attrs",
",",
"association_attrs",
"=",
"attributes_and_associations",
"(",
"record",
".",
"class",
",",
"attributes",
")",
"attrs",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"begin",
"record",
".",
"send",
"(",
"\"#{key}=\"",
",",
"value",
")",
"rescue",
"record",
".",
"errors",
".",
"add",
"(",
"key",
".",
"to_sym",
",",
"\"could not be restored to #{value.inspect}\"",
")",
"end",
"end",
"association_attrs",
".",
"each_pair",
"do",
"|",
"key",
",",
"values",
"|",
"restore_association",
"(",
"record",
",",
"key",
",",
"values",
")",
"if",
"values",
"end",
"# Check if the record already exists in the database and restore its state.",
"# This must be done last because otherwise associations on an existing record",
"# can be deleted when a revision is restored to memory.",
"exists",
"=",
"record",
".",
"class",
".",
"find",
"(",
"record",
".",
"send",
"(",
"record",
".",
"class",
".",
"primary_key",
")",
")",
"rescue",
"nil",
"if",
"exists",
"record",
".",
"instance_variable_set",
"(",
":@new_record",
",",
"nil",
")",
"if",
"record",
".",
"instance_variable_defined?",
"(",
":@new_record",
")",
"# ActiveRecord 3.0.2 and 3.0.3 used @persisted instead of @new_record",
"record",
".",
"instance_variable_set",
"(",
":@persisted",
",",
"true",
")",
"if",
"record",
".",
"instance_variable_defined?",
"(",
":@persisted",
")",
"end",
"end"
] | Restore a record and all its associations. | [
"Restore",
"a",
"record",
"and",
"all",
"its",
"associations",
"."
] | cabc9b9e35b58463d2a942f6cd2b4ab3d4fe64fc | https://github.com/bdurand/acts_as_revisionable/blob/cabc9b9e35b58463d2a942f6cd2b4ab3d4fe64fc/lib/acts_as_revisionable/revision_record.rb#L237-L266 |
2,987 | ShipCompliant/ship_compliant-ruby | lib/ship_compliant/search_sales_orders_result.rb | ShipCompliant.SearchSalesOrdersResult.parse! | def parse!
unless raw.has_key?(:sales_orders)
raw[:sales_orders] = {}
end
# force orders to be an array
orders = raw[:sales_orders].fetch(:sales_order_summary, {})
unless orders.kind_of?(Array)
raw[:sales_orders][:sales_order_summary] = [orders]
end
# typecast :count_more_sales_orders_available to integer
if raw.has_key?(:count_more_sales_orders_available)
convert_to_integer!(:count_more_sales_orders_available, raw)
end
# typecast :count_sales_orders_returned to integer
if raw.has_key?(:count_sales_orders_returned)
convert_to_integer!(:count_sales_orders_returned, raw)
end
raw[:sales_orders][:sales_order_summary].each do |summary|
# typecast :shipment_key to integer
if summary.fetch(:shipments, {}).fetch(:shipment_summary, {}).has_key?(:shipment_key)
convert_to_integer!(:shipment_key, summary[:shipments][:shipment_summary])
end
# typecast :zip1 to integer
if summary.fetch(:shipments, {}).fetch(:shipment_summary, {}).fetch(:ship_to, {}).has_key?(:zip1)
convert_to_integer!(:zip1, summary[:shipments][:shipment_summary][:ship_to])
end
end
end | ruby | def parse!
unless raw.has_key?(:sales_orders)
raw[:sales_orders] = {}
end
# force orders to be an array
orders = raw[:sales_orders].fetch(:sales_order_summary, {})
unless orders.kind_of?(Array)
raw[:sales_orders][:sales_order_summary] = [orders]
end
# typecast :count_more_sales_orders_available to integer
if raw.has_key?(:count_more_sales_orders_available)
convert_to_integer!(:count_more_sales_orders_available, raw)
end
# typecast :count_sales_orders_returned to integer
if raw.has_key?(:count_sales_orders_returned)
convert_to_integer!(:count_sales_orders_returned, raw)
end
raw[:sales_orders][:sales_order_summary].each do |summary|
# typecast :shipment_key to integer
if summary.fetch(:shipments, {}).fetch(:shipment_summary, {}).has_key?(:shipment_key)
convert_to_integer!(:shipment_key, summary[:shipments][:shipment_summary])
end
# typecast :zip1 to integer
if summary.fetch(:shipments, {}).fetch(:shipment_summary, {}).fetch(:ship_to, {}).has_key?(:zip1)
convert_to_integer!(:zip1, summary[:shipments][:shipment_summary][:ship_to])
end
end
end | [
"def",
"parse!",
"unless",
"raw",
".",
"has_key?",
"(",
":sales_orders",
")",
"raw",
"[",
":sales_orders",
"]",
"=",
"{",
"}",
"end",
"# force orders to be an array",
"orders",
"=",
"raw",
"[",
":sales_orders",
"]",
".",
"fetch",
"(",
":sales_order_summary",
",",
"{",
"}",
")",
"unless",
"orders",
".",
"kind_of?",
"(",
"Array",
")",
"raw",
"[",
":sales_orders",
"]",
"[",
":sales_order_summary",
"]",
"=",
"[",
"orders",
"]",
"end",
"# typecast :count_more_sales_orders_available to integer",
"if",
"raw",
".",
"has_key?",
"(",
":count_more_sales_orders_available",
")",
"convert_to_integer!",
"(",
":count_more_sales_orders_available",
",",
"raw",
")",
"end",
"# typecast :count_sales_orders_returned to integer",
"if",
"raw",
".",
"has_key?",
"(",
":count_sales_orders_returned",
")",
"convert_to_integer!",
"(",
":count_sales_orders_returned",
",",
"raw",
")",
"end",
"raw",
"[",
":sales_orders",
"]",
"[",
":sales_order_summary",
"]",
".",
"each",
"do",
"|",
"summary",
"|",
"# typecast :shipment_key to integer",
"if",
"summary",
".",
"fetch",
"(",
":shipments",
",",
"{",
"}",
")",
".",
"fetch",
"(",
":shipment_summary",
",",
"{",
"}",
")",
".",
"has_key?",
"(",
":shipment_key",
")",
"convert_to_integer!",
"(",
":shipment_key",
",",
"summary",
"[",
":shipments",
"]",
"[",
":shipment_summary",
"]",
")",
"end",
"# typecast :zip1 to integer",
"if",
"summary",
".",
"fetch",
"(",
":shipments",
",",
"{",
"}",
")",
".",
"fetch",
"(",
":shipment_summary",
",",
"{",
"}",
")",
".",
"fetch",
"(",
":ship_to",
",",
"{",
"}",
")",
".",
"has_key?",
"(",
":zip1",
")",
"convert_to_integer!",
"(",
":zip1",
",",
"summary",
"[",
":shipments",
"]",
"[",
":shipment_summary",
"]",
"[",
":ship_to",
"]",
")",
"end",
"end",
"end"
] | Standardizes the XML response by converting fields to integers
and forcing the order summaries into an array. | [
"Standardizes",
"the",
"XML",
"response",
"by",
"converting",
"fields",
"to",
"integers",
"and",
"forcing",
"the",
"order",
"summaries",
"into",
"an",
"array",
"."
] | aa12852a58cd6cb7939eb9fbb7fdc03e46e18197 | https://github.com/ShipCompliant/ship_compliant-ruby/blob/aa12852a58cd6cb7939eb9fbb7fdc03e46e18197/lib/ship_compliant/search_sales_orders_result.rb#L64-L97 |
2,988 | ShipCompliant/ship_compliant-ruby | lib/ship_compliant/client.rb | ShipCompliant.Client.call | def call(operation, locals = {})
locals['Security'] = ShipCompliant.configuration.credentials
response = savon_call(operation, message: {
'Request' => locals
})
get_result_from_response(operation, response)
end | ruby | def call(operation, locals = {})
locals['Security'] = ShipCompliant.configuration.credentials
response = savon_call(operation, message: {
'Request' => locals
})
get_result_from_response(operation, response)
end | [
"def",
"call",
"(",
"operation",
",",
"locals",
"=",
"{",
"}",
")",
"locals",
"[",
"'Security'",
"]",
"=",
"ShipCompliant",
".",
"configuration",
".",
"credentials",
"response",
"=",
"savon_call",
"(",
"operation",
",",
"message",
":",
"{",
"'Request'",
"=>",
"locals",
"}",
")",
"get_result_from_response",
"(",
"operation",
",",
"response",
")",
"end"
] | Adds the required security credentials and formats
the message to match the ShipCompliant structure.
ShipCompliant.client.call(:some_operation, {
'SomeKey' => 'SomeValue'
}) | [
"Adds",
"the",
"required",
"security",
"credentials",
"and",
"formats",
"the",
"message",
"to",
"match",
"the",
"ShipCompliant",
"structure",
"."
] | aa12852a58cd6cb7939eb9fbb7fdc03e46e18197 | https://github.com/ShipCompliant/ship_compliant-ruby/blob/aa12852a58cd6cb7939eb9fbb7fdc03e46e18197/lib/ship_compliant/client.rb#L35-L43 |
2,989 | rossf7/elasticrawl | lib/elasticrawl/job.rb | Elasticrawl.Job.confirm_message | def confirm_message
cluster = Cluster.new
case self.type
when 'Elasticrawl::ParseJob'
message = segment_list
else
message = []
end
message.push('Job configuration')
message.push(self.job_desc)
message.push('')
message.push(cluster.cluster_desc)
message.join("\n")
end | ruby | def confirm_message
cluster = Cluster.new
case self.type
when 'Elasticrawl::ParseJob'
message = segment_list
else
message = []
end
message.push('Job configuration')
message.push(self.job_desc)
message.push('')
message.push(cluster.cluster_desc)
message.join("\n")
end | [
"def",
"confirm_message",
"cluster",
"=",
"Cluster",
".",
"new",
"case",
"self",
".",
"type",
"when",
"'Elasticrawl::ParseJob'",
"message",
"=",
"segment_list",
"else",
"message",
"=",
"[",
"]",
"end",
"message",
".",
"push",
"(",
"'Job configuration'",
")",
"message",
".",
"push",
"(",
"self",
".",
"job_desc",
")",
"message",
".",
"push",
"(",
"''",
")",
"message",
".",
"push",
"(",
"cluster",
".",
"cluster_desc",
")",
"message",
".",
"join",
"(",
"\"\\n\"",
")",
"end"
] | Displays a confirmation message showing the configuration of the
Elastic MapReduce job flow and cluster. | [
"Displays",
"a",
"confirmation",
"message",
"showing",
"the",
"configuration",
"of",
"the",
"Elastic",
"MapReduce",
"job",
"flow",
"and",
"cluster",
"."
] | db70bb6819c86805869f389daf1920f3acc87cef | https://github.com/rossf7/elasticrawl/blob/db70bb6819c86805869f389daf1920f3acc87cef/lib/elasticrawl/job.rb#L8-L24 |
2,990 | rossf7/elasticrawl | lib/elasticrawl/job.rb | Elasticrawl.Job.run_job_flow | def run_job_flow(emr_config)
cluster = Cluster.new
job_flow = cluster.create_job_flow(self, emr_config)
job_steps.each do |step|
job_flow.add_step(step.job_flow_step(job_config))
end
begin
job_flow.run
rescue StandardError => e
raise ElasticMapReduceAccessError, e.message
end
end | ruby | def run_job_flow(emr_config)
cluster = Cluster.new
job_flow = cluster.create_job_flow(self, emr_config)
job_steps.each do |step|
job_flow.add_step(step.job_flow_step(job_config))
end
begin
job_flow.run
rescue StandardError => e
raise ElasticMapReduceAccessError, e.message
end
end | [
"def",
"run_job_flow",
"(",
"emr_config",
")",
"cluster",
"=",
"Cluster",
".",
"new",
"job_flow",
"=",
"cluster",
".",
"create_job_flow",
"(",
"self",
",",
"emr_config",
")",
"job_steps",
".",
"each",
"do",
"|",
"step",
"|",
"job_flow",
".",
"add_step",
"(",
"step",
".",
"job_flow_step",
"(",
"job_config",
")",
")",
"end",
"begin",
"job_flow",
".",
"run",
"rescue",
"StandardError",
"=>",
"e",
"raise",
"ElasticMapReduceAccessError",
",",
"e",
".",
"message",
"end",
"end"
] | Calls the Elastic MapReduce API to create a Job Flow. Returns the Job Flow ID. | [
"Calls",
"the",
"Elastic",
"MapReduce",
"API",
"to",
"create",
"a",
"Job",
"Flow",
".",
"Returns",
"the",
"Job",
"Flow",
"ID",
"."
] | db70bb6819c86805869f389daf1920f3acc87cef | https://github.com/rossf7/elasticrawl/blob/db70bb6819c86805869f389daf1920f3acc87cef/lib/elasticrawl/job.rb#L40-L54 |
2,991 | brasten/scruffy | lib/scruffy/layers/scatter.rb | Scruffy::Layers.Scatter.draw | def draw(svg, coords, options={})
options.merge!(@options)
if options[:shadow]
svg.g(:class => 'shadow', :transform => "translate(#{relative(0.5)}, #{relative(0.5)})") {
coords.each { |coord| svg.circle( :cx => coord.first, :cy => coord.last + relative(0.9), :r => relative(2),
:style => "stroke-width: #{relative(2)}; stroke: black; opacity: 0.35;" ) }
}
end
coords.each { |coord| svg.circle( :cx => coord.first, :cy => coord.last, :r => relative(2),
:style => "stroke-width: #{relative(2)}; stroke: #{color.to_s}; fill: #{color.to_s}" ) }
end | ruby | def draw(svg, coords, options={})
options.merge!(@options)
if options[:shadow]
svg.g(:class => 'shadow', :transform => "translate(#{relative(0.5)}, #{relative(0.5)})") {
coords.each { |coord| svg.circle( :cx => coord.first, :cy => coord.last + relative(0.9), :r => relative(2),
:style => "stroke-width: #{relative(2)}; stroke: black; opacity: 0.35;" ) }
}
end
coords.each { |coord| svg.circle( :cx => coord.first, :cy => coord.last, :r => relative(2),
:style => "stroke-width: #{relative(2)}; stroke: #{color.to_s}; fill: #{color.to_s}" ) }
end | [
"def",
"draw",
"(",
"svg",
",",
"coords",
",",
"options",
"=",
"{",
"}",
")",
"options",
".",
"merge!",
"(",
"@options",
")",
"if",
"options",
"[",
":shadow",
"]",
"svg",
".",
"g",
"(",
":class",
"=>",
"'shadow'",
",",
":transform",
"=>",
"\"translate(#{relative(0.5)}, #{relative(0.5)})\"",
")",
"{",
"coords",
".",
"each",
"{",
"|",
"coord",
"|",
"svg",
".",
"circle",
"(",
":cx",
"=>",
"coord",
".",
"first",
",",
":cy",
"=>",
"coord",
".",
"last",
"+",
"relative",
"(",
"0.9",
")",
",",
":r",
"=>",
"relative",
"(",
"2",
")",
",",
":style",
"=>",
"\"stroke-width: #{relative(2)}; stroke: black; opacity: 0.35;\"",
")",
"}",
"}",
"end",
"coords",
".",
"each",
"{",
"|",
"coord",
"|",
"svg",
".",
"circle",
"(",
":cx",
"=>",
"coord",
".",
"first",
",",
":cy",
"=>",
"coord",
".",
"last",
",",
":r",
"=>",
"relative",
"(",
"2",
")",
",",
":style",
"=>",
"\"stroke-width: #{relative(2)}; stroke: #{color.to_s}; fill: #{color.to_s}\"",
")",
"}",
"end"
] | Renders scatter graph. | [
"Renders",
"scatter",
"graph",
"."
] | 4aad4f9ab2b946ba0f6e6251dc7eb3b9747a4e9e | https://github.com/brasten/scruffy/blob/4aad4f9ab2b946ba0f6e6251dc7eb3b9747a4e9e/lib/scruffy/layers/scatter.rb#L13-L26 |
2,992 | brasten/scruffy | lib/scruffy/layers/area.rb | Scruffy::Layers.Area.draw | def draw(svg, coords, options={})
# svg.polygon wants a long string of coords.
points_value = "0,#{height} #{stringify_coords(coords).join(' ')} #{width},#{height}"
# Experimental, for later user.
# This was supposed to add some fun filters, 3d effects and whatnot.
# Neither ImageMagick nor Mozilla SVG render this well (at all). Maybe a future thing.
#
# svg.defs {
# svg.filter(:id => 'MyFilter', :filterUnits => 'userSpaceOnUse', :x => 0, :y => 0, :width => 200, :height => '120') {
# svg.feGaussianBlur(:in => 'SourceAlpha', :stdDeviation => 4, :result => 'blur')
# svg.feOffset(:in => 'blur', :dx => 4, :dy => 4, :result => 'offsetBlur')
# svg.feSpecularLighting( :in => 'blur', :surfaceScale => 5, :specularConstant => '.75',
# :specularExponent => 20, 'lighting-color' => '#bbbbbb',
# :result => 'specOut') {
# svg.fePointLight(:x => '-5000', :y => '-10000', :z => '20000')
# }
#
# svg.feComposite(:in => 'specOut', :in2 => 'SourceAlpha', :operator => 'in', :result => 'specOut')
# svg.feComposite(:in => 'sourceGraphic', :in2 => 'specOut', :operator => 'arithmetic',
# :k1 => 0, :k2 => 1, :k3 => 1, :k4 => 0, :result => 'litPaint')
#
# svg.feMerge {
# svg.feMergeNode(:in => 'offsetBlur')
# svg.feMergeNode(:in => 'litPaint')
# }
# }
# }
svg.g(:transform => "translate(0, -#{relative(2)})") {
svg.polygon(:points => points_value, :style => "fill: black; stroke: black; fill-opacity: 0.06; stroke-opacity: 0.06;")
}
svg.polygon(:points => points_value, :fill => color.to_s, :stroke => color.to_s, 'style' => "opacity: #{opacity}")
end | ruby | def draw(svg, coords, options={})
# svg.polygon wants a long string of coords.
points_value = "0,#{height} #{stringify_coords(coords).join(' ')} #{width},#{height}"
# Experimental, for later user.
# This was supposed to add some fun filters, 3d effects and whatnot.
# Neither ImageMagick nor Mozilla SVG render this well (at all). Maybe a future thing.
#
# svg.defs {
# svg.filter(:id => 'MyFilter', :filterUnits => 'userSpaceOnUse', :x => 0, :y => 0, :width => 200, :height => '120') {
# svg.feGaussianBlur(:in => 'SourceAlpha', :stdDeviation => 4, :result => 'blur')
# svg.feOffset(:in => 'blur', :dx => 4, :dy => 4, :result => 'offsetBlur')
# svg.feSpecularLighting( :in => 'blur', :surfaceScale => 5, :specularConstant => '.75',
# :specularExponent => 20, 'lighting-color' => '#bbbbbb',
# :result => 'specOut') {
# svg.fePointLight(:x => '-5000', :y => '-10000', :z => '20000')
# }
#
# svg.feComposite(:in => 'specOut', :in2 => 'SourceAlpha', :operator => 'in', :result => 'specOut')
# svg.feComposite(:in => 'sourceGraphic', :in2 => 'specOut', :operator => 'arithmetic',
# :k1 => 0, :k2 => 1, :k3 => 1, :k4 => 0, :result => 'litPaint')
#
# svg.feMerge {
# svg.feMergeNode(:in => 'offsetBlur')
# svg.feMergeNode(:in => 'litPaint')
# }
# }
# }
svg.g(:transform => "translate(0, -#{relative(2)})") {
svg.polygon(:points => points_value, :style => "fill: black; stroke: black; fill-opacity: 0.06; stroke-opacity: 0.06;")
}
svg.polygon(:points => points_value, :fill => color.to_s, :stroke => color.to_s, 'style' => "opacity: #{opacity}")
end | [
"def",
"draw",
"(",
"svg",
",",
"coords",
",",
"options",
"=",
"{",
"}",
")",
"# svg.polygon wants a long string of coords. ",
"points_value",
"=",
"\"0,#{height} #{stringify_coords(coords).join(' ')} #{width},#{height}\"",
"# Experimental, for later user.",
"# This was supposed to add some fun filters, 3d effects and whatnot.",
"# Neither ImageMagick nor Mozilla SVG render this well (at all). Maybe a future thing.",
"#",
"# svg.defs {",
"# svg.filter(:id => 'MyFilter', :filterUnits => 'userSpaceOnUse', :x => 0, :y => 0, :width => 200, :height => '120') {",
"# svg.feGaussianBlur(:in => 'SourceAlpha', :stdDeviation => 4, :result => 'blur')",
"# svg.feOffset(:in => 'blur', :dx => 4, :dy => 4, :result => 'offsetBlur')",
"# svg.feSpecularLighting( :in => 'blur', :surfaceScale => 5, :specularConstant => '.75',",
"# :specularExponent => 20, 'lighting-color' => '#bbbbbb',",
"# :result => 'specOut') {",
"# svg.fePointLight(:x => '-5000', :y => '-10000', :z => '20000')",
"# }",
"# ",
"# svg.feComposite(:in => 'specOut', :in2 => 'SourceAlpha', :operator => 'in', :result => 'specOut')",
"# svg.feComposite(:in => 'sourceGraphic', :in2 => 'specOut', :operator => 'arithmetic',",
"# :k1 => 0, :k2 => 1, :k3 => 1, :k4 => 0, :result => 'litPaint')",
"# ",
"# svg.feMerge {",
"# svg.feMergeNode(:in => 'offsetBlur')",
"# svg.feMergeNode(:in => 'litPaint')",
"# }",
"# }",
"# }",
"svg",
".",
"g",
"(",
":transform",
"=>",
"\"translate(0, -#{relative(2)})\"",
")",
"{",
"svg",
".",
"polygon",
"(",
":points",
"=>",
"points_value",
",",
":style",
"=>",
"\"fill: black; stroke: black; fill-opacity: 0.06; stroke-opacity: 0.06;\"",
")",
"}",
"svg",
".",
"polygon",
"(",
":points",
"=>",
"points_value",
",",
":fill",
"=>",
"color",
".",
"to_s",
",",
":stroke",
"=>",
"color",
".",
"to_s",
",",
"'style'",
"=>",
"\"opacity: #{opacity}\"",
")",
"end"
] | Render area graph. | [
"Render",
"area",
"graph",
"."
] | 4aad4f9ab2b946ba0f6e6251dc7eb3b9747a4e9e | https://github.com/brasten/scruffy/blob/4aad4f9ab2b946ba0f6e6251dc7eb3b9747a4e9e/lib/scruffy/layers/area.rb#L11-L44 |
2,993 | waiting-for-dev/landing_page | app/controllers/landing_page/users_controller.rb | LandingPage.UsersController.create | def create
params.require(:user).permit!
user = User.new(params[:user])
if user.valid?
user.save
flash.now[:success] = t('landing_page.subscribed')
render :create
else
@user = user
render :new
end
end | ruby | def create
params.require(:user).permit!
user = User.new(params[:user])
if user.valid?
user.save
flash.now[:success] = t('landing_page.subscribed')
render :create
else
@user = user
render :new
end
end | [
"def",
"create",
"params",
".",
"require",
"(",
":user",
")",
".",
"permit!",
"user",
"=",
"User",
".",
"new",
"(",
"params",
"[",
":user",
"]",
")",
"if",
"user",
".",
"valid?",
"user",
".",
"save",
"flash",
".",
"now",
"[",
":success",
"]",
"=",
"t",
"(",
"'landing_page.subscribed'",
")",
"render",
":create",
"else",
"@user",
"=",
"user",
"render",
":new",
"end",
"end"
] | Register a new user or show errors | [
"Register",
"a",
"new",
"user",
"or",
"show",
"errors"
] | be564fc12fd838f8845d42b5c8ade54e3c3c7c1a | https://github.com/waiting-for-dev/landing_page/blob/be564fc12fd838f8845d42b5c8ade54e3c3c7c1a/app/controllers/landing_page/users_controller.rb#L10-L21 |
2,994 | orta/travish | lib/environment_parser.rb | Travish.EnvironmentParser.build_environment_hash | def build_environment_hash
parsed_variables = {}
@env.each do |env_row|
# Each row can potentially contain multiple environment
# variables
variables = extract_variables(env_row)
variables.each do |variables_with_values|
variables_with_values.each do |key, value|
parsed_variables[key] = value
end
end
end
@override_envs.each do |env|
parsed_variables = parsed_variables.merge env
end
parsed_variables
end | ruby | def build_environment_hash
parsed_variables = {}
@env.each do |env_row|
# Each row can potentially contain multiple environment
# variables
variables = extract_variables(env_row)
variables.each do |variables_with_values|
variables_with_values.each do |key, value|
parsed_variables[key] = value
end
end
end
@override_envs.each do |env|
parsed_variables = parsed_variables.merge env
end
parsed_variables
end | [
"def",
"build_environment_hash",
"parsed_variables",
"=",
"{",
"}",
"@env",
".",
"each",
"do",
"|",
"env_row",
"|",
"# Each row can potentially contain multiple environment",
"# variables",
"variables",
"=",
"extract_variables",
"(",
"env_row",
")",
"variables",
".",
"each",
"do",
"|",
"variables_with_values",
"|",
"variables_with_values",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"parsed_variables",
"[",
"key",
"]",
"=",
"value",
"end",
"end",
"end",
"@override_envs",
".",
"each",
"do",
"|",
"env",
"|",
"parsed_variables",
"=",
"parsed_variables",
".",
"merge",
"env",
"end",
"parsed_variables",
"end"
] | Build the environment hash by extracting the environment
variables from the provided travis environment and merging
with any provided overrides | [
"Build",
"the",
"environment",
"hash",
"by",
"extracting",
"the",
"environment",
"variables",
"from",
"the",
"provided",
"travis",
"environment",
"and",
"merging",
"with",
"any",
"provided",
"overrides"
] | fe71115690c8cef69979cea0dca8176eba304ab1 | https://github.com/orta/travish/blob/fe71115690c8cef69979cea0dca8176eba304ab1/lib/environment_parser.rb#L31-L50 |
2,995 | orta/travish | lib/environment_parser.rb | Travish.EnvironmentParser.extract_variables | def extract_variables(variable)
return [variable] if variable.is_a? Hash
return extract_variables_from_string(variable) if variable.is_a? String
[]
end | ruby | def extract_variables(variable)
return [variable] if variable.is_a? Hash
return extract_variables_from_string(variable) if variable.is_a? String
[]
end | [
"def",
"extract_variables",
"(",
"variable",
")",
"return",
"[",
"variable",
"]",
"if",
"variable",
".",
"is_a?",
"Hash",
"return",
"extract_variables_from_string",
"(",
"variable",
")",
"if",
"variable",
".",
"is_a?",
"String",
"[",
"]",
"end"
] | Extract environment variables from a value
The value is expected to be either a hash or a string with
one or more key value pairs on the form
KEY=VALUE | [
"Extract",
"environment",
"variables",
"from",
"a",
"value",
"The",
"value",
"is",
"expected",
"to",
"be",
"either",
"a",
"hash",
"or",
"a",
"string",
"with",
"one",
"or",
"more",
"key",
"value",
"pairs",
"on",
"the",
"form",
"KEY",
"=",
"VALUE"
] | fe71115690c8cef69979cea0dca8176eba304ab1 | https://github.com/orta/travish/blob/fe71115690c8cef69979cea0dca8176eba304ab1/lib/environment_parser.rb#L56-L61 |
2,996 | orta/travish | lib/environment_parser.rb | Travish.EnvironmentParser.extract_variables_from_string | def extract_variables_from_string(string)
string.split(/ /).map do |defintion|
match = defintion.match STRING_REG_EX
next nil unless match
{ match[1] => match[2] }
end.reject(&:nil?)
end | ruby | def extract_variables_from_string(string)
string.split(/ /).map do |defintion|
match = defintion.match STRING_REG_EX
next nil unless match
{ match[1] => match[2] }
end.reject(&:nil?)
end | [
"def",
"extract_variables_from_string",
"(",
"string",
")",
"string",
".",
"split",
"(",
"/",
"/",
")",
".",
"map",
"do",
"|",
"defintion",
"|",
"match",
"=",
"defintion",
".",
"match",
"STRING_REG_EX",
"next",
"nil",
"unless",
"match",
"{",
"match",
"[",
"1",
"]",
"=>",
"match",
"[",
"2",
"]",
"}",
"end",
".",
"reject",
"(",
":nil?",
")",
"end"
] | Extract variables from a string on the form
KEY1=VALUE1 KEY2="VALUE2"
Optional quoting around the value is allowed | [
"Extract",
"variables",
"from",
"a",
"string",
"on",
"the",
"form",
"KEY1",
"=",
"VALUE1",
"KEY2",
"=",
"VALUE2",
"Optional",
"quoting",
"around",
"the",
"value",
"is",
"allowed"
] | fe71115690c8cef69979cea0dca8176eba304ab1 | https://github.com/orta/travish/blob/fe71115690c8cef69979cea0dca8176eba304ab1/lib/environment_parser.rb#L66-L73 |
2,997 | poise/poise-profiler | lib/poise_profiler/base.rb | PoiseProfiler.Base._monkey_patch_old_chef! | def _monkey_patch_old_chef!
require 'chef/event_dispatch/dispatcher'
instance = self
orig_method = Chef::EventDispatch::Dispatcher.instance_method(:library_file_loaded)
Chef::EventDispatch::Dispatcher.send(:define_method, :library_file_loaded) do |filename|
instance.events = self
instance.monkey_patched = false
@subscribers |= [instance]
Chef::EventDispatch::Dispatcher.send(:define_method, :library_file_loaded, orig_method)
orig_method.bind(self).call(filename)
end
end | ruby | def _monkey_patch_old_chef!
require 'chef/event_dispatch/dispatcher'
instance = self
orig_method = Chef::EventDispatch::Dispatcher.instance_method(:library_file_loaded)
Chef::EventDispatch::Dispatcher.send(:define_method, :library_file_loaded) do |filename|
instance.events = self
instance.monkey_patched = false
@subscribers |= [instance]
Chef::EventDispatch::Dispatcher.send(:define_method, :library_file_loaded, orig_method)
orig_method.bind(self).call(filename)
end
end | [
"def",
"_monkey_patch_old_chef!",
"require",
"'chef/event_dispatch/dispatcher'",
"instance",
"=",
"self",
"orig_method",
"=",
"Chef",
"::",
"EventDispatch",
"::",
"Dispatcher",
".",
"instance_method",
"(",
":library_file_loaded",
")",
"Chef",
"::",
"EventDispatch",
"::",
"Dispatcher",
".",
"send",
"(",
":define_method",
",",
":library_file_loaded",
")",
"do",
"|",
"filename",
"|",
"instance",
".",
"events",
"=",
"self",
"instance",
".",
"monkey_patched",
"=",
"false",
"@subscribers",
"|=",
"[",
"instance",
"]",
"Chef",
"::",
"EventDispatch",
"::",
"Dispatcher",
".",
"send",
"(",
":define_method",
",",
":library_file_loaded",
",",
"orig_method",
")",
"orig_method",
".",
"bind",
"(",
"self",
")",
".",
"call",
"(",
"filename",
")",
"end",
"end"
] | Inject this instance for Chef < 12.3. Don't call this on newer Chef.
@api private
@see Base.install
@return [void] | [
"Inject",
"this",
"instance",
"for",
"Chef",
"<",
"12",
".",
"3",
".",
"Don",
"t",
"call",
"this",
"on",
"newer",
"Chef",
"."
] | a190acc6bdd4fcdac34ef43bbe4f59dddb9c0f67 | https://github.com/poise/poise-profiler/blob/a190acc6bdd4fcdac34ef43bbe4f59dddb9c0f67/lib/poise_profiler/base.rb#L76-L87 |
2,998 | botanicus/rango | lib/rango/controller.rb | Rango.Controller.rescue_http_error | def rescue_http_error(exception)
# we need to call it before we assign the variables
body = self.render_http_error(exception)
[exception.status, exception.headers, body]
end | ruby | def rescue_http_error(exception)
# we need to call it before we assign the variables
body = self.render_http_error(exception)
[exception.status, exception.headers, body]
end | [
"def",
"rescue_http_error",
"(",
"exception",
")",
"# we need to call it before we assign the variables",
"body",
"=",
"self",
".",
"render_http_error",
"(",
"exception",
")",
"[",
"exception",
".",
"status",
",",
"exception",
".",
"headers",
",",
"body",
"]",
"end"
] | redefine this method for your controller if you want to provide custom error pages
returns response array for rack
if you need to change just body of error message, define render_http_error method
@api plugin | [
"redefine",
"this",
"method",
"for",
"your",
"controller",
"if",
"you",
"want",
"to",
"provide",
"custom",
"error",
"pages",
"returns",
"response",
"array",
"for",
"rack",
"if",
"you",
"need",
"to",
"change",
"just",
"body",
"of",
"error",
"message",
"define",
"render_http_error",
"method"
] | b8904453f3b7d3cd65e2bcc5236bfe645aa78e8e | https://github.com/botanicus/rango/blob/b8904453f3b7d3cd65e2bcc5236bfe645aa78e8e/lib/rango/controller.rb#L139-L143 |
2,999 | mezis/tsuga | lib/tsuga/service/clusterer.rb | Tsuga::Service.Clusterer._build_clusters | def _build_clusters(tile)
used_ids = []
clusters = []
_adapter.in_tile(*tile.children).find_each do |child|
cluster = _adapter.build_from(tile.depth, child)
clusters << cluster
used_ids << child.id
end
return [used_ids, clusters]
end | ruby | def _build_clusters(tile)
used_ids = []
clusters = []
_adapter.in_tile(*tile.children).find_each do |child|
cluster = _adapter.build_from(tile.depth, child)
clusters << cluster
used_ids << child.id
end
return [used_ids, clusters]
end | [
"def",
"_build_clusters",
"(",
"tile",
")",
"used_ids",
"=",
"[",
"]",
"clusters",
"=",
"[",
"]",
"_adapter",
".",
"in_tile",
"(",
"tile",
".",
"children",
")",
".",
"find_each",
"do",
"|",
"child",
"|",
"cluster",
"=",
"_adapter",
".",
"build_from",
"(",
"tile",
".",
"depth",
",",
"child",
")",
"clusters",
"<<",
"cluster",
"used_ids",
"<<",
"child",
".",
"id",
"end",
"return",
"[",
"used_ids",
",",
"clusters",
"]",
"end"
] | return the record IDs used | [
"return",
"the",
"record",
"IDs",
"used"
] | 418a1dac7af068fb388883c47f39eb52113af096 | https://github.com/mezis/tsuga/blob/418a1dac7af068fb388883c47f39eb52113af096/lib/tsuga/service/clusterer.rb#L245-L256 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.