code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def entity_to_str(e, original = nil)
entity_output = @options[:entity_output]
if entity_output == :as_char &&
(c = e.char.encode(@root.options[:encoding]) rescue nil) &&
((c = e.char) == '"' || !ESCAPE_MAP.key?(c))
c
elsif (entity_output == :as_input || entity_output == :as_char) && original
original
elsif (entity_output == :symbolic || ESCAPE_MAP.key?(e.char)) && !e.name.nil?
"&#{e.name};"
else # default to :numeric
"&##{e.code_point};"
end
end
|
Convert the entity +e+ to a string. The optional parameter +original+ may contain the
original representation of the entity.
This method uses the option +entity_output+ to determine the output form for the entity.
|
entity_to_str
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/html.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/html.rb
|
Apache-2.0
|
def html_attributes(attr)
return '' if attr.empty?
attr.map do |k, v|
v.nil? || (k == 'id' && v.strip.empty?) ? '' : " #{k}=\"#{escape_html(v.to_s, :attribute)}\""
end.join('')
end
|
Return the HTML representation of the attributes +attr+.
|
html_attributes
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/html.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/html.rb
|
Apache-2.0
|
def escape_html(str, type = :all)
str.gsub(ESCAPE_RE_FROM_TYPE[type]) {|m| ESCAPE_MAP[m] || m }
end
|
:startdoc:
Escape the special HTML characters in the string +str+. The parameter +type+ specifies what
is escaped: :all - all special HTML characters except the quotation mark as well as
entities, :text - all special HTML characters except the quotation mark but no entities and
:attribute - all special HTML characters including the quotation mark but no entities.
|
escape_html
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/html.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/html.rb
|
Apache-2.0
|
def initialize(size)
@size = size
@cache = {}
end
|
Creates a new LRUCache that can hold +size+ entries.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/lru_cache.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/lru_cache.rb
|
Apache-2.0
|
def initialize(string, start_line_number = 1)
super(string)
@start_line_number = start_line_number || 1
@previous_pos = 0
@previous_line_number = @start_line_number
end
|
Takes the start line number as optional second argument.
Note: The original second argument is no longer used so this should be safe.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/string_scanner.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/string_scanner.rb
|
Apache-2.0
|
def save_pos
[pos, @previous_pos, @previous_line_number]
end
|
Return information needed to revert the byte position of the string scanner in a performant
way.
The returned data can be fed to #revert_pos to revert the position to the saved one.
Note: Just saving #pos won't be enough.
|
save_pos
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/string_scanner.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/string_scanner.rb
|
Apache-2.0
|
def revert_pos(data)
self.pos = data[0]
@previous_pos, @previous_line_number = data[1], data[2]
end
|
Revert the position to one saved by #save_pos.
|
revert_pos
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/string_scanner.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/string_scanner.rb
|
Apache-2.0
|
def current_line_number
# Not using string[@previous_pos..best_pos].count('\n') because it is slower
strscan = ::StringScanner.new(string)
strscan.pos = @previous_pos
old_pos = pos + 1
@previous_line_number += 1 while strscan.skip_until(/\n/) && strscan.pos <= old_pos
@previous_pos = (eos? ? pos : pos + 1)
@previous_line_number
end
|
Returns the line number for current charpos.
NOTE: Requires that all line endings are normalized to '\n'
NOTE: Normally we'd have to add one to the count of newlines to get the correct line number.
However we add the one indirectly by using a one-based start_line_number.
|
current_line_number
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/string_scanner.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/utils/string_scanner.rb
|
Apache-2.0
|
def check_element_for_location(element)
if (match = /^line-(\d+)/.match(element.attr['class'] || ''))
expected_line = match[1].to_i
assert_equal(expected_line, element.options[:location])
end
element.children.each do |child|
check_element_for_location(child)
end
end
|
checks that +element+'s :location option corresponds to the location stored
in the element.attr['class']
|
check_element_for_location
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/test/test_location.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/test/test_location.rb
|
Apache-2.0
|
def add_filters(filters)
filters = [filters].flatten.compact
@filters += filters
@strainer = nil
end
|
Adds filters to this context.
Note that this does not register the filters with the main Template object. see <tt>Template.register_filter</tt>
for that
|
add_filters
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/context.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/context.rb
|
Apache-2.0
|
def push(new_scope = {})
@scopes.unshift(new_scope)
raise StackLevelError, "Nesting too deep".freeze if @scopes.length > Block::MAX_DEPTH
end
|
Push new local scope on the stack. use <tt>Context#stack</tt> instead
|
push
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/context.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/context.rb
|
Apache-2.0
|
def pop
raise ContextError if @scopes.size == 1
@scopes.shift
end
|
Pop from the stack. use <tt>Context#stack</tt> instead
|
pop
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/context.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/context.rb
|
Apache-2.0
|
def stack(new_scope = nil)
old_stack_used = @this_stack_used
if new_scope
push(new_scope)
@this_stack_used = true
else
@this_stack_used = false
end
yield
ensure
pop if @this_stack_used
@this_stack_used = old_stack_used
end
|
Pushes a new local scope on the stack, pops it at the end of the block
Example:
context.stack do
context['var'] = 'hi'
end
context['var] #=> nil
|
stack
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/context.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/context.rb
|
Apache-2.0
|
def find_variable(key, raise_on_not_found: true)
# This was changed from find() to find_index() because this is a very hot
# path and find_index() is optimized in MRI to reduce object allocation
index = @scopes.find_index { |s| s.key?(key) }
scope = @scopes[index] if index
variable = nil
if scope.nil?
@environments.each do |e|
variable = lookup_and_evaluate(e, key, raise_on_not_found: raise_on_not_found)
# When lookup returned a value OR there is no value but the lookup also did not raise
# then it is the value we are looking for.
if !variable.nil? || @strict_variables && raise_on_not_found
scope = e
break
end
end
end
scope ||= @environments.last || @scopes.last
variable ||= lookup_and_evaluate(scope, key, raise_on_not_found: raise_on_not_found)
variable = variable.to_liquid
variable.context = self if variable.respond_to?(:context=)
variable
end
|
Fetches an object starting at the local scope and then moving up the hierachy
|
find_variable
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/context.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/context.rb
|
Apache-2.0
|
def invoke_drop(method_or_key)
if self.class.invokable?(method_or_key)
send(method_or_key)
else
liquid_method_missing(method_or_key)
end
end
|
called by liquid to invoke a drop
|
invoke_drop
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/drop.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/drop.rb
|
Apache-2.0
|
def read_template_file(_template_path)
raise FileSystemError, "This liquid context does not allow includes."
end
|
Called by Liquid to retrieve a template file
|
read_template_file
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/file_system.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/file_system.rb
|
Apache-2.0
|
def consume?(type)
token = @tokens[@p]
return false unless token && token[0] == type
@p += 1
token[1]
end
|
Only consumes the token if it matches the type
Returns the token's contents if it was consumed
or false otherwise.
|
consume?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/parser.rb
|
Apache-2.0
|
def id?(str)
token = @tokens[@p]
return false unless token && token[0] == :id
return false unless token[1] == str
@p += 1
token[1]
end
|
Like consume? Except for an :id token of a certain name
|
id?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/parser.rb
|
Apache-2.0
|
def size(input)
input.respond_to?(:size) ? input.size : 0
end
|
Return the size of an array or of an string
|
size
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def strip_newlines(input)
input.to_s.gsub(/\r?\n/, ''.freeze)
end
|
Remove all newlines from the string
|
strip_newlines
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def sort(input, property = nil)
ary = InputIterator.new(input)
return [] if ary.empty?
if property.nil?
ary.sort do |a, b|
nil_safe_compare(a, b)
end
elsif ary.all? { |el| el.respond_to?(:[]) }
begin
ary.sort { |a, b| nil_safe_compare(a[property], b[property]) }
rescue TypeError
raise_property_error(property)
end
end
end
|
Sort elements of the array
provide optional property with which to sort an array of hashes or drops
|
sort
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def sort_natural(input, property = nil)
ary = InputIterator.new(input)
return [] if ary.empty?
if property.nil?
ary.sort do |a, b|
nil_safe_casecmp(a, b)
end
elsif ary.all? { |el| el.respond_to?(:[]) }
begin
ary.sort { |a, b| nil_safe_casecmp(a[property], b[property]) }
rescue TypeError
raise_property_error(property)
end
end
end
|
Sort elements of an array ignoring case if strings
provide optional property with which to sort an array of hashes or drops
|
sort_natural
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def where(input, property, target_value = nil)
ary = InputIterator.new(input)
if ary.empty?
[]
elsif ary.first.respond_to?(:[]) && target_value.nil?
begin
ary.select { |item| item[property] }
rescue TypeError
raise_property_error(property)
end
elsif ary.first.respond_to?(:[])
begin
ary.select { |item| item[property] == target_value }
rescue TypeError
raise_property_error(property)
end
end
end
|
Filter the elements of an array to those with a certain property value.
By default the target is any truthy value.
|
where
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def uniq(input, property = nil)
ary = InputIterator.new(input)
if property.nil?
ary.uniq
elsif ary.empty? # The next two cases assume a non-empty array.
[]
elsif ary.first.respond_to?(:[])
begin
ary.uniq { |a| a[property] }
rescue TypeError
raise_property_error(property)
end
end
end
|
Remove duplicate elements from an array
provide optional property with which to determine uniqueness
|
uniq
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def reverse(input)
ary = InputIterator.new(input)
ary.reverse
end
|
Reverse the elements of an array
|
reverse
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def compact(input, property = nil)
ary = InputIterator.new(input)
if property.nil?
ary.compact
elsif ary.empty? # The next two cases assume a non-empty array.
[]
elsif ary.first.respond_to?(:[])
begin
ary.reject { |a| a[property].nil? }
rescue TypeError
raise_property_error(property)
end
end
end
|
Remove nils within an array
provide optional property with which to check for nil
|
compact
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def replace(input, string, replacement = ''.freeze)
input.to_s.gsub(string.to_s, replacement.to_s)
end
|
Replace occurrences of a string with another
|
replace
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def replace_first(input, string, replacement = ''.freeze)
input.to_s.sub(string.to_s, replacement.to_s)
end
|
Replace the first occurrences of a string with another
|
replace_first
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def remove_first(input, string)
input.to_s.sub(string.to_s, ''.freeze)
end
|
remove the first occurrences of a substring
|
remove_first
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def newline_to_br(input)
input.to_s.gsub(/\n/, "<br />\n".freeze)
end
|
Add <br /> tags in front of all newlines in input string
|
newline_to_br
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def date(input, format)
return input if format.to_s.empty?
return input unless date = Utils.to_date(input)
date.strftime(format.to_s)
end
|
Reformat a date using Ruby's core Time#strftime( string ) -> string
%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%s - Number of seconds since 1970-01-01 00:00:00 UTC.
%S - Second of the minute (00..60)
%U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
%% - Literal ``%'' character
See also: http://www.ruby-doc.org/core/Time.html#method-i-strftime
|
date
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def first(array)
array.first if array.respond_to?(:first)
end
|
Get the first element of the passed in array
Example:
{{ product.images | first | to_img }}
|
first
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def last(array)
array.last if array.respond_to?(:last)
end
|
Get the last element of the passed in array
Example:
{{ product.images | last | to_img }}
|
last
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/standardfilters.rb
|
Apache-2.0
|
def parse(source, options = {})
template = Template.new
template.parse(source, options)
end
|
creates a new <tt>Template</tt> object from liquid source code
To enable profiling, pass in <tt>profile: true</tt> as an option.
See Liquid::Profiler for more information
|
parse
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/template.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/template.rb
|
Apache-2.0
|
def parse(source, options = {})
@options = options
@profiling = options[:profile]
@line_numbers = options[:line_numbers] || @profiling
parse_context = options.is_a?(ParseContext) ? options : ParseContext.new(options)
@root = Document.parse(tokenize(source), parse_context)
@warnings = parse_context.warnings
self
end
|
Parse source code.
Returns self for easy chaining
|
parse
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/template.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/template.rb
|
Apache-2.0
|
def render(*args)
return ''.freeze if @root.nil?
context = case args.first
when Liquid::Context
c = args.shift
if @rethrow_errors
c.exception_renderer = ->(e) { raise }
end
c
when Liquid::Drop
drop = args.shift
drop.context = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits)
when Hash
Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits)
when nil
Context.new(assigns, instance_assigns, registers, @rethrow_errors, @resource_limits)
else
raise ArgumentError, "Expected Hash or Liquid::Context as parameter"
end
case args.last
when Hash
options = args.pop
registers.merge!(options[:registers]) if options[:registers].is_a?(Hash)
apply_options_to_context(context, options)
when Module, Array
context.add_filters(args.pop)
end
# Retrying a render resets resource usage
context.resource_limits.reset
begin
# render the nodelist.
# for performance reasons we get an array back here. join will make a string out of it.
result = with_profiling(context) do
@root.render(context)
end
result.respond_to?(:join) ? result.join : result
rescue Liquid::MemoryError => e
context.handle_error(e)
ensure
@errors = context.errors
end
end
|
Render takes a hash with local variables.
if you use the same filters over and over again consider registering them globally
with <tt>Template.register_filter</tt>
if profiling was enabled in <tt>Template#parse</tt> then the resulting profiling information
will be available via <tt>Template#profiler</tt>
Following options can be passed:
* <tt>filters</tt> : array with local filters
* <tt>registers</tt> : hash with register variables. Those can be accessed from
filters and tags and might be useful to integrate liquid more with its host application
|
render
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/template.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/lib/liquid/template.rb
|
Apache-2.0
|
def test_exceptions_propagate
assert_raises Exception do
template = Liquid::Template.parse('{{ errors.exception }}')
template.render('errors' => ErrorDrop.new)
end
end
|
Liquid should not catch Exceptions that are not subclasses of StandardError, like Interrupt and NoMemoryError
|
test_exceptions_propagate
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/error_handling_test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/error_handling_test.rb
|
Apache-2.0
|
def test_standard_output
text = <<-END_TEMPLATE
<div>
<p>
{{ 'John' }}
</p>
</div>
END_TEMPLATE
expected = <<-END_EXPECTED
<div>
<p>
John
</p>
</div>
END_EXPECTED
assert_template_result(expected, text)
end
|
Make sure the trim isn't applied to standard output
|
test_standard_output
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/trim_mode_test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/trim_mode_test.rb
|
Apache-2.0
|
def test_standard_tags
whitespace = ' '
text = <<-END_TEMPLATE
<div>
<p>
{% if true %}
yes
{% endif %}
</p>
</div>
END_TEMPLATE
expected = <<-END_EXPECTED
<div>
<p>
#{whitespace}
yes
#{whitespace}
</p>
</div>
END_EXPECTED
assert_template_result(expected, text)
text = <<-END_TEMPLATE
<div>
<p>
{% if false %}
no
{% endif %}
</p>
</div>
END_TEMPLATE
expected = <<-END_EXPECTED
<div>
<p>
#{whitespace}
</p>
</div>
END_EXPECTED
assert_template_result(expected, text)
end
|
Make sure the trim isn't applied to standard tags
|
test_standard_tags
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/trim_mode_test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/trim_mode_test.rb
|
Apache-2.0
|
def test_no_trim_output
text = '<p>{{- \'John\' -}}</p>'
expected = '<p>John</p>'
assert_template_result(expected, text)
end
|
Make sure the trim isn't too agressive
|
test_no_trim_output
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/trim_mode_test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/trim_mode_test.rb
|
Apache-2.0
|
def test_no_trim_tags
text = '<p>{%- if true -%}yes{%- endif -%}</p>'
expected = '<p>yes</p>'
assert_template_result(expected, text)
text = '<p>{%- if false -%}no{%- endif -%}</p>'
expected = '<p></p>'
assert_template_result(expected, text)
end
|
Make sure the trim isn't too agressive
|
test_no_trim_tags
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/trim_mode_test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/trim_mode_test.rb
|
Apache-2.0
|
def test_break_with_no_block
assigns = { 'i' => 1 }
markup = '{% break %}'
expected = ''
assert_template_result(expected, markup, assigns)
end
|
tests that no weird errors are raised if break is called outside of a
block
|
test_break_with_no_block
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/tags/break_tag_test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/tags/break_tag_test.rb
|
Apache-2.0
|
def test_continue_with_no_block
assigns = {}
markup = '{% continue %}'
expected = ''
assert_template_result(expected, markup, assigns)
end
|
tests that no weird errors are raised if continue is called outside of a
block
|
test_continue_with_no_block
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/tags/continue_tag_test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/tags/continue_tag_test.rb
|
Apache-2.0
|
def test_is_collection_empty
text = ' {% if array == empty %} true {% else %} false {% endif %} '
assert_template_result ' true ', text, 'array' => []
end
|
def test_is_nil
text = %| {% if var != nil %} true {% else %} false {% end %} |
@template.assigns = { 'var' => 'hello there!'}
expected = %| true |
assert_equal expected, @template.parse(text)
end
|
test_is_collection_empty
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/tags/statements_test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/integration/tags/statements_test.rb
|
Apache-2.0
|
def test_raises_unknown_translation
assert_raises I18n::TranslationError do
@i18n.translate("doesnt_exist")
end
end
|
def test_raises_translation_error_on_undefined_interpolation_key
assert_raises I18n::TranslationError do
@i18n.translate("whatever", :oopstypos => "yes")
end
end
|
test_raises_unknown_translation
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/unit/i18n_unit_test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/liquid-4.0.4/test/unit/i18n_unit_test.rb
|
Apache-2.0
|
def to(*args, &block)
Listener.new(*args, &block).tap do |listener|
@listeners.enq(WeakRef.new(listener))
end
end
|
Listens to file system modifications on a either single directory or
multiple directories.
@param (see Listen::Listener#new)
@yield [modified, added, removed] the changed files
@yieldparam [Array<String>] modified the list of modified files
@yieldparam [Array<String>] added the list of added files
@yieldparam [Array<String>] removed the list of removed files
@return [Listen::Listener] the listener
|
to
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen.rb
|
Apache-2.0
|
def stop
while (listener = @listeners.deq(true))
begin
listener.stop
rescue WeakRef::RefError
end
end
rescue ThreadError
end
|
This is used by the `listen` binary to handle Ctrl-C
|
stop
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen.rb
|
Apache-2.0
|
def invalidate(type, rel_path, options)
watched_dir = Pathname.new(record.root)
change = options[:change]
cookie = options[:cookie]
if !cookie && @config.silenced?(rel_path, type)
Listen.logger.debug { "(silenced): #{rel_path.inspect}" }
return
end
path = watched_dir + rel_path
Listen.logger.debug do
log_details = options[:silence] && 'recording' || change || 'unknown'
"#{log_details}: #{type}:#{path} (#{options.inspect})"
end
if change
options = cookie ? { cookie: cookie } : {}
@config.queue(type, change, watched_dir, rel_path, options)
elsif type == :dir
# NOTE: POSSIBLE RECURSION
# TODO: fix - use a queue instead
Directory.scan(self, rel_path, options)
elsif (change = File.change(record, rel_path)) && !options[:silence]
@config.queue(:file, change, watched_dir, rel_path)
end
end
|
Invalidate some part of the snapshot/record (dir, file, subtree, etc.)
rubocop:disable Metrics/MethodLength
rubocop:disable Metrics/CyclomaticComplexity
rubocop:disable Metrics/PerceivedComplexity
|
invalidate
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/change.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/change.rb
|
Apache-2.0
|
def start_state(new_start_state = nil)
if new_start_state
new_start_state.is_a?(Symbol) or raise ArgumentError, "state name must be a Symbol (got #{new_start_state.inspect})"
@start_state = new_start_state
else
defined?(@start_state) or raise ArgumentError, "`start_state :<state>` must be declared before `new`"
@start_state
end
end
|
Obtain or set the start state
Passing a state name sets the start state
|
start_state
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
Apache-2.0
|
def states
@states ||= {}
end
|
The valid states for this FSM, as a hash with state name symbols as keys and State objects as values.
|
states
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
Apache-2.0
|
def state(state_name, to: nil, &block)
state_name.is_a?(Symbol) or raise ArgumentError, "state name must be a Symbol (got #{state_name.inspect})"
states[state_name] = State.new(state_name, to, &block)
end
|
Declare an FSM state and optionally provide a callback block to fire on state entry
Options:
* to: a state or array of states this state can transition to
|
state
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
Apache-2.0
|
def initialize_fsm
@fsm_initialized = true
@state = self.class.start_state
@mutex = ::Mutex.new
@state_changed = ::ConditionVariable.new
end
|
Note: including classes must call initialize_fsm from their initialize method.
|
initialize_fsm
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
Apache-2.0
|
def wait_for_state(*wait_for_states, timeout: nil)
wait_for_states.each do |state|
state.is_a?(Symbol) or raise ArgumentError, "states must be symbols (got #{state.inspect})"
end
@mutex.synchronize do
if !wait_for_states.include?(@state)
@state_changed.wait(@mutex, timeout)
end
wait_for_states.include?(@state)
end
end
|
checks for one of the given states to wait for
if not already, waits for a state change (up to timeout seconds--`nil` means infinite)
returns truthy iff the transition to one of the desired state has occurred
|
wait_for_state
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
Apache-2.0
|
def transition!(new_state_name)
new_state_name.is_a?(Symbol) or raise ArgumentError, "state name must be a Symbol (got #{new_state_name.inspect})"
@fsm_initialized or raise ArgumentError, "FSM not initialized. You must call initialize_fsm from initialize!"
@mutex.synchronize do
yield if block_given?
@state = new_state_name
@state_changed.broadcast
end
end
|
Low-level, immediate state transition with no checks or callbacks.
|
transition!
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/fsm.rb
|
Apache-2.0
|
def initialize(*dirs, &block)
options = dirs.last.is_a?(Hash) ? dirs.pop : {}
@config = Config.new(options)
eq_config = Event::Queue::Config.new(@config.relative?)
queue = Event::Queue.new(eq_config)
silencer = Silencer.new
rules = @config.silencer_rules
@silencer_controller = Silencer::Controller.new(silencer, rules)
@backend = Backend.new(dirs, queue, silencer, @config)
optimizer_config = QueueOptimizer::Config.new(@backend, silencer)
pconfig = Event::Config.new(
self,
queue,
QueueOptimizer.new(optimizer_config),
@backend.min_delay_between_events,
&block)
@processor = Event::Loop.new(pconfig)
initialize_fsm
end
|
Initializes the directories listener.
@param [String] directory the directories to listen to
@param [Hash] options the listen options (see Listen::Listener::Options)
@yield [modified, added, removed] the changed files
@yieldparam [Array<String>] modified the list of modified files
@yieldparam [Array<String>] added the list of added files
@yieldparam [Array<String>] removed the list of removed files
rubocop:disable Metrics/MethodLength
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/listener.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/listener.rb
|
Apache-2.0
|
def start
case state
when :initializing
transition :backend_started
transition :processing_events
when :paused
transition :processing_events
else
raise ArgumentError, "cannot start from state #{state.inspect}"
end
end
|
Starts processing events and starts adapters
or resumes invoking callbacks if paused
|
start
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/listener.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/listener.rb
|
Apache-2.0
|
def stop
transition :stopped
end
|
Stops both listening for events and processing them
|
stop
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/listener.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/listener.rb
|
Apache-2.0
|
def pause
transition :paused
end
|
Stops invoking callbacks (messages pile up)
|
pause
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/listener.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/listener.rb
|
Apache-2.0
|
def _reinterpret_related_changes(cookies)
table = { moved_to: :added, moved_from: :removed }
cookies.flat_map do |_, changes|
if (editor_modified = editor_modified?(changes))
[[:modified, *editor_modified]]
else
not_silenced = changes.reject do |type, _, _, path, _|
config.silenced?(Pathname(path), type)
end
not_silenced.map do |_, change, dir, path, _|
[table.fetch(change, change), dir, path]
end
end
end
end
|
remove extraneous rb-inotify events, keeping them only if it's a possible
editor rename() call (e.g. Kate and Sublime)
|
_reinterpret_related_changes
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/queue_optimizer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/queue_optimizer.rb
|
Apache-2.0
|
def new(name, &block)
thread_name = "listen-#{name}"
caller_stack = caller
::Thread.new do
rescue_and_log(thread_name, caller_stack: caller_stack, &block)
end.tap do |thread|
thread.name = thread_name
end
end
|
Creates a new thread with the given name.
Any exceptions raised by the thread will be logged with the thread name and complete backtrace.
rubocop:disable Style/MultilineBlockChain
|
new
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/thread.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/thread.rb
|
Apache-2.0
|
def configure
if @configured
Listen.logger.warn('Adapter already configured!')
return
end
@configured = true
@callbacks ||= {}
config.directories.each do |dir|
callback = @callbacks[dir] || lambda do |event|
_process_event(dir, event)
end
@callbacks[dir] = callback
_configure(dir, &callback)
end
@snapshots ||= {}
# TODO: separate config per directory (some day maybe)
change_config = Change::Config.new(config.queue, config.silencer)
config.directories.each do |dir|
record = Record.new(dir, config.silencer)
snapshot = Change.new(change_config, record)
@snapshots[dir] = snapshot
end
end
|
TODO: it's a separate method as a temporary workaround for tests
rubocop:disable Metrics/MethodLength
|
configure
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/adapter/base.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/adapter/base.rb
|
Apache-2.0
|
def _queue_change(type, dir, rel_path, options)
@snapshots[dir].invalidate(type, rel_path, options)
end
|
TODO: allow backend adapters to pass specific invalidation objects
e.g. Darwin -> DirRescan, INotify -> MoveScan, etc.
|
_queue_change
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/adapter/base.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/adapter/base.rb
|
Apache-2.0
|
def start
# TODO: use a Fiber instead?
return unless state == :pre_start
transition! :starting
@wait_thread = Listen::Thread.new("wait_thread") do
_process_changes
end
Listen.logger.debug("Waiting for processing to start...")
wait_for_state(:started, timeout: MAX_STARTUP_SECONDS) or
raise Error::NotStarted, "thread didn't start in #{MAX_STARTUP_SECONDS} seconds (in state: #{state.inspect})"
Listen.logger.debug('Processing started.')
end
|
@raises Error::NotStarted if background thread hasn't started in MAX_STARTUP_SECONDS
|
start
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/event/loop.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/event/loop.rb
|
Apache-2.0
|
def loop_for(latency)
@latency = latency
loop do
event = _wait_until_events
_check_stopped
_wait_until_events_calm_down
_wait_until_no_longer_paused
_process_changes(event)
end
rescue Stopped
Listen.logger.debug('Processing stopped')
end
|
TODO: implement this properly instead of checking the state at arbitrary
points in time
|
loop_for
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/event/processor.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/event/processor.rb
|
Apache-2.0
|
def _wait_until_events
config.event_queue.pop.tap do |_event|
@_remember_time_of_first_unprocessed_event ||= MonotonicTime.now
end
end
|
blocks until event is popped
returns the event or `nil` when the event_queue is closed
|
_wait_until_events
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/event/processor.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/event/processor.rb
|
Apache-2.0
|
def _process_changes(event)
_reset_no_unprocessed_events
changes = [event]
changes << config.event_queue.pop until config.event_queue.empty?
return unless config.callable?
hash = config.optimize_changes(changes)
result = [hash[:modified], hash[:added], hash[:removed]]
return if result.all?(&:empty?)
block_start = MonotonicTime.now
exception_note = " (exception)"
::Listen::Thread.rescue_and_log('_process_changes') do
config.call(*result)
exception_note = nil
end
Listen.logger.debug "Callback#{exception_note} took #{MonotonicTime.now - block_start} sec"
end
|
for easier testing without sleep loop
|
_process_changes
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/event/processor.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/event/processor.rb
|
Apache-2.0
|
def initialize(root, relative, name = nil)
@root = root
@relative = relative
@name = name
end
|
file: "/home/me/watched_dir", "app/models", "foo.rb"
dir, "/home/me/watched_dir", "."
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/record/entry.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/record/entry.rb
|
Apache-2.0
|
def record_dir_key
::File.join(*[@relative, @name].compact)
end
|
record hash is e.g.
if @record["/home/me/watched_dir"]["project/app/models"]["foo.rb"]
if @record["/home/me/watched_dir"]["project/app"]["models"]
record_dir_key is "project/app/models"
|
record_dir_key
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/record/entry.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/listen-3.8.0/lib/listen/record/entry.rb
|
Apache-2.0
|
def initialize(name, parent = nil)
@name = name
@options = []
@commands = {}
@actions = []
@map = {}
@parent = parent
@trace = false
@aliases = []
end
|
Public: Creates a new Command
name - the name of the command
parent - (optional) the instancce of Mercenary::Command which you wish to
be the parent of this command
Returns nothing
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def version(version = nil)
@version = version if version
@version
end
|
Public: Sets or gets the command version
version - the command version (optional)
Returns the version and sets it if an argument is non-nil
|
version
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def syntax(syntax = nil)
@syntax = syntax if syntax
syntax_list = []
if parent
syntax_list << parent.syntax.to_s.gsub(/<[\w\s-]+>/, '').gsub(/\[[\w\s-]+\]/, '').strip
end
syntax_list << (@syntax || name.to_s)
syntax_list.join(" ")
end
|
Public: Sets or gets the syntax string
syntax - the string which describes this command's usage syntax (optional)
Returns the syntax string and sets it if an argument is present
|
syntax
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def description(desc = nil)
@description = desc if desc
@description
end
|
Public: Sets or gets the command description
description - the description of what the command does (optional)
Returns the description and sets it if an argument is present
|
description
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def default_command(command_name = nil)
if command_name
if commands.has_key?(command_name)
@default_command = commands[command_name] if command_name
@default_command
else
raise ArgumentError.new("'#{command_name}' couldn't be found in this command's list of commands.")
end
else
@default_command
end
end
|
Public: Sets the default command
command_name - the command name to be executed in the event no args are
present
Returns the default command if there is one, `nil` otherwise
|
default_command
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def option(sym, *options)
new_option = Option.new(sym, options)
@options << new_option
@map[new_option] = sym
end
|
Public: Adds an option switch
sym - the variable key which is used to identify the value of the switch
at runtime in the options hash
Returns nothing
|
option
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def command(cmd_name)
cmd = Command.new(cmd_name, self)
yield cmd
@commands[cmd_name] = cmd
end
|
Public: Adds a subcommand
cmd_name - the name of the command
block - a block accepting the new instance of Mercenary::Command to be
modified (optional)
Returns nothing
|
command
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def alias(cmd_name)
logger.debug "adding alias to parent for self: '#{cmd_name}'"
aliases << cmd_name
@parent.commands[cmd_name] = self
end
|
Public: Add an alias for this command's name to be attached to the parent
cmd_name - the name of the alias
Returns nothing
|
alias
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def action(&block)
@actions << block
end
|
Public: Add an action Proc to be executed at runtime
block - the Proc to be executed at runtime
Returns nothing
|
action
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def logger(level = nil)
unless @logger
@logger = Logger.new(STDOUT)
@logger.level = level || Logger::INFO
@logger.formatter = proc do |severity, datetime, progname, msg|
"#{identity} | " << "#{severity.downcase.capitalize}:".ljust(7) << " #{msg}\n"
end
end
@logger.level = level unless level.nil?
@logger
end
|
Public: Fetch a Logger (stdlib)
level - the logger level (a Logger constant, see docs for more info)
Returns the instance of Logger
|
logger
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def go(argv, opts, config)
opts.banner = "Usage: #{syntax}"
process_options(opts, config)
add_default_options(opts)
if argv[0] && cmd = commands[argv[0].to_sym]
logger.debug "Found subcommand '#{cmd.name}'"
argv.shift
cmd.go(argv, opts, config)
else
logger.debug "No additional command found, time to exec"
self
end
end
|
Public: Run the command
argv - an array of string args
opts - the instance of OptionParser
config - the output config hash
Returns the command to be executed
|
go
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def process_options(opts, config)
options.each do |option|
opts.on(*option.for_option_parser) do |x|
config[map[option]] = x
end
end
end
|
Public: Add this command's options to OptionParser and set a default
action of setting the value of the option to the inputted hash
opts - instance of OptionParser
config - the Hash in which the option values should be placed
Returns nothing
|
process_options
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def add_default_options(opts)
option 'show_help', '-h', '--help', 'Show this message'
option 'show_version', '-v', '--version', 'Print the name and version'
option 'show_backtrace', '-t', '--trace', 'Show the full backtrace when an error occurs'
opts.on("-v", "--version", "Print the version") do
puts "#{name} #{version}"
exit(0)
end
opts.on('-t', '--trace', 'Show full backtrace if an error occurs') do
@trace = true
end
opts.on_tail("-h", "--help", "Show this message") do
puts self
exit
end
end
|
Public: Add version and help options to the command
opts - instance of OptionParser
Returns nothing
|
add_default_options
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def execute(argv = [], config = {})
if actions.empty? && !default_command.nil?
default_command.execute
else
actions.each { |a| a.call(argv, config) }
end
end
|
Public: Execute all actions given the inputted args and options
argv - (optional) command-line args (sans opts)
config - (optional) the Hash configuration of string key to value
Returns nothing
|
execute
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def ident
"<Command name=#{identity}>"
end
|
Public: Identify this command
Returns a string which identifies this command
|
ident
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def identity
"#{full_name} #{version if version}".strip
end
|
Public: Get the full identity (name & version) of this command
Returns a string containing the name and version if it exists
|
identity
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def full_name
the_name = []
the_name << parent.full_name if parent && parent.full_name
the_name << name
the_name.join(" ")
end
|
Public: Get the name of the current command plus that of
its parent commands
Returns the full name of the command
|
full_name
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def names_and_aliases
([name.to_s] + aliases).compact.join(", ")
end
|
Public: Return all the names and aliases for this command.
Returns a comma-separated String list of the name followed by its aliases
|
names_and_aliases
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def summarize
" #{names_and_aliases.ljust(20)} #{description}"
end
|
Public: Build a string containing a summary of the command
Returns a one-line summary of the command.
|
summarize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb
|
Apache-2.0
|
def initialize(config_key, info)
@config_key = config_key
while arg = info.shift
begin
@return_type = Object.const_get("#{arg}")
next
rescue NameError
end
if arg.start_with?("-")
if arg.start_with?("--")
@long = arg
else
@short = arg
end
next
end
@description = arg
end
end
|
Public: Create a new Option
config_key - the key in the config hash to which the value of this option
will map
info - an array containing first the switches, then an optional
return type (e.g. Array), then a description of the option
Returns nothing
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
Apache-2.0
|
def for_option_parser
[short, long, return_type, description].flatten.reject{ |o| o.to_s.empty? }
end
|
Public: Fetch the array containing the info OptionParser is interested in
Returns the array which OptionParser#on wants
|
for_option_parser
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
Apache-2.0
|
def to_s
"#{formatted_switches} #{description}"
end
|
Public: Build a string representation of this option including the
switches and description
Returns a string representation of this option
|
to_s
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
Apache-2.0
|
def formatted_switches
[
switches.first.rjust(10),
switches.last.ljust(13)
].join(", ").gsub(/ , /, ' ').gsub(/, /, ' ')
end
|
Public: Build a beautifully-formatted string representation of the switches
Returns a formatted string representation of the switches
|
formatted_switches
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
Apache-2.0
|
def hash
instance_variables.map do |var|
instance_variable_get(var).hash
end.reduce(:^)
end
|
Public: Hash based on the hash value of instance variables
Returns a Fixnum which is unique to this Option based on the instance variables
|
hash
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
Apache-2.0
|
def eql?(other)
return false unless self.class.eql?(other.class)
instance_variables.map do |var|
instance_variable_get(var).eql?(other.instance_variable_get(var))
end.all?
end
|
Public: Check equivalence of two Options based on equivalence of their
instance variables
Returns true if all the instance variables are equal, false otherwise
|
eql?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
Apache-2.0
|
def switches
[short, long].map(&:to_s)
end
|
Public: Fetch an array of switches, including the short and long versions
Returns an array of two strings. An empty string represents no switch in
that position.
|
switches
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/option.rb
|
Apache-2.0
|
def initialize(command)
@command = command
end
|
Public: Make a new Presenter
command - a Mercenary::Command to present
Returns nothing
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
Apache-2.0
|
def usage_presentation
" #{command.syntax}"
end
|
Public: Builds a string representation of the command usage
Returns the string representation of the command usage
|
usage_presentation
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
Apache-2.0
|
def options_presentation
return nil unless command_options_presentation || parent_command_options_presentation
[command_options_presentation, parent_command_options_presentation].compact.join("\n")
end
|
Public: Builds a string representation of the options
Returns the string representation of the options
|
options_presentation
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
Apache-2.0
|
def parent_command_options_presentation
return nil unless command.parent
Presenter.new(command.parent).options_presentation
end
|
Public: Builds a string representation of the options for parent
commands
Returns the string representation of the options for parent commands
|
parent_command_options_presentation
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
Apache-2.0
|
def subcommands_presentation
return nil unless command.commands.size > 0
command.commands.values.uniq.map(&:summarize).join("\n")
end
|
Public: Builds a string representation of the subcommands
Returns the string representation of the subcommands
|
subcommands_presentation
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
Apache-2.0
|
def command_header
header = "#{command.identity}"
header << " -- #{command.description}" if command.description
header
end
|
Public: Builds the command header, including the command identity and description
Returns the command header as a String
|
command_header
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.