id int32 0 24.9k | repo stringlengths 5 58 | path stringlengths 9 168 | func_name stringlengths 9 130 | original_string stringlengths 66 10.5k | language stringclasses 1
value | code stringlengths 66 10.5k | code_tokens list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 |
|---|---|---|---|---|---|---|---|---|---|---|---|
15,400 | tiagopog/jsonapi-utils | lib/jsonapi/utils/support/filter/default.rb | JSONAPI::Utils::Support::Filter.Default.apply_filter? | def apply_filter?(records, options = {})
params[:filter].present? && records.respond_to?(:where) &&
(options[:filter].nil? || options[:filter])
end | ruby | def apply_filter?(records, options = {})
params[:filter].present? && records.respond_to?(:where) &&
(options[:filter].nil? || options[:filter])
end | [
"def",
"apply_filter?",
"(",
"records",
",",
"options",
"=",
"{",
"}",
")",
"params",
"[",
":filter",
"]",
".",
"present?",
"&&",
"records",
".",
"respond_to?",
"(",
":where",
")",
"&&",
"(",
"options",
"[",
":filter",
"]",
".",
"nil?",
"||",
"options"... | Check whether default filters should be applied.
@param records [ActiveRecord::Relation, Array] collection of records
e.g.: User.all or [{ id: 1, name: 'Tiago' }, { id: 2, name: 'Doug' }]
@param options [Hash] JU's options
e.g.: { filter: false, paginate: false }
@return [Boolean]
@api public | [
"Check",
"whether",
"default",
"filters",
"should",
"be",
"applied",
"."
] | a2c2b0e3843376718929723d9f609611f68b665e | https://github.com/tiagopog/jsonapi-utils/blob/a2c2b0e3843376718929723d9f609611f68b665e/lib/jsonapi/utils/support/filter/default.rb#L34-L37 |
15,401 | tiagopog/jsonapi-utils | lib/jsonapi/utils/support/filter/default.rb | JSONAPI::Utils::Support::Filter.Default.filter_params | def filter_params
@_filter_params ||=
case params[:filter]
when Hash, ActionController::Parameters
default_filters.each_with_object({}) do |field, hash|
unformatted_field = @request.unformat_key(field)
hash[unformatted_field] = params[:filter][field]
end... | ruby | def filter_params
@_filter_params ||=
case params[:filter]
when Hash, ActionController::Parameters
default_filters.each_with_object({}) do |field, hash|
unformatted_field = @request.unformat_key(field)
hash[unformatted_field] = params[:filter][field]
end... | [
"def",
"filter_params",
"@_filter_params",
"||=",
"case",
"params",
"[",
":filter",
"]",
"when",
"Hash",
",",
"ActionController",
"::",
"Parameters",
"default_filters",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"field",
",",
"hash",
"|",
"unforma... | Build a Hash with the default filters.
@return [Hash, NilClass]
@api public | [
"Build",
"a",
"Hash",
"with",
"the",
"default",
"filters",
"."
] | a2c2b0e3843376718929723d9f609611f68b665e | https://github.com/tiagopog/jsonapi-utils/blob/a2c2b0e3843376718929723d9f609611f68b665e/lib/jsonapi/utils/support/filter/default.rb#L44-L53 |
15,402 | tiagopog/jsonapi-utils | lib/jsonapi/utils/support/sort.rb | JSONAPI::Utils::Support.Sort.sort_params | def sort_params
@_sort_params ||=
if params[:sort].present?
params[:sort].split(',').each_with_object({}) do |field, hash|
unformatted_field = @request.unformat_key(field)
desc, field = unformatted_field.to_s.match(/^([-_])?(\w+)$/i)[1..2]
hash[field.t... | ruby | def sort_params
@_sort_params ||=
if params[:sort].present?
params[:sort].split(',').each_with_object({}) do |field, hash|
unformatted_field = @request.unformat_key(field)
desc, field = unformatted_field.to_s.match(/^([-_])?(\w+)$/i)[1..2]
hash[field.t... | [
"def",
"sort_params",
"@_sort_params",
"||=",
"if",
"params",
"[",
":sort",
"]",
".",
"present?",
"params",
"[",
":sort",
"]",
".",
"split",
"(",
"','",
")",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"field",
",",
"hash",
"|",
"unformatte... | Build a Hash with the sort criteria.
@return [Hash, NilClass]
@api public | [
"Build",
"a",
"Hash",
"with",
"the",
"sort",
"criteria",
"."
] | a2c2b0e3843376718929723d9f609611f68b665e | https://github.com/tiagopog/jsonapi-utils/blob/a2c2b0e3843376718929723d9f609611f68b665e/lib/jsonapi/utils/support/sort.rb#L42-L51 |
15,403 | tiagopog/jsonapi-utils | lib/jsonapi/utils/request.rb | JSONAPI::Utils.Request.setup_request | def setup_request
@request ||= JSONAPI::RequestParser.new(
params,
context: context,
key_formatter: key_formatter,
server_error_callbacks: (self.class.server_error_callbacks || [])
)
end | ruby | def setup_request
@request ||= JSONAPI::RequestParser.new(
params,
context: context,
key_formatter: key_formatter,
server_error_callbacks: (self.class.server_error_callbacks || [])
)
end | [
"def",
"setup_request",
"@request",
"||=",
"JSONAPI",
"::",
"RequestParser",
".",
"new",
"(",
"params",
",",
"context",
":",
"context",
",",
"key_formatter",
":",
"key_formatter",
",",
"server_error_callbacks",
":",
"(",
"self",
".",
"class",
".",
"server_error_... | Instantiate the request object.
@return [JSONAPI::RequestParser]
@api public | [
"Instantiate",
"the",
"request",
"object",
"."
] | a2c2b0e3843376718929723d9f609611f68b665e | https://github.com/tiagopog/jsonapi-utils/blob/a2c2b0e3843376718929723d9f609611f68b665e/lib/jsonapi/utils/request.rb#L16-L23 |
15,404 | tiagopog/jsonapi-utils | lib/jsonapi/utils/request.rb | JSONAPI::Utils.Request.build_params_for | def build_params_for(param_type)
return {} if @request.operations.empty?
keys = %i(attributes to_one to_many)
operation = @request.operations.find { |e| e.options[:data].keys & keys == keys }
if operation.nil?
{}
elsif param_type == :relationship
operation.options[:data].... | ruby | def build_params_for(param_type)
return {} if @request.operations.empty?
keys = %i(attributes to_one to_many)
operation = @request.operations.find { |e| e.options[:data].keys & keys == keys }
if operation.nil?
{}
elsif param_type == :relationship
operation.options[:data].... | [
"def",
"build_params_for",
"(",
"param_type",
")",
"return",
"{",
"}",
"if",
"@request",
".",
"operations",
".",
"empty?",
"keys",
"=",
"%i(",
"attributes",
"to_one",
"to_many",
")",
"operation",
"=",
"@request",
".",
"operations",
".",
"find",
"{",
"|",
"... | Extract params from request and build a Hash with params
for either the main resource or relationships.
@return [Hash]
@api private | [
"Extract",
"params",
"from",
"request",
"and",
"build",
"a",
"Hash",
"with",
"params",
"for",
"either",
"the",
"main",
"resource",
"or",
"relationships",
"."
] | a2c2b0e3843376718929723d9f609611f68b665e | https://github.com/tiagopog/jsonapi-utils/blob/a2c2b0e3843376718929723d9f609611f68b665e/lib/jsonapi/utils/request.rb#L77-L90 |
15,405 | jenseng/hair_trigger | lib/hair_trigger/builder.rb | HairTrigger.Builder.initialize_copy | def initialize_copy(other)
@trigger_group = other
@triggers = nil
@chained_calls = []
@errors = []
@warnings = []
@options = @options.dup
@options.delete(:name) # this will be inferred (or set further down the line)
@options.each do |key, value|
@options[key] = va... | ruby | def initialize_copy(other)
@trigger_group = other
@triggers = nil
@chained_calls = []
@errors = []
@warnings = []
@options = @options.dup
@options.delete(:name) # this will be inferred (or set further down the line)
@options.each do |key, value|
@options[key] = va... | [
"def",
"initialize_copy",
"(",
"other",
")",
"@trigger_group",
"=",
"other",
"@triggers",
"=",
"nil",
"@chained_calls",
"=",
"[",
"]",
"@errors",
"=",
"[",
"]",
"@warnings",
"=",
"[",
"]",
"@options",
"=",
"@options",
".",
"dup",
"@options",
".",
"delete",... | after delayed interpolation | [
"after",
"delayed",
"interpolation"
] | 567ace98e896f0107ca1ea50c448d32409453811 | https://github.com/jenseng/hair_trigger/blob/567ace98e896f0107ca1ea50c448d32409453811/lib/hair_trigger/builder.rb#L29-L40 |
15,406 | cgriego/active_attr | lib/active_attr/typecasting.rb | ActiveAttr.Typecasting.typecast_attribute | def typecast_attribute(typecaster, value)
raise ArgumentError, "a typecaster must be given" unless typecaster.respond_to?(:call)
return value if value.nil?
typecaster.call(value)
end | ruby | def typecast_attribute(typecaster, value)
raise ArgumentError, "a typecaster must be given" unless typecaster.respond_to?(:call)
return value if value.nil?
typecaster.call(value)
end | [
"def",
"typecast_attribute",
"(",
"typecaster",
",",
"value",
")",
"raise",
"ArgumentError",
",",
"\"a typecaster must be given\"",
"unless",
"typecaster",
".",
"respond_to?",
"(",
":call",
")",
"return",
"value",
"if",
"value",
".",
"nil?",
"typecaster",
".",
"ca... | Typecasts a value using a Class
@param [#call] typecaster The typecaster to use for typecasting
@param [Object] value The value to be typecasted
@return [Object, nil] The typecasted value or nil if it cannot be
typecasted
@since 0.5.0 | [
"Typecasts",
"a",
"value",
"using",
"a",
"Class"
] | 1f3a49309561491fe436e3253de7d2faa92012ec | https://github.com/cgriego/active_attr/blob/1f3a49309561491fe436e3253de7d2faa92012ec/lib/active_attr/typecasting.rb#L48-L52 |
15,407 | cgriego/active_attr | lib/active_attr/attributes.rb | ActiveAttr.Attributes.inspect | def inspect
attribute_descriptions = attributes.sort.map { |key, value| "#{key}: #{value.inspect}" }.join(", ")
separator = " " unless attribute_descriptions.empty?
"#<#{self.class.name}#{separator}#{attribute_descriptions}>"
end | ruby | def inspect
attribute_descriptions = attributes.sort.map { |key, value| "#{key}: #{value.inspect}" }.join(", ")
separator = " " unless attribute_descriptions.empty?
"#<#{self.class.name}#{separator}#{attribute_descriptions}>"
end | [
"def",
"inspect",
"attribute_descriptions",
"=",
"attributes",
".",
"sort",
".",
"map",
"{",
"|",
"key",
",",
"value",
"|",
"\"#{key}: #{value.inspect}\"",
"}",
".",
"join",
"(",
"\", \"",
")",
"separator",
"=",
"\" \"",
"unless",
"attribute_descriptions",
".",
... | Returns the class name plus its attributes
@example Inspect the model.
person.inspect
@return [String] Human-readable presentation of the attribute
definitions
@since 0.2.0 | [
"Returns",
"the",
"class",
"name",
"plus",
"its",
"attributes"
] | 1f3a49309561491fe436e3253de7d2faa92012ec | https://github.com/cgriego/active_attr/blob/1f3a49309561491fe436e3253de7d2faa92012ec/lib/active_attr/attributes.rb#L72-L76 |
15,408 | cgriego/active_attr | lib/active_attr/attribute_definition.rb | ActiveAttr.AttributeDefinition.inspect | def inspect
options_description = options.map { |key, value| "#{key.inspect} => #{value.inspect}" }.sort.join(", ")
inspected_options = ", #{options_description}" unless options_description.empty?
"attribute :#{name}#{inspected_options}"
end | ruby | def inspect
options_description = options.map { |key, value| "#{key.inspect} => #{value.inspect}" }.sort.join(", ")
inspected_options = ", #{options_description}" unless options_description.empty?
"attribute :#{name}#{inspected_options}"
end | [
"def",
"inspect",
"options_description",
"=",
"options",
".",
"map",
"{",
"|",
"key",
",",
"value",
"|",
"\"#{key.inspect} => #{value.inspect}\"",
"}",
".",
"sort",
".",
"join",
"(",
"\", \"",
")",
"inspected_options",
"=",
"\", #{options_description}\"",
"unless",
... | Creates a new AttributeDefinition
@example Create an attribute defintion
AttributeDefinition.new(:amount)
@param [Symbol, String, #to_sym] name attribute name
@param [Hash{Symbol => Object}] options attribute options
@return [ActiveAttr::AttributeDefinition]
@since 0.2.0
Returns the code that would generat... | [
"Creates",
"a",
"new",
"AttributeDefinition"
] | 1f3a49309561491fe436e3253de7d2faa92012ec | https://github.com/cgriego/active_attr/blob/1f3a49309561491fe436e3253de7d2faa92012ec/lib/active_attr/attribute_definition.rb#L70-L74 |
15,409 | cgriego/active_attr | lib/active_attr/attribute_defaults.rb | ActiveAttr.AttributeDefaults.apply_defaults | def apply_defaults(defaults=attribute_defaults)
@attributes ||= {}
defaults.each do |name, value|
# instance variable is used here to avoid any dirty tracking in attribute setter methods
@attributes[name] = value unless @attributes.has_key? name
end
end | ruby | def apply_defaults(defaults=attribute_defaults)
@attributes ||= {}
defaults.each do |name, value|
# instance variable is used here to avoid any dirty tracking in attribute setter methods
@attributes[name] = value unless @attributes.has_key? name
end
end | [
"def",
"apply_defaults",
"(",
"defaults",
"=",
"attribute_defaults",
")",
"@attributes",
"||=",
"{",
"}",
"defaults",
".",
"each",
"do",
"|",
"name",
",",
"value",
"|",
"# instance variable is used here to avoid any dirty tracking in attribute setter methods",
"@attributes"... | Applies the attribute defaults
Applies all the default values to any attributes not yet set, avoiding
any attribute setter logic, such as dirty tracking.
@example Usage
class Person
include ActiveAttr::AttributeDefaults
attribute :first_name, :default => "John"
def reset!
@attributes = {... | [
"Applies",
"the",
"attribute",
"defaults"
] | 1f3a49309561491fe436e3253de7d2faa92012ec | https://github.com/cgriego/active_attr/blob/1f3a49309561491fe436e3253de7d2faa92012ec/lib/active_attr/attribute_defaults.rb#L70-L76 |
15,410 | cgriego/active_attr | lib/active_attr/attribute_defaults.rb | ActiveAttr.AttributeDefaults._attribute_default | def _attribute_default(attribute_name)
default = self.class.attributes[attribute_name][:default]
case
when default.respond_to?(:call) then instance_exec(&default)
when default.duplicable? then default.dup
else default
end
end | ruby | def _attribute_default(attribute_name)
default = self.class.attributes[attribute_name][:default]
case
when default.respond_to?(:call) then instance_exec(&default)
when default.duplicable? then default.dup
else default
end
end | [
"def",
"_attribute_default",
"(",
"attribute_name",
")",
"default",
"=",
"self",
".",
"class",
".",
"attributes",
"[",
"attribute_name",
"]",
"[",
":default",
"]",
"case",
"when",
"default",
".",
"respond_to?",
"(",
":call",
")",
"then",
"instance_exec",
"(",
... | Calculates an attribute default
@private
@since 0.5.0 | [
"Calculates",
"an",
"attribute",
"default"
] | 1f3a49309561491fe436e3253de7d2faa92012ec | https://github.com/cgriego/active_attr/blob/1f3a49309561491fe436e3253de7d2faa92012ec/lib/active_attr/attribute_defaults.rb#L110-L118 |
15,411 | cgriego/active_attr | lib/active_attr/mass_assignment.rb | ActiveAttr.MassAssignment.sanitize_for_mass_assignment_with_or_without_role | def sanitize_for_mass_assignment_with_or_without_role(new_attributes, options)
if method(:sanitize_for_mass_assignment).arity.abs > 1
sanitize_for_mass_assignment new_attributes, options[:as] || :default
else
sanitize_for_mass_assignment new_attributes
end
end | ruby | def sanitize_for_mass_assignment_with_or_without_role(new_attributes, options)
if method(:sanitize_for_mass_assignment).arity.abs > 1
sanitize_for_mass_assignment new_attributes, options[:as] || :default
else
sanitize_for_mass_assignment new_attributes
end
end | [
"def",
"sanitize_for_mass_assignment_with_or_without_role",
"(",
"new_attributes",
",",
"options",
")",
"if",
"method",
"(",
":sanitize_for_mass_assignment",
")",
".",
"arity",
".",
"abs",
">",
"1",
"sanitize_for_mass_assignment",
"new_attributes",
",",
"options",
"[",
... | Rails 3.0 and 4.0 do not take a role argument for the sanitizer
@since 0.7.0 | [
"Rails",
"3",
".",
"0",
"and",
"4",
".",
"0",
"do",
"not",
"take",
"a",
"role",
"argument",
"for",
"the",
"sanitizer"
] | 1f3a49309561491fe436e3253de7d2faa92012ec | https://github.com/cgriego/active_attr/blob/1f3a49309561491fe436e3253de7d2faa92012ec/lib/active_attr/mass_assignment.rb#L87-L93 |
15,412 | jmfederico/draftsman | lib/draftsman/frameworks/sinatra.rb | Draftsman.Sinatra.user_for_draftsman | def user_for_draftsman
return unless defined?(current_user)
ActiveSupport::VERSION::MAJOR >= 4 ? current_user.try!(:id) : current_user.try(:id)
rescue NoMethodError
current_user
end | ruby | def user_for_draftsman
return unless defined?(current_user)
ActiveSupport::VERSION::MAJOR >= 4 ? current_user.try!(:id) : current_user.try(:id)
rescue NoMethodError
current_user
end | [
"def",
"user_for_draftsman",
"return",
"unless",
"defined?",
"(",
"current_user",
")",
"ActiveSupport",
"::",
"VERSION",
"::",
"MAJOR",
">=",
"4",
"?",
"current_user",
".",
"try!",
"(",
":id",
")",
":",
"current_user",
".",
"try",
"(",
":id",
")",
"rescue",
... | Returns the user who is responsible for any changes that occur.
By default this calls `current_user` and returns the result.
Override this method in your controller to call a different
method, e.g. `current_person`, or anything you like. | [
"Returns",
"the",
"user",
"who",
"is",
"responsible",
"for",
"any",
"changes",
"that",
"occur",
".",
"By",
"default",
"this",
"calls",
"current_user",
"and",
"returns",
"the",
"result",
"."
] | fe7d29d37f12d126e502647c68ab9468747f5719 | https://github.com/jmfederico/draftsman/blob/fe7d29d37f12d126e502647c68ab9468747f5719/lib/draftsman/frameworks/sinatra.rb#L19-L24 |
15,413 | rocketjob/rocketjob | lib/rocket_job/dirmon_entry.rb | RocketJob.DirmonEntry.set_exception | def set_exception(worker_name, exc_or_message)
if exc_or_message.is_a?(Exception)
self.exception = JobException.from_exception(exc_or_message)
exception.worker_name = worker_name
else
build_exception(
class_name: 'RocketJob::DirmonEntryException',
message:... | ruby | def set_exception(worker_name, exc_or_message)
if exc_or_message.is_a?(Exception)
self.exception = JobException.from_exception(exc_or_message)
exception.worker_name = worker_name
else
build_exception(
class_name: 'RocketJob::DirmonEntryException',
message:... | [
"def",
"set_exception",
"(",
"worker_name",
",",
"exc_or_message",
")",
"if",
"exc_or_message",
".",
"is_a?",
"(",
"Exception",
")",
"self",
".",
"exception",
"=",
"JobException",
".",
"from_exception",
"(",
"exc_or_message",
")",
"exception",
".",
"worker_name",
... | Set exception information for this DirmonEntry and fail it | [
"Set",
"exception",
"information",
"for",
"this",
"DirmonEntry",
"and",
"fail",
"it"
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/dirmon_entry.rb#L220-L232 |
15,414 | rocketjob/rocketjob | lib/rocket_job/dirmon_entry.rb | RocketJob.DirmonEntry.later | def later(pathname)
job_id = BSON::ObjectId.new
archived_file_name = archive_file(job_id, pathname)
job = RocketJob::Jobs::UploadFileJob.create!(
job_class_name: job_class_name,
properties: properties,
description: "#{name}: #{pathname.basename}"... | ruby | def later(pathname)
job_id = BSON::ObjectId.new
archived_file_name = archive_file(job_id, pathname)
job = RocketJob::Jobs::UploadFileJob.create!(
job_class_name: job_class_name,
properties: properties,
description: "#{name}: #{pathname.basename}"... | [
"def",
"later",
"(",
"pathname",
")",
"job_id",
"=",
"BSON",
"::",
"ObjectId",
".",
"new",
"archived_file_name",
"=",
"archive_file",
"(",
"job_id",
",",
"pathname",
")",
"job",
"=",
"RocketJob",
"::",
"Jobs",
"::",
"UploadFileJob",
".",
"create!",
"(",
"j... | Archives the file and kicks off a proxy job to upload the file. | [
"Archives",
"the",
"file",
"and",
"kicks",
"off",
"a",
"proxy",
"job",
"to",
"upload",
"the",
"file",
"."
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/dirmon_entry.rb#L243-L268 |
15,415 | rocketjob/rocketjob | lib/rocket_job/dirmon_entry.rb | RocketJob.DirmonEntry.strip_whitespace | def strip_whitespace
self.pattern = pattern.strip unless pattern.nil?
self.archive_directory = archive_directory.strip unless archive_directory.nil?
end | ruby | def strip_whitespace
self.pattern = pattern.strip unless pattern.nil?
self.archive_directory = archive_directory.strip unless archive_directory.nil?
end | [
"def",
"strip_whitespace",
"self",
".",
"pattern",
"=",
"pattern",
".",
"strip",
"unless",
"pattern",
".",
"nil?",
"self",
".",
"archive_directory",
"=",
"archive_directory",
".",
"strip",
"unless",
"archive_directory",
".",
"nil?",
"end"
] | strip whitespaces from all variables that reference paths or patterns | [
"strip",
"whitespaces",
"from",
"all",
"variables",
"that",
"reference",
"paths",
"or",
"patterns"
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/dirmon_entry.rb#L273-L276 |
15,416 | rocketjob/rocketjob | lib/rocket_job/dirmon_entry.rb | RocketJob.DirmonEntry.archive_file | def archive_file(job_id, pathname)
target_path = archive_pathname(pathname)
target_path.mkpath
target_file_name = target_path.join("#{job_id}_#{pathname.basename}")
# In case the file is being moved across partitions
FileUtils.move(pathname.to_s, target_file_name.to_s)
target_file_na... | ruby | def archive_file(job_id, pathname)
target_path = archive_pathname(pathname)
target_path.mkpath
target_file_name = target_path.join("#{job_id}_#{pathname.basename}")
# In case the file is being moved across partitions
FileUtils.move(pathname.to_s, target_file_name.to_s)
target_file_na... | [
"def",
"archive_file",
"(",
"job_id",
",",
"pathname",
")",
"target_path",
"=",
"archive_pathname",
"(",
"pathname",
")",
"target_path",
".",
"mkpath",
"target_file_name",
"=",
"target_path",
".",
"join",
"(",
"\"#{job_id}_#{pathname.basename}\"",
")",
"# In case the ... | Move the file to the archive directory
The archived file name is prefixed with the job id
Returns [String] the fully qualified archived file name
Note:
- Works across partitions when the file and the archive are on different partitions | [
"Move",
"the",
"file",
"to",
"the",
"archive",
"directory"
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/dirmon_entry.rb#L289-L296 |
15,417 | rocketjob/rocketjob | lib/rocket_job/dirmon_entry.rb | RocketJob.DirmonEntry.job_is_a_rocket_job | def job_is_a_rocket_job
klass = job_class
return if job_class_name.nil? || klass&.ancestors&.include?(RocketJob::Job)
errors.add(:job_class_name, "Job #{job_class_name} must be defined and inherit from RocketJob::Job")
end | ruby | def job_is_a_rocket_job
klass = job_class
return if job_class_name.nil? || klass&.ancestors&.include?(RocketJob::Job)
errors.add(:job_class_name, "Job #{job_class_name} must be defined and inherit from RocketJob::Job")
end | [
"def",
"job_is_a_rocket_job",
"klass",
"=",
"job_class",
"return",
"if",
"job_class_name",
".",
"nil?",
"||",
"klass",
"&.",
"ancestors",
"&.",
"include?",
"(",
"RocketJob",
"::",
"Job",
")",
"errors",
".",
"add",
"(",
":job_class_name",
",",
"\"Job #{job_class_... | Validates job_class is a Rocket Job | [
"Validates",
"job_class",
"is",
"a",
"Rocket",
"Job"
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/dirmon_entry.rb#L315-L319 |
15,418 | rocketjob/rocketjob | lib/rocket_job/dirmon_entry.rb | RocketJob.DirmonEntry.job_has_properties | def job_has_properties
klass = job_class
return unless klass
properties.each_pair do |k, _v|
next if klass.public_method_defined?("#{k}=".to_sym)
errors.add(:properties, "Unknown Property: Attempted to set a value for #{k.inspect} which is not allowed on the job #{job_class_name}")
... | ruby | def job_has_properties
klass = job_class
return unless klass
properties.each_pair do |k, _v|
next if klass.public_method_defined?("#{k}=".to_sym)
errors.add(:properties, "Unknown Property: Attempted to set a value for #{k.inspect} which is not allowed on the job #{job_class_name}")
... | [
"def",
"job_has_properties",
"klass",
"=",
"job_class",
"return",
"unless",
"klass",
"properties",
".",
"each_pair",
"do",
"|",
"k",
",",
"_v",
"|",
"next",
"if",
"klass",
".",
"public_method_defined?",
"(",
"\"#{k}=\"",
".",
"to_sym",
")",
"errors",
".",
"a... | Does the job have all the supplied properties | [
"Does",
"the",
"job",
"have",
"all",
"the",
"supplied",
"properties"
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/dirmon_entry.rb#L322-L330 |
15,419 | rocketjob/rocketjob | lib/rocket_job/cli.rb | RocketJob.CLI.boot_standalone | def boot_standalone
# Try to load bundler if present
begin
require 'bundler/setup'
Bundler.require(environment)
rescue LoadError
nil
end
require 'rocketjob'
begin
require 'rocketjob_enterprise'
rescue LoadError
nil
end
# Log... | ruby | def boot_standalone
# Try to load bundler if present
begin
require 'bundler/setup'
Bundler.require(environment)
rescue LoadError
nil
end
require 'rocketjob'
begin
require 'rocketjob_enterprise'
rescue LoadError
nil
end
# Log... | [
"def",
"boot_standalone",
"# Try to load bundler if present",
"begin",
"require",
"'bundler/setup'",
"Bundler",
".",
"require",
"(",
"environment",
")",
"rescue",
"LoadError",
"nil",
"end",
"require",
"'rocketjob'",
"begin",
"require",
"'rocketjob_enterprise'",
"rescue",
... | In a standalone environment, explicitly load config files | [
"In",
"a",
"standalone",
"environment",
"explicitly",
"load",
"config",
"files"
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/cli.rb#L88-L113 |
15,420 | rocketjob/rocketjob | lib/rocket_job/cli.rb | RocketJob.CLI.write_pidfile | def write_pidfile
return unless pidfile
pid = $PID
File.open(pidfile, 'w') { |f| f.puts(pid) }
# Remove pidfile on exit
at_exit do
File.delete(pidfile) if pid == $PID
end
end | ruby | def write_pidfile
return unless pidfile
pid = $PID
File.open(pidfile, 'w') { |f| f.puts(pid) }
# Remove pidfile on exit
at_exit do
File.delete(pidfile) if pid == $PID
end
end | [
"def",
"write_pidfile",
"return",
"unless",
"pidfile",
"pid",
"=",
"$PID",
"File",
".",
"open",
"(",
"pidfile",
",",
"'w'",
")",
"{",
"|",
"f",
"|",
"f",
".",
"puts",
"(",
"pid",
")",
"}",
"# Remove pidfile on exit",
"at_exit",
"do",
"File",
".",
"dele... | Create a PID file if requested | [
"Create",
"a",
"PID",
"file",
"if",
"requested"
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/cli.rb#L116-L125 |
15,421 | rocketjob/rocketjob | lib/rocket_job/cli.rb | RocketJob.CLI.parse | def parse(argv)
parser = OptionParser.new do |o|
o.on('-n', '--name NAME', 'Unique Name of this server (Default: host_name:PID)') do |arg|
@name = arg
end
o.on('-w', '--workers COUNT', 'Number of workers (threads) to start') do |arg|
@workers = arg.to_i
e... | ruby | def parse(argv)
parser = OptionParser.new do |o|
o.on('-n', '--name NAME', 'Unique Name of this server (Default: host_name:PID)') do |arg|
@name = arg
end
o.on('-w', '--workers COUNT', 'Number of workers (threads) to start') do |arg|
@workers = arg.to_i
e... | [
"def",
"parse",
"(",
"argv",
")",
"parser",
"=",
"OptionParser",
".",
"new",
"do",
"|",
"o",
"|",
"o",
".",
"on",
"(",
"'-n'",
",",
"'--name NAME'",
",",
"'Unique Name of this server (Default: host_name:PID)'",
")",
"do",
"|",
"arg",
"|",
"@name",
"=",
"ar... | Parse command line options placing results in the corresponding instance variables | [
"Parse",
"command",
"line",
"options",
"placing",
"results",
"in",
"the",
"corresponding",
"instance",
"variables"
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/cli.rb#L168-L224 |
15,422 | rocketjob/rocketjob | lib/rocket_job/worker.rb | RocketJob.Worker.run | def run
Thread.current.name = format('rocketjob %03i', id)
logger.info 'Started'
until shutdown?
wait = RocketJob::Config.instance.max_poll_seconds
if process_available_jobs
# Keeps workers staggered across the poll interval so that
# all workers don't poll at the s... | ruby | def run
Thread.current.name = format('rocketjob %03i', id)
logger.info 'Started'
until shutdown?
wait = RocketJob::Config.instance.max_poll_seconds
if process_available_jobs
# Keeps workers staggered across the poll interval so that
# all workers don't poll at the s... | [
"def",
"run",
"Thread",
".",
"current",
".",
"name",
"=",
"format",
"(",
"'rocketjob %03i'",
",",
"id",
")",
"logger",
".",
"info",
"'Started'",
"until",
"shutdown?",
"wait",
"=",
"RocketJob",
"::",
"Config",
".",
"instance",
".",
"max_poll_seconds",
"if",
... | Process jobs until it shuts down
Params
worker_id [Integer]
The number of this worker for logging purposes | [
"Process",
"jobs",
"until",
"it",
"shuts",
"down"
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/worker.rb#L92-L109 |
15,423 | rocketjob/rocketjob | lib/rocket_job/worker.rb | RocketJob.Worker.reset_filter_if_expired | def reset_filter_if_expired
# Only clear out the current_filter after every `re_check_seconds`
time = Time.now
return unless (time - @re_check_start) > re_check_seconds
@re_check_start = time
self.current_filter = filter.dup if current_filter != filter
end | ruby | def reset_filter_if_expired
# Only clear out the current_filter after every `re_check_seconds`
time = Time.now
return unless (time - @re_check_start) > re_check_seconds
@re_check_start = time
self.current_filter = filter.dup if current_filter != filter
end | [
"def",
"reset_filter_if_expired",
"# Only clear out the current_filter after every `re_check_seconds`",
"time",
"=",
"Time",
".",
"now",
"return",
"unless",
"(",
"time",
"-",
"@re_check_start",
")",
">",
"re_check_seconds",
"@re_check_start",
"=",
"time",
"self",
".",
"cu... | Resets the current job filter if the relevant time interval has passed | [
"Resets",
"the",
"current",
"job",
"filter",
"if",
"the",
"relevant",
"time",
"interval",
"has",
"passed"
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/worker.rb#L128-L135 |
15,424 | rocketjob/rocketjob | lib/rocket_job/plugins/rufus/cron_line.rb | RocketJob::Plugins::Rufus.CronLine.previous_time | def previous_time(from=ZoTime.now)
pt = nil
zt = ZoTime.new(from.to_i - 1, @timezone)
miny = from.year - NEXT_TIME_MAX_YEARS
loop do
pt = zt.dup
fail RangeError.new(
"failed to reach occurrence within " +
"#{NEXT_TIME_MAX_YEARS} years for '#{original}'"
... | ruby | def previous_time(from=ZoTime.now)
pt = nil
zt = ZoTime.new(from.to_i - 1, @timezone)
miny = from.year - NEXT_TIME_MAX_YEARS
loop do
pt = zt.dup
fail RangeError.new(
"failed to reach occurrence within " +
"#{NEXT_TIME_MAX_YEARS} years for '#{original}'"
... | [
"def",
"previous_time",
"(",
"from",
"=",
"ZoTime",
".",
"now",
")",
"pt",
"=",
"nil",
"zt",
"=",
"ZoTime",
".",
"new",
"(",
"from",
".",
"to_i",
"-",
"1",
",",
"@timezone",
")",
"miny",
"=",
"from",
".",
"year",
"-",
"NEXT_TIME_MAX_YEARS",
"loop",
... | Returns the previous time the cronline matched. It's like next_time, but
for the past. | [
"Returns",
"the",
"previous",
"time",
"the",
"cronline",
"matched",
".",
"It",
"s",
"like",
"next_time",
"but",
"for",
"the",
"past",
"."
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/plugins/rufus/cron_line.rb#L182-L218 |
15,425 | rocketjob/rocketjob | lib/rocket_job/worker_pool.rb | RocketJob.WorkerPool.rebalance | def rebalance(max_workers, stagger_start = false)
count = max_workers.to_i - living_count
return 0 unless count > 0
logger.info("#{'Stagger ' if stagger_start}Starting #{count} workers")
add_one
count -= 1
delay = Config.instance.max_poll_seconds.to_f / max_workers
count.tim... | ruby | def rebalance(max_workers, stagger_start = false)
count = max_workers.to_i - living_count
return 0 unless count > 0
logger.info("#{'Stagger ' if stagger_start}Starting #{count} workers")
add_one
count -= 1
delay = Config.instance.max_poll_seconds.to_f / max_workers
count.tim... | [
"def",
"rebalance",
"(",
"max_workers",
",",
"stagger_start",
"=",
"false",
")",
"count",
"=",
"max_workers",
".",
"to_i",
"-",
"living_count",
"return",
"0",
"unless",
"count",
">",
"0",
"logger",
".",
"info",
"(",
"\"#{'Stagger ' if stagger_start}Starting #{coun... | Add new workers to get back to the `max_workers` if not already at `max_workers`
Parameters
stagger_start
Whether to stagger when the workers poll for work the first time.
It spreads out the queue polling over the max_poll_seconds so
that not all workers poll at the same time.
The wo... | [
"Add",
"new",
"workers",
"to",
"get",
"back",
"to",
"the",
"max_workers",
"if",
"not",
"already",
"at",
"max_workers",
"Parameters",
"stagger_start",
"Whether",
"to",
"stagger",
"when",
"the",
"workers",
"poll",
"for",
"work",
"the",
"first",
"time",
".",
"I... | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/worker_pool.rb#L29-L44 |
15,426 | rocketjob/rocketjob | lib/rocket_job/performance.rb | RocketJob.Performance.export_results | def export_results(results)
CSV.open("job_results_#{ruby}_#{servers}s_#{workers}w_v#{version}.csv", 'wb') do |csv|
csv << results.first.keys
results.each { |result| csv << result.values }
end
end | ruby | def export_results(results)
CSV.open("job_results_#{ruby}_#{servers}s_#{workers}w_v#{version}.csv", 'wb') do |csv|
csv << results.first.keys
results.each { |result| csv << result.values }
end
end | [
"def",
"export_results",
"(",
"results",
")",
"CSV",
".",
"open",
"(",
"\"job_results_#{ruby}_#{servers}s_#{workers}w_v#{version}.csv\"",
",",
"'wb'",
")",
"do",
"|",
"csv",
"|",
"csv",
"<<",
"results",
".",
"first",
".",
"keys",
"results",
".",
"each",
"{",
"... | Export the Results hash to a CSV file | [
"Export",
"the",
"Results",
"hash",
"to",
"a",
"CSV",
"file"
] | 6492dd68bf8b906fcca6d374cca65e0238ce07b7 | https://github.com/rocketjob/rocketjob/blob/6492dd68bf8b906fcca6d374cca65e0238ce07b7/lib/rocket_job/performance.rb#L60-L65 |
15,427 | envato/event_sourcery | lib/event_sourcery/event.rb | EventSourcery.Event.with | def with(event_class: self.class, **attributes)
if self.class != Event && !attributes[:type].nil? && attributes[:type] != type
raise Error, 'When using typed events change the type by changing the event class.'
end
event_class.new(**to_h.merge!(attributes))
end | ruby | def with(event_class: self.class, **attributes)
if self.class != Event && !attributes[:type].nil? && attributes[:type] != type
raise Error, 'When using typed events change the type by changing the event class.'
end
event_class.new(**to_h.merge!(attributes))
end | [
"def",
"with",
"(",
"event_class",
":",
"self",
".",
"class",
",",
"**",
"attributes",
")",
"if",
"self",
".",
"class",
"!=",
"Event",
"&&",
"!",
"attributes",
"[",
":type",
"]",
".",
"nil?",
"&&",
"attributes",
"[",
":type",
"]",
"!=",
"type",
"rais... | create a new event identical to the old event except for the provided changes
@param attributes [Hash]
@return Event
@example
old_event = EventSourcery::Event.new(type: "item_added", causation_id: nil)
new_event = old_event.with(causation_id: "05781bd6-796a-4a58-8573-b109f683fd99")
new_event.type # ... | [
"create",
"a",
"new",
"event",
"identical",
"to",
"the",
"old",
"event",
"except",
"for",
"the",
"provided",
"changes"
] | f844921b0368af2ee6342a988ee0a2635c7c821c | https://github.com/envato/event_sourcery/blob/f844921b0368af2ee6342a988ee0a2635c7c821c/lib/event_sourcery/event.rb#L138-L144 |
15,428 | envato/event_sourcery | lib/event_sourcery/event.rb | EventSourcery.Event.to_h | def to_h
{
id: id,
uuid: uuid,
aggregate_id: aggregate_id,
type: type,
body: body,
version: version,
created_at: created_at,
correlation_id: correlation_id,
causation_id: causation_id,
... | ruby | def to_h
{
id: id,
uuid: uuid,
aggregate_id: aggregate_id,
type: type,
body: body,
version: version,
created_at: created_at,
correlation_id: correlation_id,
causation_id: causation_id,
... | [
"def",
"to_h",
"{",
"id",
":",
"id",
",",
"uuid",
":",
"uuid",
",",
"aggregate_id",
":",
"aggregate_id",
",",
"type",
":",
"type",
",",
"body",
":",
"body",
",",
"version",
":",
"version",
",",
"created_at",
":",
"created_at",
",",
"correlation_id",
":... | returns a hash of the event attributes
@return Hash | [
"returns",
"a",
"hash",
"of",
"the",
"event",
"attributes"
] | f844921b0368af2ee6342a988ee0a2635c7c821c | https://github.com/envato/event_sourcery/blob/f844921b0368af2ee6342a988ee0a2635c7c821c/lib/event_sourcery/event.rb#L149-L161 |
15,429 | senchalabs/jsduck | lib/jsduck/parser.rb | JsDuck.Parser.parse | def parse(contents, filename="", options={})
@doc_processor.filename = @filename = filename
parse_js_or_scss(contents, filename, options).map do |docset|
expand(docset)
end.flatten.map do |docset|
merge(docset)
end
end | ruby | def parse(contents, filename="", options={})
@doc_processor.filename = @filename = filename
parse_js_or_scss(contents, filename, options).map do |docset|
expand(docset)
end.flatten.map do |docset|
merge(docset)
end
end | [
"def",
"parse",
"(",
"contents",
",",
"filename",
"=",
"\"\"",
",",
"options",
"=",
"{",
"}",
")",
"@doc_processor",
".",
"filename",
"=",
"@filename",
"=",
"filename",
"parse_js_or_scss",
"(",
"contents",
",",
"filename",
",",
"options",
")",
".",
"map",
... | Parses file into final docset that can be fed into Aggregator | [
"Parses",
"file",
"into",
"final",
"docset",
"that",
"can",
"be",
"fed",
"into",
"Aggregator"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/parser.rb#L27-L35 |
15,430 | senchalabs/jsduck | lib/jsduck/parser.rb | JsDuck.Parser.parse_js_or_scss | def parse_js_or_scss(contents, filename, options)
if filename =~ /\.scss$/
docs = Css::Parser.new(contents, options).parse
else
docs = Js::Parser.new(contents, options).parse
docs = Js::Ast.new(docs).detect_all!
end
end | ruby | def parse_js_or_scss(contents, filename, options)
if filename =~ /\.scss$/
docs = Css::Parser.new(contents, options).parse
else
docs = Js::Parser.new(contents, options).parse
docs = Js::Ast.new(docs).detect_all!
end
end | [
"def",
"parse_js_or_scss",
"(",
"contents",
",",
"filename",
",",
"options",
")",
"if",
"filename",
"=~",
"/",
"\\.",
"/",
"docs",
"=",
"Css",
"::",
"Parser",
".",
"new",
"(",
"contents",
",",
"options",
")",
".",
"parse",
"else",
"docs",
"=",
"Js",
... | Parses the file depending on filename as JS or SCSS | [
"Parses",
"the",
"file",
"depending",
"on",
"filename",
"as",
"JS",
"or",
"SCSS"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/parser.rb#L40-L47 |
15,431 | senchalabs/jsduck | lib/jsduck/parser.rb | JsDuck.Parser.expand | def expand(docset)
docset[:comment] = @doc_parser.parse(docset[:comment], @filename, docset[:linenr])
docset[:doc_map] = Doc::Map.build(docset[:comment])
docset[:tagname] = BaseType.detect(docset[:doc_map], docset[:code])
if docset[:tagname] == :class
# expand class into several docsets... | ruby | def expand(docset)
docset[:comment] = @doc_parser.parse(docset[:comment], @filename, docset[:linenr])
docset[:doc_map] = Doc::Map.build(docset[:comment])
docset[:tagname] = BaseType.detect(docset[:doc_map], docset[:code])
if docset[:tagname] == :class
# expand class into several docsets... | [
"def",
"expand",
"(",
"docset",
")",
"docset",
"[",
":comment",
"]",
"=",
"@doc_parser",
".",
"parse",
"(",
"docset",
"[",
":comment",
"]",
",",
"@filename",
",",
"docset",
"[",
":linenr",
"]",
")",
"docset",
"[",
":doc_map",
"]",
"=",
"Doc",
"::",
"... | Parses the docs, detects tagname and expands class docset | [
"Parses",
"the",
"docs",
"detects",
"tagname",
"and",
"expands",
"class",
"docset"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/parser.rb#L50-L64 |
15,432 | senchalabs/jsduck | lib/jsduck/parser.rb | JsDuck.Parser.merge | def merge(docset)
@doc_processor.linenr = docset[:linenr]
docset[:comment] = @doc_processor.process(docset[:tagname], docset[:doc_map])
docset.delete(:doc_map)
@merger.merge(docset, @filename, docset[:linenr])
end | ruby | def merge(docset)
@doc_processor.linenr = docset[:linenr]
docset[:comment] = @doc_processor.process(docset[:tagname], docset[:doc_map])
docset.delete(:doc_map)
@merger.merge(docset, @filename, docset[:linenr])
end | [
"def",
"merge",
"(",
"docset",
")",
"@doc_processor",
".",
"linenr",
"=",
"docset",
"[",
":linenr",
"]",
"docset",
"[",
":comment",
"]",
"=",
"@doc_processor",
".",
"process",
"(",
"docset",
"[",
":tagname",
"]",
",",
"docset",
"[",
":doc_map",
"]",
")",... | Merges comment and code parts of docset | [
"Merges",
"comment",
"and",
"code",
"parts",
"of",
"docset"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/parser.rb#L67-L73 |
15,433 | senchalabs/jsduck | lib/jsduck/cache.rb | JsDuck.Cache.read | def read(file_name, file_contents)
fname = cache_file_name(file_name, file_contents)
if File.exists?(fname)
@previous_entry = fname
File.open(fname, "rb") {|file| Marshal::load(file) }
else
@previous_entry = nil
nil
end
end | ruby | def read(file_name, file_contents)
fname = cache_file_name(file_name, file_contents)
if File.exists?(fname)
@previous_entry = fname
File.open(fname, "rb") {|file| Marshal::load(file) }
else
@previous_entry = nil
nil
end
end | [
"def",
"read",
"(",
"file_name",
",",
"file_contents",
")",
"fname",
"=",
"cache_file_name",
"(",
"file_name",
",",
"file_contents",
")",
"if",
"File",
".",
"exists?",
"(",
"fname",
")",
"@previous_entry",
"=",
"fname",
"File",
".",
"open",
"(",
"fname",
"... | Given the name and contents of a source file, reads the already
parsed data structure from cache. Returns nil when not found. | [
"Given",
"the",
"name",
"and",
"contents",
"of",
"a",
"source",
"file",
"reads",
"the",
"already",
"parsed",
"data",
"structure",
"from",
"cache",
".",
"Returns",
"nil",
"when",
"not",
"found",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/cache.rb#L76-L85 |
15,434 | senchalabs/jsduck | lib/jsduck/cache.rb | JsDuck.Cache.write | def write(file_name, file_contents, data)
fname = cache_file_name(file_name, file_contents)
@previous_entry = fname
File.open(fname, "wb") {|file| Marshal::dump(data, file) }
end | ruby | def write(file_name, file_contents, data)
fname = cache_file_name(file_name, file_contents)
@previous_entry = fname
File.open(fname, "wb") {|file| Marshal::dump(data, file) }
end | [
"def",
"write",
"(",
"file_name",
",",
"file_contents",
",",
"data",
")",
"fname",
"=",
"cache_file_name",
"(",
"file_name",
",",
"file_contents",
")",
"@previous_entry",
"=",
"fname",
"File",
".",
"open",
"(",
"fname",
",",
"\"wb\"",
")",
"{",
"|",
"file"... | Writes parse data into cache under a name generated from the
name and contents of a source file. | [
"Writes",
"parse",
"data",
"into",
"cache",
"under",
"a",
"name",
"generated",
"from",
"the",
"name",
"and",
"contents",
"of",
"a",
"source",
"file",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/cache.rb#L89-L93 |
15,435 | senchalabs/jsduck | lib/jsduck/guides.rb | JsDuck.Guides.write | def write(dir)
FileUtils.mkdir(dir) unless File.exists?(dir)
each_item {|guide| write_guide(guide, dir) }
end | ruby | def write(dir)
FileUtils.mkdir(dir) unless File.exists?(dir)
each_item {|guide| write_guide(guide, dir) }
end | [
"def",
"write",
"(",
"dir",
")",
"FileUtils",
".",
"mkdir",
"(",
"dir",
")",
"unless",
"File",
".",
"exists?",
"(",
"dir",
")",
"each_item",
"{",
"|",
"guide",
"|",
"write_guide",
"(",
"guide",
",",
"dir",
")",
"}",
"end"
] | Parses guides config file
Writes all guides to given dir in JsonP format | [
"Parses",
"guides",
"config",
"file",
"Writes",
"all",
"guides",
"to",
"given",
"dir",
"in",
"JsonP",
"format"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/guides.rb#L36-L39 |
15,436 | senchalabs/jsduck | lib/jsduck/guides.rb | JsDuck.Guides.fix_icon | def fix_icon(dir)
if File.exists?(dir+"/icon.png")
# All ok
elsif File.exists?(dir+"/icon-lg.png")
FileUtils.mv(dir+"/icon-lg.png", dir+"/icon.png")
else
FileUtils.cp(@opts.template+"/resources/images/default-guide.png", dir+"/icon.png")
end
end | ruby | def fix_icon(dir)
if File.exists?(dir+"/icon.png")
# All ok
elsif File.exists?(dir+"/icon-lg.png")
FileUtils.mv(dir+"/icon-lg.png", dir+"/icon.png")
else
FileUtils.cp(@opts.template+"/resources/images/default-guide.png", dir+"/icon.png")
end
end | [
"def",
"fix_icon",
"(",
"dir",
")",
"if",
"File",
".",
"exists?",
"(",
"dir",
"+",
"\"/icon.png\"",
")",
"# All ok",
"elsif",
"File",
".",
"exists?",
"(",
"dir",
"+",
"\"/icon-lg.png\"",
")",
"FileUtils",
".",
"mv",
"(",
"dir",
"+",
"\"/icon-lg.png\"",
"... | Ensures the guide dir contains icon.png.
When there isn't looks for icon-lg.png and renames it to icon.png.
When neither exists, copies over default icon. | [
"Ensures",
"the",
"guide",
"dir",
"contains",
"icon",
".",
"png",
".",
"When",
"there",
"isn",
"t",
"looks",
"for",
"icon",
"-",
"lg",
".",
"png",
"and",
"renames",
"it",
"to",
"icon",
".",
"png",
".",
"When",
"neither",
"exists",
"copies",
"over",
"... | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/guides.rb#L145-L153 |
15,437 | senchalabs/jsduck | lib/jsduck/aggregator.rb | JsDuck.Aggregator.add_class | def add_class(cls)
old_cls = @classes[cls[:name]]
if !old_cls && @alt_names[cls[:name]]
old_cls = @alt_names[cls[:name]]
warn_alt_name(cls)
end
if old_cls
merge_classes(old_cls, cls)
@current_class = old_cls
else
@current_class = cls
@classe... | ruby | def add_class(cls)
old_cls = @classes[cls[:name]]
if !old_cls && @alt_names[cls[:name]]
old_cls = @alt_names[cls[:name]]
warn_alt_name(cls)
end
if old_cls
merge_classes(old_cls, cls)
@current_class = old_cls
else
@current_class = cls
@classe... | [
"def",
"add_class",
"(",
"cls",
")",
"old_cls",
"=",
"@classes",
"[",
"cls",
"[",
":name",
"]",
"]",
"if",
"!",
"old_cls",
"&&",
"@alt_names",
"[",
"cls",
"[",
":name",
"]",
"]",
"old_cls",
"=",
"@alt_names",
"[",
"cls",
"[",
":name",
"]",
"]",
"wa... | When class exists, merge it with class node.
Otherwise add as new class. | [
"When",
"class",
"exists",
"merge",
"it",
"with",
"class",
"node",
".",
"Otherwise",
"add",
"as",
"new",
"class",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/aggregator.rb#L53-L87 |
15,438 | senchalabs/jsduck | lib/jsduck/aggregator.rb | JsDuck.Aggregator.merge_classes | def merge_classes(old, new)
# Merge booleans
[:extends, :singleton, :private].each do |tag|
old[tag] = old[tag] || new[tag]
end
# Merge arrays
[:mixins, :alternateClassNames, :requires, :uses, :files].each do |tag|
old[tag] = (old[tag] || []) + (new[tag] || [])
end
... | ruby | def merge_classes(old, new)
# Merge booleans
[:extends, :singleton, :private].each do |tag|
old[tag] = old[tag] || new[tag]
end
# Merge arrays
[:mixins, :alternateClassNames, :requires, :uses, :files].each do |tag|
old[tag] = (old[tag] || []) + (new[tag] || [])
end
... | [
"def",
"merge_classes",
"(",
"old",
",",
"new",
")",
"# Merge booleans",
"[",
":extends",
",",
":singleton",
",",
":private",
"]",
".",
"each",
"do",
"|",
"tag",
"|",
"old",
"[",
"tag",
"]",
"=",
"old",
"[",
"tag",
"]",
"||",
"new",
"[",
"tag",
"]"... | Merges new class-doc into old one. | [
"Merges",
"new",
"class",
"-",
"doc",
"into",
"old",
"one",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/aggregator.rb#L94-L112 |
15,439 | senchalabs/jsduck | lib/jsduck/aggregator.rb | JsDuck.Aggregator.add_member | def add_member(node)
# Completely ignore member if @ignore used
return if node[:ignore]
if node[:owner]
if @classes[node[:owner]]
add_to_class(@classes[node[:owner]], node)
else
add_orphan(node)
end
elsif @current_class
node[:owner] = @current... | ruby | def add_member(node)
# Completely ignore member if @ignore used
return if node[:ignore]
if node[:owner]
if @classes[node[:owner]]
add_to_class(@classes[node[:owner]], node)
else
add_orphan(node)
end
elsif @current_class
node[:owner] = @current... | [
"def",
"add_member",
"(",
"node",
")",
"# Completely ignore member if @ignore used",
"return",
"if",
"node",
"[",
":ignore",
"]",
"if",
"node",
"[",
":owner",
"]",
"if",
"@classes",
"[",
"node",
"[",
":owner",
"]",
"]",
"add_to_class",
"(",
"@classes",
"[",
... | Tries to place members into classes where they belong.
@member explicitly defines the containing class, but we can meet
item with @member=Foo before we actually meet class Foo - in
that case we register them as orphans. (Later when we finally
meet class Foo, orphans are inserted into it.)
Items without @member ... | [
"Tries",
"to",
"place",
"members",
"into",
"classes",
"where",
"they",
"belong",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/aggregator.rb#L123-L139 |
15,440 | senchalabs/jsduck | lib/jsduck/aggregator.rb | JsDuck.Aggregator.insert_orphans | def insert_orphans(cls)
members = @orphans.find_all {|node| node[:owner] == cls[:name] }
members.each do |node|
add_to_class(cls, node)
@orphans.delete(node)
end
end | ruby | def insert_orphans(cls)
members = @orphans.find_all {|node| node[:owner] == cls[:name] }
members.each do |node|
add_to_class(cls, node)
@orphans.delete(node)
end
end | [
"def",
"insert_orphans",
"(",
"cls",
")",
"members",
"=",
"@orphans",
".",
"find_all",
"{",
"|",
"node",
"|",
"node",
"[",
":owner",
"]",
"==",
"cls",
"[",
":name",
"]",
"}",
"members",
".",
"each",
"do",
"|",
"node",
"|",
"add_to_class",
"(",
"cls",... | Inserts available orphans to class | [
"Inserts",
"available",
"orphans",
"to",
"class"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/aggregator.rb#L150-L156 |
15,441 | senchalabs/jsduck | lib/jsduck/merger.rb | JsDuck.Merger.general_merge | def general_merge(h, docs, code)
# Add all items in docs not already in result.
docs.each_pair do |key, value|
h[key] = value unless h[key]
end
# Add all items in code not already in result and mark them as
# auto-detected. But only if the explicit and auto-detected
# names... | ruby | def general_merge(h, docs, code)
# Add all items in docs not already in result.
docs.each_pair do |key, value|
h[key] = value unless h[key]
end
# Add all items in code not already in result and mark them as
# auto-detected. But only if the explicit and auto-detected
# names... | [
"def",
"general_merge",
"(",
"h",
",",
"docs",
",",
"code",
")",
"# Add all items in docs not already in result.",
"docs",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"h",
"[",
"key",
"]",
"=",
"value",
"unless",
"h",
"[",
"key",
"]",
"end",
"... | Applies default merge algorithm to the rest of the data. | [
"Applies",
"default",
"merge",
"algorithm",
"to",
"the",
"rest",
"of",
"the",
"data",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/merger.rb#L49-L66 |
15,442 | senchalabs/jsduck | lib/jsduck/members_index.rb | JsDuck.MembersIndex.merge! | def merge!(hash1, hash2)
hash2.each_pair do |name, m|
if m[:hide]
if hash1[name]
hash1.delete(name)
else
msg = "@hide used but #{m[:tagname]} #{m[:name]} not found in parent class"
Logger.warn(:hide, msg, m[:files][0])
end
else
... | ruby | def merge!(hash1, hash2)
hash2.each_pair do |name, m|
if m[:hide]
if hash1[name]
hash1.delete(name)
else
msg = "@hide used but #{m[:tagname]} #{m[:name]} not found in parent class"
Logger.warn(:hide, msg, m[:files][0])
end
else
... | [
"def",
"merge!",
"(",
"hash1",
",",
"hash2",
")",
"hash2",
".",
"each_pair",
"do",
"|",
"name",
",",
"m",
"|",
"if",
"m",
"[",
":hide",
"]",
"if",
"hash1",
"[",
"name",
"]",
"hash1",
".",
"delete",
"(",
"name",
")",
"else",
"msg",
"=",
"\"@hide u... | merges second members hash into first one | [
"merges",
"second",
"members",
"hash",
"into",
"first",
"one"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/members_index.rb#L93-L109 |
15,443 | senchalabs/jsduck | lib/jsduck/members_index.rb | JsDuck.MembersIndex.store_overrides | def store_overrides(old, new)
# Sometimes a class is included multiple times (like Ext.Base)
# resulting in its members overriding themselves. Because of
# this, ignore overriding itself.
if new[:owner] != old[:owner]
new[:overrides] = [] unless new[:overrides]
unless new[:overr... | ruby | def store_overrides(old, new)
# Sometimes a class is included multiple times (like Ext.Base)
# resulting in its members overriding themselves. Because of
# this, ignore overriding itself.
if new[:owner] != old[:owner]
new[:overrides] = [] unless new[:overrides]
unless new[:overr... | [
"def",
"store_overrides",
"(",
"old",
",",
"new",
")",
"# Sometimes a class is included multiple times (like Ext.Base)",
"# resulting in its members overriding themselves. Because of",
"# this, ignore overriding itself.",
"if",
"new",
"[",
":owner",
"]",
"!=",
"old",
"[",
":owne... | Invoked when merge! finds two members with the same name.
New member always overrides the old, but inside new we keep
a list of members it overrides. Normally one member will
override one other member, but a member from mixin can override
multiple members - although there's not a single such case in
ExtJS, we hav... | [
"Invoked",
"when",
"merge!",
"finds",
"two",
"members",
"with",
"the",
"same",
"name",
".",
"New",
"member",
"always",
"overrides",
"the",
"old",
"but",
"inside",
"new",
"we",
"keep",
"a",
"list",
"of",
"members",
"it",
"overrides",
".",
"Normally",
"one",... | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/members_index.rb#L119-L137 |
15,444 | senchalabs/jsduck | lib/jsduck/news.rb | JsDuck.News.filter_new_members | def filter_new_members(cls)
members = cls.all_local_members.find_all do |m|
visible?(m) && (m[:new] || new_params?(m))
end
members = discard_accessors(members)
members.sort! {|a, b| a[:name] <=> b[:name] }
end | ruby | def filter_new_members(cls)
members = cls.all_local_members.find_all do |m|
visible?(m) && (m[:new] || new_params?(m))
end
members = discard_accessors(members)
members.sort! {|a, b| a[:name] <=> b[:name] }
end | [
"def",
"filter_new_members",
"(",
"cls",
")",
"members",
"=",
"cls",
".",
"all_local_members",
".",
"find_all",
"do",
"|",
"m",
"|",
"visible?",
"(",
"m",
")",
"&&",
"(",
"m",
"[",
":new",
"]",
"||",
"new_params?",
"(",
"m",
")",
")",
"end",
"members... | Returns all members of a class that have been marked as new, or
have parameters marked as new. | [
"Returns",
"all",
"members",
"of",
"a",
"class",
"that",
"have",
"been",
"marked",
"as",
"new",
"or",
"have",
"parameters",
"marked",
"as",
"new",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/news.rb#L68-L74 |
15,445 | senchalabs/jsduck | lib/jsduck/guide_toc.rb | JsDuck.GuideToc.inject! | def inject!
@html.each_line do |line|
if line =~ /^\s*<h([1-6])>(.*?)<\/h[1-6]>$/
level = $1.to_i
original_text = $2
text = Util::HTML.strip_tags(original_text)
id = title_to_id(text)
if include_to_toc?(level)
@toc.add(level, id, text)
... | ruby | def inject!
@html.each_line do |line|
if line =~ /^\s*<h([1-6])>(.*?)<\/h[1-6]>$/
level = $1.to_i
original_text = $2
text = Util::HTML.strip_tags(original_text)
id = title_to_id(text)
if include_to_toc?(level)
@toc.add(level, id, text)
... | [
"def",
"inject!",
"@html",
".",
"each_line",
"do",
"|",
"line",
"|",
"if",
"line",
"=~",
"/",
"\\s",
"\\/",
"/",
"level",
"=",
"$1",
".",
"to_i",
"original_text",
"=",
"$2",
"text",
"=",
"Util",
"::",
"HTML",
".",
"strip_tags",
"(",
"original_text",
... | Inserts table of contents at the top of guide HTML by looking
for headings at or below the specified maximum level. | [
"Inserts",
"table",
"of",
"contents",
"at",
"the",
"top",
"of",
"guide",
"HTML",
"by",
"looking",
"for",
"headings",
"at",
"or",
"below",
"the",
"specified",
"maximum",
"level",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/guide_toc.rb#L21-L42 |
15,446 | senchalabs/jsduck | lib/jsduck/class.rb | JsDuck.Class.internal_doc= | def internal_doc=(doc)
@doc.merge!(doc) do |key, oldval, newval|
if key == :members
oldval.zip(newval) do |ms|
ms[0].merge!(ms[1])
end
oldval
else
newval
end
end
end | ruby | def internal_doc=(doc)
@doc.merge!(doc) do |key, oldval, newval|
if key == :members
oldval.zip(newval) do |ms|
ms[0].merge!(ms[1])
end
oldval
else
newval
end
end
end | [
"def",
"internal_doc",
"=",
"(",
"doc",
")",
"@doc",
".",
"merge!",
"(",
"doc",
")",
"do",
"|",
"key",
",",
"oldval",
",",
"newval",
"|",
"if",
"key",
"==",
":members",
"oldval",
".",
"zip",
"(",
"newval",
")",
"do",
"|",
"ms",
"|",
"ms",
"[",
... | Sets the internal doc object.
The doc object is processed in parallel and then assigned back
through this method. But because of parallel processing the
assigned doc object will not be just a modified old @doc but a
completely new. If we were to just assign to @doc the
#find_members caches would still point to ... | [
"Sets",
"the",
"internal",
"doc",
"object",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/class.rb#L46-L57 |
15,447 | senchalabs/jsduck | lib/jsduck/class.rb | JsDuck.Class.lookup | def lookup(classname)
if @relations[classname]
@relations[classname]
elsif @relations.ignore?(classname) || classname =~ /\*/
# Ignore explicitly ignored classes and classnames with
# wildcards in them. We could expand the wildcard, but that
# can result in a very long list ... | ruby | def lookup(classname)
if @relations[classname]
@relations[classname]
elsif @relations.ignore?(classname) || classname =~ /\*/
# Ignore explicitly ignored classes and classnames with
# wildcards in them. We could expand the wildcard, but that
# can result in a very long list ... | [
"def",
"lookup",
"(",
"classname",
")",
"if",
"@relations",
"[",
"classname",
"]",
"@relations",
"[",
"classname",
"]",
"elsif",
"@relations",
".",
"ignore?",
"(",
"classname",
")",
"||",
"classname",
"=~",
"/",
"\\*",
"/",
"# Ignore explicitly ignored classes a... | Looks up class object by name
When not found, prints warning message. | [
"Looks",
"up",
"class",
"object",
"by",
"name",
"When",
"not",
"found",
"prints",
"warning",
"message",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/class.rb#L107-L122 |
15,448 | senchalabs/jsduck | lib/jsduck/class.rb | JsDuck.Class.find_members | def find_members(query={})
if query[:name]
ms = @members_index.global_by_name[query[:name]] || []
ms = ms.find_all {|m| m[:owner] == @doc[:name]} if query[:local]
elsif query[:local]
ms = @members_index.all_local
else
ms = @members_index.all_global
end
if q... | ruby | def find_members(query={})
if query[:name]
ms = @members_index.global_by_name[query[:name]] || []
ms = ms.find_all {|m| m[:owner] == @doc[:name]} if query[:local]
elsif query[:local]
ms = @members_index.all_local
else
ms = @members_index.all_global
end
if q... | [
"def",
"find_members",
"(",
"query",
"=",
"{",
"}",
")",
"if",
"query",
"[",
":name",
"]",
"ms",
"=",
"@members_index",
".",
"global_by_name",
"[",
"query",
"[",
":name",
"]",
"]",
"||",
"[",
"]",
"ms",
"=",
"ms",
".",
"find_all",
"{",
"|",
"m",
... | Returns list of members filtered by a query.
Searches both local and inherited members.
The query hash can contain the following fields:
- :name : String - the name of the member to find.
- :tagname : Symbol - the member type to look for.
- :static : Boolean - true to only return static members,
... | [
"Returns",
"list",
"of",
"members",
"filtered",
"by",
"a",
"query",
".",
"Searches",
"both",
"local",
"and",
"inherited",
"members",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/class.rb#L149-L170 |
15,449 | senchalabs/jsduck | lib/jsduck/tag/member_tag.rb | JsDuck::Tag.MemberTag.process_code | def process_code(code)
return {
:tagname => code[:tagname],
# An auto-detected name might be "MyClass.prototype.myMethod" -
# for member name we only want the last "myMethod" part.
:name => code[:name] ? code[:name].split(/\./).last : nil,
:autodetected => code[:autodetect... | ruby | def process_code(code)
return {
:tagname => code[:tagname],
# An auto-detected name might be "MyClass.prototype.myMethod" -
# for member name we only want the last "myMethod" part.
:name => code[:name] ? code[:name].split(/\./).last : nil,
:autodetected => code[:autodetect... | [
"def",
"process_code",
"(",
"code",
")",
"return",
"{",
":tagname",
"=>",
"code",
"[",
":tagname",
"]",
",",
"# An auto-detected name might be \"MyClass.prototype.myMethod\" -",
"# for member name we only want the last \"myMethod\" part.",
":name",
"=>",
"code",
"[",
":name",... | Extracts the fields auto-detected from code that are relevant to
the member type and returns a hash with them.
The implementation here extracts fields applicable to all member
types. When additional member-specific fields are to be
extracted, override this method, but be sure to call the
superclass method too.
... | [
"Extracts",
"the",
"fields",
"auto",
"-",
"detected",
"from",
"code",
"that",
"are",
"relevant",
"to",
"the",
"member",
"type",
"and",
"returns",
"a",
"hash",
"with",
"them",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/tag/member_tag.rb#L81-L95 |
15,450 | senchalabs/jsduck | lib/jsduck/grouped_asset.rb | JsDuck.GroupedAsset.each_item | def each_item(group=nil, &block)
group = group || @groups
group.each do |item|
if item["items"]
each_item(item["items"], &block)
else
block.call(item)
end
end
end | ruby | def each_item(group=nil, &block)
group = group || @groups
group.each do |item|
if item["items"]
each_item(item["items"], &block)
else
block.call(item)
end
end
end | [
"def",
"each_item",
"(",
"group",
"=",
"nil",
",",
"&",
"block",
")",
"group",
"=",
"group",
"||",
"@groups",
"group",
".",
"each",
"do",
"|",
"item",
"|",
"if",
"item",
"[",
"\"items\"",
"]",
"each_item",
"(",
"item",
"[",
"\"items\"",
"]",
",",
"... | Iterates over all items in all groups | [
"Iterates",
"over",
"all",
"items",
"in",
"all",
"groups"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/grouped_asset.rb#L26-L36 |
15,451 | senchalabs/jsduck | lib/jsduck/batch_processor.rb | JsDuck.BatchProcessor.aggregate | def aggregate(parsed_files)
agr = Aggregator.new
parsed_files.each do |file|
Logger.log("Aggregating", file.filename)
agr.aggregate(file)
end
agr.result
end | ruby | def aggregate(parsed_files)
agr = Aggregator.new
parsed_files.each do |file|
Logger.log("Aggregating", file.filename)
agr.aggregate(file)
end
agr.result
end | [
"def",
"aggregate",
"(",
"parsed_files",
")",
"agr",
"=",
"Aggregator",
".",
"new",
"parsed_files",
".",
"each",
"do",
"|",
"file",
"|",
"Logger",
".",
"log",
"(",
"\"Aggregating\"",
",",
"file",
".",
"filename",
")",
"agr",
".",
"aggregate",
"(",
"file"... | Aggregates parsing results sequencially | [
"Aggregates",
"parsing",
"results",
"sequencially"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/batch_processor.rb#L39-L46 |
15,452 | senchalabs/jsduck | lib/jsduck/batch_processor.rb | JsDuck.BatchProcessor.pre_process | def pre_process(classes_hash, opts)
Process::IgnoredClasses.new(classes_hash).process_all!
Process::GlobalMembers.new(classes_hash, opts).process_all!
Process::Accessors.new(classes_hash).process_all!
Process::Ext4Events.new(classes_hash, opts).process_all!
Process::Enums.new(classes_hash)... | ruby | def pre_process(classes_hash, opts)
Process::IgnoredClasses.new(classes_hash).process_all!
Process::GlobalMembers.new(classes_hash, opts).process_all!
Process::Accessors.new(classes_hash).process_all!
Process::Ext4Events.new(classes_hash, opts).process_all!
Process::Enums.new(classes_hash)... | [
"def",
"pre_process",
"(",
"classes_hash",
",",
"opts",
")",
"Process",
"::",
"IgnoredClasses",
".",
"new",
"(",
"classes_hash",
")",
".",
"process_all!",
"Process",
"::",
"GlobalMembers",
".",
"new",
"(",
"classes_hash",
",",
"opts",
")",
".",
"process_all!",... | Do all kinds of processing on the classes hash before turning it
into Relations object. | [
"Do",
"all",
"kinds",
"of",
"processing",
"on",
"the",
"classes",
"hash",
"before",
"turning",
"it",
"into",
"Relations",
"object",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/batch_processor.rb#L50-L59 |
15,453 | senchalabs/jsduck | lib/jsduck/batch_processor.rb | JsDuck.BatchProcessor.to_class_objects | def to_class_objects(docs, opts)
classes = docs.map {|d| Class.new(d) }
Relations.new(classes, opts.external)
end | ruby | def to_class_objects(docs, opts)
classes = docs.map {|d| Class.new(d) }
Relations.new(classes, opts.external)
end | [
"def",
"to_class_objects",
"(",
"docs",
",",
"opts",
")",
"classes",
"=",
"docs",
".",
"map",
"{",
"|",
"d",
"|",
"Class",
".",
"new",
"(",
"d",
")",
"}",
"Relations",
".",
"new",
"(",
"classes",
",",
"opts",
".",
"external",
")",
"end"
] | Turns all aggregated data into Class objects and places the
classes inside Relations container. | [
"Turns",
"all",
"aggregated",
"data",
"into",
"Class",
"objects",
"and",
"places",
"the",
"classes",
"inside",
"Relations",
"container",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/batch_processor.rb#L63-L66 |
15,454 | senchalabs/jsduck | lib/jsduck/batch_processor.rb | JsDuck.BatchProcessor.post_process | def post_process(relations, opts)
Process::CircularDeps.new(relations).process_all!
Process::InheritDoc.new(relations).process_all!
Process::Versions.new(relations, opts).process_all!
Process::ReturnValues.new(relations).process_all!
Process::Fires.new(relations).process_all!
Process... | ruby | def post_process(relations, opts)
Process::CircularDeps.new(relations).process_all!
Process::InheritDoc.new(relations).process_all!
Process::Versions.new(relations, opts).process_all!
Process::ReturnValues.new(relations).process_all!
Process::Fires.new(relations).process_all!
Process... | [
"def",
"post_process",
"(",
"relations",
",",
"opts",
")",
"Process",
"::",
"CircularDeps",
".",
"new",
"(",
"relations",
")",
".",
"process_all!",
"Process",
"::",
"InheritDoc",
".",
"new",
"(",
"relations",
")",
".",
"process_all!",
"Process",
"::",
"Versi... | Do all kinds of post-processing on Relations object. | [
"Do",
"all",
"kinds",
"of",
"post",
"-",
"processing",
"on",
"Relations",
"object",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/batch_processor.rb#L69-L79 |
15,455 | senchalabs/jsduck | lib/jsduck/columns.rb | JsDuck.Columns.split | def split(items, n)
if n == 1
[items]
elsif items.length <= n
Array.new(n) {|i| items[i] ? [items[i]] : [] }
else
min_max = nil
min_arr = nil
i = 0
while i <= items.length-n
i += 1
# Try placing 1, 2, 3, ... items to first chunk.
... | ruby | def split(items, n)
if n == 1
[items]
elsif items.length <= n
Array.new(n) {|i| items[i] ? [items[i]] : [] }
else
min_max = nil
min_arr = nil
i = 0
while i <= items.length-n
i += 1
# Try placing 1, 2, 3, ... items to first chunk.
... | [
"def",
"split",
"(",
"items",
",",
"n",
")",
"if",
"n",
"==",
"1",
"[",
"items",
"]",
"elsif",
"items",
".",
"length",
"<=",
"n",
"Array",
".",
"new",
"(",
"n",
")",
"{",
"|",
"i",
"|",
"items",
"[",
"i",
"]",
"?",
"[",
"items",
"[",
"i",
... | Initialized with the name of subitems field.
Splits the array of items into n chunks so that the sum of
largest chunk is as small as possible.
This is a brute-force implementation - we just try all the
combinations and choose the best one. | [
"Initialized",
"with",
"the",
"name",
"of",
"subitems",
"field",
".",
"Splits",
"the",
"array",
"of",
"items",
"into",
"n",
"chunks",
"so",
"that",
"the",
"sum",
"of",
"largest",
"chunk",
"is",
"as",
"small",
"as",
"possible",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/columns.rb#L16-L39 |
15,456 | senchalabs/jsduck | lib/jsduck/guide_toc_entry.rb | JsDuck.GuideTocEntry.add | def add(level, id, text)
if level == @min_level
@items << GuideTocEntry.new(self)
@items.last.label = "#{prefix} <a href='#!/guide/#{id}'>#{text}</a>\n"
else
if @items.empty?
@items << GuideTocEntry.new(self)
end
@items.last.add(level-1, id, text)
end
... | ruby | def add(level, id, text)
if level == @min_level
@items << GuideTocEntry.new(self)
@items.last.label = "#{prefix} <a href='#!/guide/#{id}'>#{text}</a>\n"
else
if @items.empty?
@items << GuideTocEntry.new(self)
end
@items.last.add(level-1, id, text)
end
... | [
"def",
"add",
"(",
"level",
",",
"id",
",",
"text",
")",
"if",
"level",
"==",
"@min_level",
"@items",
"<<",
"GuideTocEntry",
".",
"new",
"(",
"self",
")",
"@items",
".",
"last",
".",
"label",
"=",
"\"#{prefix} <a href='#!/guide/#{id}'>#{text}</a>\\n\"",
"else"... | Adds entry at the corresponding heading level. | [
"Adds",
"entry",
"at",
"the",
"corresponding",
"heading",
"level",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/guide_toc_entry.rb#L17-L27 |
15,457 | senchalabs/jsduck | lib/jsduck/external_classes.rb | JsDuck.ExternalClasses.add | def add(name)
if name =~ /\*/
@patterns << make_pattern(name)
elsif name =~ /^@browser$/i
WEB_APIS.each do |cls|
@class_names[cls] = true
end
else
@class_names[name] = true
end
end | ruby | def add(name)
if name =~ /\*/
@patterns << make_pattern(name)
elsif name =~ /^@browser$/i
WEB_APIS.each do |cls|
@class_names[cls] = true
end
else
@class_names[name] = true
end
end | [
"def",
"add",
"(",
"name",
")",
"if",
"name",
"=~",
"/",
"\\*",
"/",
"@patterns",
"<<",
"make_pattern",
"(",
"name",
")",
"elsif",
"name",
"=~",
"/",
"/i",
"WEB_APIS",
".",
"each",
"do",
"|",
"cls",
"|",
"@class_names",
"[",
"cls",
"]",
"=",
"true"... | Adds a classname or pattern to list of external classes. | [
"Adds",
"a",
"classname",
"or",
"pattern",
"to",
"list",
"of",
"external",
"classes",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/external_classes.rb#L18-L28 |
15,458 | senchalabs/jsduck | lib/jsduck/logger.rb | JsDuck.Logger.configure_defaults | def configure_defaults
# Enable all warnings except some.
set_warning(:all, true)
set_warning(:link_auto, false)
set_warning(:param_count, false)
set_warning(:fires, false)
set_warning(:nodoc, false)
end | ruby | def configure_defaults
# Enable all warnings except some.
set_warning(:all, true)
set_warning(:link_auto, false)
set_warning(:param_count, false)
set_warning(:fires, false)
set_warning(:nodoc, false)
end | [
"def",
"configure_defaults",
"# Enable all warnings except some.",
"set_warning",
"(",
":all",
",",
"true",
")",
"set_warning",
"(",
":link_auto",
",",
"false",
")",
"set_warning",
"(",
":param_count",
",",
"false",
")",
"set_warning",
"(",
":fires",
",",
"false",
... | Configures warnings to default settings.
NB! Needs to be called before retrieving the documentation with
#doc_warnings (otherwise the +/- signs will be wrong). | [
"Configures",
"warnings",
"to",
"default",
"settings",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/logger.rb#L32-L39 |
15,459 | senchalabs/jsduck | lib/jsduck/logger.rb | JsDuck.Logger.configure | def configure(opts)
self.verbose = true if opts.verbose
self.colors = opts.color unless opts.color.nil?
begin
opts.warnings.each do |w|
set_warning(w[:type], w[:enabled], w[:path], w[:params])
end
rescue Warning::WarnException => e
warn(nil, e.message)
e... | ruby | def configure(opts)
self.verbose = true if opts.verbose
self.colors = opts.color unless opts.color.nil?
begin
opts.warnings.each do |w|
set_warning(w[:type], w[:enabled], w[:path], w[:params])
end
rescue Warning::WarnException => e
warn(nil, e.message)
e... | [
"def",
"configure",
"(",
"opts",
")",
"self",
".",
"verbose",
"=",
"true",
"if",
"opts",
".",
"verbose",
"self",
".",
"colors",
"=",
"opts",
".",
"color",
"unless",
"opts",
".",
"color",
".",
"nil?",
"begin",
"opts",
".",
"warnings",
".",
"each",
"do... | Configures the logger with command line options. | [
"Configures",
"the",
"logger",
"with",
"command",
"line",
"options",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/logger.rb#L42-L54 |
15,460 | senchalabs/jsduck | lib/jsduck/logger.rb | JsDuck.Logger.warn | def warn(type, msg, file={}, args=[])
if warning_enabled?(type, file[:filename], args)
print_warning(msg, file[:filename], file[:linenr])
end
return false
end | ruby | def warn(type, msg, file={}, args=[])
if warning_enabled?(type, file[:filename], args)
print_warning(msg, file[:filename], file[:linenr])
end
return false
end | [
"def",
"warn",
"(",
"type",
",",
"msg",
",",
"file",
"=",
"{",
"}",
",",
"args",
"=",
"[",
"]",
")",
"if",
"warning_enabled?",
"(",
"type",
",",
"file",
"[",
":filename",
"]",
",",
"args",
")",
"print_warning",
"(",
"msg",
",",
"file",
"[",
":fil... | Prints warning message.
The type must be one of predefined warning types which can be
toggled on/off with command-line options, or it can be nil, in
which case the warning is always shown.
Ignores duplicate warnings - only prints the first one.
Works best when --processes=0, but it reduces the amount of
warning... | [
"Prints",
"warning",
"message",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/logger.rb#L99-L105 |
15,461 | senchalabs/jsduck | lib/jsduck/logger.rb | JsDuck.Logger.format | def format(filename=nil, line=nil)
out = ""
if filename
out = Util::OS.windows? ? filename.gsub('/', '\\') : filename
if line
out += ":#{line}:"
end
end
paint(:magenta, out)
end | ruby | def format(filename=nil, line=nil)
out = ""
if filename
out = Util::OS.windows? ? filename.gsub('/', '\\') : filename
if line
out += ":#{line}:"
end
end
paint(:magenta, out)
end | [
"def",
"format",
"(",
"filename",
"=",
"nil",
",",
"line",
"=",
"nil",
")",
"out",
"=",
"\"\"",
"if",
"filename",
"out",
"=",
"Util",
"::",
"OS",
".",
"windows?",
"?",
"filename",
".",
"gsub",
"(",
"'/'",
",",
"'\\\\'",
")",
":",
"filename",
"if",
... | Formats filename and line number for output | [
"Formats",
"filename",
"and",
"line",
"number",
"for",
"output"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/logger.rb#L162-L171 |
15,462 | senchalabs/jsduck | lib/jsduck/logger.rb | JsDuck.Logger.paint | def paint(color_name, msg)
if @colors == false || @colors == nil && (Util::OS.windows? || !$stderr.tty?)
msg
else
COLORS[color_name] + msg + CLEAR
end
end | ruby | def paint(color_name, msg)
if @colors == false || @colors == nil && (Util::OS.windows? || !$stderr.tty?)
msg
else
COLORS[color_name] + msg + CLEAR
end
end | [
"def",
"paint",
"(",
"color_name",
",",
"msg",
")",
"if",
"@colors",
"==",
"false",
"||",
"@colors",
"==",
"nil",
"&&",
"(",
"Util",
"::",
"OS",
".",
"windows?",
"||",
"!",
"$stderr",
".",
"tty?",
")",
"msg",
"else",
"COLORS",
"[",
"color_name",
"]",... | Helper for doing colored output in UNIX terminal
Only does color output when STDERR is attached to TTY
i.e. is not piped/redirected. | [
"Helper",
"for",
"doing",
"colored",
"output",
"in",
"UNIX",
"terminal"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/logger.rb#L177-L183 |
15,463 | senchalabs/jsduck | lib/jsduck/inline_examples.rb | JsDuck.InlineExamples.add_classes | def add_classes(relations)
relations.each do |cls|
extract(cls[:doc]).each_with_index do |ex, i|
@examples << {
:id => cls[:name] + "-" + i.to_s,
:name => cls[:name] + " example #" + (i+1).to_s,
:href => '#!/api/' + cls[:name],
:code => ex[:code],
... | ruby | def add_classes(relations)
relations.each do |cls|
extract(cls[:doc]).each_with_index do |ex, i|
@examples << {
:id => cls[:name] + "-" + i.to_s,
:name => cls[:name] + " example #" + (i+1).to_s,
:href => '#!/api/' + cls[:name],
:code => ex[:code],
... | [
"def",
"add_classes",
"(",
"relations",
")",
"relations",
".",
"each",
"do",
"|",
"cls",
"|",
"extract",
"(",
"cls",
"[",
":doc",
"]",
")",
".",
"each_with_index",
"do",
"|",
"ex",
",",
"i",
"|",
"@examples",
"<<",
"{",
":id",
"=>",
"cls",
"[",
":n... | Extracts inline examples from classes | [
"Extracts",
"inline",
"examples",
"from",
"classes"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/inline_examples.rb#L15-L29 |
15,464 | senchalabs/jsduck | lib/jsduck/inline_examples.rb | JsDuck.InlineExamples.add_guides | def add_guides(guides)
guides.each_item do |guide|
extract(guide[:html]).each_with_index do |ex, i|
@examples << {
:id => guide["name"] + "-" + i.to_s,
:name => guide["title"] + " example #" + (i+1).to_s,
:href => '#!/guide/' + guide["name"],
:code... | ruby | def add_guides(guides)
guides.each_item do |guide|
extract(guide[:html]).each_with_index do |ex, i|
@examples << {
:id => guide["name"] + "-" + i.to_s,
:name => guide["title"] + " example #" + (i+1).to_s,
:href => '#!/guide/' + guide["name"],
:code... | [
"def",
"add_guides",
"(",
"guides",
")",
"guides",
".",
"each_item",
"do",
"|",
"guide",
"|",
"extract",
"(",
"guide",
"[",
":html",
"]",
")",
".",
"each_with_index",
"do",
"|",
"ex",
",",
"i",
"|",
"@examples",
"<<",
"{",
":id",
"=>",
"guide",
"[",
... | Extracts inline examples from guides | [
"Extracts",
"inline",
"examples",
"from",
"guides"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/inline_examples.rb#L32-L46 |
15,465 | senchalabs/jsduck | lib/jsduck/inline_examples.rb | JsDuck.InlineExamples.extract | def extract(html)
examples = []
s = StringScanner.new(html)
while !s.eos? do
if s.check(/</)
if s.check(@begin_example_re)
s.scan(@begin_example_re) =~ @begin_example_re
options = build_options_hash($1)
ex = s.scan_until(@end_example_re).sub(@en... | ruby | def extract(html)
examples = []
s = StringScanner.new(html)
while !s.eos? do
if s.check(/</)
if s.check(@begin_example_re)
s.scan(@begin_example_re) =~ @begin_example_re
options = build_options_hash($1)
ex = s.scan_until(@end_example_re).sub(@en... | [
"def",
"extract",
"(",
"html",
")",
"examples",
"=",
"[",
"]",
"s",
"=",
"StringScanner",
".",
"new",
"(",
"html",
")",
"while",
"!",
"s",
".",
"eos?",
"do",
"if",
"s",
".",
"check",
"(",
"/",
"/",
")",
"if",
"s",
".",
"check",
"(",
"@begin_exa... | Extracts inline examples from HTML | [
"Extracts",
"inline",
"examples",
"from",
"HTML"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/inline_examples.rb#L54-L80 |
15,466 | senchalabs/jsduck | lib/jsduck/class_doc_expander.rb | JsDuck.ClassDocExpander.expand_comment | def expand_comment(docset)
groups = {
:class => [],
:cfg => [],
:constructor => [],
}
# By default everything goes to :class group
group_name = :class
docset[:comment].each do |tag|
tagname = tag[:tagname]
if tagname == :cfg || tagname == :constru... | ruby | def expand_comment(docset)
groups = {
:class => [],
:cfg => [],
:constructor => [],
}
# By default everything goes to :class group
group_name = :class
docset[:comment].each do |tag|
tagname = tag[:tagname]
if tagname == :cfg || tagname == :constru... | [
"def",
"expand_comment",
"(",
"docset",
")",
"groups",
"=",
"{",
":class",
"=>",
"[",
"]",
",",
":cfg",
"=>",
"[",
"]",
",",
":constructor",
"=>",
"[",
"]",
",",
"}",
"# By default everything goes to :class group",
"group_name",
"=",
":class",
"docset",
"[",... | Handles old syntax where configs and constructor are part of class
doc-comment.
Gathers all tags until first @cfg or @constructor into the first
bare :class group. We have a special case for @xtype which in
ExtJS comments often appears after @constructor - so we
explicitly place it into :class group.
Then gath... | [
"Handles",
"old",
"syntax",
"where",
"configs",
"and",
"constructor",
"are",
"part",
"of",
"class",
"doc",
"-",
"comment",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/class_doc_expander.rb#L38-L69 |
15,467 | senchalabs/jsduck | lib/jsduck/class_doc_expander.rb | JsDuck.ClassDocExpander.groups_to_docsets | def groups_to_docsets(groups, docset)
results = []
results << {
:tagname => :class,
:type => docset[:type],
:comment => groups[:class],
:code => docset[:code],
:linenr => docset[:linenr],
}
groups[:cfg].each do |cfg|
results << {
:tagname... | ruby | def groups_to_docsets(groups, docset)
results = []
results << {
:tagname => :class,
:type => docset[:type],
:comment => groups[:class],
:code => docset[:code],
:linenr => docset[:linenr],
}
groups[:cfg].each do |cfg|
results << {
:tagname... | [
"def",
"groups_to_docsets",
"(",
"groups",
",",
"docset",
")",
"results",
"=",
"[",
"]",
"results",
"<<",
"{",
":tagname",
"=>",
":class",
",",
":type",
"=>",
"docset",
"[",
":type",
"]",
",",
":comment",
"=>",
"groups",
"[",
":class",
"]",
",",
":code... | Turns groups hash into list of docsets | [
"Turns",
"groups",
"hash",
"into",
"list",
"of",
"docsets"
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/class_doc_expander.rb#L72-L104 |
15,468 | senchalabs/jsduck | lib/jsduck/class_doc_expander.rb | JsDuck.ClassDocExpander.expand_code | def expand_code(docset)
results = []
if docset[:code]
(docset[:code][:members] || []).each do |m|
results << code_to_docset(m) unless @constructor_found && JsDuck::Class.constructor?(m)
end
end
results
end | ruby | def expand_code(docset)
results = []
if docset[:code]
(docset[:code][:members] || []).each do |m|
results << code_to_docset(m) unless @constructor_found && JsDuck::Class.constructor?(m)
end
end
results
end | [
"def",
"expand_code",
"(",
"docset",
")",
"results",
"=",
"[",
"]",
"if",
"docset",
"[",
":code",
"]",
"(",
"docset",
"[",
":code",
"]",
"[",
":members",
"]",
"||",
"[",
"]",
")",
".",
"each",
"do",
"|",
"m",
"|",
"results",
"<<",
"code_to_docset",... | Turns auto-detected class members into docsets in their own
right. | [
"Turns",
"auto",
"-",
"detected",
"class",
"members",
"into",
"docsets",
"in",
"their",
"own",
"right",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/class_doc_expander.rb#L108-L118 |
15,469 | senchalabs/jsduck | lib/jsduck/tag_loader.rb | JsDuck.TagLoader.load | def load(path)
if File.directory?(path)
Dir[path+"/**/*.rb"].each do |file|
# Ruby 1.8 doesn't understand that "jsduck/tag/tag" and
# "./lib/jsduck/tag/tag.rb" refer to the same file. So
# explicitly avoid loading this file (as it's required on
# top already) to pr... | ruby | def load(path)
if File.directory?(path)
Dir[path+"/**/*.rb"].each do |file|
# Ruby 1.8 doesn't understand that "jsduck/tag/tag" and
# "./lib/jsduck/tag/tag.rb" refer to the same file. So
# explicitly avoid loading this file (as it's required on
# top already) to pr... | [
"def",
"load",
"(",
"path",
")",
"if",
"File",
".",
"directory?",
"(",
"path",
")",
"Dir",
"[",
"path",
"+",
"\"/**/*.rb\"",
"]",
".",
"each",
"do",
"|",
"file",
"|",
"# Ruby 1.8 doesn't understand that \"jsduck/tag/tag\" and",
"# \"./lib/jsduck/tag/tag.rb\" refer t... | Loads tag classes from given dir or single file. | [
"Loads",
"tag",
"classes",
"from",
"given",
"dir",
"or",
"single",
"file",
"."
] | febef5558ecd05da25f5c260365acc3afd0cafd8 | https://github.com/senchalabs/jsduck/blob/febef5558ecd05da25f5c260365acc3afd0cafd8/lib/jsduck/tag_loader.rb#L25-L38 |
15,470 | vmware/rbvmomi | lib/rbvmomi/optimist.rb | Optimist.Parser.rbvmomi_connection_opts | def rbvmomi_connection_opts
opt :host, "host", :type => :string, :short => 'o', :default => ENV['RBVMOMI_HOST']
opt :port, "port", :type => :int, :short => :none, :default => (ENV.member?('RBVMOMI_PORT') ? ENV['RBVMOMI_PORT'].to_i : 443)
opt :"no-ssl", "don't use ssl", :short => :none, :default => (ENV['RBV... | ruby | def rbvmomi_connection_opts
opt :host, "host", :type => :string, :short => 'o', :default => ENV['RBVMOMI_HOST']
opt :port, "port", :type => :int, :short => :none, :default => (ENV.member?('RBVMOMI_PORT') ? ENV['RBVMOMI_PORT'].to_i : 443)
opt :"no-ssl", "don't use ssl", :short => :none, :default => (ENV['RBV... | [
"def",
"rbvmomi_connection_opts",
"opt",
":host",
",",
"\"host\"",
",",
":type",
"=>",
":string",
",",
":short",
"=>",
"'o'",
",",
":default",
"=>",
"ENV",
"[",
"'RBVMOMI_HOST'",
"]",
"opt",
":port",
",",
"\"port\"",
",",
":type",
"=>",
":int",
",",
":shor... | Options used by VIM.connect
!!!plain
host: -o --host RBVMOMI_HOST
port: --port RBVMOMI_PORT (443)
no-ssl: --no-ssl RBVMOMI_SSL (false)
insecure: -k --insecure RBVMOMI_INSECURE (false)
user: -u --user RBVMOMI_USER (root)
password: -p --password RBVMOMI_PASSWORD ()
path: --path RBVMOMI_PATH (/sdk)
debu... | [
"Options",
"used",
"by",
"VIM",
".",
"connect"
] | 0cb564b2a2ca1d7b78ffbd63dc15763c5e36db81 | https://github.com/vmware/rbvmomi/blob/0cb564b2a2ca1d7b78ffbd63dc15763c5e36db81/lib/rbvmomi/optimist.rb#L29-L38 |
15,471 | vmware/rbvmomi | lib/rbvmomi/type_loader.rb | RbVmomi.TypeLoader.reload_extensions_dir | def reload_extensions_dir path
loaded = Set.new(typenames.select { |x| @namespace.const_defined? x })
Dir.open(path) do |dir|
dir.each do |file|
next unless file =~ /\.rb$/
next unless loaded.member? $`
file_path = File.join(dir, file)
load file_path
end
end
end | ruby | def reload_extensions_dir path
loaded = Set.new(typenames.select { |x| @namespace.const_defined? x })
Dir.open(path) do |dir|
dir.each do |file|
next unless file =~ /\.rb$/
next unless loaded.member? $`
file_path = File.join(dir, file)
load file_path
end
end
end | [
"def",
"reload_extensions_dir",
"path",
"loaded",
"=",
"Set",
".",
"new",
"(",
"typenames",
".",
"select",
"{",
"|",
"x",
"|",
"@namespace",
".",
"const_defined?",
"x",
"}",
")",
"Dir",
".",
"open",
"(",
"path",
")",
"do",
"|",
"dir",
"|",
"dir",
"."... | Reload all extensions for loaded VMODL types from the given directory | [
"Reload",
"all",
"extensions",
"for",
"loaded",
"VMODL",
"types",
"from",
"the",
"given",
"directory"
] | 0cb564b2a2ca1d7b78ffbd63dc15763c5e36db81 | https://github.com/vmware/rbvmomi/blob/0cb564b2a2ca1d7b78ffbd63dc15763c5e36db81/lib/rbvmomi/type_loader.rb#L38-L48 |
15,472 | vmware/rbvmomi | lib/rbvmomi/deserialization.rb | RbVmomi.NewDeserializer.leaf_keyvalue | def leaf_keyvalue node
h = {}
node.children.each do |child|
next unless child.element?
h[child.name] = child.content
end
[h['key'], h['value']]
end | ruby | def leaf_keyvalue node
h = {}
node.children.each do |child|
next unless child.element?
h[child.name] = child.content
end
[h['key'], h['value']]
end | [
"def",
"leaf_keyvalue",
"node",
"h",
"=",
"{",
"}",
"node",
".",
"children",
".",
"each",
"do",
"|",
"child",
"|",
"next",
"unless",
"child",
".",
"element?",
"h",
"[",
"child",
".",
"name",
"]",
"=",
"child",
".",
"content",
"end",
"[",
"h",
"[",
... | XXX does the value need to be deserialized? | [
"XXX",
"does",
"the",
"value",
"need",
"to",
"be",
"deserialized?"
] | 0cb564b2a2ca1d7b78ffbd63dc15763c5e36db81 | https://github.com/vmware/rbvmomi/blob/0cb564b2a2ca1d7b78ffbd63dc15763c5e36db81/lib/rbvmomi/deserialization.rb#L147-L154 |
15,473 | andymeneely/squib | lib/squib/sample_helpers.rb | Squib.Deck.draw_graph_paper | def draw_graph_paper(width, height)
background color: 'white'
grid width: 50, height: 50, stroke_color: '#659ae9', stroke_width: 1.5
grid width: 200, height: 200, stroke_color: '#659ae9', stroke_width: 3, x: 50, y: 50
(50..height).step(200) do |y|
text str: "y=#{y}", x: 3, y: y - 18, f... | ruby | def draw_graph_paper(width, height)
background color: 'white'
grid width: 50, height: 50, stroke_color: '#659ae9', stroke_width: 1.5
grid width: 200, height: 200, stroke_color: '#659ae9', stroke_width: 3, x: 50, y: 50
(50..height).step(200) do |y|
text str: "y=#{y}", x: 3, y: y - 18, f... | [
"def",
"draw_graph_paper",
"(",
"width",
",",
"height",
")",
"background",
"color",
":",
"'white'",
"grid",
"width",
":",
"50",
",",
"height",
":",
"50",
",",
"stroke_color",
":",
"'#659ae9'",
",",
"stroke_width",
":",
"1.5",
"grid",
"width",
":",
"200",
... | Draw graph paper for samples | [
"Draw",
"graph",
"paper",
"for",
"samples"
] | 1d307fe6e00306e7b21f35e6c51955724e4e0673 | https://github.com/andymeneely/squib/blob/1d307fe6e00306e7b21f35e6c51955724e4e0673/lib/squib/sample_helpers.rb#L9-L16 |
15,474 | andymeneely/squib | lib/squib/sample_helpers.rb | Squib.Deck.sample | def sample(str)
@sample_x ||= 100
@sample_y ||= 100
rect x: 460, y: @sample_y - 40, width: 600,
height: 180, fill_color: '#FFD655', stroke_color: 'black', radius: 15
text str: str, x: 460, y: @sample_y - 40,
width: 540, height: 180,
valign: 'middle', align: 'cent... | ruby | def sample(str)
@sample_x ||= 100
@sample_y ||= 100
rect x: 460, y: @sample_y - 40, width: 600,
height: 180, fill_color: '#FFD655', stroke_color: 'black', radius: 15
text str: str, x: 460, y: @sample_y - 40,
width: 540, height: 180,
valign: 'middle', align: 'cent... | [
"def",
"sample",
"(",
"str",
")",
"@sample_x",
"||=",
"100",
"@sample_y",
"||=",
"100",
"rect",
"x",
":",
"460",
",",
"y",
":",
"@sample_y",
"-",
"40",
",",
"width",
":",
"600",
",",
"height",
":",
"180",
",",
"fill_color",
":",
"'#FFD655'",
",",
"... | Define a set of samples on some graph paper | [
"Define",
"a",
"set",
"of",
"samples",
"on",
"some",
"graph",
"paper"
] | 1d307fe6e00306e7b21f35e6c51955724e4e0673 | https://github.com/andymeneely/squib/blob/1d307fe6e00306e7b21f35e6c51955724e4e0673/lib/squib/sample_helpers.rb#L19-L30 |
15,475 | andymeneely/squib | lib/squib/api/groups.rb | Squib.Deck.enable_groups_from_env! | def enable_groups_from_env!
return if ENV['SQUIB_BUILD'].nil?
ENV['SQUIB_BUILD'].split(',').each do |grp|
enable_build grp.strip.to_sym
end
end | ruby | def enable_groups_from_env!
return if ENV['SQUIB_BUILD'].nil?
ENV['SQUIB_BUILD'].split(',').each do |grp|
enable_build grp.strip.to_sym
end
end | [
"def",
"enable_groups_from_env!",
"return",
"if",
"ENV",
"[",
"'SQUIB_BUILD'",
"]",
".",
"nil?",
"ENV",
"[",
"'SQUIB_BUILD'",
"]",
".",
"split",
"(",
"','",
")",
".",
"each",
"do",
"|",
"grp",
"|",
"enable_build",
"grp",
".",
"strip",
".",
"to_sym",
"end... | Not a DSL method, but initialized from Deck.new | [
"Not",
"a",
"DSL",
"method",
"but",
"initialized",
"from",
"Deck",
".",
"new"
] | 1d307fe6e00306e7b21f35e6c51955724e4e0673 | https://github.com/andymeneely/squib/blob/1d307fe6e00306e7b21f35e6c51955724e4e0673/lib/squib/api/groups.rb#L46-L51 |
15,476 | andymeneely/squib | lib/squib/layout_parser.rb | Squib.LayoutParser.parents_exist? | def parents_exist?(yml, key)
exists = true
Array(yml[key]['extends']).each do |parent|
unless yml.key?(parent)
exists = false unless
Squib.logger.error "Processing layout: '#{key}' attempts to extend a missing '#{yml[key]['extends']}'"
end
end
return exists
... | ruby | def parents_exist?(yml, key)
exists = true
Array(yml[key]['extends']).each do |parent|
unless yml.key?(parent)
exists = false unless
Squib.logger.error "Processing layout: '#{key}' attempts to extend a missing '#{yml[key]['extends']}'"
end
end
return exists
... | [
"def",
"parents_exist?",
"(",
"yml",
",",
"key",
")",
"exists",
"=",
"true",
"Array",
"(",
"yml",
"[",
"key",
"]",
"[",
"'extends'",
"]",
")",
".",
"each",
"do",
"|",
"parent",
"|",
"unless",
"yml",
".",
"key?",
"(",
"parent",
")",
"exists",
"=",
... | Checks if we have any absentee parents
@api private | [
"Checks",
"if",
"we",
"have",
"any",
"absentee",
"parents"
] | 1d307fe6e00306e7b21f35e6c51955724e4e0673 | https://github.com/andymeneely/squib/blob/1d307fe6e00306e7b21f35e6c51955724e4e0673/lib/squib/layout_parser.rb#L117-L126 |
15,477 | andymeneely/squib | lib/squib/graphics/text.rb | Squib.Card.compute_carve | def compute_carve(rule, range)
w = rule[:box].width[@index]
if w == :native
file = rule[:file][@index].file
case rule[:type]
when :png
Squib.cache_load_image(file).width.to_f / (range.size - 1)
when :svg
svg_data = rule[:svg_args].data[@index]
un... | ruby | def compute_carve(rule, range)
w = rule[:box].width[@index]
if w == :native
file = rule[:file][@index].file
case rule[:type]
when :png
Squib.cache_load_image(file).width.to_f / (range.size - 1)
when :svg
svg_data = rule[:svg_args].data[@index]
un... | [
"def",
"compute_carve",
"(",
"rule",
",",
"range",
")",
"w",
"=",
"rule",
"[",
":box",
"]",
".",
"width",
"[",
"@index",
"]",
"if",
"w",
"==",
":native",
"file",
"=",
"rule",
"[",
":file",
"]",
"[",
"@index",
"]",
".",
"file",
"case",
"rule",
"["... | Compute the width of the carve that we need | [
"Compute",
"the",
"width",
"of",
"the",
"carve",
"that",
"we",
"need"
] | 1d307fe6e00306e7b21f35e6c51955724e4e0673 | https://github.com/andymeneely/squib/blob/1d307fe6e00306e7b21f35e6c51955724e4e0673/lib/squib/graphics/text.rb#L56-L75 |
15,478 | andymeneely/squib | lib/squib/graphics/hand.rb | Squib.Deck.render_hand | def render_hand(range, sheet, hand)
cards = range.collect { |i| @cards[i] }
center_x = width / 2.0
center_y = hand.radius + height
out_size = 3.0 * center_y
angle_delta = (hand.angle_range.last - hand.angle_range.first) / cards.size
cxt = Cairo::Context.new(Cairo::Reco... | ruby | def render_hand(range, sheet, hand)
cards = range.collect { |i| @cards[i] }
center_x = width / 2.0
center_y = hand.radius + height
out_size = 3.0 * center_y
angle_delta = (hand.angle_range.last - hand.angle_range.first) / cards.size
cxt = Cairo::Context.new(Cairo::Reco... | [
"def",
"render_hand",
"(",
"range",
",",
"sheet",
",",
"hand",
")",
"cards",
"=",
"range",
".",
"collect",
"{",
"|",
"i",
"|",
"@cards",
"[",
"i",
"]",
"}",
"center_x",
"=",
"width",
"/",
"2.0",
"center_y",
"=",
"hand",
".",
"radius",
"+",
"height"... | Draw cards in a fan.
@api private | [
"Draw",
"cards",
"in",
"a",
"fan",
"."
] | 1d307fe6e00306e7b21f35e6c51955724e4e0673 | https://github.com/andymeneely/squib/blob/1d307fe6e00306e7b21f35e6c51955724e4e0673/lib/squib/graphics/hand.rb#L8-L40 |
15,479 | andymeneely/squib | lib/squib/sprues/sprue.rb | Squib.Sprue.parse_crop_line | def parse_crop_line(line)
new_line = @crop_line_default.merge line
new_line['width'] = Args::UnitConversion.parse(new_line['width'], @dpi)
new_line['color'] = colorify new_line['color']
new_line['style_desc'] = new_line['style']
new_line['style'] = Sprues::CropLineDash.new(new_line['style'... | ruby | def parse_crop_line(line)
new_line = @crop_line_default.merge line
new_line['width'] = Args::UnitConversion.parse(new_line['width'], @dpi)
new_line['color'] = colorify new_line['color']
new_line['style_desc'] = new_line['style']
new_line['style'] = Sprues::CropLineDash.new(new_line['style'... | [
"def",
"parse_crop_line",
"(",
"line",
")",
"new_line",
"=",
"@crop_line_default",
".",
"merge",
"line",
"new_line",
"[",
"'width'",
"]",
"=",
"Args",
"::",
"UnitConversion",
".",
"parse",
"(",
"new_line",
"[",
"'width'",
"]",
",",
"@dpi",
")",
"new_line",
... | Parse crop line definitions from template. | [
"Parse",
"crop",
"line",
"definitions",
"from",
"template",
"."
] | 1d307fe6e00306e7b21f35e6c51955724e4e0673 | https://github.com/andymeneely/squib/blob/1d307fe6e00306e7b21f35e6c51955724e4e0673/lib/squib/sprues/sprue.rb#L150-L160 |
15,480 | andymeneely/squib | lib/squib/sprues/sprue.rb | Squib.Sprue.parse_card | def parse_card(card)
new_card = card.clone
x = Args::UnitConversion.parse(card['x'], @dpi)
y = Args::UnitConversion.parse(card['y'], @dpi)
if @template_hash['position_reference'] == :center
# Normalize it to a top-left positional reference
x -= card_width / 2
y -= card_h... | ruby | def parse_card(card)
new_card = card.clone
x = Args::UnitConversion.parse(card['x'], @dpi)
y = Args::UnitConversion.parse(card['y'], @dpi)
if @template_hash['position_reference'] == :center
# Normalize it to a top-left positional reference
x -= card_width / 2
y -= card_h... | [
"def",
"parse_card",
"(",
"card",
")",
"new_card",
"=",
"card",
".",
"clone",
"x",
"=",
"Args",
"::",
"UnitConversion",
".",
"parse",
"(",
"card",
"[",
"'x'",
"]",
",",
"@dpi",
")",
"y",
"=",
"Args",
"::",
"UnitConversion",
".",
"parse",
"(",
"card",... | Parse card definitions from template. | [
"Parse",
"card",
"definitions",
"from",
"template",
"."
] | 1d307fe6e00306e7b21f35e6c51955724e4e0673 | https://github.com/andymeneely/squib/blob/1d307fe6e00306e7b21f35e6c51955724e4e0673/lib/squib/sprues/sprue.rb#L163-L179 |
15,481 | westonganger/paper_trail-association_tracking | lib/paper_trail_association_tracking/record_trail.rb | PaperTrailAssociationTracking.RecordTrail.save_habtm_associations | def save_habtm_associations(version)
@record.class.reflect_on_all_associations(:has_and_belongs_to_many).each do |a|
next unless save_habtm_association?(a)
habtm_assoc_ids(a).each do |id|
::PaperTrail::VersionAssociation.create(
version_id: version.transaction_id,
... | ruby | def save_habtm_associations(version)
@record.class.reflect_on_all_associations(:has_and_belongs_to_many).each do |a|
next unless save_habtm_association?(a)
habtm_assoc_ids(a).each do |id|
::PaperTrail::VersionAssociation.create(
version_id: version.transaction_id,
... | [
"def",
"save_habtm_associations",
"(",
"version",
")",
"@record",
".",
"class",
".",
"reflect_on_all_associations",
"(",
":has_and_belongs_to_many",
")",
".",
"each",
"do",
"|",
"a",
"|",
"next",
"unless",
"save_habtm_association?",
"(",
"a",
")",
"habtm_assoc_ids",... | When a record is created, updated, or destroyed, we determine what the
HABTM associations looked like before any changes were made, by using
the `paper_trail_habtm` data structure. Then, we create
`VersionAssociation` records for each of the associated records.
@api private | [
"When",
"a",
"record",
"is",
"created",
"updated",
"or",
"destroyed",
"we",
"determine",
"what",
"the",
"HABTM",
"associations",
"looked",
"like",
"before",
"any",
"changes",
"were",
"made",
"by",
"using",
"the",
"paper_trail_habtm",
"data",
"structure",
".",
... | cfda3e0642323e78cf28196d22bd4c9533398b41 | https://github.com/westonganger/paper_trail-association_tracking/blob/cfda3e0642323e78cf28196d22bd4c9533398b41/lib/paper_trail_association_tracking/record_trail.rb#L132-L144 |
15,482 | westonganger/paper_trail-association_tracking | lib/paper_trail_association_tracking/record_trail.rb | PaperTrailAssociationTracking.RecordTrail.habtm_assoc_ids | def habtm_assoc_ids(habtm_assoc)
current = @record.send(habtm_assoc.name).to_a.map(&:id) # TODO: `pluck` would use less memory
removed = @record.paper_trail_habtm.try(:[], habtm_assoc.name).try(:[], :removed) || []
added = @record.paper_trail_habtm.try(:[], habtm_assoc.name).try(:[], :added) || []
... | ruby | def habtm_assoc_ids(habtm_assoc)
current = @record.send(habtm_assoc.name).to_a.map(&:id) # TODO: `pluck` would use less memory
removed = @record.paper_trail_habtm.try(:[], habtm_assoc.name).try(:[], :removed) || []
added = @record.paper_trail_habtm.try(:[], habtm_assoc.name).try(:[], :added) || []
... | [
"def",
"habtm_assoc_ids",
"(",
"habtm_assoc",
")",
"current",
"=",
"@record",
".",
"send",
"(",
"habtm_assoc",
".",
"name",
")",
".",
"to_a",
".",
"map",
"(",
":id",
")",
"# TODO: `pluck` would use less memory",
"removed",
"=",
"@record",
".",
"paper_trail_habtm... | Given a HABTM association, returns an array of ids.
@api private | [
"Given",
"a",
"HABTM",
"association",
"returns",
"an",
"array",
"of",
"ids",
"."
] | cfda3e0642323e78cf28196d22bd4c9533398b41 | https://github.com/westonganger/paper_trail-association_tracking/blob/cfda3e0642323e78cf28196d22bd4c9533398b41/lib/paper_trail_association_tracking/record_trail.rb#L156-L161 |
15,483 | westonganger/paper_trail-association_tracking | lib/paper_trail_association_tracking/record_trail.rb | PaperTrailAssociationTracking.RecordTrail.save_bt_association | def save_bt_association(assoc, version)
assoc_version_args = {
version_id: version.id,
foreign_key_name: assoc.foreign_key
}
if assoc.options[:polymorphic]
foreign_type = @record.send(assoc.foreign_type)
if foreign_type && ::PaperTrail.request.enabled_for_model?(foreig... | ruby | def save_bt_association(assoc, version)
assoc_version_args = {
version_id: version.id,
foreign_key_name: assoc.foreign_key
}
if assoc.options[:polymorphic]
foreign_type = @record.send(assoc.foreign_type)
if foreign_type && ::PaperTrail.request.enabled_for_model?(foreig... | [
"def",
"save_bt_association",
"(",
"assoc",
",",
"version",
")",
"assoc_version_args",
"=",
"{",
"version_id",
":",
"version",
".",
"id",
",",
"foreign_key_name",
":",
"assoc",
".",
"foreign_key",
"}",
"if",
"assoc",
".",
"options",
"[",
":polymorphic",
"]",
... | Save a single `belongs_to` association.
@api private | [
"Save",
"a",
"single",
"belongs_to",
"association",
"."
] | cfda3e0642323e78cf28196d22bd4c9533398b41 | https://github.com/westonganger/paper_trail-association_tracking/blob/cfda3e0642323e78cf28196d22bd4c9533398b41/lib/paper_trail_association_tracking/record_trail.rb#L165-L185 |
15,484 | westonganger/paper_trail-association_tracking | lib/paper_trail_association_tracking/record_trail.rb | PaperTrailAssociationTracking.RecordTrail.save_habtm_association? | def save_habtm_association?(assoc)
@record.class.paper_trail_save_join_tables.include?(assoc.name) ||
::PaperTrail.request.enabled_for_model?(assoc.klass)
end | ruby | def save_habtm_association?(assoc)
@record.class.paper_trail_save_join_tables.include?(assoc.name) ||
::PaperTrail.request.enabled_for_model?(assoc.klass)
end | [
"def",
"save_habtm_association?",
"(",
"assoc",
")",
"@record",
".",
"class",
".",
"paper_trail_save_join_tables",
".",
"include?",
"(",
"assoc",
".",
"name",
")",
"||",
"::",
"PaperTrail",
".",
"request",
".",
"enabled_for_model?",
"(",
"assoc",
".",
"klass",
... | Returns true if the given HABTM association should be saved.
@api private | [
"Returns",
"true",
"if",
"the",
"given",
"HABTM",
"association",
"should",
"be",
"saved",
"."
] | cfda3e0642323e78cf28196d22bd4c9533398b41 | https://github.com/westonganger/paper_trail-association_tracking/blob/cfda3e0642323e78cf28196d22bd4c9533398b41/lib/paper_trail_association_tracking/record_trail.rb#L189-L192 |
15,485 | westonganger/paper_trail-association_tracking | lib/paper_trail_association_tracking/model_config.rb | PaperTrailAssociationTracking.ModelConfig.assert_concrete_activerecord_class | def assert_concrete_activerecord_class(class_name)
if class_name.constantize.abstract_class?
raise format(::PaperTrail::ModelConfig::E_HPT_ABSTRACT_CLASS, @model_class, class_name)
end
end | ruby | def assert_concrete_activerecord_class(class_name)
if class_name.constantize.abstract_class?
raise format(::PaperTrail::ModelConfig::E_HPT_ABSTRACT_CLASS, @model_class, class_name)
end
end | [
"def",
"assert_concrete_activerecord_class",
"(",
"class_name",
")",
"if",
"class_name",
".",
"constantize",
".",
"abstract_class?",
"raise",
"format",
"(",
"::",
"PaperTrail",
"::",
"ModelConfig",
"::",
"E_HPT_ABSTRACT_CLASS",
",",
"@model_class",
",",
"class_name",
... | Raises an error if the provided class is an `abstract_class`.
@api private | [
"Raises",
"an",
"error",
"if",
"the",
"provided",
"class",
"is",
"an",
"abstract_class",
"."
] | cfda3e0642323e78cf28196d22bd4c9533398b41 | https://github.com/westonganger/paper_trail-association_tracking/blob/cfda3e0642323e78cf28196d22bd4c9533398b41/lib/paper_trail_association_tracking/model_config.rb#L21-L25 |
15,486 | chef/chef-provisioning-aws | lib/chef/provisioning/aws_driver/aws_provider.rb | Chef::Provisioning::AWSDriver.AWSProvider.wait_for | def wait_for(opts = {})
aws_object = opts[:aws_object]
query_method = opts[:query_method]
expected_responses = [opts[:expected_responses]].flatten
acceptable_errors = [opts[:acceptable_errors] || []].flatten
tries = opts[:tries] || 60
sleep = opts[:sleep] || 5
Retryable.retrya... | ruby | def wait_for(opts = {})
aws_object = opts[:aws_object]
query_method = opts[:query_method]
expected_responses = [opts[:expected_responses]].flatten
acceptable_errors = [opts[:acceptable_errors] || []].flatten
tries = opts[:tries] || 60
sleep = opts[:sleep] || 5
Retryable.retrya... | [
"def",
"wait_for",
"(",
"opts",
"=",
"{",
"}",
")",
"aws_object",
"=",
"opts",
"[",
":aws_object",
"]",
"query_method",
"=",
"opts",
"[",
":query_method",
"]",
"expected_responses",
"=",
"[",
"opts",
"[",
":expected_responses",
"]",
"]",
".",
"flatten",
"a... | Wait until aws_object obtains one of expected_responses
@param aws_object Aws SDK Object to check state on
@param query_method Method to call on aws_object to get current state
@param expected_responses [Symbol,Array<Symbol>] Final state(s) to look for
@param acceptable_errors [Exception,Array<Exception>] Acceptab... | [
"Wait",
"until",
"aws_object",
"obtains",
"one",
"of",
"expected_responses"
] | 1ee70af5c4a9c23d028218736df089bbe5ec3c08 | https://github.com/chef/chef-provisioning-aws/blob/1ee70af5c4a9c23d028218736df089bbe5ec3c08/lib/chef/provisioning/aws_driver/aws_provider.rb#L257-L287 |
15,487 | chicks/aes | lib/aes/aes.rb | AES.AES._random_seed | def _random_seed(size=32)
if defined? OpenSSL::Random
return OpenSSL::Random.random_bytes(size)
else
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
(1..size).collect{|a| chars[rand(chars.size)] }.join
end
end | ruby | def _random_seed(size=32)
if defined? OpenSSL::Random
return OpenSSL::Random.random_bytes(size)
else
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
(1..size).collect{|a| chars[rand(chars.size)] }.join
end
end | [
"def",
"_random_seed",
"(",
"size",
"=",
"32",
")",
"if",
"defined?",
"OpenSSL",
"::",
"Random",
"return",
"OpenSSL",
"::",
"Random",
".",
"random_bytes",
"(",
"size",
")",
"else",
"chars",
"=",
"(",
"\"a\"",
"..",
"\"z\"",
")",
".",
"to_a",
"+",
"(",
... | Generates a random seed value | [
"Generates",
"a",
"random",
"seed",
"value"
] | 001f77806a2cbef513315993e19a8f679f8f5786 | https://github.com/chicks/aes/blob/001f77806a2cbef513315993e19a8f679f8f5786/lib/aes/aes.rb#L93-L100 |
15,488 | chicks/aes | lib/aes/aes.rb | AES.AES.b64_d | def b64_d(data)
iv_and_ctext = []
data.split('$').each do |part|
iv_and_ctext << Base64.decode64(part)
end
iv_and_ctext
end | ruby | def b64_d(data)
iv_and_ctext = []
data.split('$').each do |part|
iv_and_ctext << Base64.decode64(part)
end
iv_and_ctext
end | [
"def",
"b64_d",
"(",
"data",
")",
"iv_and_ctext",
"=",
"[",
"]",
"data",
".",
"split",
"(",
"'$'",
")",
".",
"each",
"do",
"|",
"part",
"|",
"iv_and_ctext",
"<<",
"Base64",
".",
"decode64",
"(",
"part",
")",
"end",
"iv_and_ctext",
"end"
] | Un-Base64's the IV and CipherText
Returns an array containing the IV, and CipherText | [
"Un",
"-",
"Base64",
"s",
"the",
"IV",
"and",
"CipherText",
"Returns",
"an",
"array",
"containing",
"the",
"IV",
"and",
"CipherText"
] | 001f77806a2cbef513315993e19a8f679f8f5786 | https://github.com/chicks/aes/blob/001f77806a2cbef513315993e19a8f679f8f5786/lib/aes/aes.rb#L104-L110 |
15,489 | chicks/aes | lib/aes/aes.rb | AES.AES._setup | def _setup(action)
@cipher ||= OpenSSL::Cipher.new(@options[:cipher])
# Toggles encryption mode
@cipher.send(action)
@cipher.padding = @options[:padding]
@cipher.key = @key.unpack('a2'*32).map{|x| x.hex}.pack('c'*32)
end | ruby | def _setup(action)
@cipher ||= OpenSSL::Cipher.new(@options[:cipher])
# Toggles encryption mode
@cipher.send(action)
@cipher.padding = @options[:padding]
@cipher.key = @key.unpack('a2'*32).map{|x| x.hex}.pack('c'*32)
end | [
"def",
"_setup",
"(",
"action",
")",
"@cipher",
"||=",
"OpenSSL",
"::",
"Cipher",
".",
"new",
"(",
"@options",
"[",
":cipher",
"]",
")",
"# Toggles encryption mode",
"@cipher",
".",
"send",
"(",
"action",
")",
"@cipher",
".",
"padding",
"=",
"@options",
"[... | Create a new cipher using the cipher type specified | [
"Create",
"a",
"new",
"cipher",
"using",
"the",
"cipher",
"type",
"specified"
] | 001f77806a2cbef513315993e19a8f679f8f5786 | https://github.com/chicks/aes/blob/001f77806a2cbef513315993e19a8f679f8f5786/lib/aes/aes.rb#L150-L156 |
15,490 | radiant/radiant | lib/radiant/engine.rb | Radiant.Engine.default_load_paths | def default_load_paths
paths = ["#{RADIANT_ROOT}/test/mocks/#{environment}"]
# Add the app's controller directory
paths.concat(Dir["#{RADIANT_ROOT}/app/controllers/"])
# Followed by the standard includes.
paths.concat %w(
app
app/metal
app/models
... | ruby | def default_load_paths
paths = ["#{RADIANT_ROOT}/test/mocks/#{environment}"]
# Add the app's controller directory
paths.concat(Dir["#{RADIANT_ROOT}/app/controllers/"])
# Followed by the standard includes.
paths.concat %w(
app
app/metal
app/models
... | [
"def",
"default_load_paths",
"paths",
"=",
"[",
"\"#{RADIANT_ROOT}/test/mocks/#{environment}\"",
"]",
"# Add the app's controller directory",
"paths",
".",
"concat",
"(",
"Dir",
"[",
"\"#{RADIANT_ROOT}/app/controllers/\"",
"]",
")",
"# Followed by the standard includes.",
"paths"... | Provide the load paths for the Radiant installation | [
"Provide",
"the",
"load",
"paths",
"for",
"the",
"Radiant",
"installation"
] | 5802d7bac2630a1959c463baa3aa7adcd0f497ee | https://github.com/radiant/radiant/blob/5802d7bac2630a1959c463baa3aa7adcd0f497ee/lib/radiant/engine.rb#L141-L161 |
15,491 | radiant/radiant | lib/radiant/extension.rb | Radiant.Extension.extension_enabled? | def extension_enabled?(extension)
begin
extension = (extension.to_s.camelcase + 'Extension').constantize
extension.enabled?
rescue NameError
false
end
end | ruby | def extension_enabled?(extension)
begin
extension = (extension.to_s.camelcase + 'Extension').constantize
extension.enabled?
rescue NameError
false
end
end | [
"def",
"extension_enabled?",
"(",
"extension",
")",
"begin",
"extension",
"=",
"(",
"extension",
".",
"to_s",
".",
"camelcase",
"+",
"'Extension'",
")",
".",
"constantize",
"extension",
".",
"enabled?",
"rescue",
"NameError",
"false",
"end",
"end"
] | Determine if another extension is installed and up to date.
if MyExtension.extension_enabled?(:third_party)
ThirdPartyExtension.extend(MyExtension::IntegrationPoints)
end | [
"Determine",
"if",
"another",
"extension",
"is",
"installed",
"and",
"up",
"to",
"date",
"."
] | 5802d7bac2630a1959c463baa3aa7adcd0f497ee | https://github.com/radiant/radiant/blob/5802d7bac2630a1959c463baa3aa7adcd0f497ee/lib/radiant/extension.rb#L97-L104 |
15,492 | radiant/radiant | lib/radiant/extension_path.rb | Radiant.ExtensionPath.check_subdirectory | def check_subdirectory(subpath)
subdirectory = File.join(path, subpath)
subdirectory if File.directory?(subdirectory)
end | ruby | def check_subdirectory(subpath)
subdirectory = File.join(path, subpath)
subdirectory if File.directory?(subdirectory)
end | [
"def",
"check_subdirectory",
"(",
"subpath",
")",
"subdirectory",
"=",
"File",
".",
"join",
"(",
"path",
",",
"subpath",
")",
"subdirectory",
"if",
"File",
".",
"directory?",
"(",
"subdirectory",
")",
"end"
] | If the supplied path within the extension root exists and is a directory, its absolute path is returned. Otherwise, nil. | [
"If",
"the",
"supplied",
"path",
"within",
"the",
"extension",
"root",
"exists",
"and",
"is",
"a",
"directory",
"its",
"absolute",
"path",
"is",
"returned",
".",
"Otherwise",
"nil",
"."
] | 5802d7bac2630a1959c463baa3aa7adcd0f497ee | https://github.com/radiant/radiant/blob/5802d7bac2630a1959c463baa3aa7adcd0f497ee/lib/radiant/extension_path.rb#L194-L197 |
15,493 | radiant/radiant | lib/radiant/extension_loader.rb | Radiant.ExtensionLoader.load_extension | def load_extension(name)
extension_path = ExtensionPath.find(name)
begin
constant = "#{name}_extension".camelize
extension = constant.constantize
extension.unloadable
extension.path = extension_path
extension
rescue LoadError, NameError => e
$stderr.puts... | ruby | def load_extension(name)
extension_path = ExtensionPath.find(name)
begin
constant = "#{name}_extension".camelize
extension = constant.constantize
extension.unloadable
extension.path = extension_path
extension
rescue LoadError, NameError => e
$stderr.puts... | [
"def",
"load_extension",
"(",
"name",
")",
"extension_path",
"=",
"ExtensionPath",
".",
"find",
"(",
"name",
")",
"begin",
"constant",
"=",
"\"#{name}_extension\"",
".",
"camelize",
"extension",
"=",
"constant",
".",
"constantize",
"extension",
".",
"unloadable",
... | Loads the specified extension. | [
"Loads",
"the",
"specified",
"extension",
"."
] | 5802d7bac2630a1959c463baa3aa7adcd0f497ee | https://github.com/radiant/radiant/blob/5802d7bac2630a1959c463baa3aa7adcd0f497ee/lib/radiant/extension_loader.rb#L71-L83 |
15,494 | radiant/radiant | app/helpers/radiant/application_helper.rb | Radiant.ApplicationHelper.pagination_for | def pagination_for(list, options={})
if list.respond_to? :total_pages
options = {
max_per_page: detail['pagination.max_per_page'] || 500,
depaginate: true
}.merge(options.symbolize_keys)
depaginate = options.delete(:depaginate) # supp... | ruby | def pagination_for(list, options={})
if list.respond_to? :total_pages
options = {
max_per_page: detail['pagination.max_per_page'] || 500,
depaginate: true
}.merge(options.symbolize_keys)
depaginate = options.delete(:depaginate) # supp... | [
"def",
"pagination_for",
"(",
"list",
",",
"options",
"=",
"{",
"}",
")",
"if",
"list",
".",
"respond_to?",
":total_pages",
"options",
"=",
"{",
"max_per_page",
":",
"detail",
"[",
"'pagination.max_per_page'",
"]",
"||",
"500",
",",
"depaginate",
":",
"true"... | returns the usual set of pagination links.
options are passed through to will_paginate
and a 'show all' depagination link is added if relevant. | [
"returns",
"the",
"usual",
"set",
"of",
"pagination",
"links",
".",
"options",
"are",
"passed",
"through",
"to",
"will_paginate",
"and",
"a",
"show",
"all",
"depagination",
"link",
"is",
"added",
"if",
"relevant",
"."
] | 5802d7bac2630a1959c463baa3aa7adcd0f497ee | https://github.com/radiant/radiant/blob/5802d7bac2630a1959c463baa3aa7adcd0f497ee/app/helpers/radiant/application_helper.rb#L216-L232 |
15,495 | CrossRef/pdfextract | lib/pdf/extract/view/xml_view.rb | PdfExtract.XmlView.get_xml_attributes | def get_xml_attributes obj, parent=true
attribs = obj.reject { |k, _| @@ignored_attributes.include? k }
if parent
attribs = attribs.reject { |k, _| @@parent_ignored_attributes.include? k }
end
attribs = attribs.reject { |_, v| v.kind_of?(Hash) || v.kind_of?(Array) }
attribs.each_pa... | ruby | def get_xml_attributes obj, parent=true
attribs = obj.reject { |k, _| @@ignored_attributes.include? k }
if parent
attribs = attribs.reject { |k, _| @@parent_ignored_attributes.include? k }
end
attribs = attribs.reject { |_, v| v.kind_of?(Hash) || v.kind_of?(Array) }
attribs.each_pa... | [
"def",
"get_xml_attributes",
"obj",
",",
"parent",
"=",
"true",
"attribs",
"=",
"obj",
".",
"reject",
"{",
"|",
"k",
",",
"_",
"|",
"@@ignored_attributes",
".",
"include?",
"k",
"}",
"if",
"parent",
"attribs",
"=",
"attribs",
".",
"reject",
"{",
"|",
"... | Return renderable attributes | [
"Return",
"renderable",
"attributes"
] | 8be42eb0f5f77904ddba49d26f3b241e9fb6cf90 | https://github.com/CrossRef/pdfextract/blob/8be42eb0f5f77904ddba49d26f3b241e9fb6cf90/lib/pdf/extract/view/xml_view.rb#L18-L30 |
15,496 | lml/commontator | app/models/commontator/thread.rb | Commontator.Thread.clear | def clear
return if commontable.blank? || !is_closed?
new_thread = Thread.new
new_thread.commontable = commontable
with_lock do
self.commontable = nil
save!
new_thread.save!
subscriptions.each do |s|
s.thread = new_thread
s.save!
end
... | ruby | def clear
return if commontable.blank? || !is_closed?
new_thread = Thread.new
new_thread.commontable = commontable
with_lock do
self.commontable = nil
save!
new_thread.save!
subscriptions.each do |s|
s.thread = new_thread
s.save!
end
... | [
"def",
"clear",
"return",
"if",
"commontable",
".",
"blank?",
"||",
"!",
"is_closed?",
"new_thread",
"=",
"Thread",
".",
"new",
"new_thread",
".",
"commontable",
"=",
"commontable",
"with_lock",
"do",
"self",
".",
"commontable",
"=",
"nil",
"save!",
"new_threa... | Creates a new empty thread and assigns it to the commontable
The old thread is kept in the database for archival purposes | [
"Creates",
"a",
"new",
"empty",
"thread",
"and",
"assigns",
"it",
"to",
"the",
"commontable",
"The",
"old",
"thread",
"is",
"kept",
"in",
"the",
"database",
"for",
"archival",
"purposes"
] | 1cfc72bc4078fb3c92fa74987af219de583e82ff | https://github.com/lml/commontator/blob/1cfc72bc4078fb3c92fa74987af219de583e82ff/app/models/commontator/thread.rb#L119-L133 |
15,497 | lml/commontator | app/models/commontator/thread.rb | Commontator.Thread.can_be_edited_by? | def can_be_edited_by?(user)
!commontable.nil? && !user.nil? && user.is_commontator &&\
config.thread_moderator_proc.call(self, user)
end | ruby | def can_be_edited_by?(user)
!commontable.nil? && !user.nil? && user.is_commontator &&\
config.thread_moderator_proc.call(self, user)
end | [
"def",
"can_be_edited_by?",
"(",
"user",
")",
"!",
"commontable",
".",
"nil?",
"&&",
"!",
"user",
".",
"nil?",
"&&",
"user",
".",
"is_commontator",
"&&",
"config",
".",
"thread_moderator_proc",
".",
"call",
"(",
"self",
",",
"user",
")",
"end"
] | Thread moderator capabilities | [
"Thread",
"moderator",
"capabilities"
] | 1cfc72bc4078fb3c92fa74987af219de583e82ff | https://github.com/lml/commontator/blob/1cfc72bc4078fb3c92fa74987af219de583e82ff/app/models/commontator/thread.rb#L147-L150 |
15,498 | piotrmurach/strings | lib/strings/truncate.rb | Strings.Truncate.shorten | def shorten(original_chars, chars, length_without_trailing)
truncated = []
char_width = display_width(chars[0])
while length_without_trailing - char_width > 0
orig_char = original_chars.shift
char = chars.shift
break unless char
while orig_char != char # consume ansi
... | ruby | def shorten(original_chars, chars, length_without_trailing)
truncated = []
char_width = display_width(chars[0])
while length_without_trailing - char_width > 0
orig_char = original_chars.shift
char = chars.shift
break unless char
while orig_char != char # consume ansi
... | [
"def",
"shorten",
"(",
"original_chars",
",",
"chars",
",",
"length_without_trailing",
")",
"truncated",
"=",
"[",
"]",
"char_width",
"=",
"display_width",
"(",
"chars",
"[",
"0",
"]",
")",
"while",
"length_without_trailing",
"-",
"char_width",
">",
"0",
"orig... | Perform actual shortening of the text
@return [String]
@api private | [
"Perform",
"actual",
"shortening",
"of",
"the",
"text"
] | 1166dabcdd369600b37084e432dce7868b9a6759 | https://github.com/piotrmurach/strings/blob/1166dabcdd369600b37084e432dce7868b9a6759/lib/strings/truncate.rb#L71-L89 |
15,499 | piotrmurach/strings | lib/strings/pad.rb | Strings.Pad.pad | def pad(text, padding, fill: SPACE, separator: NEWLINE)
padding = Strings::Padder.parse(padding)
text_copy = text.dup
line_width = max_line_length(text, separator)
output = []
filler_line = fill * line_width
padding.top.times do
output << pad_around(filler_line, padding, ... | ruby | def pad(text, padding, fill: SPACE, separator: NEWLINE)
padding = Strings::Padder.parse(padding)
text_copy = text.dup
line_width = max_line_length(text, separator)
output = []
filler_line = fill * line_width
padding.top.times do
output << pad_around(filler_line, padding, ... | [
"def",
"pad",
"(",
"text",
",",
"padding",
",",
"fill",
":",
"SPACE",
",",
"separator",
":",
"NEWLINE",
")",
"padding",
"=",
"Strings",
"::",
"Padder",
".",
"parse",
"(",
"padding",
")",
"text_copy",
"=",
"text",
".",
"dup",
"line_width",
"=",
"max_lin... | Apply padding to multiline text with ANSI codes
@param [String] text
the text to pad out
@param [Integer, Array[Integer]] padding
the padding to apply to text
@example
text = "Ignorance is the parent of fear."
Strings::Pad.pad(text, [1, 2], fill: "*")
# =>
# "************************************\n"
... | [
"Apply",
"padding",
"to",
"multiline",
"text",
"with",
"ANSI",
"codes"
] | 1166dabcdd369600b37084e432dce7868b9a6759 | https://github.com/piotrmurach/strings/blob/1166dabcdd369600b37084e432dce7868b9a6759/lib/strings/pad.rb#L34-L55 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.