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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
11,500 | plataformatec/responders | lib/responders/controller_method.rb | Responders.ControllerMethod.responders | def responders(*responders)
self.responder = responders.inject(Class.new(responder)) do |klass, responder|
responder = case responder
when Module
responder
when String, Symbol
Responders.const_get("#{responder.to_s.camelize}Responder")
else
... | ruby | def responders(*responders)
self.responder = responders.inject(Class.new(responder)) do |klass, responder|
responder = case responder
when Module
responder
when String, Symbol
Responders.const_get("#{responder.to_s.camelize}Responder")
else
... | [
"def",
"responders",
"(",
"*",
"responders",
")",
"self",
".",
"responder",
"=",
"responders",
".",
"inject",
"(",
"Class",
".",
"new",
"(",
"responder",
")",
")",
"do",
"|",
"klass",
",",
"responder",
"|",
"responder",
"=",
"case",
"responder",
"when",
... | Adds the given responders to the current controller's responder, allowing you to cherry-pick
which responders you want per controller.
class InvitationsController < ApplicationController
responders :flash, :http_cache
end
Takes symbols and strings and translates them to VariableResponder (eg. :flash beco... | [
"Adds",
"the",
"given",
"responders",
"to",
"the",
"current",
"controller",
"s",
"responder",
"allowing",
"you",
"to",
"cherry",
"-",
"pick",
"which",
"responders",
"you",
"want",
"per",
"controller",
"."
] | a1a2706091d4ffcbbe387407ddfc5671a59ad842 | https://github.com/plataformatec/responders/blob/a1a2706091d4ffcbbe387407ddfc5671a59ad842/lib/responders/controller_method.rb#L19-L33 |
11,501 | plataformatec/responders | lib/action_controller/respond_with.rb | ActionController.RespondWith.respond_with | def respond_with(*resources, &block)
if self.class.mimes_for_respond_to.empty?
raise "In order to use respond_with, first you need to declare the " \
"formats your controller responds to in the class level."
end
mimes = collect_mimes_from_class_level
collector = ActionControll... | ruby | def respond_with(*resources, &block)
if self.class.mimes_for_respond_to.empty?
raise "In order to use respond_with, first you need to declare the " \
"formats your controller responds to in the class level."
end
mimes = collect_mimes_from_class_level
collector = ActionControll... | [
"def",
"respond_with",
"(",
"*",
"resources",
",",
"&",
"block",
")",
"if",
"self",
".",
"class",
".",
"mimes_for_respond_to",
".",
"empty?",
"raise",
"\"In order to use respond_with, first you need to declare the \"",
"\"formats your controller responds to in the class level.\... | For a given controller action, respond_with generates an appropriate
response based on the mime-type requested by the client.
If the method is called with just a resource, as in this example -
class PeopleController < ApplicationController
respond_to :html, :xml, :json
def index
@people = Perso... | [
"For",
"a",
"given",
"controller",
"action",
"respond_with",
"generates",
"an",
"appropriate",
"response",
"based",
"on",
"the",
"mime",
"-",
"type",
"requested",
"by",
"the",
"client",
"."
] | a1a2706091d4ffcbbe387407ddfc5671a59ad842 | https://github.com/plataformatec/responders/blob/a1a2706091d4ffcbbe387407ddfc5671a59ad842/lib/action_controller/respond_with.rb#L196-L215 |
11,502 | plataformatec/responders | lib/action_controller/respond_with.rb | ActionController.RespondWith.collect_mimes_from_class_level | def collect_mimes_from_class_level #:nodoc:
action = action_name.to_sym
self.class.mimes_for_respond_to.keys.select do |mime|
config = self.class.mimes_for_respond_to[mime]
if config[:except]
!config[:except].include?(action)
elsif config[:only]
config[:only].in... | ruby | def collect_mimes_from_class_level #:nodoc:
action = action_name.to_sym
self.class.mimes_for_respond_to.keys.select do |mime|
config = self.class.mimes_for_respond_to[mime]
if config[:except]
!config[:except].include?(action)
elsif config[:only]
config[:only].in... | [
"def",
"collect_mimes_from_class_level",
"#:nodoc:",
"action",
"=",
"action_name",
".",
"to_sym",
"self",
".",
"class",
".",
"mimes_for_respond_to",
".",
"keys",
".",
"select",
"do",
"|",
"mime",
"|",
"config",
"=",
"self",
".",
"class",
".",
"mimes_for_respond_... | Collect mimes declared in the class method respond_to valid for the
current action. | [
"Collect",
"mimes",
"declared",
"in",
"the",
"class",
"method",
"respond_to",
"valid",
"for",
"the",
"current",
"action",
"."
] | a1a2706091d4ffcbbe387407ddfc5671a59ad842 | https://github.com/plataformatec/responders/blob/a1a2706091d4ffcbbe387407ddfc5671a59ad842/lib/action_controller/respond_with.rb#L240-L254 |
11,503 | algolia/algoliasearch-rails | lib/algoliasearch-rails.rb | AlgoliaSearch.ClassMethods.algolia_reindex | def algolia_reindex(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
return if algolia_without_auto_index_scope
algolia_configurations.each do |options, settings|
next if algolia_indexing_disabled?(options)
next if options[:slave] || options[:replica]
... | ruby | def algolia_reindex(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
return if algolia_without_auto_index_scope
algolia_configurations.each do |options, settings|
next if algolia_indexing_disabled?(options)
next if options[:slave] || options[:replica]
... | [
"def",
"algolia_reindex",
"(",
"batch_size",
"=",
"AlgoliaSearch",
"::",
"IndexSettings",
"::",
"DEFAULT_BATCH_SIZE",
",",
"synchronous",
"=",
"false",
")",
"return",
"if",
"algolia_without_auto_index_scope",
"algolia_configurations",
".",
"each",
"do",
"|",
"options",
... | reindex whole database using a extra temporary index + move operation | [
"reindex",
"whole",
"database",
"using",
"a",
"extra",
"temporary",
"index",
"+",
"move",
"operation"
] | 360e47d733476e6611d9874cf89e57942b7f2939 | https://github.com/algolia/algoliasearch-rails/blob/360e47d733476e6611d9874cf89e57942b7f2939/lib/algoliasearch-rails.rb#L540-L577 |
11,504 | algolia/algoliasearch-rails | lib/algoliasearch-rails.rb | AlgoliaSearch.SafeIndex.get_settings | def get_settings(*args)
SafeIndex.log_or_throw(:get_settings, @raise_on_failure) do
begin
@index.get_settings(*args)
rescue Algolia::AlgoliaError => e
return {} if e.code == 404 # not fatal
raise e
end
end
end | ruby | def get_settings(*args)
SafeIndex.log_or_throw(:get_settings, @raise_on_failure) do
begin
@index.get_settings(*args)
rescue Algolia::AlgoliaError => e
return {} if e.code == 404 # not fatal
raise e
end
end
end | [
"def",
"get_settings",
"(",
"*",
"args",
")",
"SafeIndex",
".",
"log_or_throw",
"(",
":get_settings",
",",
"@raise_on_failure",
")",
"do",
"begin",
"@index",
".",
"get_settings",
"(",
"args",
")",
"rescue",
"Algolia",
"::",
"AlgoliaError",
"=>",
"e",
"return",... | special handling of get_settings to avoid raising errors on 404 | [
"special",
"handling",
"of",
"get_settings",
"to",
"avoid",
"raising",
"errors",
"on",
"404"
] | 360e47d733476e6611d9874cf89e57942b7f2939 | https://github.com/algolia/algoliasearch-rails/blob/360e47d733476e6611d9874cf89e57942b7f2939/lib/algoliasearch-rails.rb#L328-L337 |
11,505 | jhund/filterrific | lib/filterrific/param_set.rb | Filterrific.ParamSet.define_and_assign_attr_accessors_for_each_filter | def define_and_assign_attr_accessors_for_each_filter(fp)
model_class.filterrific_available_filters.each do |filter_name|
self.class.send(:attr_accessor, filter_name)
v = fp[filter_name]
self.send("#{ filter_name }=", v) if v.present?
end
end | ruby | def define_and_assign_attr_accessors_for_each_filter(fp)
model_class.filterrific_available_filters.each do |filter_name|
self.class.send(:attr_accessor, filter_name)
v = fp[filter_name]
self.send("#{ filter_name }=", v) if v.present?
end
end | [
"def",
"define_and_assign_attr_accessors_for_each_filter",
"(",
"fp",
")",
"model_class",
".",
"filterrific_available_filters",
".",
"each",
"do",
"|",
"filter_name",
"|",
"self",
".",
"class",
".",
"send",
"(",
":attr_accessor",
",",
"filter_name",
")",
"v",
"=",
... | Defines attr accessors for each available_filter on self and assigns
values based on fp.
@param fp [Hash] filterrific_params with stringified keys | [
"Defines",
"attr",
"accessors",
"for",
"each",
"available_filter",
"on",
"self",
"and",
"assigns",
"values",
"based",
"on",
"fp",
"."
] | 811edc57d3e2a3e538c1f0e9554e0909be052881 | https://github.com/jhund/filterrific/blob/811edc57d3e2a3e538c1f0e9554e0909be052881/lib/filterrific/param_set.rb#L120-L126 |
11,506 | jhund/filterrific | lib/filterrific/action_controller_extension.rb | Filterrific.ActionControllerExtension.compute_filterrific_params | def compute_filterrific_params(model_class, filterrific_params, opts, persistence_id)
opts = { "sanitize_params" => true }.merge(opts.stringify_keys)
r = (
filterrific_params.presence || # start with passed in params
(persistence_id && session[persistence_id].presence) || # then try session ... | ruby | def compute_filterrific_params(model_class, filterrific_params, opts, persistence_id)
opts = { "sanitize_params" => true }.merge(opts.stringify_keys)
r = (
filterrific_params.presence || # start with passed in params
(persistence_id && session[persistence_id].presence) || # then try session ... | [
"def",
"compute_filterrific_params",
"(",
"model_class",
",",
"filterrific_params",
",",
"opts",
",",
"persistence_id",
")",
"opts",
"=",
"{",
"\"sanitize_params\"",
"=>",
"true",
"}",
".",
"merge",
"(",
"opts",
".",
"stringify_keys",
")",
"r",
"=",
"(",
"filt... | Computes filterrific params using a number of strategies. Limits params
to 'available_filters' if given via opts.
@param model_class [ActiveRecord::Base]
@param filterrific_params [ActionController::Params, Hash]
@param opts [Hash]
@option opts [Boolean, optional] "sanitize_params"
if true, sanitizes all filter... | [
"Computes",
"filterrific",
"params",
"using",
"a",
"number",
"of",
"strategies",
".",
"Limits",
"params",
"to",
"available_filters",
"if",
"given",
"via",
"opts",
"."
] | 811edc57d3e2a3e538c1f0e9554e0909be052881 | https://github.com/jhund/filterrific/blob/811edc57d3e2a3e538c1f0e9554e0909be052881/lib/filterrific/action_controller_extension.rb#L70-L84 |
11,507 | jhund/filterrific | lib/filterrific/action_view_extension.rb | Filterrific.ActionViewExtension.form_for_filterrific | def form_for_filterrific(record, options = {}, &block)
options[:as] ||= :filterrific
options[:html] ||= {}
options[:html][:method] ||= :get
options[:html][:id] ||= :filterrific_filter
options[:url] ||= url_for(
:controller => controller.controller_name,
:action => controlle... | ruby | def form_for_filterrific(record, options = {}, &block)
options[:as] ||= :filterrific
options[:html] ||= {}
options[:html][:method] ||= :get
options[:html][:id] ||= :filterrific_filter
options[:url] ||= url_for(
:controller => controller.controller_name,
:action => controlle... | [
"def",
"form_for_filterrific",
"(",
"record",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"options",
"[",
":as",
"]",
"||=",
":filterrific",
"options",
"[",
":html",
"]",
"||=",
"{",
"}",
"options",
"[",
":html",
"]",
"[",
":method",
"]",
... | Sets all options on form_for to defaults that work with Filterrific
@param record [Filterrific] the @filterrific object
@param options [Hash] standard options for form_for
@param block [Proc] the form body | [
"Sets",
"all",
"options",
"on",
"form_for",
"to",
"defaults",
"that",
"work",
"with",
"Filterrific"
] | 811edc57d3e2a3e538c1f0e9554e0909be052881 | https://github.com/jhund/filterrific/blob/811edc57d3e2a3e538c1f0e9554e0909be052881/lib/filterrific/action_view_extension.rb#L14-L24 |
11,508 | jhund/filterrific | lib/filterrific/action_view_extension.rb | Filterrific.ActionViewExtension.filterrific_sorting_link_reverse_order | def filterrific_sorting_link_reverse_order(filterrific, new_sort_key, opts)
# current sort column, toggle search_direction
new_sort_direction = 'asc' == opts[:current_sort_direction] ? 'desc' : 'asc'
new_sorting = safe_join([new_sort_key, new_sort_direction], '_')
css_classes = safe_join([
... | ruby | def filterrific_sorting_link_reverse_order(filterrific, new_sort_key, opts)
# current sort column, toggle search_direction
new_sort_direction = 'asc' == opts[:current_sort_direction] ? 'desc' : 'asc'
new_sorting = safe_join([new_sort_key, new_sort_direction], '_')
css_classes = safe_join([
... | [
"def",
"filterrific_sorting_link_reverse_order",
"(",
"filterrific",
",",
"new_sort_key",
",",
"opts",
")",
"# current sort column, toggle search_direction",
"new_sort_direction",
"=",
"'asc'",
"==",
"opts",
"[",
":current_sort_direction",
"]",
"?",
"'desc'",
":",
"'asc'",
... | Renders HTML to reverse sort order on currently sorted column.
@param filterrific [Filterrific::ParamSet]
@param new_sort_key [String]
@param opts [Hash]
@return [String] an HTML fragment | [
"Renders",
"HTML",
"to",
"reverse",
"sort",
"order",
"on",
"currently",
"sorted",
"column",
"."
] | 811edc57d3e2a3e538c1f0e9554e0909be052881 | https://github.com/jhund/filterrific/blob/811edc57d3e2a3e538c1f0e9554e0909be052881/lib/filterrific/action_view_extension.rb#L102-L119 |
11,509 | dotless-de/vagrant-vbguest | lib/vagrant-vbguest/config.rb | VagrantVbguest.Config.to_hash | def to_hash
{
:installer => installer,
:installer_arguments => installer_arguments,
:iso_path => iso_path,
:iso_upload_path => iso_upload_path,
:iso_mount_point => iso_mount_point,
:auto_update => auto_update,
:auto_reboot => auto_reboot,
:no_install... | ruby | def to_hash
{
:installer => installer,
:installer_arguments => installer_arguments,
:iso_path => iso_path,
:iso_upload_path => iso_upload_path,
:iso_mount_point => iso_mount_point,
:auto_update => auto_update,
:auto_reboot => auto_reboot,
:no_install... | [
"def",
"to_hash",
"{",
":installer",
"=>",
"installer",
",",
":installer_arguments",
"=>",
"installer_arguments",
",",
":iso_path",
"=>",
"iso_path",
",",
":iso_upload_path",
"=>",
"iso_upload_path",
",",
":iso_mount_point",
"=>",
"iso_mount_point",
",",
":auto_update",... | explicit hash, to get symbols in hash keys | [
"explicit",
"hash",
"to",
"get",
"symbols",
"in",
"hash",
"keys"
] | 934fd22864c811c951c020cfcfc5c2ef9d79d5ef | https://github.com/dotless-de/vagrant-vbguest/blob/934fd22864c811c951c020cfcfc5c2ef9d79d5ef/lib/vagrant-vbguest/config.rb#L42-L55 |
11,510 | dotless-de/vagrant-vbguest | lib/vagrant-vbguest/command.rb | VagrantVbguest.Command.execute_on_vm | def execute_on_vm(vm, options)
check_runable_on(vm)
options = options.clone
_method = options.delete(:_method)
_rebootable = options.delete(:_rebootable)
options = vm.config.vbguest.to_hash.merge(options)
machine = VagrantVbguest::Machine.new(vm, options)
status = ma... | ruby | def execute_on_vm(vm, options)
check_runable_on(vm)
options = options.clone
_method = options.delete(:_method)
_rebootable = options.delete(:_rebootable)
options = vm.config.vbguest.to_hash.merge(options)
machine = VagrantVbguest::Machine.new(vm, options)
status = ma... | [
"def",
"execute_on_vm",
"(",
"vm",
",",
"options",
")",
"check_runable_on",
"(",
"vm",
")",
"options",
"=",
"options",
".",
"clone",
"_method",
"=",
"options",
".",
"delete",
"(",
":_method",
")",
"_rebootable",
"=",
"options",
".",
"delete",
"(",
":_reboo... | Executes a task on a specific VM.
@param vm [Vagrant::VM]
@param options [Hash] Parsed options from the command line | [
"Executes",
"a",
"task",
"on",
"a",
"specific",
"VM",
"."
] | 934fd22864c811c951c020cfcfc5c2ef9d79d5ef | https://github.com/dotless-de/vagrant-vbguest/blob/934fd22864c811c951c020cfcfc5c2ef9d79d5ef/lib/vagrant-vbguest/command.rb#L87-L106 |
11,511 | nathanvda/cocoon | lib/cocoon/view_helpers.rb | Cocoon.ViewHelpers.link_to_add_association | def link_to_add_association(*args, &block)
if block_given?
link_to_add_association(capture(&block), *args)
elsif args.first.respond_to?(:object)
association = args.second
name = I18n.translate("cocoon.#{association}.add", default: I18n.translate('cocoon.defaults.add'))
link_... | ruby | def link_to_add_association(*args, &block)
if block_given?
link_to_add_association(capture(&block), *args)
elsif args.first.respond_to?(:object)
association = args.second
name = I18n.translate("cocoon.#{association}.add", default: I18n.translate('cocoon.defaults.add'))
link_... | [
"def",
"link_to_add_association",
"(",
"*",
"args",
",",
"&",
"block",
")",
"if",
"block_given?",
"link_to_add_association",
"(",
"capture",
"(",
"block",
")",
",",
"args",
")",
"elsif",
"args",
".",
"first",
".",
"respond_to?",
"(",
":object",
")",
"associa... | shows a link that will allow to dynamically add a new associated object.
- *name* : the text to show in the link
- *f* : the form this should come in (the formtastic form)
- *association* : the associated objects, e.g. :tasks, this should be the name of the <tt>has_many</tt> relation.
- *html_o... | [
"shows",
"a",
"link",
"that",
"will",
"allow",
"to",
"dynamically",
"add",
"a",
"new",
"associated",
"object",
"."
] | ec18c446a5475aa4959c699c797ee0fe9b0c9136 | https://github.com/nathanvda/cocoon/blob/ec18c446a5475aa4959c699c797ee0fe9b0c9136/lib/cocoon/view_helpers.rb#L71-L104 |
11,512 | getsentry/raven-ruby | lib/raven/instance.rb | Raven.Instance.capture | def capture(options = {})
if block_given?
begin
yield
rescue Error
raise # Don't capture Raven errors
rescue Exception => e
capture_type(e, options)
raise
end
else
install_at_exit_hook(options)
end
end | ruby | def capture(options = {})
if block_given?
begin
yield
rescue Error
raise # Don't capture Raven errors
rescue Exception => e
capture_type(e, options)
raise
end
else
install_at_exit_hook(options)
end
end | [
"def",
"capture",
"(",
"options",
"=",
"{",
"}",
")",
"if",
"block_given?",
"begin",
"yield",
"rescue",
"Error",
"raise",
"# Don't capture Raven errors",
"rescue",
"Exception",
"=>",
"e",
"capture_type",
"(",
"e",
",",
"options",
")",
"raise",
"end",
"else",
... | Capture and process any exceptions from the given block.
@example
Raven.capture do
MyApp.run
end | [
"Capture",
"and",
"process",
"any",
"exceptions",
"from",
"the",
"given",
"block",
"."
] | 729c22f9284939695f14822683bff1a0b72502bd | https://github.com/getsentry/raven-ruby/blob/729c22f9284939695f14822683bff1a0b72502bd/lib/raven/instance.rb#L90-L103 |
11,513 | getsentry/raven-ruby | lib/raven/instance.rb | Raven.Instance.annotate_exception | def annotate_exception(exc, options = {})
notes = (exc.instance_variable_defined?(:@__raven_context) && exc.instance_variable_get(:@__raven_context)) || {}
Raven::Utils::DeepMergeHash.deep_merge!(notes, options)
exc.instance_variable_set(:@__raven_context, notes)
exc
end | ruby | def annotate_exception(exc, options = {})
notes = (exc.instance_variable_defined?(:@__raven_context) && exc.instance_variable_get(:@__raven_context)) || {}
Raven::Utils::DeepMergeHash.deep_merge!(notes, options)
exc.instance_variable_set(:@__raven_context, notes)
exc
end | [
"def",
"annotate_exception",
"(",
"exc",
",",
"options",
"=",
"{",
"}",
")",
"notes",
"=",
"(",
"exc",
".",
"instance_variable_defined?",
"(",
":@__raven_context",
")",
"&&",
"exc",
".",
"instance_variable_get",
"(",
":@__raven_context",
")",
")",
"||",
"{",
... | Provides extra context to the exception prior to it being handled by
Raven. An exception can have multiple annotations, which are merged
together.
The options (annotation) is treated the same as the ``options``
parameter to ``capture_exception`` or ``Event.from_exception``, and
can contain the same ``:user``, ``:... | [
"Provides",
"extra",
"context",
"to",
"the",
"exception",
"prior",
"to",
"it",
"being",
"handled",
"by",
"Raven",
".",
"An",
"exception",
"can",
"have",
"multiple",
"annotations",
"which",
"are",
"merged",
"together",
"."
] | 729c22f9284939695f14822683bff1a0b72502bd | https://github.com/getsentry/raven-ruby/blob/729c22f9284939695f14822683bff1a0b72502bd/lib/raven/instance.rb#L159-L164 |
11,514 | getsentry/raven-ruby | lib/raven/integrations/sidekiq.rb | Raven.SidekiqErrorHandler.filter_context | def filter_context(context)
case context
when Array
context.map { |arg| filter_context(arg) }
when Hash
Hash[context.map { |key, value| filter_context_hash(key, value) }]
else
format_globalid(context)
end
end | ruby | def filter_context(context)
case context
when Array
context.map { |arg| filter_context(arg) }
when Hash
Hash[context.map { |key, value| filter_context_hash(key, value) }]
else
format_globalid(context)
end
end | [
"def",
"filter_context",
"(",
"context",
")",
"case",
"context",
"when",
"Array",
"context",
".",
"map",
"{",
"|",
"arg",
"|",
"filter_context",
"(",
"arg",
")",
"}",
"when",
"Hash",
"Hash",
"[",
"context",
".",
"map",
"{",
"|",
"key",
",",
"value",
... | Once an ActiveJob is queued, ActiveRecord references get serialized into
some internal reserved keys, such as _aj_globalid.
The problem is, if this job in turn gets queued back into ActiveJob with
these magic reserved keys, ActiveJob will throw up and error. We want to
capture these and mutate the keys so we can s... | [
"Once",
"an",
"ActiveJob",
"is",
"queued",
"ActiveRecord",
"references",
"get",
"serialized",
"into",
"some",
"internal",
"reserved",
"keys",
"such",
"as",
"_aj_globalid",
"."
] | 729c22f9284939695f14822683bff1a0b72502bd | https://github.com/getsentry/raven-ruby/blob/729c22f9284939695f14822683bff1a0b72502bd/lib/raven/integrations/sidekiq.rb#L39-L48 |
11,515 | chef/ohai | lib/ohai/system.rb | Ohai.System.run_plugins | def run_plugins(safe = false, attribute_filter = nil)
begin
@provides_map.all_plugins(attribute_filter).each do |plugin|
@runner.run_plugin(plugin)
end
rescue Ohai::Exceptions::AttributeNotFound, Ohai::Exceptions::DependencyCycle => e
logger.error("Encountered error while r... | ruby | def run_plugins(safe = false, attribute_filter = nil)
begin
@provides_map.all_plugins(attribute_filter).each do |plugin|
@runner.run_plugin(plugin)
end
rescue Ohai::Exceptions::AttributeNotFound, Ohai::Exceptions::DependencyCycle => e
logger.error("Encountered error while r... | [
"def",
"run_plugins",
"(",
"safe",
"=",
"false",
",",
"attribute_filter",
"=",
"nil",
")",
"begin",
"@provides_map",
".",
"all_plugins",
"(",
"attribute_filter",
")",
".",
"each",
"do",
"|",
"plugin",
"|",
"@runner",
".",
"run_plugin",
"(",
"plugin",
")",
... | run all plugins or those that match the attribute filter is provided
@param safe [Boolean]
@param [Array<String>] attribute_filter the attributes to run. All will be run if not specified
@return [Mash] | [
"run",
"all",
"plugins",
"or",
"those",
"that",
"match",
"the",
"attribute",
"filter",
"is",
"provided"
] | 8d66449940f04237586b2f928231c6b26e2cc19a | https://github.com/chef/ohai/blob/8d66449940f04237586b2f928231c6b26e2cc19a/lib/ohai/system.rb#L109-L131 |
11,516 | chef/ohai | lib/ohai/system.rb | Ohai.System.json_pretty_print | def json_pretty_print(item = nil)
FFI_Yajl::Encoder.new(pretty: true, validate_utf8: false).encode(item || @data)
end | ruby | def json_pretty_print(item = nil)
FFI_Yajl::Encoder.new(pretty: true, validate_utf8: false).encode(item || @data)
end | [
"def",
"json_pretty_print",
"(",
"item",
"=",
"nil",
")",
"FFI_Yajl",
"::",
"Encoder",
".",
"new",
"(",
"pretty",
":",
"true",
",",
"validate_utf8",
":",
"false",
")",
".",
"encode",
"(",
"item",
"||",
"@data",
")",
"end"
] | Pretty Print this object as JSON | [
"Pretty",
"Print",
"this",
"object",
"as",
"JSON"
] | 8d66449940f04237586b2f928231c6b26e2cc19a | https://github.com/chef/ohai/blob/8d66449940f04237586b2f928231c6b26e2cc19a/lib/ohai/system.rb#L152-L154 |
11,517 | chef/ohai | lib/ohai/provides_map.rb | Ohai.ProvidesMap.find_providers_for | def find_providers_for(attributes)
plugins = []
attributes.each do |attribute|
attrs = select_subtree(@map, attribute)
raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'" unless attrs
raise Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing... | ruby | def find_providers_for(attributes)
plugins = []
attributes.each do |attribute|
attrs = select_subtree(@map, attribute)
raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'" unless attrs
raise Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing... | [
"def",
"find_providers_for",
"(",
"attributes",
")",
"plugins",
"=",
"[",
"]",
"attributes",
".",
"each",
"do",
"|",
"attribute",
"|",
"attrs",
"=",
"select_subtree",
"(",
"@map",
",",
"attribute",
")",
"raise",
"Ohai",
"::",
"Exceptions",
"::",
"AttributeNo... | gather plugins providing exactly the attributes listed | [
"gather",
"plugins",
"providing",
"exactly",
"the",
"attributes",
"listed"
] | 8d66449940f04237586b2f928231c6b26e2cc19a | https://github.com/chef/ohai/blob/8d66449940f04237586b2f928231c6b26e2cc19a/lib/ohai/provides_map.rb#L52-L61 |
11,518 | chef/ohai | lib/ohai/provides_map.rb | Ohai.ProvidesMap.deep_find_providers_for | def deep_find_providers_for(attributes)
plugins = []
attributes.each do |attribute|
attrs = select_subtree(@map, attribute)
unless attrs
attrs = select_closest_subtree(@map, attribute)
unless attrs
raise Ohai::Exceptions::AttributeNotFound, "No such attribut... | ruby | def deep_find_providers_for(attributes)
plugins = []
attributes.each do |attribute|
attrs = select_subtree(@map, attribute)
unless attrs
attrs = select_closest_subtree(@map, attribute)
unless attrs
raise Ohai::Exceptions::AttributeNotFound, "No such attribut... | [
"def",
"deep_find_providers_for",
"(",
"attributes",
")",
"plugins",
"=",
"[",
"]",
"attributes",
".",
"each",
"do",
"|",
"attribute",
"|",
"attrs",
"=",
"select_subtree",
"(",
"@map",
",",
"attribute",
")",
"unless",
"attrs",
"attrs",
"=",
"select_closest_sub... | This function is used to fetch the plugins for the attributes specified
in the CLI options to Ohai.
It first attempts to find the plugins for the attributes
or the sub attributes given.
If it can't find any, it looks for plugins that might
provide the parents of a given attribute and returns the
first parent foun... | [
"This",
"function",
"is",
"used",
"to",
"fetch",
"the",
"plugins",
"for",
"the",
"attributes",
"specified",
"in",
"the",
"CLI",
"options",
"to",
"Ohai",
".",
"It",
"first",
"attempts",
"to",
"find",
"the",
"plugins",
"for",
"the",
"attributes",
"or",
"the"... | 8d66449940f04237586b2f928231c6b26e2cc19a | https://github.com/chef/ohai/blob/8d66449940f04237586b2f928231c6b26e2cc19a/lib/ohai/provides_map.rb#L70-L87 |
11,519 | chef/ohai | lib/ohai/provides_map.rb | Ohai.ProvidesMap.find_closest_providers_for | def find_closest_providers_for(attributes)
plugins = []
attributes.each do |attribute|
parts = normalize_and_validate(attribute)
raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'" unless @map[parts[0]]
attrs = select_closest_subtree(@map, attribute)
... | ruby | def find_closest_providers_for(attributes)
plugins = []
attributes.each do |attribute|
parts = normalize_and_validate(attribute)
raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'" unless @map[parts[0]]
attrs = select_closest_subtree(@map, attribute)
... | [
"def",
"find_closest_providers_for",
"(",
"attributes",
")",
"plugins",
"=",
"[",
"]",
"attributes",
".",
"each",
"do",
"|",
"attribute",
"|",
"parts",
"=",
"normalize_and_validate",
"(",
"attribute",
")",
"raise",
"Ohai",
"::",
"Exceptions",
"::",
"AttributeNot... | This function is used to fetch the plugins from
'depends "languages"' statements in plugins.
It gathers plugins providing each of the attributes listed, or the
plugins providing the closest parent attribute | [
"This",
"function",
"is",
"used",
"to",
"fetch",
"the",
"plugins",
"from",
"depends",
"languages",
"statements",
"in",
"plugins",
".",
"It",
"gathers",
"plugins",
"providing",
"each",
"of",
"the",
"attributes",
"listed",
"or",
"the",
"plugins",
"providing",
"t... | 8d66449940f04237586b2f928231c6b26e2cc19a | https://github.com/chef/ohai/blob/8d66449940f04237586b2f928231c6b26e2cc19a/lib/ohai/provides_map.rb#L93-L103 |
11,520 | chef/ohai | lib/ohai/provides_map.rb | Ohai.ProvidesMap.collect_plugins_in | def collect_plugins_in(provides_map, collected)
provides_map.each_key do |plugin|
if plugin.eql?("_plugins")
collected.concat(provides_map[plugin])
else
collect_plugins_in(provides_map[plugin], collected)
end
end
collected
end | ruby | def collect_plugins_in(provides_map, collected)
provides_map.each_key do |plugin|
if plugin.eql?("_plugins")
collected.concat(provides_map[plugin])
else
collect_plugins_in(provides_map[plugin], collected)
end
end
collected
end | [
"def",
"collect_plugins_in",
"(",
"provides_map",
",",
"collected",
")",
"provides_map",
".",
"each_key",
"do",
"|",
"plugin",
"|",
"if",
"plugin",
".",
"eql?",
"(",
"\"_plugins\"",
")",
"collected",
".",
"concat",
"(",
"provides_map",
"[",
"plugin",
"]",
")... | Takes a section of the map, recursively searches for a `_plugins` key
to find all the plugins in that section of the map. If given the whole
map, it will find all of the plugins that have at least one provided
attribute. | [
"Takes",
"a",
"section",
"of",
"the",
"map",
"recursively",
"searches",
"for",
"a",
"_plugins",
"key",
"to",
"find",
"all",
"the",
"plugins",
"in",
"that",
"section",
"of",
"the",
"map",
".",
"If",
"given",
"the",
"whole",
"map",
"it",
"will",
"find",
... | 8d66449940f04237586b2f928231c6b26e2cc19a | https://github.com/chef/ohai/blob/8d66449940f04237586b2f928231c6b26e2cc19a/lib/ohai/provides_map.rb#L173-L182 |
11,521 | chef/ohai | lib/ohai/loader.rb | Ohai.Loader.plugin_files_by_dir | def plugin_files_by_dir(plugin_dir = Ohai.config[:plugin_path])
Array(plugin_dir).map do |path|
if Dir.exist?(path)
Ohai::Log.trace("Searching for Ohai plugins in #{path}")
escaped = ChefConfig::PathHelper.escape_glob_dir(path)
Dir[File.join(escaped, "**", "*.rb")]
e... | ruby | def plugin_files_by_dir(plugin_dir = Ohai.config[:plugin_path])
Array(plugin_dir).map do |path|
if Dir.exist?(path)
Ohai::Log.trace("Searching for Ohai plugins in #{path}")
escaped = ChefConfig::PathHelper.escape_glob_dir(path)
Dir[File.join(escaped, "**", "*.rb")]
e... | [
"def",
"plugin_files_by_dir",
"(",
"plugin_dir",
"=",
"Ohai",
".",
"config",
"[",
":plugin_path",
"]",
")",
"Array",
"(",
"plugin_dir",
")",
".",
"map",
"do",
"|",
"path",
"|",
"if",
"Dir",
".",
"exist?",
"(",
"path",
")",
"Ohai",
"::",
"Log",
".",
"... | Searches all plugin paths and returns an Array of file paths to plugins
@param dir [Array, String] directory/directories to load plugins from
@return [Array<String>] | [
"Searches",
"all",
"plugin",
"paths",
"and",
"returns",
"an",
"Array",
"of",
"file",
"paths",
"to",
"plugins"
] | 8d66449940f04237586b2f928231c6b26e2cc19a | https://github.com/chef/ohai/blob/8d66449940f04237586b2f928231c6b26e2cc19a/lib/ohai/loader.rb#L43-L55 |
11,522 | chef/ohai | lib/ohai/loader.rb | Ohai.Loader.load_additional | def load_additional(from)
from = [ Ohai.config[:plugin_path], from].flatten
plugin_files_by_dir(from).collect do |plugin_file|
logger.trace "Loading additional plugin: #{plugin_file}"
plugin = load_plugin_class(plugin_file)
load_v7_plugin(plugin)
end
end | ruby | def load_additional(from)
from = [ Ohai.config[:plugin_path], from].flatten
plugin_files_by_dir(from).collect do |plugin_file|
logger.trace "Loading additional plugin: #{plugin_file}"
plugin = load_plugin_class(plugin_file)
load_v7_plugin(plugin)
end
end | [
"def",
"load_additional",
"(",
"from",
")",
"from",
"=",
"[",
"Ohai",
".",
"config",
"[",
":plugin_path",
"]",
",",
"from",
"]",
".",
"flatten",
"plugin_files_by_dir",
"(",
"from",
")",
".",
"collect",
"do",
"|",
"plugin_file",
"|",
"logger",
".",
"trace... | load additional plugins classes from a given directory
@param from [String] path to a directory with additional plugins to load | [
"load",
"additional",
"plugins",
"classes",
"from",
"a",
"given",
"directory"
] | 8d66449940f04237586b2f928231c6b26e2cc19a | https://github.com/chef/ohai/blob/8d66449940f04237586b2f928231c6b26e2cc19a/lib/ohai/loader.rb#L70-L77 |
11,523 | chef/ohai | lib/ohai/loader.rb | Ohai.Loader.load_plugin | def load_plugin(plugin_path)
plugin_class = load_plugin_class(plugin_path)
return nil unless plugin_class.kind_of?(Class)
if plugin_class < Ohai::DSL::Plugin::VersionVII
load_v7_plugin(plugin_class)
else
raise Exceptions::IllegalPluginDefinition, "cannot create plugin of type #{p... | ruby | def load_plugin(plugin_path)
plugin_class = load_plugin_class(plugin_path)
return nil unless plugin_class.kind_of?(Class)
if plugin_class < Ohai::DSL::Plugin::VersionVII
load_v7_plugin(plugin_class)
else
raise Exceptions::IllegalPluginDefinition, "cannot create plugin of type #{p... | [
"def",
"load_plugin",
"(",
"plugin_path",
")",
"plugin_class",
"=",
"load_plugin_class",
"(",
"plugin_path",
")",
"return",
"nil",
"unless",
"plugin_class",
".",
"kind_of?",
"(",
"Class",
")",
"if",
"plugin_class",
"<",
"Ohai",
"::",
"DSL",
"::",
"Plugin",
"::... | Load a specified file as an ohai plugin and creates an instance of it.
Not used by ohai itself, but is used in the specs to load plugins for testing
@private
@param plugin_path [String] | [
"Load",
"a",
"specified",
"file",
"as",
"an",
"ohai",
"plugin",
"and",
"creates",
"an",
"instance",
"of",
"it",
".",
"Not",
"used",
"by",
"ohai",
"itself",
"but",
"is",
"used",
"in",
"the",
"specs",
"to",
"load",
"plugins",
"for",
"testing"
] | 8d66449940f04237586b2f928231c6b26e2cc19a | https://github.com/chef/ohai/blob/8d66449940f04237586b2f928231c6b26e2cc19a/lib/ohai/loader.rb#L84-L92 |
11,524 | chef/ohai | lib/ohai/runner.rb | Ohai.Runner.get_cycle | def get_cycle(plugins, cycle_start)
cycle = plugins.drop_while { |plugin| !plugin.eql?(cycle_start) }
names = []
cycle.each { |plugin| names << plugin.name }
names
end | ruby | def get_cycle(plugins, cycle_start)
cycle = plugins.drop_while { |plugin| !plugin.eql?(cycle_start) }
names = []
cycle.each { |plugin| names << plugin.name }
names
end | [
"def",
"get_cycle",
"(",
"plugins",
",",
"cycle_start",
")",
"cycle",
"=",
"plugins",
".",
"drop_while",
"{",
"|",
"plugin",
"|",
"!",
"plugin",
".",
"eql?",
"(",
"cycle_start",
")",
"}",
"names",
"=",
"[",
"]",
"cycle",
".",
"each",
"{",
"|",
"plugi... | Given a list of plugins and the first plugin in the cycle,
returns the list of plugin source files responsible for the
cycle. Does not include plugins that aren't a part of the cycle | [
"Given",
"a",
"list",
"of",
"plugins",
"and",
"the",
"first",
"plugin",
"in",
"the",
"cycle",
"returns",
"the",
"list",
"of",
"plugin",
"source",
"files",
"responsible",
"for",
"the",
"cycle",
".",
"Does",
"not",
"include",
"plugins",
"that",
"aren",
"t",
... | 8d66449940f04237586b2f928231c6b26e2cc19a | https://github.com/chef/ohai/blob/8d66449940f04237586b2f928231c6b26e2cc19a/lib/ohai/runner.rb#L104-L109 |
11,525 | ruby2d/ruby2d | lib/ruby2d/triangle.rb | Ruby2D.Triangle.contains? | def contains?(x, y)
self_area = triangle_area(@x1, @y1, @x2, @y2, @x3, @y3)
questioned_area =
triangle_area(@x1, @y1, @x2, @y2, x, y) +
triangle_area(@x2, @y2, @x3, @y3, x, y) +
triangle_area(@x3, @y3, @x1, @y1, x, y)
questioned_area <= self_area
end | ruby | def contains?(x, y)
self_area = triangle_area(@x1, @y1, @x2, @y2, @x3, @y3)
questioned_area =
triangle_area(@x1, @y1, @x2, @y2, x, y) +
triangle_area(@x2, @y2, @x3, @y3, x, y) +
triangle_area(@x3, @y3, @x1, @y1, x, y)
questioned_area <= self_area
end | [
"def",
"contains?",
"(",
"x",
",",
"y",
")",
"self_area",
"=",
"triangle_area",
"(",
"@x1",
",",
"@y1",
",",
"@x2",
",",
"@y2",
",",
"@x3",
",",
"@y3",
")",
"questioned_area",
"=",
"triangle_area",
"(",
"@x1",
",",
"@y1",
",",
"@x2",
",",
"@y2",
",... | A point is inside a triangle if the area of 3 triangles, constructed from
triangle sides and the given point, is equal to the area of triangle. | [
"A",
"point",
"is",
"inside",
"a",
"triangle",
"if",
"the",
"area",
"of",
"3",
"triangles",
"constructed",
"from",
"triangle",
"sides",
"and",
"the",
"given",
"point",
"is",
"equal",
"to",
"the",
"area",
"of",
"triangle",
"."
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/triangle.rb#L31-L39 |
11,526 | ruby2d/ruby2d | lib/ruby2d/sprite.rb | Ruby2D.Sprite.play | def play(opts = {}, &done_proc)
animation = opts[:animation]
loop = opts[:loop]
flip = opts[:flip]
if !@playing || (animation != @playing_animation && animation != nil) || flip != @flip
@playing = true
@playing_animation = animation || :default
frames = @animations[@pl... | ruby | def play(opts = {}, &done_proc)
animation = opts[:animation]
loop = opts[:loop]
flip = opts[:flip]
if !@playing || (animation != @playing_animation && animation != nil) || flip != @flip
@playing = true
@playing_animation = animation || :default
frames = @animations[@pl... | [
"def",
"play",
"(",
"opts",
"=",
"{",
"}",
",",
"&",
"done_proc",
")",
"animation",
"=",
"opts",
"[",
":animation",
"]",
"loop",
"=",
"opts",
"[",
":loop",
"]",
"flip",
"=",
"opts",
"[",
":flip",
"]",
"if",
"!",
"@playing",
"||",
"(",
"animation",
... | Play an animation | [
"Play",
"an",
"animation"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/sprite.rb#L111-L144 |
11,527 | ruby2d/ruby2d | lib/ruby2d/sprite.rb | Ruby2D.Sprite.set_frame | def set_frame
frames = @animations[@playing_animation]
case frames
when Range
reset_clipping_rect
@clip_x = @current_frame * @clip_width
when Array
f = frames[@current_frame]
@clip_x = f[:x] || @defaults[:clip_x]
@clip_y = f[:y] || @def... | ruby | def set_frame
frames = @animations[@playing_animation]
case frames
when Range
reset_clipping_rect
@clip_x = @current_frame * @clip_width
when Array
f = frames[@current_frame]
@clip_x = f[:x] || @defaults[:clip_x]
@clip_y = f[:y] || @def... | [
"def",
"set_frame",
"frames",
"=",
"@animations",
"[",
"@playing_animation",
"]",
"case",
"frames",
"when",
"Range",
"reset_clipping_rect",
"@clip_x",
"=",
"@current_frame",
"*",
"@clip_width",
"when",
"Array",
"f",
"=",
"frames",
"[",
"@current_frame",
"]",
"@cli... | Set the position of the clipping retangle based on the current frame | [
"Set",
"the",
"position",
"of",
"the",
"clipping",
"retangle",
"based",
"on",
"the",
"current",
"frame"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/sprite.rb#L198-L212 |
11,528 | ruby2d/ruby2d | lib/ruby2d/line.rb | Ruby2D.Line.points_distance | def points_distance(x1, y1, x2, y2)
Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
end | ruby | def points_distance(x1, y1, x2, y2)
Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
end | [
"def",
"points_distance",
"(",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
")",
"Math",
".",
"sqrt",
"(",
"(",
"x1",
"-",
"x2",
")",
"**",
"2",
"+",
"(",
"y1",
"-",
"y2",
")",
"**",
"2",
")",
"end"
] | Calculate the distance between two points | [
"Calculate",
"the",
"distance",
"between",
"two",
"points"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/line.rb#L44-L46 |
11,529 | ruby2d/ruby2d | lib/ruby2d/window.rb | Ruby2D.Window.set | def set(opts)
# Store new window attributes, or ignore if nil
@title = opts[:title] || @title
if Color.is_valid? opts[:background]
@background = Color.new(opts[:background])
end
@icon = opts[:icon] || @icon
@width = opts[... | ruby | def set(opts)
# Store new window attributes, or ignore if nil
@title = opts[:title] || @title
if Color.is_valid? opts[:background]
@background = Color.new(opts[:background])
end
@icon = opts[:icon] || @icon
@width = opts[... | [
"def",
"set",
"(",
"opts",
")",
"# Store new window attributes, or ignore if nil",
"@title",
"=",
"opts",
"[",
":title",
"]",
"||",
"@title",
"if",
"Color",
".",
"is_valid?",
"opts",
"[",
":background",
"]",
"@background",
"=",
"Color",
".",
"new",
"(",
"opts"... | Set a window attribute | [
"Set",
"a",
"window",
"attribute"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/window.rb#L195-L215 |
11,530 | ruby2d/ruby2d | lib/ruby2d/window.rb | Ruby2D.Window.add | def add(o)
case o
when nil
raise Error, "Cannot add '#{o.class}' to window!"
when Array
o.each { |x| add_object(x) }
else
add_object(o)
end
end | ruby | def add(o)
case o
when nil
raise Error, "Cannot add '#{o.class}' to window!"
when Array
o.each { |x| add_object(x) }
else
add_object(o)
end
end | [
"def",
"add",
"(",
"o",
")",
"case",
"o",
"when",
"nil",
"raise",
"Error",
",",
"\"Cannot add '#{o.class}' to window!\"",
"when",
"Array",
"o",
".",
"each",
"{",
"|",
"x",
"|",
"add_object",
"(",
"x",
")",
"}",
"else",
"add_object",
"(",
"o",
")",
"end... | Add an object to the window | [
"Add",
"an",
"object",
"to",
"the",
"window"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/window.rb#L218-L227 |
11,531 | ruby2d/ruby2d | lib/ruby2d/window.rb | Ruby2D.Window.remove | def remove(o)
if o == nil
raise Error, "Cannot remove '#{o.class}' from window!"
end
if i = @objects.index(o)
@objects.delete_at(i)
true
else
false
end
end | ruby | def remove(o)
if o == nil
raise Error, "Cannot remove '#{o.class}' from window!"
end
if i = @objects.index(o)
@objects.delete_at(i)
true
else
false
end
end | [
"def",
"remove",
"(",
"o",
")",
"if",
"o",
"==",
"nil",
"raise",
"Error",
",",
"\"Cannot remove '#{o.class}' from window!\"",
"end",
"if",
"i",
"=",
"@objects",
".",
"index",
"(",
"o",
")",
"@objects",
".",
"delete_at",
"(",
"i",
")",
"true",
"else",
"fa... | Remove an object from the window | [
"Remove",
"an",
"object",
"from",
"the",
"window"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/window.rb#L230-L241 |
11,532 | ruby2d/ruby2d | lib/ruby2d/window.rb | Ruby2D.Window.on | def on(event, &proc)
unless @events.has_key? event
raise Error, "`#{event}` is not a valid event type"
end
event_id = new_event_key
@events[event][event_id] = proc
EventDescriptor.new(event, event_id)
end | ruby | def on(event, &proc)
unless @events.has_key? event
raise Error, "`#{event}` is not a valid event type"
end
event_id = new_event_key
@events[event][event_id] = proc
EventDescriptor.new(event, event_id)
end | [
"def",
"on",
"(",
"event",
",",
"&",
"proc",
")",
"unless",
"@events",
".",
"has_key?",
"event",
"raise",
"Error",
",",
"\"`#{event}` is not a valid event type\"",
"end",
"event_id",
"=",
"new_event_key",
"@events",
"[",
"event",
"]",
"[",
"event_id",
"]",
"="... | Set an event handler | [
"Set",
"an",
"event",
"handler"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/window.rb#L260-L267 |
11,533 | ruby2d/ruby2d | lib/ruby2d/window.rb | Ruby2D.Window.key_callback | def key_callback(type, key)
key = key.downcase
# All key events
@events[:key].each do |id, e|
e.call(KeyEvent.new(type, key))
end
case type
# When key is pressed, fired once
when :down
@events[:key_down].each do |id, e|
e.call(KeyEvent.new(type, key)... | ruby | def key_callback(type, key)
key = key.downcase
# All key events
@events[:key].each do |id, e|
e.call(KeyEvent.new(type, key))
end
case type
# When key is pressed, fired once
when :down
@events[:key_down].each do |id, e|
e.call(KeyEvent.new(type, key)... | [
"def",
"key_callback",
"(",
"type",
",",
"key",
")",
"key",
"=",
"key",
".",
"downcase",
"# All key events",
"@events",
"[",
":key",
"]",
".",
"each",
"do",
"|",
"id",
",",
"e",
"|",
"e",
".",
"call",
"(",
"KeyEvent",
".",
"new",
"(",
"type",
",",
... | Key callback method, called by the native and web extentions | [
"Key",
"callback",
"method",
"called",
"by",
"the",
"native",
"and",
"web",
"extentions"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/window.rb#L275-L300 |
11,534 | ruby2d/ruby2d | lib/ruby2d/window.rb | Ruby2D.Window.mouse_callback | def mouse_callback(type, button, direction, x, y, delta_x, delta_y)
# All mouse events
@events[:mouse].each do |id, e|
e.call(MouseEvent.new(type, button, direction, x, y, delta_x, delta_y))
end
case type
# When mouse button pressed
when :down
@events[:mouse_down].ea... | ruby | def mouse_callback(type, button, direction, x, y, delta_x, delta_y)
# All mouse events
@events[:mouse].each do |id, e|
e.call(MouseEvent.new(type, button, direction, x, y, delta_x, delta_y))
end
case type
# When mouse button pressed
when :down
@events[:mouse_down].ea... | [
"def",
"mouse_callback",
"(",
"type",
",",
"button",
",",
"direction",
",",
"x",
",",
"y",
",",
"delta_x",
",",
"delta_y",
")",
"# All mouse events",
"@events",
"[",
":mouse",
"]",
".",
"each",
"do",
"|",
"id",
",",
"e",
"|",
"e",
".",
"call",
"(",
... | Mouse callback method, called by the native and web extentions | [
"Mouse",
"callback",
"method",
"called",
"by",
"the",
"native",
"and",
"web",
"extentions"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/window.rb#L303-L331 |
11,535 | ruby2d/ruby2d | lib/ruby2d/window.rb | Ruby2D.Window.controller_callback | def controller_callback(which, type, axis, value, button)
# All controller events
@events[:controller].each do |id, e|
e.call(ControllerEvent.new(which, type, axis, value, button))
end
case type
# When controller axis motion, like analog sticks
when :axis
@events[:co... | ruby | def controller_callback(which, type, axis, value, button)
# All controller events
@events[:controller].each do |id, e|
e.call(ControllerEvent.new(which, type, axis, value, button))
end
case type
# When controller axis motion, like analog sticks
when :axis
@events[:co... | [
"def",
"controller_callback",
"(",
"which",
",",
"type",
",",
"axis",
",",
"value",
",",
"button",
")",
"# All controller events",
"@events",
"[",
":controller",
"]",
".",
"each",
"do",
"|",
"id",
",",
"e",
"|",
"e",
".",
"call",
"(",
"ControllerEvent",
... | Controller callback method, called by the native and web extentions | [
"Controller",
"callback",
"method",
"called",
"by",
"the",
"native",
"and",
"web",
"extentions"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/window.rb#L341-L364 |
11,536 | ruby2d/ruby2d | lib/ruby2d/window.rb | Ruby2D.Window.update_callback | def update_callback
@update_proc.call
# Accept and eval commands if in console mode
if @console
if STDIN.ready?
cmd = STDIN.gets
begin
res = eval(cmd, TOPLEVEL_BINDING)
STDOUT.puts "=> #{res.inspect}"
STDOUT.flush
rescue Syntax... | ruby | def update_callback
@update_proc.call
# Accept and eval commands if in console mode
if @console
if STDIN.ready?
cmd = STDIN.gets
begin
res = eval(cmd, TOPLEVEL_BINDING)
STDOUT.puts "=> #{res.inspect}"
STDOUT.flush
rescue Syntax... | [
"def",
"update_callback",
"@update_proc",
".",
"call",
"# Accept and eval commands if in console mode",
"if",
"@console",
"if",
"STDIN",
".",
"ready?",
"cmd",
"=",
"STDIN",
".",
"gets",
"begin",
"res",
"=",
"eval",
"(",
"cmd",
",",
"TOPLEVEL_BINDING",
")",
"STDOUT... | Update callback method, called by the native and web extentions | [
"Update",
"callback",
"method",
"called",
"by",
"the",
"native",
"and",
"web",
"extentions"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/window.rb#L367-L388 |
11,537 | ruby2d/ruby2d | lib/ruby2d/window.rb | Ruby2D.Window.add_object | def add_object(o)
if !@objects.include?(o)
index = @objects.index do |object|
object.z > o.z
end
if index
@objects.insert(index, o)
else
@objects.push(o)
end
true
else
false
end
end | ruby | def add_object(o)
if !@objects.include?(o)
index = @objects.index do |object|
object.z > o.z
end
if index
@objects.insert(index, o)
else
@objects.push(o)
end
true
else
false
end
end | [
"def",
"add_object",
"(",
"o",
")",
"if",
"!",
"@objects",
".",
"include?",
"(",
"o",
")",
"index",
"=",
"@objects",
".",
"index",
"do",
"|",
"object",
"|",
"object",
".",
"z",
">",
"o",
".",
"z",
"end",
"if",
"index",
"@objects",
".",
"insert",
... | An an object to the window, used by the public `add` method | [
"An",
"an",
"object",
"to",
"the",
"window",
"used",
"by",
"the",
"public",
"add",
"method"
] | 43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4 | https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/window.rb#L419-L433 |
11,538 | scenic-views/scenic | lib/scenic/statements.rb | Scenic.Statements.create_view | def create_view(name, version: nil, sql_definition: nil, materialized: false)
if version.present? && sql_definition.present?
raise(
ArgumentError,
"sql_definition and version cannot both be set",
)
end
if version.blank? && sql_definition.blank?
version = 1
... | ruby | def create_view(name, version: nil, sql_definition: nil, materialized: false)
if version.present? && sql_definition.present?
raise(
ArgumentError,
"sql_definition and version cannot both be set",
)
end
if version.blank? && sql_definition.blank?
version = 1
... | [
"def",
"create_view",
"(",
"name",
",",
"version",
":",
"nil",
",",
"sql_definition",
":",
"nil",
",",
"materialized",
":",
"false",
")",
"if",
"version",
".",
"present?",
"&&",
"sql_definition",
".",
"present?",
"raise",
"(",
"ArgumentError",
",",
"\"sql_de... | Create a new database view.
@param name [String, Symbol] The name of the database view.
@param version [Fixnum] The version number of the view, used to find the
definition file in `db/views`. This defaults to `1` if not provided.
@param sql_definition [String] The SQL query for the view schema. An error
will ... | [
"Create",
"a",
"new",
"database",
"view",
"."
] | cc6adbde2bded9c895c41025d371c4c0f34c9253 | https://github.com/scenic-views/scenic/blob/cc6adbde2bded9c895c41025d371c4c0f34c9253/lib/scenic/statements.rb#L25-L48 |
11,539 | scenic-views/scenic | lib/scenic/statements.rb | Scenic.Statements.drop_view | def drop_view(name, revert_to_version: nil, materialized: false)
if materialized
Scenic.database.drop_materialized_view(name)
else
Scenic.database.drop_view(name)
end
end | ruby | def drop_view(name, revert_to_version: nil, materialized: false)
if materialized
Scenic.database.drop_materialized_view(name)
else
Scenic.database.drop_view(name)
end
end | [
"def",
"drop_view",
"(",
"name",
",",
"revert_to_version",
":",
"nil",
",",
"materialized",
":",
"false",
")",
"if",
"materialized",
"Scenic",
".",
"database",
".",
"drop_materialized_view",
"(",
"name",
")",
"else",
"Scenic",
".",
"database",
".",
"drop_view"... | Drop a database view by name.
@param name [String, Symbol] The name of the database view.
@param revert_to_version [Fixnum] Used to reverse the `drop_view` command
on `rake db:rollback`. The provided version will be passed as the
`version` argument to {#create_view}.
@param materialized [Boolean] Set to true ... | [
"Drop",
"a",
"database",
"view",
"by",
"name",
"."
] | cc6adbde2bded9c895c41025d371c4c0f34c9253 | https://github.com/scenic-views/scenic/blob/cc6adbde2bded9c895c41025d371c4c0f34c9253/lib/scenic/statements.rb#L63-L69 |
11,540 | scenic-views/scenic | lib/scenic/statements.rb | Scenic.Statements.update_view | def update_view(name, version: nil, sql_definition: nil, revert_to_version: nil, materialized: false)
if version.blank? && sql_definition.blank?
raise(
ArgumentError,
"sql_definition or version must be specified",
)
end
if version.present? && sql_definition.present... | ruby | def update_view(name, version: nil, sql_definition: nil, revert_to_version: nil, materialized: false)
if version.blank? && sql_definition.blank?
raise(
ArgumentError,
"sql_definition or version must be specified",
)
end
if version.present? && sql_definition.present... | [
"def",
"update_view",
"(",
"name",
",",
"version",
":",
"nil",
",",
"sql_definition",
":",
"nil",
",",
"revert_to_version",
":",
"nil",
",",
"materialized",
":",
"false",
")",
"if",
"version",
".",
"blank?",
"&&",
"sql_definition",
".",
"blank?",
"raise",
... | Update a database view to a new version.
The existing view is dropped and recreated using the supplied `version`
parameter.
@param name [String, Symbol] The name of the database view.
@param version [Fixnum] The version number of the view.
@param sql_definition [String] The SQL query for the view schema. An erro... | [
"Update",
"a",
"database",
"view",
"to",
"a",
"new",
"version",
"."
] | cc6adbde2bded9c895c41025d371c4c0f34c9253 | https://github.com/scenic-views/scenic/blob/cc6adbde2bded9c895c41025d371c4c0f34c9253/lib/scenic/statements.rb#L91-L117 |
11,541 | scenic-views/scenic | lib/scenic/statements.rb | Scenic.Statements.replace_view | def replace_view(name, version: nil, revert_to_version: nil, materialized: false)
if version.blank?
raise ArgumentError, "version is required"
end
if materialized
raise ArgumentError, "Cannot replace materialized views"
end
sql_definition = definition(name, version)
... | ruby | def replace_view(name, version: nil, revert_to_version: nil, materialized: false)
if version.blank?
raise ArgumentError, "version is required"
end
if materialized
raise ArgumentError, "Cannot replace materialized views"
end
sql_definition = definition(name, version)
... | [
"def",
"replace_view",
"(",
"name",
",",
"version",
":",
"nil",
",",
"revert_to_version",
":",
"nil",
",",
"materialized",
":",
"false",
")",
"if",
"version",
".",
"blank?",
"raise",
"ArgumentError",
",",
"\"version is required\"",
"end",
"if",
"materialized",
... | Update a database view to a new version using `CREATE OR REPLACE VIEW`.
The existing view is replaced using the supplied `version`
parameter.
Does not work with materialized views due to lack of database support.
@param name [String, Symbol] The name of the database view.
@param version [Fixnum] The version num... | [
"Update",
"a",
"database",
"view",
"to",
"a",
"new",
"version",
"using",
"CREATE",
"OR",
"REPLACE",
"VIEW",
"."
] | cc6adbde2bded9c895c41025d371c4c0f34c9253 | https://github.com/scenic-views/scenic/blob/cc6adbde2bded9c895c41025d371c4c0f34c9253/lib/scenic/statements.rb#L135-L147 |
11,542 | RailsEventStore/rails_event_store | ruby_event_store/lib/ruby_event_store/event.rb | RubyEventStore.Event.to_h | def to_h
{
event_id: event_id,
metadata: metadata.to_h,
data: data,
type: type,
}
end | ruby | def to_h
{
event_id: event_id,
metadata: metadata.to_h,
data: data,
type: type,
}
end | [
"def",
"to_h",
"{",
"event_id",
":",
"event_id",
",",
"metadata",
":",
"metadata",
".",
"to_h",
",",
"data",
":",
"data",
",",
"type",
":",
"type",
",",
"}",
"end"
] | Returns a hash representation of the event.
Metadata is converted to hash as well
@return [Hash] with :event_id, :metadata, :data, :type keys | [
"Returns",
"a",
"hash",
"representation",
"of",
"the",
"event",
"."
] | 3ee4f3148499794154ee6fec74ccf6d4670d85ac | https://github.com/RailsEventStore/rails_event_store/blob/3ee4f3148499794154ee6fec74ccf6d4670d85ac/ruby_event_store/lib/ruby_event_store/event.rb#L40-L47 |
11,543 | RailsEventStore/rails_event_store | ruby_event_store/lib/ruby_event_store/client.rb | RubyEventStore.Client.publish | def publish(events, stream_name: GLOBAL_STREAM, expected_version: :any)
enriched_events = enrich_events_metadata(events)
serialized_events = serialize_events(enriched_events)
append_to_stream_serialized_events(serialized_events, stream_name: stream_name, expected_version: expected_version)
enric... | ruby | def publish(events, stream_name: GLOBAL_STREAM, expected_version: :any)
enriched_events = enrich_events_metadata(events)
serialized_events = serialize_events(enriched_events)
append_to_stream_serialized_events(serialized_events, stream_name: stream_name, expected_version: expected_version)
enric... | [
"def",
"publish",
"(",
"events",
",",
"stream_name",
":",
"GLOBAL_STREAM",
",",
"expected_version",
":",
":any",
")",
"enriched_events",
"=",
"enrich_events_metadata",
"(",
"events",
")",
"serialized_events",
"=",
"serialize_events",
"(",
"enriched_events",
")",
"ap... | Persists events and notifies subscribed handlers about them
@param events [Array<Event, Proto>, Event, Proto] event(s)
@param stream_name [String] name of the stream for persisting events.
@param expected_version [:any, :auto, :none, Integer] controls optimistic locking strategy. {http://railseventstore.org/docs/ex... | [
"Persists",
"events",
"and",
"notifies",
"subscribed",
"handlers",
"about",
"them"
] | 3ee4f3148499794154ee6fec74ccf6d4670d85ac | https://github.com/RailsEventStore/rails_event_store/blob/3ee4f3148499794154ee6fec74ccf6d4670d85ac/ruby_event_store/lib/ruby_event_store/client.rb#L25-L38 |
11,544 | twitter/secure_headers | lib/secure_headers/middleware.rb | SecureHeaders.Middleware.call | def call(env)
req = Rack::Request.new(env)
status, headers, response = @app.call(env)
config = SecureHeaders.config_for(req)
flag_cookies!(headers, override_secure(env, config.cookies)) unless config.cookies == OPT_OUT
headers.merge!(SecureHeaders.header_hash_for(req))
[status, head... | ruby | def call(env)
req = Rack::Request.new(env)
status, headers, response = @app.call(env)
config = SecureHeaders.config_for(req)
flag_cookies!(headers, override_secure(env, config.cookies)) unless config.cookies == OPT_OUT
headers.merge!(SecureHeaders.header_hash_for(req))
[status, head... | [
"def",
"call",
"(",
"env",
")",
"req",
"=",
"Rack",
"::",
"Request",
".",
"new",
"(",
"env",
")",
"status",
",",
"headers",
",",
"response",
"=",
"@app",
".",
"call",
"(",
"env",
")",
"config",
"=",
"SecureHeaders",
".",
"config_for",
"(",
"req",
"... | merges the hash of headers into the current header set. | [
"merges",
"the",
"hash",
"of",
"headers",
"into",
"the",
"current",
"header",
"set",
"."
] | 543e6712aadae08f1653ed973e6b6204f7eac26a | https://github.com/twitter/secure_headers/blob/543e6712aadae08f1653ed973e6b6204f7eac26a/lib/secure_headers/middleware.rb#L9-L17 |
11,545 | twitter/secure_headers | lib/secure_headers/middleware.rb | SecureHeaders.Middleware.override_secure | def override_secure(env, config = {})
if scheme(env) != "https" && config != OPT_OUT
config[:secure] = OPT_OUT
end
config
end | ruby | def override_secure(env, config = {})
if scheme(env) != "https" && config != OPT_OUT
config[:secure] = OPT_OUT
end
config
end | [
"def",
"override_secure",
"(",
"env",
",",
"config",
"=",
"{",
"}",
")",
"if",
"scheme",
"(",
"env",
")",
"!=",
"\"https\"",
"&&",
"config",
"!=",
"OPT_OUT",
"config",
"[",
":secure",
"]",
"=",
"OPT_OUT",
"end",
"config",
"end"
] | disable Secure cookies for non-https requests | [
"disable",
"Secure",
"cookies",
"for",
"non",
"-",
"https",
"requests"
] | 543e6712aadae08f1653ed973e6b6204f7eac26a | https://github.com/twitter/secure_headers/blob/543e6712aadae08f1653ed973e6b6204f7eac26a/lib/secure_headers/middleware.rb#L34-L40 |
11,546 | twitter/secure_headers | lib/secure_headers/utils/cookies_config.rb | SecureHeaders.CookiesConfig.validate_samesite_boolean_config! | def validate_samesite_boolean_config!
if config[:samesite].key?(:lax) && config[:samesite][:lax].is_a?(TrueClass) && config[:samesite].key?(:strict)
raise CookiesConfigError.new("samesite cookie config is invalid, combination use of booleans and Hash to configure lax and strict enforcement is not permitte... | ruby | def validate_samesite_boolean_config!
if config[:samesite].key?(:lax) && config[:samesite][:lax].is_a?(TrueClass) && config[:samesite].key?(:strict)
raise CookiesConfigError.new("samesite cookie config is invalid, combination use of booleans and Hash to configure lax and strict enforcement is not permitte... | [
"def",
"validate_samesite_boolean_config!",
"if",
"config",
"[",
":samesite",
"]",
".",
"key?",
"(",
":lax",
")",
"&&",
"config",
"[",
":samesite",
"]",
"[",
":lax",
"]",
".",
"is_a?",
"(",
"TrueClass",
")",
"&&",
"config",
"[",
":samesite",
"]",
".",
"k... | when configuring with booleans, only one enforcement is permitted | [
"when",
"configuring",
"with",
"booleans",
"only",
"one",
"enforcement",
"is",
"permitted"
] | 543e6712aadae08f1653ed973e6b6204f7eac26a | https://github.com/twitter/secure_headers/blob/543e6712aadae08f1653ed973e6b6204f7eac26a/lib/secure_headers/utils/cookies_config.rb#L45-L51 |
11,547 | twitter/secure_headers | lib/secure_headers/utils/cookies_config.rb | SecureHeaders.CookiesConfig.validate_exclusive_use_of_hash_constraints! | def validate_exclusive_use_of_hash_constraints!(conf, attribute)
return unless is_hash?(conf)
if conf.key?(:only) && conf.key?(:except)
raise CookiesConfigError.new("#{attribute} cookie config is invalid, simultaneous use of conditional arguments `only` and `except` is not permitted.")
end
... | ruby | def validate_exclusive_use_of_hash_constraints!(conf, attribute)
return unless is_hash?(conf)
if conf.key?(:only) && conf.key?(:except)
raise CookiesConfigError.new("#{attribute} cookie config is invalid, simultaneous use of conditional arguments `only` and `except` is not permitted.")
end
... | [
"def",
"validate_exclusive_use_of_hash_constraints!",
"(",
"conf",
",",
"attribute",
")",
"return",
"unless",
"is_hash?",
"(",
"conf",
")",
"if",
"conf",
".",
"key?",
"(",
":only",
")",
"&&",
"conf",
".",
"key?",
"(",
":except",
")",
"raise",
"CookiesConfigErr... | validate exclusive use of only or except but not both at the same time | [
"validate",
"exclusive",
"use",
"of",
"only",
"or",
"except",
"but",
"not",
"both",
"at",
"the",
"same",
"time"
] | 543e6712aadae08f1653ed973e6b6204f7eac26a | https://github.com/twitter/secure_headers/blob/543e6712aadae08f1653ed973e6b6204f7eac26a/lib/secure_headers/utils/cookies_config.rb#L73-L78 |
11,548 | twitter/secure_headers | lib/secure_headers/utils/cookies_config.rb | SecureHeaders.CookiesConfig.validate_exclusive_use_of_samesite_enforcement! | def validate_exclusive_use_of_samesite_enforcement!(attribute)
if (intersection = (config[:samesite][:lax].fetch(attribute, []) & config[:samesite][:strict].fetch(attribute, []))).any?
raise CookiesConfigError.new("samesite cookie config is invalid, cookie(s) #{intersection.join(', ')} cannot be enforced ... | ruby | def validate_exclusive_use_of_samesite_enforcement!(attribute)
if (intersection = (config[:samesite][:lax].fetch(attribute, []) & config[:samesite][:strict].fetch(attribute, []))).any?
raise CookiesConfigError.new("samesite cookie config is invalid, cookie(s) #{intersection.join(', ')} cannot be enforced ... | [
"def",
"validate_exclusive_use_of_samesite_enforcement!",
"(",
"attribute",
")",
"if",
"(",
"intersection",
"=",
"(",
"config",
"[",
":samesite",
"]",
"[",
":lax",
"]",
".",
"fetch",
"(",
"attribute",
",",
"[",
"]",
")",
"&",
"config",
"[",
":samesite",
"]",... | validate exclusivity of only and except members within strict and lax | [
"validate",
"exclusivity",
"of",
"only",
"and",
"except",
"members",
"within",
"strict",
"and",
"lax"
] | 543e6712aadae08f1653ed973e6b6204f7eac26a | https://github.com/twitter/secure_headers/blob/543e6712aadae08f1653ed973e6b6204f7eac26a/lib/secure_headers/utils/cookies_config.rb#L81-L85 |
11,549 | twitter/secure_headers | lib/secure_headers/headers/content_security_policy.rb | SecureHeaders.ContentSecurityPolicy.reject_all_values_if_none | def reject_all_values_if_none(source_list)
if source_list.length > 1
source_list.reject { |value| value == NONE }
else
source_list
end
end | ruby | def reject_all_values_if_none(source_list)
if source_list.length > 1
source_list.reject { |value| value == NONE }
else
source_list
end
end | [
"def",
"reject_all_values_if_none",
"(",
"source_list",
")",
"if",
"source_list",
".",
"length",
">",
"1",
"source_list",
".",
"reject",
"{",
"|",
"value",
"|",
"value",
"==",
"NONE",
"}",
"else",
"source_list",
"end",
"end"
] | Discard any 'none' values if more directives are supplied since none may override values. | [
"Discard",
"any",
"none",
"values",
"if",
"more",
"directives",
"are",
"supplied",
"since",
"none",
"may",
"override",
"values",
"."
] | 543e6712aadae08f1653ed973e6b6204f7eac26a | https://github.com/twitter/secure_headers/blob/543e6712aadae08f1653ed973e6b6204f7eac26a/lib/secure_headers/headers/content_security_policy.rb#L137-L143 |
11,550 | twitter/secure_headers | lib/secure_headers/headers/content_security_policy.rb | SecureHeaders.ContentSecurityPolicy.dedup_source_list | def dedup_source_list(sources)
sources = sources.uniq
wild_sources = sources.select { |source| source =~ STAR_REGEXP }
if wild_sources.any?
sources.reject do |source|
!wild_sources.include?(source) &&
wild_sources.any? { |pattern| File.fnmatch(pattern, source) }
... | ruby | def dedup_source_list(sources)
sources = sources.uniq
wild_sources = sources.select { |source| source =~ STAR_REGEXP }
if wild_sources.any?
sources.reject do |source|
!wild_sources.include?(source) &&
wild_sources.any? { |pattern| File.fnmatch(pattern, source) }
... | [
"def",
"dedup_source_list",
"(",
"sources",
")",
"sources",
"=",
"sources",
".",
"uniq",
"wild_sources",
"=",
"sources",
".",
"select",
"{",
"|",
"source",
"|",
"source",
"=~",
"STAR_REGEXP",
"}",
"if",
"wild_sources",
".",
"any?",
"sources",
".",
"reject",
... | Removes duplicates and sources that already match an existing wild card.
e.g. *.github.com asdf.github.com becomes *.github.com | [
"Removes",
"duplicates",
"and",
"sources",
"that",
"already",
"match",
"an",
"existing",
"wild",
"card",
"."
] | 543e6712aadae08f1653ed973e6b6204f7eac26a | https://github.com/twitter/secure_headers/blob/543e6712aadae08f1653ed973e6b6204f7eac26a/lib/secure_headers/headers/content_security_policy.rb#L148-L160 |
11,551 | ambethia/recaptcha | lib/recaptcha/client_helper.rb | Recaptcha.ClientHelper.invisible_recaptcha_tags | def invisible_recaptcha_tags(options = {})
options = {callback: 'invisibleRecaptchaSubmit', ui: :button}.merge options
text = options.delete(:text)
html, tag_attributes = Recaptcha::ClientHelper.recaptcha_components(options)
html << recaptcha_default_callback(options) if recaptcha_default_callba... | ruby | def invisible_recaptcha_tags(options = {})
options = {callback: 'invisibleRecaptchaSubmit', ui: :button}.merge options
text = options.delete(:text)
html, tag_attributes = Recaptcha::ClientHelper.recaptcha_components(options)
html << recaptcha_default_callback(options) if recaptcha_default_callba... | [
"def",
"invisible_recaptcha_tags",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"callback",
":",
"'invisibleRecaptchaSubmit'",
",",
"ui",
":",
":button",
"}",
".",
"merge",
"options",
"text",
"=",
"options",
".",
"delete",
"(",
":text",
")",
"h... | Invisible reCAPTCHA implementation | [
"Invisible",
"reCAPTCHA",
"implementation"
] | fcac97960ce29ebd7473315d9ffe89dccce6615e | https://github.com/ambethia/recaptcha/blob/fcac97960ce29ebd7473315d9ffe89dccce6615e/lib/recaptcha/client_helper.rb#L51-L67 |
11,552 | ambethia/recaptcha | lib/recaptcha/verify.rb | Recaptcha.Verify.verify_recaptcha | def verify_recaptcha(options = {})
options = {model: options} unless options.is_a? Hash
return true if Recaptcha::Verify.skip?(options[:env])
model = options[:model]
attribute = options[:attribute] || :base
recaptcha_response = options[:response] || params['g-recaptcha-response'].to_s
... | ruby | def verify_recaptcha(options = {})
options = {model: options} unless options.is_a? Hash
return true if Recaptcha::Verify.skip?(options[:env])
model = options[:model]
attribute = options[:attribute] || :base
recaptcha_response = options[:response] || params['g-recaptcha-response'].to_s
... | [
"def",
"verify_recaptcha",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"model",
":",
"options",
"}",
"unless",
"options",
".",
"is_a?",
"Hash",
"return",
"true",
"if",
"Recaptcha",
"::",
"Verify",
".",
"skip?",
"(",
"options",
"[",
":env",
... | Your private API can be specified in the +options+ hash or preferably
using the Configuration. | [
"Your",
"private",
"API",
"can",
"be",
"specified",
"in",
"the",
"+",
"options",
"+",
"hash",
"or",
"preferably",
"using",
"the",
"Configuration",
"."
] | fcac97960ce29ebd7473315d9ffe89dccce6615e | https://github.com/ambethia/recaptcha/blob/fcac97960ce29ebd7473315d9ffe89dccce6615e/lib/recaptcha/verify.rb#L10-L54 |
11,553 | sds/haml-lint | lib/haml_lint/configuration.rb | HamlLint.Configuration.for_linter | def for_linter(linter)
linter_name =
case linter
when Class
linter.name.split('::').last
when HamlLint::Linter
linter.name
end
@hash['linters'].fetch(linter_name, {}).dup.freeze
end | ruby | def for_linter(linter)
linter_name =
case linter
when Class
linter.name.split('::').last
when HamlLint::Linter
linter.name
end
@hash['linters'].fetch(linter_name, {}).dup.freeze
end | [
"def",
"for_linter",
"(",
"linter",
")",
"linter_name",
"=",
"case",
"linter",
"when",
"Class",
"linter",
".",
"name",
".",
"split",
"(",
"'::'",
")",
".",
"last",
"when",
"HamlLint",
"::",
"Linter",
"linter",
".",
"name",
"end",
"@hash",
"[",
"'linters'... | Compares this configuration with another.
@param other [HamlLint::Configuration]
@return [true,false] whether the given configuration is equivalent
Returns a non-modifiable configuration for the specified linter.
@param linter [HamlLint::Linter,Class] | [
"Compares",
"this",
"configuration",
"with",
"another",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/configuration.rb#L43-L53 |
11,554 | sds/haml-lint | lib/haml_lint/configuration.rb | HamlLint.Configuration.smart_merge | def smart_merge(parent, child)
parent.merge(child) do |_key, old, new|
case old
when Hash
smart_merge(old, new)
else
new
end
end
end | ruby | def smart_merge(parent, child)
parent.merge(child) do |_key, old, new|
case old
when Hash
smart_merge(old, new)
else
new
end
end
end | [
"def",
"smart_merge",
"(",
"parent",
",",
"child",
")",
"parent",
".",
"merge",
"(",
"child",
")",
"do",
"|",
"_key",
",",
"old",
",",
"new",
"|",
"case",
"old",
"when",
"Hash",
"smart_merge",
"(",
"old",
",",
"new",
")",
"else",
"new",
"end",
"end... | Merge two hashes such that nested hashes are merged rather than replaced.
@param parent [Hash]
@param child [Hash]
@return [Hash] | [
"Merge",
"two",
"hashes",
"such",
"that",
"nested",
"hashes",
"are",
"merged",
"rather",
"than",
"replaced",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/configuration.rb#L71-L80 |
11,555 | sds/haml-lint | lib/haml_lint/reporter/disabled_config_reporter.rb | HamlLint.Reporter::DisabledConfigReporter.display_report | def display_report(report)
super
File.write(ConfigurationLoader::AUTO_GENERATED_FILE, config_file_contents)
log.log "Created #{ConfigurationLoader::AUTO_GENERATED_FILE}."
log.log "Run `haml-lint --config #{ConfigurationLoader::AUTO_GENERATED_FILE}`" \
", or add `inherits_from: #{Configu... | ruby | def display_report(report)
super
File.write(ConfigurationLoader::AUTO_GENERATED_FILE, config_file_contents)
log.log "Created #{ConfigurationLoader::AUTO_GENERATED_FILE}."
log.log "Run `haml-lint --config #{ConfigurationLoader::AUTO_GENERATED_FILE}`" \
", or add `inherits_from: #{Configu... | [
"def",
"display_report",
"(",
"report",
")",
"super",
"File",
".",
"write",
"(",
"ConfigurationLoader",
"::",
"AUTO_GENERATED_FILE",
",",
"config_file_contents",
")",
"log",
".",
"log",
"\"Created #{ConfigurationLoader::AUTO_GENERATED_FILE}.\"",
"log",
".",
"log",
"\"Ru... | Prints the standard progress reporter output and writes the new config file.
@param report [HamlLint::Report]
@return [void] | [
"Prints",
"the",
"standard",
"progress",
"reporter",
"output",
"and",
"writes",
"the",
"new",
"config",
"file",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/reporter/disabled_config_reporter.rb#L56-L64 |
11,556 | sds/haml-lint | lib/haml_lint/reporter/disabled_config_reporter.rb | HamlLint.Reporter::DisabledConfigReporter.finished_file | def finished_file(file, lints)
super
if lints.any?
lints.each do |lint|
linters_with_lints[lint.linter.name] |= [lint.filename]
linters_lint_count[lint.linter.name] += 1
end
end
end | ruby | def finished_file(file, lints)
super
if lints.any?
lints.each do |lint|
linters_with_lints[lint.linter.name] |= [lint.filename]
linters_lint_count[lint.linter.name] += 1
end
end
end | [
"def",
"finished_file",
"(",
"file",
",",
"lints",
")",
"super",
"if",
"lints",
".",
"any?",
"lints",
".",
"each",
"do",
"|",
"lint",
"|",
"linters_with_lints",
"[",
"lint",
".",
"linter",
".",
"name",
"]",
"|=",
"[",
"lint",
".",
"filename",
"]",
"l... | Prints the standard progress report marks and tracks files with lint.
@param file [String]
@param lints [Array<HamlLint::Lint>]
@return [void] | [
"Prints",
"the",
"standard",
"progress",
"report",
"marks",
"and",
"tracks",
"files",
"with",
"lint",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/reporter/disabled_config_reporter.rb#L71-L80 |
11,557 | sds/haml-lint | lib/haml_lint/reporter/disabled_config_reporter.rb | HamlLint.Reporter::DisabledConfigReporter.config_file_contents | def config_file_contents
output = []
output << HEADING
output << 'linters:' if linters_with_lints.any?
linters_with_lints.each do |linter, files|
output << generate_config_for_linter(linter, files)
end
output.join("\n\n")
end | ruby | def config_file_contents
output = []
output << HEADING
output << 'linters:' if linters_with_lints.any?
linters_with_lints.each do |linter, files|
output << generate_config_for_linter(linter, files)
end
output.join("\n\n")
end | [
"def",
"config_file_contents",
"output",
"=",
"[",
"]",
"output",
"<<",
"HEADING",
"output",
"<<",
"'linters:'",
"if",
"linters_with_lints",
".",
"any?",
"linters_with_lints",
".",
"each",
"do",
"|",
"linter",
",",
"files",
"|",
"output",
"<<",
"generate_config_... | The contents of the generated configuration file based on captured lint.
@return [String] a Yaml-formatted configuration file's contents | [
"The",
"contents",
"of",
"the",
"generated",
"configuration",
"file",
"based",
"on",
"captured",
"lint",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/reporter/disabled_config_reporter.rb#L87-L95 |
11,558 | sds/haml-lint | lib/haml_lint/reporter/disabled_config_reporter.rb | HamlLint.Reporter::DisabledConfigReporter.generate_config_for_linter | def generate_config_for_linter(linter, files)
[].tap do |output|
output << " # Offense count: #{linters_lint_count[linter]}"
output << " #{linter}:"
# disable the linter when there are many files with offenses.
# exclude the affected files otherwise.
if files.count > excl... | ruby | def generate_config_for_linter(linter, files)
[].tap do |output|
output << " # Offense count: #{linters_lint_count[linter]}"
output << " #{linter}:"
# disable the linter when there are many files with offenses.
# exclude the affected files otherwise.
if files.count > excl... | [
"def",
"generate_config_for_linter",
"(",
"linter",
",",
"files",
")",
"[",
"]",
".",
"tap",
"do",
"|",
"output",
"|",
"output",
"<<",
"\" # Offense count: #{linters_lint_count[linter]}\"",
"output",
"<<",
"\" #{linter}:\"",
"# disable the linter when there are many files... | Constructs the configuration for excluding a linter in some files.
@param linter [String] the name of the linter to exclude
@param files [Array<String>] the files in which the linter is excluded
@return [String] a Yaml-formatted configuration | [
"Constructs",
"the",
"configuration",
"for",
"excluding",
"a",
"linter",
"in",
"some",
"files",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/reporter/disabled_config_reporter.rb#L102-L117 |
11,559 | sds/haml-lint | lib/haml_lint/options.rb | HamlLint.Options.load_reporter_class | def load_reporter_class(reporter_name)
HamlLint::Reporter.const_get("#{reporter_name}Reporter")
rescue NameError
raise HamlLint::Exceptions::InvalidCLIOption,
"#{reporter_name}Reporter does not exist"
end | ruby | def load_reporter_class(reporter_name)
HamlLint::Reporter.const_get("#{reporter_name}Reporter")
rescue NameError
raise HamlLint::Exceptions::InvalidCLIOption,
"#{reporter_name}Reporter does not exist"
end | [
"def",
"load_reporter_class",
"(",
"reporter_name",
")",
"HamlLint",
"::",
"Reporter",
".",
"const_get",
"(",
"\"#{reporter_name}Reporter\"",
")",
"rescue",
"NameError",
"raise",
"HamlLint",
"::",
"Exceptions",
"::",
"InvalidCLIOption",
",",
"\"#{reporter_name}Reporter do... | Returns the class of the specified Reporter.
@param reporter_name [String]
@raise [HamlLint::Exceptions::InvalidCLIOption] if reporter doesn't exist
@return [Class] | [
"Returns",
"the",
"class",
"of",
"the",
"specified",
"Reporter",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/options.rb#L79-L84 |
11,560 | sds/haml-lint | lib/haml_lint/linter/instance_variables.rb | HamlLint.Linter::InstanceVariables.visit_root | def visit_root(node)
@enabled = matcher.match(File.basename(node.file)) ? true : false
end | ruby | def visit_root(node)
@enabled = matcher.match(File.basename(node.file)) ? true : false
end | [
"def",
"visit_root",
"(",
"node",
")",
"@enabled",
"=",
"matcher",
".",
"match",
"(",
"File",
".",
"basename",
"(",
"node",
".",
"file",
")",
")",
"?",
"true",
":",
"false",
"end"
] | Enables the linter if the tree is for the right file type.
@param [HamlLint::Tree::RootNode] the root of a syntax tree
@return [true, false] whether the linter is enabled for the tree | [
"Enables",
"the",
"linter",
"if",
"the",
"tree",
"is",
"for",
"the",
"right",
"file",
"type",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter/instance_variables.rb#L12-L14 |
11,561 | sds/haml-lint | lib/haml_lint/linter/instance_variables.rb | HamlLint.Linter::InstanceVariables.visit_tag | def visit_tag(node)
return unless enabled?
visit_script(node) ||
if node.parsed_attributes.contains_instance_variables?
record_lint(node, "Avoid using instance variables in #{file_types} views")
end
end | ruby | def visit_tag(node)
return unless enabled?
visit_script(node) ||
if node.parsed_attributes.contains_instance_variables?
record_lint(node, "Avoid using instance variables in #{file_types} views")
end
end | [
"def",
"visit_tag",
"(",
"node",
")",
"return",
"unless",
"enabled?",
"visit_script",
"(",
"node",
")",
"||",
"if",
"node",
".",
"parsed_attributes",
".",
"contains_instance_variables?",
"record_lint",
"(",
"node",
",",
"\"Avoid using instance variables in #{file_types}... | Checks for instance variables in tag nodes when the linter is enabled.
@param [HamlLint::Tree:TagNode]
@return [void] | [
"Checks",
"for",
"instance",
"variables",
"in",
"tag",
"nodes",
"when",
"the",
"linter",
"is",
"enabled",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter/instance_variables.rb#L39-L46 |
11,562 | sds/haml-lint | lib/haml_lint/runner.rb | HamlLint.Runner.run | def run(options = {})
@config = load_applicable_config(options)
@files = extract_applicable_files(config, options)
@linter_selector = HamlLint::LinterSelector.new(config, options)
@fail_fast = options.fetch(:fail_fast, false)
report(options)
end | ruby | def run(options = {})
@config = load_applicable_config(options)
@files = extract_applicable_files(config, options)
@linter_selector = HamlLint::LinterSelector.new(config, options)
@fail_fast = options.fetch(:fail_fast, false)
report(options)
end | [
"def",
"run",
"(",
"options",
"=",
"{",
"}",
")",
"@config",
"=",
"load_applicable_config",
"(",
"options",
")",
"@files",
"=",
"extract_applicable_files",
"(",
"config",
",",
"options",
")",
"@linter_selector",
"=",
"HamlLint",
"::",
"LinterSelector",
".",
"n... | Runs the appropriate linters against the desired files given the specified
options.
@param [Hash] options
@option options :config_file [String] path of configuration file to load
@option options :config [HamlLint::Configuration] configuration to use
@option options :excluded_files [Array<String>]
@option options... | [
"Runs",
"the",
"appropriate",
"linters",
"against",
"the",
"desired",
"files",
"given",
"the",
"specified",
"options",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/runner.rb#L19-L26 |
11,563 | sds/haml-lint | lib/haml_lint/runner.rb | HamlLint.Runner.collect_lints | def collect_lints(file, linter_selector, config)
begin
document = HamlLint::Document.new(File.read(file), file: file, config: config)
rescue HamlLint::Exceptions::ParseError => e
return [HamlLint::Lint.new(HamlLint::Linter::Syntax.new(config), file,
e.line,... | ruby | def collect_lints(file, linter_selector, config)
begin
document = HamlLint::Document.new(File.read(file), file: file, config: config)
rescue HamlLint::Exceptions::ParseError => e
return [HamlLint::Lint.new(HamlLint::Linter::Syntax.new(config), file,
e.line,... | [
"def",
"collect_lints",
"(",
"file",
",",
"linter_selector",
",",
"config",
")",
"begin",
"document",
"=",
"HamlLint",
"::",
"Document",
".",
"new",
"(",
"File",
".",
"read",
"(",
"file",
")",
",",
"file",
":",
"file",
",",
"config",
":",
"config",
")"... | Runs all provided linters using the specified config against the given
file.
@param file [String] path to file to lint
@param linter_selector [HamlLint::LinterSelector]
@param config [HamlLint::Configuration] | [
"Runs",
"all",
"provided",
"linters",
"using",
"the",
"specified",
"config",
"against",
"the",
"given",
"file",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/runner.rb#L80-L91 |
11,564 | sds/haml-lint | lib/haml_lint/runner.rb | HamlLint.Runner.extract_applicable_files | def extract_applicable_files(config, options)
included_patterns = options[:files]
excluded_patterns = config['exclude']
excluded_patterns += options.fetch(:excluded_files, [])
HamlLint::FileFinder.new(config).find(included_patterns, excluded_patterns)
end | ruby | def extract_applicable_files(config, options)
included_patterns = options[:files]
excluded_patterns = config['exclude']
excluded_patterns += options.fetch(:excluded_files, [])
HamlLint::FileFinder.new(config).find(included_patterns, excluded_patterns)
end | [
"def",
"extract_applicable_files",
"(",
"config",
",",
"options",
")",
"included_patterns",
"=",
"options",
"[",
":files",
"]",
"excluded_patterns",
"=",
"config",
"[",
"'exclude'",
"]",
"excluded_patterns",
"+=",
"options",
".",
"fetch",
"(",
":excluded_files",
"... | Returns the list of files that should be linted given the specified
configuration and options.
@param config [HamlLint::Configuration]
@param options [Hash]
@return [Array<String>] | [
"Returns",
"the",
"list",
"of",
"files",
"that",
"should",
"be",
"linted",
"given",
"the",
"specified",
"configuration",
"and",
"options",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/runner.rb#L99-L105 |
11,565 | sds/haml-lint | lib/haml_lint/runner.rb | HamlLint.Runner.process_files | def process_files(report)
files.each do |file|
process_file(file, report)
break if report.failed? && fail_fast?
end
end | ruby | def process_files(report)
files.each do |file|
process_file(file, report)
break if report.failed? && fail_fast?
end
end | [
"def",
"process_files",
"(",
"report",
")",
"files",
".",
"each",
"do",
"|",
"file",
"|",
"process_file",
"(",
"file",
",",
"report",
")",
"break",
"if",
"report",
".",
"failed?",
"&&",
"fail_fast?",
"end",
"end"
] | Process the files and add them to the given report.
@param report [HamlLint::Report]
@return [void] | [
"Process",
"the",
"files",
"and",
"add",
"them",
"to",
"the",
"given",
"report",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/runner.rb#L111-L116 |
11,566 | sds/haml-lint | lib/haml_lint/runner.rb | HamlLint.Runner.process_file | def process_file(file, report)
lints = collect_lints(file, linter_selector, config)
lints.each { |lint| report.add_lint(lint) }
report.finish_file(file, lints)
end | ruby | def process_file(file, report)
lints = collect_lints(file, linter_selector, config)
lints.each { |lint| report.add_lint(lint) }
report.finish_file(file, lints)
end | [
"def",
"process_file",
"(",
"file",
",",
"report",
")",
"lints",
"=",
"collect_lints",
"(",
"file",
",",
"linter_selector",
",",
"config",
")",
"lints",
".",
"each",
"{",
"|",
"lint",
"|",
"report",
".",
"add_lint",
"(",
"lint",
")",
"}",
"report",
"."... | Process a file and add it to the given report.
@param file [String] the name of the file to process
@param report [HamlLint::Report]
@return [void] | [
"Process",
"a",
"file",
"and",
"add",
"it",
"to",
"the",
"given",
"report",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/runner.rb#L123-L127 |
11,567 | sds/haml-lint | lib/haml_lint/runner.rb | HamlLint.Runner.report | def report(options)
report = HamlLint::Report.new(reporter: options[:reporter], fail_level: options[:fail_level])
report.start(@files)
process_files(report)
report
end | ruby | def report(options)
report = HamlLint::Report.new(reporter: options[:reporter], fail_level: options[:fail_level])
report.start(@files)
process_files(report)
report
end | [
"def",
"report",
"(",
"options",
")",
"report",
"=",
"HamlLint",
"::",
"Report",
".",
"new",
"(",
"reporter",
":",
"options",
"[",
":reporter",
"]",
",",
"fail_level",
":",
"options",
"[",
":fail_level",
"]",
")",
"report",
".",
"start",
"(",
"@files",
... | Generates a report based on the given options.
@param options [Hash]
@option options :reporter [HamlLint::Reporter] the reporter to report with
@return [HamlLint::Report] | [
"Generates",
"a",
"report",
"based",
"on",
"the",
"given",
"options",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/runner.rb#L134-L139 |
11,568 | sds/haml-lint | lib/haml_lint/file_finder.rb | HamlLint.FileFinder.find | def find(patterns, excluded_patterns)
excluded_patterns = excluded_patterns.map { |pattern| normalize_path(pattern) }
extract_files_from(patterns).reject do |file|
excluded_patterns.any? do |exclusion_glob|
HamlLint::Utils.any_glob_matches?(exclusion_glob, file)
end
end
... | ruby | def find(patterns, excluded_patterns)
excluded_patterns = excluded_patterns.map { |pattern| normalize_path(pattern) }
extract_files_from(patterns).reject do |file|
excluded_patterns.any? do |exclusion_glob|
HamlLint::Utils.any_glob_matches?(exclusion_glob, file)
end
end
... | [
"def",
"find",
"(",
"patterns",
",",
"excluded_patterns",
")",
"excluded_patterns",
"=",
"excluded_patterns",
".",
"map",
"{",
"|",
"pattern",
"|",
"normalize_path",
"(",
"pattern",
")",
"}",
"extract_files_from",
"(",
"patterns",
")",
".",
"reject",
"do",
"|"... | Create a file finder using the specified configuration.
@param config [HamlLint::Configuration]
Return list of files to lint given the specified set of paths and glob
patterns.
@param patterns [Array<String>]
@param excluded_patterns [Array<String>]
@raise [HamlLint::Exceptions::InvalidFilePath]
@return [Array<... | [
"Create",
"a",
"file",
"finder",
"using",
"the",
"specified",
"configuration",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/file_finder.rb#L26-L34 |
11,569 | sds/haml-lint | lib/haml_lint/file_finder.rb | HamlLint.FileFinder.extract_files_from | def extract_files_from(patterns) # rubocop:disable MethodLength
files = []
patterns.each do |pattern|
if File.file?(pattern)
files << pattern
else
begin
::Find.find(pattern) do |file|
files << file if haml_file?(file)
end
r... | ruby | def extract_files_from(patterns) # rubocop:disable MethodLength
files = []
patterns.each do |pattern|
if File.file?(pattern)
files << pattern
else
begin
::Find.find(pattern) do |file|
files << file if haml_file?(file)
end
r... | [
"def",
"extract_files_from",
"(",
"patterns",
")",
"# rubocop:disable MethodLength",
"files",
"=",
"[",
"]",
"patterns",
".",
"each",
"do",
"|",
"pattern",
"|",
"if",
"File",
".",
"file?",
"(",
"pattern",
")",
"files",
"<<",
"pattern",
"else",
"begin",
"::",... | Extract the list of matching files given the list of glob patterns, file
paths, and directories.
@param patterns [Array<String>]
@return [Array<String>] | [
"Extract",
"the",
"list",
"of",
"matching",
"files",
"given",
"the",
"list",
"of",
"glob",
"patterns",
"file",
"paths",
"and",
"directories",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/file_finder.rb#L43-L70 |
11,570 | sds/haml-lint | lib/haml_lint/file_finder.rb | HamlLint.FileFinder.haml_file? | def haml_file?(file)
return false unless ::FileTest.file?(file)
VALID_EXTENSIONS.include?(::File.extname(file))
end | ruby | def haml_file?(file)
return false unless ::FileTest.file?(file)
VALID_EXTENSIONS.include?(::File.extname(file))
end | [
"def",
"haml_file?",
"(",
"file",
")",
"return",
"false",
"unless",
"::",
"FileTest",
".",
"file?",
"(",
"file",
")",
"VALID_EXTENSIONS",
".",
"include?",
"(",
"::",
"File",
".",
"extname",
"(",
"file",
")",
")",
"end"
] | Whether the given file should be treated as a Haml file.
@param file [String]
@return [Boolean] | [
"Whether",
"the",
"given",
"file",
"should",
"be",
"treated",
"as",
"a",
"Haml",
"file",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/file_finder.rb#L84-L88 |
11,571 | sds/haml-lint | lib/haml_lint/linter/unnecessary_string_output.rb | HamlLint.Linter::UnnecessaryStringOutput.starts_with_reserved_character? | def starts_with_reserved_character?(stringish)
string = stringish.respond_to?(:children) ? stringish.children.first : stringish
string =~ %r{\A\s*[/#-=%~]}
end | ruby | def starts_with_reserved_character?(stringish)
string = stringish.respond_to?(:children) ? stringish.children.first : stringish
string =~ %r{\A\s*[/#-=%~]}
end | [
"def",
"starts_with_reserved_character?",
"(",
"stringish",
")",
"string",
"=",
"stringish",
".",
"respond_to?",
"(",
":children",
")",
"?",
"stringish",
".",
"children",
".",
"first",
":",
"stringish",
"string",
"=~",
"%r{",
"\\A",
"\\s",
"}",
"end"
] | Returns whether a string starts with a character that would otherwise be
given special treatment, thus making enclosing it in a string necessary. | [
"Returns",
"whether",
"a",
"string",
"starts",
"with",
"a",
"character",
"that",
"would",
"otherwise",
"be",
"given",
"special",
"treatment",
"thus",
"making",
"enclosing",
"it",
"in",
"a",
"string",
"necessary",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter/unnecessary_string_output.rb#L44-L47 |
11,572 | sds/haml-lint | lib/haml_lint/linter.rb | HamlLint.Linter.run | def run(document)
@document = document
@lints = []
visit(document.tree)
@lints
rescue Parser::SyntaxError => e
location = e.diagnostic.location
@lints <<
HamlLint::Lint.new(
HamlLint::Linter::Syntax.new(config),
document.file,
location.line,
... | ruby | def run(document)
@document = document
@lints = []
visit(document.tree)
@lints
rescue Parser::SyntaxError => e
location = e.diagnostic.location
@lints <<
HamlLint::Lint.new(
HamlLint::Linter::Syntax.new(config),
document.file,
location.line,
... | [
"def",
"run",
"(",
"document",
")",
"@document",
"=",
"document",
"@lints",
"=",
"[",
"]",
"visit",
"(",
"document",
".",
"tree",
")",
"@lints",
"rescue",
"Parser",
"::",
"SyntaxError",
"=>",
"e",
"location",
"=",
"e",
".",
"diagnostic",
".",
"location",... | Initializes a linter with the specified configuration.
@param config [Hash] configuration for this linter
Runs the linter against the given Haml document.
@param document [HamlLint::Document] | [
"Initializes",
"a",
"linter",
"with",
"the",
"specified",
"configuration",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter.rb#L27-L42 |
11,573 | sds/haml-lint | lib/haml_lint/linter.rb | HamlLint.Linter.inline_content_is_string? | def inline_content_is_string?(node)
tag_with_inline_content = tag_with_inline_text(node)
inline_content = inline_node_content(node)
index = tag_with_inline_content.rindex(inline_content) - 1
%w[' "].include?(tag_with_inline_content[index])
end | ruby | def inline_content_is_string?(node)
tag_with_inline_content = tag_with_inline_text(node)
inline_content = inline_node_content(node)
index = tag_with_inline_content.rindex(inline_content) - 1
%w[' "].include?(tag_with_inline_content[index])
end | [
"def",
"inline_content_is_string?",
"(",
"node",
")",
"tag_with_inline_content",
"=",
"tag_with_inline_text",
"(",
"node",
")",
"inline_content",
"=",
"inline_node_content",
"(",
"node",
")",
"index",
"=",
"tag_with_inline_content",
".",
"rindex",
"(",
"inline_content",... | Returns whether the inline content for a node is a string.
For example, the following node has a literal string:
%tag= "A literal #{string}"
whereas this one does not:
%tag A literal #{string}
@param node [HamlLint::Tree::Node]
@return [true,false] | [
"Returns",
"whether",
"the",
"inline",
"content",
"for",
"a",
"node",
"is",
"a",
"string",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter.rb#L118-L125 |
11,574 | sds/haml-lint | lib/haml_lint/linter.rb | HamlLint.Linter.inline_node_content | def inline_node_content(node)
inline_content = node.script
if contains_interpolation?(inline_content)
strip_surrounding_quotes(inline_content)
else
inline_content
end
end | ruby | def inline_node_content(node)
inline_content = node.script
if contains_interpolation?(inline_content)
strip_surrounding_quotes(inline_content)
else
inline_content
end
end | [
"def",
"inline_node_content",
"(",
"node",
")",
"inline_content",
"=",
"node",
".",
"script",
"if",
"contains_interpolation?",
"(",
"inline_content",
")",
"strip_surrounding_quotes",
"(",
"inline_content",
")",
"else",
"inline_content",
"end",
"end"
] | Get the inline content for this node.
Inline content is the content that appears inline right after the
tag/script. For example, in the code below...
%tag Some inline content
..."Some inline content" would be the inline content.
@param node [HamlLint::Tree::Node]
@return [String] | [
"Get",
"the",
"inline",
"content",
"for",
"this",
"node",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter.rb#L138-L146 |
11,575 | sds/haml-lint | lib/haml_lint/linter.rb | HamlLint.Linter.next_node | def next_node(node)
return unless node
siblings = node.parent ? node.parent.children : [node]
next_sibling = siblings[siblings.index(node) + 1] if siblings.count > 1
return next_sibling if next_sibling
next_node(node.parent)
end | ruby | def next_node(node)
return unless node
siblings = node.parent ? node.parent.children : [node]
next_sibling = siblings[siblings.index(node) + 1] if siblings.count > 1
return next_sibling if next_sibling
next_node(node.parent)
end | [
"def",
"next_node",
"(",
"node",
")",
"return",
"unless",
"node",
"siblings",
"=",
"node",
".",
"parent",
"?",
"node",
".",
"parent",
".",
"children",
":",
"[",
"node",
"]",
"next_sibling",
"=",
"siblings",
"[",
"siblings",
".",
"index",
"(",
"node",
"... | Gets the next node following this node, ascending up the ancestor chain
recursively if this node has no siblings.
@param node [HamlLint::Tree::Node]
@return [HamlLint::Tree::Node,nil] | [
"Gets",
"the",
"next",
"node",
"following",
"this",
"node",
"ascending",
"up",
"the",
"ancestor",
"chain",
"recursively",
"if",
"this",
"node",
"has",
"no",
"siblings",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter.rb#L153-L161 |
11,576 | sds/haml-lint | lib/haml_lint/ruby_parser.rb | HamlLint.RubyParser.parse | def parse(source)
buffer = ::Parser::Source::Buffer.new('(string)')
buffer.source = source
@parser.reset
@parser.parse(buffer)
end | ruby | def parse(source)
buffer = ::Parser::Source::Buffer.new('(string)')
buffer.source = source
@parser.reset
@parser.parse(buffer)
end | [
"def",
"parse",
"(",
"source",
")",
"buffer",
"=",
"::",
"Parser",
"::",
"Source",
"::",
"Buffer",
".",
"new",
"(",
"'(string)'",
")",
"buffer",
".",
"source",
"=",
"source",
"@parser",
".",
"reset",
"@parser",
".",
"parse",
"(",
"buffer",
")",
"end"
] | Creates a reusable parser.
Parse the given Ruby source into an abstract syntax tree.
@param source [String] Ruby source code
@return [Array] syntax tree in the form returned by Parser gem | [
"Creates",
"a",
"reusable",
"parser",
".",
"Parse",
"the",
"given",
"Ruby",
"source",
"into",
"an",
"abstract",
"syntax",
"tree",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/ruby_parser.rb#L25-L31 |
11,577 | sds/haml-lint | lib/haml_lint/cli.rb | HamlLint.CLI.act_on_options | def act_on_options(options)
configure_logger(options)
if options[:help]
print_help(options)
Sysexits::EX_OK
elsif options[:version] || options[:verbose_version]
print_version(options)
Sysexits::EX_OK
elsif options[:show_linters]
print_available_linters
... | ruby | def act_on_options(options)
configure_logger(options)
if options[:help]
print_help(options)
Sysexits::EX_OK
elsif options[:version] || options[:verbose_version]
print_version(options)
Sysexits::EX_OK
elsif options[:show_linters]
print_available_linters
... | [
"def",
"act_on_options",
"(",
"options",
")",
"configure_logger",
"(",
"options",
")",
"if",
"options",
"[",
":help",
"]",
"print_help",
"(",
"options",
")",
"Sysexits",
"::",
"EX_OK",
"elsif",
"options",
"[",
":version",
"]",
"||",
"options",
"[",
":verbose... | Given the provided options, execute the appropriate command.
@return [Integer] exit status code | [
"Given",
"the",
"provided",
"options",
"execute",
"the",
"appropriate",
"command",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L37-L55 |
11,578 | sds/haml-lint | lib/haml_lint/cli.rb | HamlLint.CLI.configure_logger | def configure_logger(options)
log.color_enabled = options.fetch(:color, log.tty?)
log.summary_enabled = options.fetch(:summary, true)
end | ruby | def configure_logger(options)
log.color_enabled = options.fetch(:color, log.tty?)
log.summary_enabled = options.fetch(:summary, true)
end | [
"def",
"configure_logger",
"(",
"options",
")",
"log",
".",
"color_enabled",
"=",
"options",
".",
"fetch",
"(",
":color",
",",
"log",
".",
"tty?",
")",
"log",
".",
"summary_enabled",
"=",
"options",
".",
"fetch",
"(",
":summary",
",",
"true",
")",
"end"
... | Given the provided options, configure the logger.
@return [void] | [
"Given",
"the",
"provided",
"options",
"configure",
"the",
"logger",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L60-L63 |
11,579 | sds/haml-lint | lib/haml_lint/cli.rb | HamlLint.CLI.handle_exception | def handle_exception(exception)
case exception
when HamlLint::Exceptions::ConfigurationError
log.error exception.message
Sysexits::EX_CONFIG
when HamlLint::Exceptions::InvalidCLIOption
log.error exception.message
log.log "Run `#{APP_NAME}` --help for usage documentation... | ruby | def handle_exception(exception)
case exception
when HamlLint::Exceptions::ConfigurationError
log.error exception.message
Sysexits::EX_CONFIG
when HamlLint::Exceptions::InvalidCLIOption
log.error exception.message
log.log "Run `#{APP_NAME}` --help for usage documentation... | [
"def",
"handle_exception",
"(",
"exception",
")",
"case",
"exception",
"when",
"HamlLint",
"::",
"Exceptions",
"::",
"ConfigurationError",
"log",
".",
"error",
"exception",
".",
"message",
"Sysexits",
"::",
"EX_CONFIG",
"when",
"HamlLint",
"::",
"Exceptions",
"::"... | Outputs a message and returns an appropriate error code for the specified
exception. | [
"Outputs",
"a",
"message",
"and",
"returns",
"an",
"appropriate",
"error",
"code",
"for",
"the",
"specified",
"exception",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L67-L86 |
11,580 | sds/haml-lint | lib/haml_lint/cli.rb | HamlLint.CLI.reporter_from_options | def reporter_from_options(options)
if options[:auto_gen_config]
HamlLint::Reporter::DisabledConfigReporter.new(log, limit: options[:auto_gen_exclude_limit] || 15) # rubocop:disable Metrics/LineLength
else
options.fetch(:reporter, HamlLint::Reporter::DefaultReporter).new(log)
end
en... | ruby | def reporter_from_options(options)
if options[:auto_gen_config]
HamlLint::Reporter::DisabledConfigReporter.new(log, limit: options[:auto_gen_exclude_limit] || 15) # rubocop:disable Metrics/LineLength
else
options.fetch(:reporter, HamlLint::Reporter::DefaultReporter).new(log)
end
en... | [
"def",
"reporter_from_options",
"(",
"options",
")",
"if",
"options",
"[",
":auto_gen_config",
"]",
"HamlLint",
"::",
"Reporter",
"::",
"DisabledConfigReporter",
".",
"new",
"(",
"log",
",",
"limit",
":",
"options",
"[",
":auto_gen_exclude_limit",
"]",
"||",
"15... | Instantiates a new reporter based on the options.
@param options [HamlLint::Configuration]
@option options [true, nil] :auto_gen_config whether to use the config
generating reporter
@option options [Class] :reporter the class of reporter to use
@return [HamlLint::Reporter] | [
"Instantiates",
"a",
"new",
"reporter",
"based",
"on",
"the",
"options",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L95-L101 |
11,581 | sds/haml-lint | lib/haml_lint/cli.rb | HamlLint.CLI.scan_for_lints | def scan_for_lints(options)
reporter = reporter_from_options(options)
report = Runner.new.run(options.merge(reporter: reporter))
report.display
report.failed? ? Sysexits::EX_DATAERR : Sysexits::EX_OK
end | ruby | def scan_for_lints(options)
reporter = reporter_from_options(options)
report = Runner.new.run(options.merge(reporter: reporter))
report.display
report.failed? ? Sysexits::EX_DATAERR : Sysexits::EX_OK
end | [
"def",
"scan_for_lints",
"(",
"options",
")",
"reporter",
"=",
"reporter_from_options",
"(",
"options",
")",
"report",
"=",
"Runner",
".",
"new",
".",
"run",
"(",
"options",
".",
"merge",
"(",
"reporter",
":",
"reporter",
")",
")",
"report",
".",
"display"... | Scans the files specified by the given options for lints.
@return [Integer] exit status code | [
"Scans",
"the",
"files",
"specified",
"by",
"the",
"given",
"options",
"for",
"lints",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L106-L111 |
11,582 | sds/haml-lint | lib/haml_lint/cli.rb | HamlLint.CLI.print_available_linters | def print_available_linters
log.info 'Available linters:'
linter_names = HamlLint::LinterRegistry.linters.map do |linter|
linter.name.split('::').last
end
linter_names.sort.each do |linter_name|
log.log " - #{linter_name}"
end
end | ruby | def print_available_linters
log.info 'Available linters:'
linter_names = HamlLint::LinterRegistry.linters.map do |linter|
linter.name.split('::').last
end
linter_names.sort.each do |linter_name|
log.log " - #{linter_name}"
end
end | [
"def",
"print_available_linters",
"log",
".",
"info",
"'Available linters:'",
"linter_names",
"=",
"HamlLint",
"::",
"LinterRegistry",
".",
"linters",
".",
"map",
"do",
"|",
"linter",
"|",
"linter",
".",
"name",
".",
"split",
"(",
"'::'",
")",
".",
"last",
"... | Outputs a list of all currently available linters. | [
"Outputs",
"a",
"list",
"of",
"all",
"currently",
"available",
"linters",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L114-L124 |
11,583 | sds/haml-lint | lib/haml_lint/cli.rb | HamlLint.CLI.print_available_reporters | def print_available_reporters
log.info 'Available reporters:'
HamlLint::Reporter.available.map(&:cli_name).sort.each do |reporter_name|
log.log " - #{reporter_name}"
end
end | ruby | def print_available_reporters
log.info 'Available reporters:'
HamlLint::Reporter.available.map(&:cli_name).sort.each do |reporter_name|
log.log " - #{reporter_name}"
end
end | [
"def",
"print_available_reporters",
"log",
".",
"info",
"'Available reporters:'",
"HamlLint",
"::",
"Reporter",
".",
"available",
".",
"map",
"(",
":cli_name",
")",
".",
"sort",
".",
"each",
"do",
"|",
"reporter_name",
"|",
"log",
".",
"log",
"\" - #{reporter_na... | Outputs a list of currently available reporters. | [
"Outputs",
"a",
"list",
"of",
"currently",
"available",
"reporters",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L127-L133 |
11,584 | sds/haml-lint | lib/haml_lint/cli.rb | HamlLint.CLI.print_version | def print_version(options)
log.log "#{HamlLint::APP_NAME} #{HamlLint::VERSION}"
if options[:verbose_version]
log.log "haml #{Gem.loaded_specs['haml'].version}"
log.log "rubocop #{Gem.loaded_specs['rubocop'].version}"
log.log RUBY_DESCRIPTION
end
end | ruby | def print_version(options)
log.log "#{HamlLint::APP_NAME} #{HamlLint::VERSION}"
if options[:verbose_version]
log.log "haml #{Gem.loaded_specs['haml'].version}"
log.log "rubocop #{Gem.loaded_specs['rubocop'].version}"
log.log RUBY_DESCRIPTION
end
end | [
"def",
"print_version",
"(",
"options",
")",
"log",
".",
"log",
"\"#{HamlLint::APP_NAME} #{HamlLint::VERSION}\"",
"if",
"options",
"[",
":verbose_version",
"]",
"log",
".",
"log",
"\"haml #{Gem.loaded_specs['haml'].version}\"",
"log",
".",
"log",
"\"rubocop #{Gem.loaded_spe... | Outputs the application name and version. | [
"Outputs",
"the",
"application",
"name",
"and",
"version",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L141-L149 |
11,585 | sds/haml-lint | lib/haml_lint/cli.rb | HamlLint.CLI.print_unexpected_exception | def print_unexpected_exception(exception) # rubocop:disable Metrics/AbcSize
log.bold_error exception.message
log.error exception.backtrace.join("\n")
log.warning 'Report this bug at ', false
log.info HamlLint::BUG_REPORT_URL
log.newline
log.success 'To help fix this issue, please inc... | ruby | def print_unexpected_exception(exception) # rubocop:disable Metrics/AbcSize
log.bold_error exception.message
log.error exception.backtrace.join("\n")
log.warning 'Report this bug at ', false
log.info HamlLint::BUG_REPORT_URL
log.newline
log.success 'To help fix this issue, please inc... | [
"def",
"print_unexpected_exception",
"(",
"exception",
")",
"# rubocop:disable Metrics/AbcSize",
"log",
".",
"bold_error",
"exception",
".",
"message",
"log",
".",
"error",
"exception",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
"log",
".",
"warning",
"'R... | Outputs the backtrace of an exception with instructions on how to report
the issue. | [
"Outputs",
"the",
"backtrace",
"of",
"an",
"exception",
"with",
"instructions",
"on",
"how",
"to",
"report",
"the",
"issue",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/cli.rb#L153-L169 |
11,586 | sds/haml-lint | lib/haml_lint/document.rb | HamlLint.Document.strip_frontmatter | def strip_frontmatter(source)
frontmatter = /
# From the start of the string
\A
# First-capture match --- followed by optional whitespace up
# to a newline then 0 or more chars followed by an optional newline.
# This matches the --- and the contents of the frontmatter
... | ruby | def strip_frontmatter(source)
frontmatter = /
# From the start of the string
\A
# First-capture match --- followed by optional whitespace up
# to a newline then 0 or more chars followed by an optional newline.
# This matches the --- and the contents of the frontmatter
... | [
"def",
"strip_frontmatter",
"(",
"source",
")",
"frontmatter",
"=",
"/",
"\\A",
"\\s",
"\\n",
"\\n",
"\\.",
"\\.",
"\\.",
"\\s",
"\\n",
"/mx",
"if",
"config",
"[",
"'skip_frontmatter'",
"]",
"&&",
"match",
"=",
"source",
".",
"match",
"(",
"frontmatter",
... | Removes YAML frontmatter | [
"Removes",
"YAML",
"frontmatter"
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/document.rb#L102-L122 |
11,587 | sds/haml-lint | lib/haml_lint/tree/node.rb | HamlLint::Tree.Node.disabled? | def disabled?(visitor)
visitor.is_a?(HamlLint::Linter) &&
comment_configuration.disabled?(visitor.name)
end | ruby | def disabled?(visitor)
visitor.is_a?(HamlLint::Linter) &&
comment_configuration.disabled?(visitor.name)
end | [
"def",
"disabled?",
"(",
"visitor",
")",
"visitor",
".",
"is_a?",
"(",
"HamlLint",
"::",
"Linter",
")",
"&&",
"comment_configuration",
".",
"disabled?",
"(",
"visitor",
".",
"name",
")",
"end"
] | Checks whether a visitor is disabled due to comment configuration.
@param [HamlLint::HamlVisitor]
@return [true, false] | [
"Checks",
"whether",
"a",
"visitor",
"is",
"disabled",
"due",
"to",
"comment",
"configuration",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/node.rb#L43-L46 |
11,588 | sds/haml-lint | lib/haml_lint/tree/node.rb | HamlLint::Tree.Node.each | def each
return to_enum(__callee__) unless block_given?
node = self
loop do
yield node
break unless (node = node.next_node)
end
end | ruby | def each
return to_enum(__callee__) unless block_given?
node = self
loop do
yield node
break unless (node = node.next_node)
end
end | [
"def",
"each",
"return",
"to_enum",
"(",
"__callee__",
")",
"unless",
"block_given?",
"node",
"=",
"self",
"loop",
"do",
"yield",
"node",
"break",
"unless",
"(",
"node",
"=",
"node",
".",
"next_node",
")",
"end",
"end"
] | Implements the Enumerable interface to walk through an entire tree.
@return [Enumerator, HamlLint::Tree::Node] | [
"Implements",
"the",
"Enumerable",
"interface",
"to",
"walk",
"through",
"an",
"entire",
"tree",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/node.rb#L51-L59 |
11,589 | sds/haml-lint | lib/haml_lint/tree/node.rb | HamlLint::Tree.Node.line_numbers | def line_numbers
return (line..line) unless @value && text
end_line = line + lines.count
end_line = nontrivial_end_line if line == end_line
(line..end_line)
end | ruby | def line_numbers
return (line..line) unless @value && text
end_line = line + lines.count
end_line = nontrivial_end_line if line == end_line
(line..end_line)
end | [
"def",
"line_numbers",
"return",
"(",
"line",
"..",
"line",
")",
"unless",
"@value",
"&&",
"text",
"end_line",
"=",
"line",
"+",
"lines",
".",
"count",
"end_line",
"=",
"nontrivial_end_line",
"if",
"line",
"==",
"end_line",
"(",
"line",
"..",
"end_line",
"... | The line numbers that are contained within the node.
@api public
@return [Range] | [
"The",
"line",
"numbers",
"that",
"are",
"contained",
"within",
"the",
"node",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/node.rb#L104-L111 |
11,590 | sds/haml-lint | lib/haml_lint/tree/node.rb | HamlLint::Tree.Node.nontrivial_end_line | def nontrivial_end_line
if (last_child = children.last)
last_child.line_numbers.end - 1
elsif successor
successor.line_numbers.begin - 1
else
@document.source_lines.count
end
end | ruby | def nontrivial_end_line
if (last_child = children.last)
last_child.line_numbers.end - 1
elsif successor
successor.line_numbers.begin - 1
else
@document.source_lines.count
end
end | [
"def",
"nontrivial_end_line",
"if",
"(",
"last_child",
"=",
"children",
".",
"last",
")",
"last_child",
".",
"line_numbers",
".",
"end",
"-",
"1",
"elsif",
"successor",
"successor",
".",
"line_numbers",
".",
"begin",
"-",
"1",
"else",
"@document",
".",
"sour... | Discovers the end line of the node when there are no lines.
@return [Integer] the end line of the node | [
"Discovers",
"the",
"end",
"line",
"of",
"the",
"node",
"when",
"there",
"are",
"no",
"lines",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/node.rb#L163-L171 |
11,591 | sds/haml-lint | lib/haml_lint/tree/root_node.rb | HamlLint::Tree.RootNode.node_for_line | def node_for_line(line)
find(-> { HamlLint::Tree::NullNode.new }) { |node| node.line_numbers.cover?(line) }
end | ruby | def node_for_line(line)
find(-> { HamlLint::Tree::NullNode.new }) { |node| node.line_numbers.cover?(line) }
end | [
"def",
"node_for_line",
"(",
"line",
")",
"find",
"(",
"->",
"{",
"HamlLint",
"::",
"Tree",
"::",
"NullNode",
".",
"new",
"}",
")",
"{",
"|",
"node",
"|",
"node",
".",
"line_numbers",
".",
"cover?",
"(",
"line",
")",
"}",
"end"
] | Gets the node of the syntax tree for a given line number.
@param line [Integer] the line number of the node
@return [HamlLint::Node] | [
"Gets",
"the",
"node",
"of",
"the",
"syntax",
"tree",
"for",
"a",
"given",
"line",
"number",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/root_node.rb#L19-L21 |
11,592 | sds/haml-lint | lib/haml_lint/linter_selector.rb | HamlLint.LinterSelector.extract_enabled_linters | def extract_enabled_linters(config, options)
included_linters =
LinterRegistry.extract_linters_from(options.fetch(:included_linters, []))
included_linters = LinterRegistry.linters if included_linters.empty?
excluded_linters =
LinterRegistry.extract_linters_from(options.fetch(:exclude... | ruby | def extract_enabled_linters(config, options)
included_linters =
LinterRegistry.extract_linters_from(options.fetch(:included_linters, []))
included_linters = LinterRegistry.linters if included_linters.empty?
excluded_linters =
LinterRegistry.extract_linters_from(options.fetch(:exclude... | [
"def",
"extract_enabled_linters",
"(",
"config",
",",
"options",
")",
"included_linters",
"=",
"LinterRegistry",
".",
"extract_linters_from",
"(",
"options",
".",
"fetch",
"(",
":included_linters",
",",
"[",
"]",
")",
")",
"included_linters",
"=",
"LinterRegistry",
... | Returns a list of linters that are enabled given the specified
configuration and additional options.
@param config [HamlLint::Configuration]
@param options [Hash]
@return [Array<HamlLint::Linter>] | [
"Returns",
"a",
"list",
"of",
"linters",
"that",
"are",
"enabled",
"given",
"the",
"specified",
"configuration",
"and",
"additional",
"options",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter_selector.rb#L33-L56 |
11,593 | sds/haml-lint | lib/haml_lint/linter_selector.rb | HamlLint.LinterSelector.run_linter_on_file? | def run_linter_on_file?(config, linter, file)
linter_config = config.for_linter(linter)
if linter_config['include'].any? &&
!HamlLint::Utils.any_glob_matches?(linter_config['include'], file)
return false
end
if HamlLint::Utils.any_glob_matches?(linter_config['exclude'], file)
... | ruby | def run_linter_on_file?(config, linter, file)
linter_config = config.for_linter(linter)
if linter_config['include'].any? &&
!HamlLint::Utils.any_glob_matches?(linter_config['include'], file)
return false
end
if HamlLint::Utils.any_glob_matches?(linter_config['exclude'], file)
... | [
"def",
"run_linter_on_file?",
"(",
"config",
",",
"linter",
",",
"file",
")",
"linter_config",
"=",
"config",
".",
"for_linter",
"(",
"linter",
")",
"if",
"linter_config",
"[",
"'include'",
"]",
".",
"any?",
"&&",
"!",
"HamlLint",
"::",
"Utils",
".",
"any_... | Whether to run the given linter against the specified file.
@param config [HamlLint::Configuration]
@param linter [HamlLint::Linter]
@param file [String]
@return [Boolean] | [
"Whether",
"to",
"run",
"the",
"given",
"linter",
"against",
"the",
"specified",
"file",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter_selector.rb#L64-L77 |
11,594 | sds/haml-lint | lib/haml_lint/tree/tag_node.rb | HamlLint::Tree.TagNode.attributes_source | def attributes_source
@attributes_source ||=
begin
_explicit_tag, static_attrs, rest =
source_code.scan(/\A\s*(%[-:\w]+)?([-:\w\.\#]*)(.*)/m)[0]
attr_types = {
'{' => [:hash, %w[{ }]],
'(' => [:html, %w[( )]],
'[' => [:object_ref, %w[[ ]... | ruby | def attributes_source
@attributes_source ||=
begin
_explicit_tag, static_attrs, rest =
source_code.scan(/\A\s*(%[-:\w]+)?([-:\w\.\#]*)(.*)/m)[0]
attr_types = {
'{' => [:hash, %w[{ }]],
'(' => [:html, %w[( )]],
'[' => [:object_ref, %w[[ ]... | [
"def",
"attributes_source",
"@attributes_source",
"||=",
"begin",
"_explicit_tag",
",",
"static_attrs",
",",
"rest",
"=",
"source_code",
".",
"scan",
"(",
"/",
"\\A",
"\\s",
"\\w",
"\\w",
"\\.",
"\\#",
"/m",
")",
"[",
"0",
"]",
"attr_types",
"=",
"{",
"'{'... | Returns the source code for the static and dynamic attributes
of a tag.
@example For `%tag.class{ id: 'hello' }(lang=en)`, this returns:
{ :static => '.class', :hash => " id: 'hello' ", :html => "lang=en" }
@return [Hash] | [
"Returns",
"the",
"source",
"code",
"for",
"the",
"static",
"and",
"dynamic",
"attributes",
"of",
"a",
"tag",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/tree/tag_node.rb#L100-L125 |
11,595 | sds/haml-lint | lib/haml_lint/linter/rubocop.rb | HamlLint.Linter::RuboCop.find_lints | def find_lints(ruby, source_map)
rubocop = ::RuboCop::CLI.new
filename =
if document.file
"#{document.file}.rb"
else
'ruby_script.rb'
end
with_ruby_from_stdin(ruby) do
extract_lints_from_offenses(lint_file(rubocop, filename), source_map)
end
... | ruby | def find_lints(ruby, source_map)
rubocop = ::RuboCop::CLI.new
filename =
if document.file
"#{document.file}.rb"
else
'ruby_script.rb'
end
with_ruby_from_stdin(ruby) do
extract_lints_from_offenses(lint_file(rubocop, filename), source_map)
end
... | [
"def",
"find_lints",
"(",
"ruby",
",",
"source_map",
")",
"rubocop",
"=",
"::",
"RuboCop",
"::",
"CLI",
".",
"new",
"filename",
"=",
"if",
"document",
".",
"file",
"\"#{document.file}.rb\"",
"else",
"'ruby_script.rb'",
"end",
"with_ruby_from_stdin",
"(",
"ruby",... | Executes RuboCop against the given Ruby code and records the offenses as
lints.
@param ruby [String] Ruby code
@param source_map [Hash] map of Ruby code line numbers to original line
numbers in the template | [
"Executes",
"RuboCop",
"against",
"the",
"given",
"Ruby",
"code",
"and",
"records",
"the",
"offenses",
"as",
"lints",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter/rubocop.rb#L38-L51 |
11,596 | sds/haml-lint | lib/haml_lint/linter/rubocop.rb | HamlLint.Linter::RuboCop.with_ruby_from_stdin | def with_ruby_from_stdin(ruby, &_block)
original_stdin = $stdin
stdin = StringIO.new
stdin.write(ruby)
stdin.rewind
$stdin = stdin
yield
ensure
$stdin = original_stdin
end | ruby | def with_ruby_from_stdin(ruby, &_block)
original_stdin = $stdin
stdin = StringIO.new
stdin.write(ruby)
stdin.rewind
$stdin = stdin
yield
ensure
$stdin = original_stdin
end | [
"def",
"with_ruby_from_stdin",
"(",
"ruby",
",",
"&",
"_block",
")",
"original_stdin",
"=",
"$stdin",
"stdin",
"=",
"StringIO",
".",
"new",
"stdin",
".",
"write",
"(",
"ruby",
")",
"stdin",
".",
"rewind",
"$stdin",
"=",
"stdin",
"yield",
"ensure",
"$stdin"... | Overrides the global stdin to allow RuboCop to read Ruby code from it.
@param ruby [String] the Ruby code to write to the overridden stdin
@param _block [Block] the block to perform with the overridden stdin
@return [void] | [
"Overrides",
"the",
"global",
"stdin",
"to",
"allow",
"RuboCop",
"to",
"read",
"Ruby",
"code",
"from",
"it",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/linter/rubocop.rb#L103-L112 |
11,597 | sds/haml-lint | lib/haml_lint/utils.rb | HamlLint.Utils.get_abs_and_rel_path | def get_abs_and_rel_path(path)
original_path = Pathname.new(path)
root_dir_path = Pathname.new(File.expand_path(Dir.pwd))
if original_path.absolute?
[path, original_path.relative_path_from(root_dir_path)]
else
[root_dir_path + original_path, path]
end
end | ruby | def get_abs_and_rel_path(path)
original_path = Pathname.new(path)
root_dir_path = Pathname.new(File.expand_path(Dir.pwd))
if original_path.absolute?
[path, original_path.relative_path_from(root_dir_path)]
else
[root_dir_path + original_path, path]
end
end | [
"def",
"get_abs_and_rel_path",
"(",
"path",
")",
"original_path",
"=",
"Pathname",
".",
"new",
"(",
"path",
")",
"root_dir_path",
"=",
"Pathname",
".",
"new",
"(",
"File",
".",
"expand_path",
"(",
"Dir",
".",
"pwd",
")",
")",
"if",
"original_path",
".",
... | Returns an array of two items, the first being the absolute path, the second
the relative path.
The relative path is relative to the current working dir. The path passed can
be either relative or absolute.
@param path [String] Path to get absolute and relative path of
@return [Array<String>] Absolute and relativ... | [
"Returns",
"an",
"array",
"of",
"two",
"items",
"the",
"first",
"being",
"the",
"absolute",
"path",
"the",
"second",
"the",
"relative",
"path",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/utils.rb#L37-L46 |
11,598 | sds/haml-lint | lib/haml_lint/utils.rb | HamlLint.Utils.extract_interpolated_values | def extract_interpolated_values(text) # rubocop:disable Metrics/AbcSize
dumped_text = text.dump
newline_positions = extract_substring_positions(dumped_text, '\\\n')
Haml::Util.handle_interpolation(dumped_text) do |scan|
line = (newline_positions.find_index { |marker| scan.pos <= marker } ||
... | ruby | def extract_interpolated_values(text) # rubocop:disable Metrics/AbcSize
dumped_text = text.dump
newline_positions = extract_substring_positions(dumped_text, '\\\n')
Haml::Util.handle_interpolation(dumped_text) do |scan|
line = (newline_positions.find_index { |marker| scan.pos <= marker } ||
... | [
"def",
"extract_interpolated_values",
"(",
"text",
")",
"# rubocop:disable Metrics/AbcSize",
"dumped_text",
"=",
"text",
".",
"dump",
"newline_positions",
"=",
"extract_substring_positions",
"(",
"dumped_text",
",",
"'\\\\\\n'",
")",
"Haml",
"::",
"Util",
".",
"handle_i... | Yields interpolated values within a block of text.
@param text [String]
@yield Passes interpolated code and line number that code appears on in
the text.
@yieldparam interpolated_code [String] code that was interpolated
@yieldparam line [Integer] line number code appears on in text | [
"Yields",
"interpolated",
"values",
"within",
"a",
"block",
"of",
"text",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/utils.rb#L55-L71 |
11,599 | sds/haml-lint | lib/haml_lint/utils.rb | HamlLint.Utils.for_consecutive_items | def for_consecutive_items(items, satisfies, min_consecutive = 2)
current_index = -1
while (current_index += 1) < items.count
next unless satisfies[items[current_index]]
count = count_consecutive(items, current_index, &satisfies)
next unless count >= min_consecutive
# Yield... | ruby | def for_consecutive_items(items, satisfies, min_consecutive = 2)
current_index = -1
while (current_index += 1) < items.count
next unless satisfies[items[current_index]]
count = count_consecutive(items, current_index, &satisfies)
next unless count >= min_consecutive
# Yield... | [
"def",
"for_consecutive_items",
"(",
"items",
",",
"satisfies",
",",
"min_consecutive",
"=",
"2",
")",
"current_index",
"=",
"-",
"1",
"while",
"(",
"current_index",
"+=",
"1",
")",
"<",
"items",
".",
"count",
"next",
"unless",
"satisfies",
"[",
"items",
"... | Find all consecutive items satisfying the given block of a minimum size,
yielding each group of consecutive items to the provided block.
@param items [Array]
@param satisfies [Proc] function that takes an item and returns true/false
@param min_consecutive [Fixnum] minimum number of consecutive items before
yiel... | [
"Find",
"all",
"consecutive",
"items",
"satisfying",
"the",
"given",
"block",
"of",
"a",
"minimum",
"size",
"yielding",
"each",
"group",
"of",
"consecutive",
"items",
"to",
"the",
"provided",
"block",
"."
] | 024c773667e54cf88db938c2b368977005d70ee8 | https://github.com/sds/haml-lint/blob/024c773667e54cf88db938c2b368977005d70ee8/lib/haml_lint/utils.rb#L108-L122 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.