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 visit_rule(node) node.resolved_rules = node.resolved_rules.do_extend(@extends, @parent_directives) end
Applies the extend to a single rule's selector.
visit_rule
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/extend.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/extend.rb
Apache-2.0
def visit(root, environment = nil) new(environment).send(:visit, root) end
@param root [Tree::Node] The root node of the tree to visit. @param environment [Sass::Environment] The lexical environment. @return [Tree::Node] The resulting tree of static nodes.
visit
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def perform_splat(splat, performed_keywords, kwarg_splat, environment) args, kwargs, separator = [], nil, :comma if splat splat = splat.perform(environment) separator = splat.separator || separator if splat.is_a?(Sass::Script::Value::ArgList) args = splat.to_a kwargs = splat.keywords elsif splat.is_a?(Sass::Script::Value::Map) kwargs = arg_hash(splat) else args = splat.to_a end end kwargs ||= Sass::Util::NormalizedMap.new kwargs.update(performed_keywords) if kwarg_splat kwarg_splat = kwarg_splat.perform(environment) unless kwarg_splat.is_a?(Sass::Script::Value::Map) raise Sass::SyntaxError.new("Variable keyword arguments must be a map " + "(was #{kwarg_splat.inspect}).") end kwargs.update(arg_hash(kwarg_splat)) end Sass::Script::Value::ArgList.new(args, kwargs, separator) end
@api private @return [Sass::Script::Value::ArgList]
perform_splat
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit(node) return super(node.dup) unless @environment @environment.stack.with_base(node.filename, node.line) {super(node.dup)} rescue Sass::SyntaxError => e e.modify_backtrace(:filename => node.filename, :line => node.line) raise e end
If an exception is raised, this adds proper metadata to the backtrace.
visit
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_children(parent) with_environment Sass::Environment.new(@environment, parent.options) do parent.children = super.flatten parent end end
Keeps track of the current environment.
visit_children
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def with_environment(env) old_env, @environment = @environment, env yield ensure @environment = old_env end
Runs a block of code with the current environment replaced with the given one. @param env [Sass::Environment] The new environment for the duration of the block. @yield A block in which the environment is set to `env`. @return [Object] The return value of the block.
with_environment
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_root(node) yield rescue Sass::SyntaxError => e e.sass_template ||= node.template raise e end
Sets the options on the environment if this is the top-level root.
visit_root
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_comment(node) return [] if node.invisible? node.resolved_value = run_interp_no_strip(node.value) node.resolved_value.gsub!(/\\([\\#])/, '\1') node end
Removes this node from the tree if it's a silent comment.
visit_comment
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_error(node) res = node.expr.perform(@environment) if res.is_a?(Sass::Script::Value::String) res = res.value else res = res.to_sass end raise Sass::SyntaxError.new(res) end
Throws the expression as an error.
visit_error
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_each(node) list = node.list.perform(@environment) with_environment Sass::SemiGlobalEnvironment.new(@environment) do list.to_a.map do |value| if node.vars.length == 1 @environment.set_local_var(node.vars.first, value) else node.vars.zip(value.to_a) do |(var, sub_value)| @environment.set_local_var(var, sub_value || Sass::Script::Value::Null.new) end end node.children.map {|c| visit(c)} end.flatten end end
Runs the child nodes once for each value in the list.
visit_each
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_extend(node) parser = Sass::SCSS::StaticParser.new(run_interp(node.selector), node.filename, node.options[:importer], node.line) node.resolved_selector = parser.parse_selector node end
Runs SassScript interpolation in the selector, and then parses the result into a {Sass::Selector::CommaSequence}.
visit_extend
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_for(node) from = node.from.perform(@environment) to = node.to.perform(@environment) from.assert_int! to.assert_int! to = to.coerce(from.numerator_units, from.denominator_units) direction = from.to_i > to.to_i ? -1 : 1 range = Range.new(direction * from.to_i, direction * to.to_i, node.exclusive) with_environment Sass::SemiGlobalEnvironment.new(@environment) do range.map do |i| @environment.set_local_var(node.var, Sass::Script::Value::Number.new(direction * i, from.numerator_units, from.denominator_units)) node.children.map {|c| visit(c)} end.flatten end end
Runs the child nodes once for each time through the loop, varying the variable each time.
visit_for
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_function(node) env = Sass::Environment.new(@environment, node.options) if node.normalized_name == 'calc' || node.normalized_name == 'element' || node.name == 'expression' || node.name == 'url' @@function_name_deprecation.warn(node.filename, node.line, <<WARNING) Naming a function "#{node.name}" is disallowed and will be an error in future versions of Sass. This name conflicts with an existing CSS function with special parse rules. WARNING end @environment.set_local_function(node.name, Sass::Callable.new(node.name, node.args, node.splat, env, node.children, false, "function", :stylesheet)) [] end
Loads the function into the environment.
visit_function
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_if(node) if node.expr.nil? || node.expr.perform(@environment).to_bool with_environment Sass::SemiGlobalEnvironment.new(@environment) do node.children.map {|c| visit(c)} end.flatten elsif node.else visit(node.else) else [] end end
Runs the child nodes if the conditional expression is true; otherwise, tries the else nodes.
visit_if
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_import(node) if (path = node.css_import?) resolved_node = Sass::Tree::CssImportNode.resolved("url(#{path})") resolved_node.options = node.options resolved_node.source_range = node.source_range return resolved_node end file = node.imported_file if @environment.stack.frames.any? {|f| f.is_import? && f.filename == file.options[:filename]} handle_import_loop!(node) end begin @environment.stack.with_import(node.filename, node.line) do root = file.to_tree Sass::Tree::Visitors::CheckNesting.visit(root) node.children = root.children.map {|c| visit(c)}.flatten node end rescue Sass::SyntaxError => e e.modify_backtrace(:filename => node.imported_file.options[:filename]) e.add_backtrace(:filename => node.filename, :line => node.line) raise e end end
Returns a static DirectiveNode if this is importing a CSS file, or parses and includes the imported Sass file.
visit_import
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_prop(node) node.resolved_name = run_interp(node.name) # If the node's value is just a variable or similar, we may get a useful # source range from evaluating it. if node.value.length == 1 && node.value.first.is_a?(Sass::Script::Tree::Node) result = node.value.first.perform(@environment) node.resolved_value = result.to_s node.value_source_range = result.source_range if result.source_range elsif node.custom_property? node.resolved_value = run_interp_no_strip(node.value) else node.resolved_value = run_interp(node.value) end yield end
Runs any SassScript that may be embedded in a property.
visit_prop
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_return(node) throw :_sass_return, node.expr.perform(@environment) end
Returns the value of the expression.
visit_return
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_rule(node) old_at_root_without_rule = @at_root_without_rule parser = Sass::SCSS::StaticParser.new(run_interp(node.rule), node.filename, node.options[:importer], node.line) if @in_keyframes keyframe_rule_node = Sass::Tree::KeyframeRuleNode.new(parser.parse_keyframes_selector) keyframe_rule_node.options = node.options keyframe_rule_node.line = node.line keyframe_rule_node.filename = node.filename keyframe_rule_node.source_range = node.source_range keyframe_rule_node.has_children = node.has_children with_environment Sass::Environment.new(@environment, node.options) do keyframe_rule_node.children = node.children.map {|c| visit(c)}.flatten end keyframe_rule_node else @at_root_without_rule = false node.parsed_rules ||= parser.parse_selector node.resolved_rules = node.parsed_rules.resolve_parent_refs( @environment.selector, !old_at_root_without_rule) node.stack_trace = @environment.stack.to_s if node.options[:trace_selectors] with_environment Sass::Environment.new(@environment, node.options) do @environment.selector = node.resolved_rules node.children = node.children.map {|c| visit(c)}.flatten end node end ensure @at_root_without_rule = old_at_root_without_rule end
Runs SassScript interpolation in the selector, and then parses the result into a {Sass::Selector::CommaSequence}.
visit_rule
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_atroot(node) if node.query parser = Sass::SCSS::StaticParser.new(run_interp(node.query), node.filename, node.options[:importer], node.line) node.resolved_type, node.resolved_value = parser.parse_static_at_root_query else node.resolved_type, node.resolved_value = :without, ['rule'] end old_at_root_without_rule = @at_root_without_rule old_in_keyframes = @in_keyframes @at_root_without_rule = true if node.exclude?('rule') @in_keyframes = false if node.exclude?('keyframes') yield ensure @in_keyframes = old_in_keyframes @at_root_without_rule = old_at_root_without_rule end
Sets a variable that indicates that the first level of rule nodes shouldn't include the parent selector by default.
visit_atroot
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_variable(node) env = @environment env = env.global_env if node.global if node.guarded var = env.var(node.name) return [] if var && !var.null? end val = node.expr.perform(@environment) if node.expr.source_range val.source_range = node.expr.source_range else val.source_range = node.source_range end env.set_var(node.name, val) [] end
Loads the new variable value into the environment.
visit_variable
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_warn(node) res = node.expr.perform(@environment) res = res.value if res.is_a?(Sass::Script::Value::String) @environment.stack.with_directive(node.filename, node.line, "@warn") do msg = "WARNING: #{res}\n " msg << @environment.stack.to_s.gsub("\n", "\n ") << "\n" Sass::Util.sass_warn msg end [] end
Prints the expression to STDERR with a stylesheet trace.
visit_warn
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def visit_while(node) children = [] with_environment Sass::SemiGlobalEnvironment.new(@environment) do children += node.children.map {|c| visit(c)} while node.expr.perform(@environment).to_bool end children.flatten end
Runs the child nodes until the continuation expression becomes false.
visit_while
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb
Apache-2.0
def initialize(build_source_mapping = false) @tabs = 0 @line = 1 @offset = 1 @result = String.new("") @source_mapping = build_source_mapping ? Sass::Source::Map.new : nil @lstrip = nil @in_directive = false end
@param build_source_mapping [Boolean] Whether to build a \{Sass::Source::Map} while creating the CSS output. The mapping will be available from \{#source\_mapping} after the visitor has completed.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
Apache-2.0
def visit(node) super rescue Sass::SyntaxError => e e.modify_backtrace(:filename => node.filename, :line => node.line) raise e end
Runs the visitor on `node`. @param node [Sass::Tree::Node] The root node of the tree to convert to CSS> @return [String] The CSS output.
visit
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
Apache-2.0
def for_node(node, attr_prefix = nil) return yield unless @source_mapping start_pos = Sass::Source::Position.new(@line, @offset) yield range_attr = attr_prefix ? :"#{attr_prefix}_source_range" : :source_range return if node.invisible? || !node.send(range_attr) source_range = node.send(range_attr) target_end_pos = Sass::Source::Position.new(@line, @offset) target_range = Sass::Source::Range.new(start_pos, target_end_pos, nil) @source_mapping.add(source_range, target_range) end
Associate all output produced in a block with a given node. Used for source mapping.
for_node
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
Apache-2.0
def erase!(chars) return if chars == 0 str = @result.slice!(-chars..-1) newlines = str.count("\n") if newlines > 0 @line -= newlines @offset = @result[@result.rindex("\n") || 0..-1].size else @offset -= chars end end
Move the output cursor back `chars` characters.
erase!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
Apache-2.0
def output(s) if @lstrip s = s.gsub(/\A\s+/, "") @lstrip = false end newlines = s.count(NEWLINE) if newlines > 0 @line += newlines @offset = s[s.rindex(NEWLINE)..-1].size else @offset += s.size end @result << s end
Add `s` to the output string and update the line and offset information accordingly.
output
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
Apache-2.0
def rstrip! erase! @result.length - 1 - (@result.rindex(/[^\s]/) || -1) end
Strip all trailing whitespace from the output string.
rstrip!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
Apache-2.0
def lstrip old_lstrip = @lstrip @lstrip = true yield ensure @lstrip &&= old_lstrip end
lstrip the first output in the given block.
lstrip
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
Apache-2.0
def prepend!(prefix) @result.insert 0, prefix return unless @source_mapping line_delta = prefix.count("\n") offset_delta = prefix.gsub(/.*\n/, '').size @source_mapping.shift_output_offsets(offset_delta) @source_mapping.shift_output_lines(line_delta) end
Prepend `prefix` to the output string.
prepend!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
Apache-2.0
def format_custom_property_value(node) value = node.resolved_value.sub(/\n[ \t\r\f\n]*\Z/, ' ') if node.style == :compact || node.style == :compressed || !value.include?("\n") # Folding not involving newlines was done in the parser. We can safely # fold newlines here because tokens like strings can't contain literal # newlines, so we know any adjacent whitespace is tokenized as whitespace. return node.resolved_value.gsub(/[ \t\r\f]*\n[ \t\r\f\n]*/, ' ') end # Find the smallest amount of indentation in the custom property and use # that as the base indentation level. lines = value.split("\n") indented_lines = lines[1..-1] min_indentation = indented_lines. map {|line| line[/^[ \t]*/]}. reject {|line| line.empty?}. min_by {|line| line.length} # Limit the base indentation to the same indentation level as the node name # so that if *every* line is indented relative to the property name that's # preserved. if node.name_source_range base_indentation = min_indentation[0...node.name_source_range.start_pos.offset - 1] end lines.first + "\n" + indented_lines.join("\n").gsub(/^#{base_indentation}/, ' ' * @tabs) end
Reformats the value of `node` so that it's nicely indented, preserving its existing relative indentation. @param node [Sass::Script::Tree::PropNode] A custom property node. @return [String]
format_custom_property_value
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/tree/visitors/to_css.rb
Apache-2.0
def normalize(key) key.tr("-", "_") end
Specifies how to transform the key. This can be overridden to create other normalization behaviors.
normalize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util/normalized_map.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util/normalized_map.rb
Apache-2.0
def denormalize(key) @key_strings[normalize(key)] || key end
Returns the version of `key` as it was stored before normalization. If `key` isn't in the map, returns it as it was passed in. @return [String]
denormalize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util/normalized_map.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util/normalized_map.rb
Apache-2.0
def as_stored Sass::Util.map_keys(@map) {|k| @key_strings[k]} end
@return [Hash] Hash with the keys as they were stored (before normalization).
as_stored
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util/normalized_map.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util/normalized_map.rb
Apache-2.0
def get(set) res = set.map do |k| subsets = @hash[k] next unless subsets subsets.map do |subenum, subset, index| next unless subset.subset?(set) [index, subenum] end end.flatten(1) res.compact! res.uniq! res.sort! res.map! {|i, s| [@vals[i], s]} res end
Returns all values associated with subsets of `set`. In the worst case, this runs in `O(m*max(n, log m))` time, where `n` is the size of `set` and `m` is the number of associations in the map. However, unless many keys in the map overlap with `set`, `m` will typically be much smaller. @param set [Set] The set to use as the map key. @return [Array<(Object, #to_set)>] An array of pairs, where the first value is the value associated with a subset of `set`, and the second value is that subset of `set` (or whatever `#to_set` object was used to set the value) This array is in insertion order. @see #[]
get
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util/subset_map.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util/subset_map.rb
Apache-2.0
def each_value @vals.each {|v| yield v} end
Iterates over each value in the subset map. Ignores keys completely. If multiple keys have the same value, this will return them multiple times. @yield [Object] Each value in the map.
each_value
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util/subset_map.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util/subset_map.rb
Apache-2.0
def to(*args, &block) @listeners ||= [] Listener.new(*args, &block).tap do |listener| @listeners << listener end end
Listens to file system modifications on a either single directory or multiple directories. @param (see SassListen::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 [SassListen::Listener] the listener
to
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen.rb
Apache-2.0
def stop Internals::ThreadPool.stop @listeners ||= [] # TODO: should use a mutex for this @listeners.each do |listener| # call stop to halt the main loop listener.stop end @listeners = nil end
This is used by the `listen` binary to handle Ctrl-C
stop
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-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) SassListen::Logger.debug { "(silenced): #{rel_path.inspect}" } return end path = watched_dir + rel_path SassListen::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) else if type == :dir # NOTE: POSSIBLE RECURSION # TODO: fix - use a queue instead Directory.scan(self, rel_path, options) else change = File.change(record, rel_path) return if !change || options[:silence] config.queue(:file, change, watched_dir, rel_path) end end rescue RuntimeError => ex msg = format( '%s#%s crashed %s:%s', self.class, __method__, exinspect, ex.backtrace * "\n") SassListen::Logger.error(msg) raise end
Invalidate some part of the snapshot/record (dir, file, subtree, etc.)
invalidate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/change.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/change.rb
Apache-2.0
def default_state(new_default = nil) if new_default @default_state = new_default.to_sym else defined?(@default_state) ? @default_state : DEFAULT_STATE end end
Obtain or set the default state Passing a state name sets the default state
default_state
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/fsm.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/fsm.rb
Apache-2.0
def states @states ||= {} end
Obtain the valid states for this FSM
states
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/fsm.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/fsm.rb
Apache-2.0
def state(*args, &block) if args.last.is_a? Hash # Stringify keys :/ options = args.pop.each_with_object({}) { |(k, v), h| h[k.to_s] = v } else options = {} end args.each do |name| name = name.to_sym default_state name if options['default'] states[name] = State.new(name, options['to'], &block) end end
Declare an FSM state and optionally provide a callback block to fire Options: * to: a state or array of states this state can transition to
state
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/fsm.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/fsm.rb
Apache-2.0
def initialize @state = self.class.default_state end
Be kind and call super if you must redefine initialize
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/fsm.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/fsm.rb
Apache-2.0
def transition!(state_name) @state = state_name end
Immediate state transition with no checks, or callbacks. "Dangerous!"
transition!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/fsm.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-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) { @processor.wakeup_on_event } 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) super() # FSM end
Initializes the directories listener. @param [String] directory the directories to listen to @param [Hash] options the listen options (see SassListen::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
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/listener.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/listener.rb
Apache-2.0
def start transition :backend_started if state == :initializing transition :frontend_ready if state == :backend_started transition :processing_events if state == :frontend_ready transition :processing_events if state == :paused end
Starts processing events and starts adapters or resumes invoking callbacks if paused
start
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/listener.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-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/sass-listen-4.0.0/lib/sass-listen/listener.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-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/sass-listen-4.0.0/lib/sass-listen/listener.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/listener.rb
Apache-2.0
def _reinterpret_related_changes(cookies) table = { moved_to: :added, moved_from: :removed } cookies.map do |_, changes| data = _detect_possible_editor_save(changes) if data to_dir, to_file = data [[:modified, to_dir, to_file]] 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.flatten(1) 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/sass-listen-4.0.0/lib/sass-listen/queue_optimizer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/queue_optimizer.rb
Apache-2.0
def configure if @configured _log(: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) snapshot = Change.new(change_config, record) @snapshots[dir] = snapshot end end
TODO: it's a separate method as a temporary workaround for tests
configure
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/adapter/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-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/sass-listen-4.0.0/lib/sass-listen/adapter/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/adapter/base.rb
Apache-2.0
def _configure(dir, &callback) opts = { latency: options.latency } @workers ||= ::Queue.new @workers << FSEvent.new.tap do |worker| _log :debug, "fsevent: watching: #{dir.to_s.inspect}" worker.watch(dir.to_s, opts, &callback) end end
NOTE: each directory gets a DIFFERENT callback!
_configure
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/adapter/darwin.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/adapter/darwin.rb
Apache-2.0
def loop_for(latency) @latency = latency loop do _wait_until_events _wait_until_events_calm_down _wait_until_no_longer_paused _process_changes end rescue Stopped SassListen::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/sass-listen-4.0.0/lib/sass-listen/event/processor.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/event/processor.rb
Apache-2.0
def _process_changes _reset_no_unprocessed_events changes = [] changes << config.event_queue.pop until config.event_queue.empty? callable = config.callable? return unless callable hash = config.optimize_changes(changes) result = [hash[:modified], hash[:added], hash[:removed]] return if result.all?(&:empty?) block_start = _timestamp config.call(*result) SassListen::Logger.debug "Callback took #{_timestamp - block_start} sec" end
for easier testing without sleep loop
_process_changes
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/event/processor.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/event/processor.rb
Apache-2.0
def initialize(root, relative, name = nil) @root, @relative, @name = root, relative, 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/sass-listen-4.0.0/lib/sass-listen/record/entry.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-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/sass-listen-4.0.0/lib/sass-listen/record/entry.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/record/entry.rb
Apache-2.0
def initialize(endpoint, options = nil) @endpoint = endpoint @conn = (options && options[:faraday]) || Faraday.new @serializer = (options && options[:serializer]) || self.class.serializer @links_parser = (options && options[:links_parser]) || Sawyer::LinkParsers::Hal.new @allow_undefined_methods = (options && options[:allow_undefined_methods]) @conn.url_prefix = @endpoint yield @conn if block_given? end
Agents handle making the requests, and passing responses to Sawyer::Response. endpoint - String URI of the API entry point. options - Hash of options. :allow_undefined_methods - Allow relations to call all the HTTP verbs, not just the ones defined. :faraday - Optional Faraday::Connection to use. :links_parser - Optional parser to parse link relations Defaults: Sawyer::LinkParsers::Hal.new :serializer - Optional serializer Class. Defaults to self.serializer_class. Yields the Faraday::Connection if a block is given.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/agent.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/agent.rb
Apache-2.0
def rels @rels ||= root.data._rels end
Public: Retains a reference to the root relations of the API. Returns a Sawyer::Relation::Map.
rels
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/agent.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/agent.rb
Apache-2.0
def root @root ||= start end
Public: Retains a reference to the root response of the API. Returns a Sawyer::Response.
root
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/agent.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/agent.rb
Apache-2.0
def start call :get, @endpoint end
Public: Hits the root of the API to get the initial actions. Returns a Sawyer::Response.
start
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/agent.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/agent.rb
Apache-2.0
def call(method, url, data = nil, options = nil) if NO_BODY.include?(method) options ||= data data = nil end options ||= {} url = expand_url(url, options[:uri]) started = nil res = @conn.send method, url do |req| if data req.body = data.is_a?(String) ? data : encode_body(data) end if params = options[:query] req.params.update params end if headers = options[:headers] req.headers.update headers end started = Time.now end Response.new self, res, :sawyer_started => started, :sawyer_ended => Time.now end
Makes a request through Faraday. method - The Symbol name of an HTTP method. url - The String URL to access. This can be relative to the Agent's endpoint. data - The Optional Hash or Resource body to be sent. :get or :head requests can have no body, so this can be the options Hash instead. options - Hash of option to configure the API request. :headers - Hash of API headers to set. :query - Hash of URL query params to set. Returns a Sawyer::Response.
call
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/agent.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/agent.rb
Apache-2.0
def initialize @map = {} end
Tracks the available next actions for a resource, and issues requests for them.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
Apache-2.0
def initialize(agent, name, href, method = nil) @agent = agent @name = name.to_sym @href = href @href_template = Addressable::Template.new(href.to_s) methods = nil if method.is_a? String if method.size.zero? method = nil else method.downcase! methods = method.split(',').map! do |m| m.strip! m.to_sym end method = methods.first end end @method = (method || :get).to_sym @available_methods = Set.new methods || [@method] end
A Relation represents an available next action for a resource. agent - The Sawyer::Agent that made the request. name - The Symbol name of the relation. href - The String URL of the location of the next action. method - The Symbol HTTP method. Default: :get
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
Apache-2.0
def head(options = nil) options ||= {} options[:method] = :head call options end
Public: Makes an API request with the curent Relation using HEAD. data - The Optional Hash or Resource body to be sent. :get or :head requests can have no body, so this can be the options Hash instead. options - Hash of option to configure the API request. :headers - Hash of API headers to set. :query - Hash of URL query params to set. :method - Symbol HTTP method. Returns a Sawyer::Response.
head
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
Apache-2.0
def get(options = nil) options ||= {} options[:method] = :get call options end
Public: Makes an API request with the curent Relation using GET. data - The Optional Hash or Resource body to be sent. :get or :head requests can have no body, so this can be the options Hash instead. options - Hash of option to configure the API request. :headers - Hash of API headers to set. :query - Hash of URL query params to set. :method - Symbol HTTP method. Returns a Sawyer::Response.
get
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
Apache-2.0
def post(data = nil, options = nil) options ||= {} options[:method] = :post call data, options end
Public: Makes an API request with the curent Relation using POST. data - The Optional Hash or Resource body to be sent. options - Hash of option to configure the API request. :headers - Hash of API headers to set. :query - Hash of URL query params to set. :method - Symbol HTTP method. Returns a Sawyer::Response.
post
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
Apache-2.0
def put(data = nil, options = nil) options ||= {} options[:method] = :put call data, options end
Public: Makes an API request with the curent Relation using PUT. data - The Optional Hash or Resource body to be sent. options - Hash of option to configure the API request. :headers - Hash of API headers to set. :query - Hash of URL query params to set. :method - Symbol HTTP method. Returns a Sawyer::Response.
put
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
Apache-2.0
def patch(data = nil, options = nil) options ||= {} options[:method] = :patch call data, options end
Public: Makes an API request with the curent Relation using PATCH. data - The Optional Hash or Resource body to be sent. options - Hash of option to configure the API request. :headers - Hash of API headers to set. :query - Hash of URL query params to set. :method - Symbol HTTP method. Returns a Sawyer::Response.
patch
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
Apache-2.0
def delete(data = nil, options = nil) options ||= {} options[:method] = :delete call data, options end
Public: Makes an API request with the curent Relation using DELETE. data - The Optional Hash or Resource body to be sent. options - Hash of option to configure the API request. :headers - Hash of API headers to set. :query - Hash of URL query params to set. :method - Symbol HTTP method. Returns a Sawyer::Response.
delete
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
Apache-2.0
def options(data = nil, opt = nil) opt ||= {} opt[:method] = :options call data, opt end
Public: Makes an API request with the curent Relation using OPTIONS. data - The Optional Hash or Resource body to be sent. options - Hash of option to configure the API request. :headers - Hash of API headers to set. :query - Hash of URL query params to set. :method - Symbol HTTP method. Returns a Sawyer::Response.
options
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
Apache-2.0
def call(data = nil, options = nil) m = options && options[:method] if m && [email protected]_undefined_methods? && !@available_methods.include?(m == :head ? :get : m) raise ArgumentError, "method #{m.inspect} is not available: #{@available_methods.to_a.inspect}" end @agent.call m || @method, @href_template, data, options end
Public: Makes an API request with the curent Relation. data - The Optional Hash or Resource body to be sent. :get or :head requests can have no body, so this can be the options Hash instead. options - Hash of option to configure the API request. :headers - Hash of API headers to set. :query - Hash of URL query params to set. :method - Symbol HTTP method. Raises ArgumentError if the :method value is not in @available_methods. Returns a Sawyer::Response.
call
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/relation.rb
Apache-2.0
def initialize(agent, data = {}) @_agent = agent data, links = agent.parse_links(data) @_rels = Relation.from_links(agent, links) @_fields = Set.new @_metaclass = (class << self; self; end) @attrs = {} data.each do |key, value| @_fields << key @attrs[key.to_sym] = process_value(value) end @_metaclass.send(:attr_accessor, *data.keys) end
Initializes a Resource with the given data. agent - The Sawyer::Agent that made the API request. data - Hash of key/value properties.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/resource.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/resource.rb
Apache-2.0
def process_value(value) case value when Hash then self.class.new(@_agent, value) when Array then value.map { |v| process_value(v) } else value end end
Processes an individual value of this resource. Hashes get exploded into another Resource, and Arrays get their values processed too. value - An Object value of a Resource's data. Returns an Object to set as the value of a Resource key.
process_value
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/resource.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/resource.rb
Apache-2.0
def key?(key) @_fields.include? key end
Checks to see if the given key is in this resource. key - A Symbol key. Returns true if the key exists, or false.
key?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/resource.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/resource.rb
Apache-2.0
def initialize(agent, res, options = {}) @agent = agent @status = res.status @headers = res.headers @env = res.env @body = res.body @rels = process_rels @started = options[:sawyer_started] @ended = options[:sawyer_ended] end
Builds a Response after a completed request. agent - The Sawyer::Agent that is managing the API connection. res - A Faraday::Response.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/response.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/response.rb
Apache-2.0
def process_data(data) case data when Hash then Resource.new(agent, data) when Array then data.map { |hash| process_data(hash) } when nil then nil else data end end
Turns parsed contents from an API response into a Resource or collection of Resources. data - Either an Array or Hash parsed from JSON. Returns either a Resource or Array of Resources.
process_data
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/response.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/response.rb
Apache-2.0
def process_rels links = ( @headers["Link"] || "" ).split(', ').map do |link| href, name = link.match(/<(.*?)>; rel="(\w+)"/).captures [name.to_sym, Relation.from_link(@agent, name, :href => href)] end Hash[*links.flatten] end
Finds link relations from 'Link' response header Returns an array of Relations
process_rels
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/response.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/response.rb
Apache-2.0
def initialize(format, dump_method_name = nil, load_method_name = nil) @format = format @dump = @format.method(dump_method_name || :dump) @load = @format.method(load_method_name || :load) end
Public: Wraps a serialization format for Sawyer. Nested objects are prepared for serialization (such as changing Times to ISO 8601 Strings). Any serialization format that responds to #dump and #load will work.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/serializer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/serializer.rb
Apache-2.0
def decode(data) return nil if data.nil? || data.strip.empty? decode_object(@load.call(data)) end
Public: Decodes a String into an Object (usually a Hash or Array of Hashes). data - An encoded String. Returns a decoded Object.
decode
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/serializer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/serializer.rb
Apache-2.0
def parse(data) links = {} inline_links = data.keys.select {|k| k.to_s[LINK_REGEX] } inline_links.each do |key| rel_name = key.to_s == 'url' ? 'self' : key.to_s.gsub(LINK_REGEX, '') links[rel_name.to_sym] = data[key] end return data, links end
Public: Parses simple *_url style links on resources data - Hash of resource data Returns a Hash of data with separate links Hash
parse
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/link_parsers/simple.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sawyer-0.9.2/lib/sawyer/link_parsers/simple.rb
Apache-2.0
def decode_digit(cp) cp - 48 < 10 ? cp - 22 : cp - 65 < 26 ? cp - 65 : cp - 97 < 26 ? cp - 97 : BASE end
decode_digit(cp) returns the numeric value of a basic code point (for use in representing integers) in the range 0 to base-1, or base if cp is does not represent a value.
decode_digit
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/simpleidn-0.2.1/lib/simpleidn.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/simpleidn-0.2.1/lib/simpleidn.rb
Apache-2.0
def encode_digit(d) d + 22 + 75 * (d < 26 ? 1 : 0) # 0..25 map to ASCII a..z # 26..35 map to ASCII 0..9 end
encode_digit(d) returns the basic code point whose value (when used for representing integers) is d, which needs to be in the range 0 to base-1.
encode_digit
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/simpleidn-0.2.1/lib/simpleidn.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/simpleidn-0.2.1/lib/simpleidn.rb
Apache-2.0
def uts46map(str, transitional = false) mapped = str.codepoints.map { |cp| UTS64MAPPING.fetch(cp, cp) } mapped = mapped.map { |cp| TRANSITIONAL.fetch(cp, cp) } if transitional mapped = mapped.flatten.map { |cp| cp.chr(Encoding::UTF_8) }.join(EMPTY) mapped.to_nfc end
Applies UTS46 mapping to a Unicode string Returns a UTF-8 string in Normalization Form C (NFC)
uts46map
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/simpleidn-0.2.1/lib/simpleidn.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/simpleidn-0.2.1/lib/simpleidn.rb
Apache-2.0
def value_for_column_width_recalc lines.map{ |s| escape(s) }.max_by{ |s| Unicode::DisplayWidth.of(s) } end
# Returns the longest line in the cell and removes all ANSI escape sequences (e.g. color)
value_for_column_width_recalc
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/cell.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/cell.rb
Apache-2.0
def width padding = (colspan - 1) * @table.cell_spacing inner_width = (1..@colspan).to_a.inject(0) do |w, counter| w + @table.column_width(@index + counter - 1) end inner_width + padding end
# Returns the width of this cell
width
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/cell.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/cell.rb
Apache-2.0
def escape(line) line.to_s.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, ''). gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, ''). gsub(/(\x03|\x1a)/, '') end
# removes all ANSI escape sequences (e.g. color)
escape
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/cell.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/cell.rb
Apache-2.0
def initialize options = {}, &block @headings = [] @rows = [] @column_widths = [] self.style = options.fetch :style, {} self.headings = options.fetch :headings, [] self.rows = options.fetch :rows, [] self.title = options.fetch :title, nil yield_or_eval(&block) if block style.on_change(:width) { require_column_widths_recalc } end
# Generates a ASCII table with the given _options_.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/table.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/table.rb
Apache-2.0
def align_column n, alignment r = rows column(n).each_with_index do |col, i| cell = r[i][n] cell.alignment = alignment unless cell.alignment? end end
# Align column _n_ to the given _alignment_ of :center, :left, or :right.
align_column
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/table.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/table.rb
Apache-2.0
def number_of_columns headings_with_rows.map { |r| r.number_of_columns }.max || 0 end
# Return total number of columns available.
number_of_columns
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/table.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/terminal-table-1.8.0/lib/terminal-table/table.rb
Apache-2.0
def update_params(req, k, v) found = false if req.GET.has_key?(k) found = true req.GET[k] = v end if req.POST.has_key?(k) found = true req.POST[k] = v end unless found req.GET[k] = v end end
Persist params change in environment. Extracted from: https://github.com/rack/rack/blob/master/lib/rack/request.rb#L243
update_params
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
Apache-2.0
def decode!(hash) return hash unless hash.is_a?(Hash) hash.each_pair do |key,value| if value.is_a?(Hash) decode!(value) hash[key] = convert(value) end end hash end
Recursively decodes Typhoeus encoded arrays in given Hash. @param hash [Hash]. This Hash will be modified! @return [Hash] Hash with properly decoded nested arrays.
decode!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder/helper.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder/helper.rb
Apache-2.0
def encoded?(hash) return false if hash.empty? if hash.keys.size > 1 keys = hash.keys.map{|i| i.to_i if i.respond_to?(:to_i)}.sort keys == hash.keys.size.times.to_a else hash.keys.first =~ /0/ end end
Checks if Hash is an Array encoded as a Hash. Specifically will check for the Hash to have this form: {'0' => v0, '1' => v1, .., 'n' => vN } @param hash [Hash] @return [Boolean] True if its a encoded Array, else false.
encoded?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder/helper.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder/helper.rb
Apache-2.0
def convert(hash) if encoded?(hash) hash.sort{ |a, b| a[0].to_i <=> b[0].to_i }.map{ |key, value| value } else hash end end
If the Hash is an array encoded by typhoeus an array is returned else the self is returned @param hash [Hash] The Hash to convert into an Array. @return [Arraya/Hash]
convert
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder/helper.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder/helper.rb
Apache-2.0
def initialize(request, hydra = nil) @request = request @hydra = hydra end
Create an easy factory. @example Create easy factory. Typhoeus::Hydra::EasyFactory.new(request, hydra) @param [ Request ] request The request to build an easy for. @param [ Hydra ] hydra The hydra to build an easy for.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/easy_factory.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/easy_factory.rb
Apache-2.0
def easy @easy ||= Typhoeus::Pool.get end
Return the easy in question. @example Return easy. easy_factory.easy @return [ Ethon::Easy ] The easy.
easy
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/easy_factory.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/easy_factory.rb
Apache-2.0
def get begin easy.http_request( request.base_url.to_s, request.options.fetch(:method, :get), sanitize(request.options) ) rescue Ethon::Errors::InvalidOption => e help = provide_help(e.message.match(/:\s(\w+)/)[1]) raise $!, "#{$!}#{help}", $!.backtrace end set_callback easy end
Fabricated easy. @example Prepared easy. easy_factory.get @return [ Ethon::Easy ] The easy.
get
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/easy_factory.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/easy_factory.rb
Apache-2.0
def set_callback if request.streaming? response = nil easy.on_headers do |easy| response = Response.new(Ethon::Easy::Mirror.from_easy(easy).options) request.execute_headers_callbacks(response) end request.on_body.each do |callback| easy.on_body do |chunk, easy| callback.call(chunk, response) end end else easy.on_headers do |easy| request.execute_headers_callbacks(Response.new(Ethon::Easy::Mirror.from_easy(easy).options)) end end request.on_progress.each do |callback| easy.on_progress do |dltotal, dlnow, ultotal, ulnow, easy| callback.call(dltotal, dlnow, ultotal, ulnow, response) end end easy.on_complete do |easy| request.finish(Response.new(easy.mirror.options)) Typhoeus::Pool.release(easy) if hydra && !hydra.queued_requests.empty? hydra.dequeue_many end end end
Sets on_complete callback on easy in order to be able to track progress. @example Set callback. easy_factory.set_callback @return [ Ethon::Easy ] The easy.
set_callback
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/easy_factory.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/easy_factory.rb
Apache-2.0
def all @expectations ||= [] end
Returns all expectations. @example Return expectations. Typhoeus::Expectation.all @return [ Array<Typhoeus::Expectation> ] The expectations.
all
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/expectation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/expectation.rb
Apache-2.0
def response_for(request) expectation = find_by(request) return nil if expectation.nil? expectation.response(request) end
Returns stubbed response matching the provided request. @example Find response Typhoeus::Expectation.response_for(request) @return [ Typhoeus::Response ] The stubbed response from a matching expectation, or nil if no matching expectation is found. @api private
response_for
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/expectation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/expectation.rb
Apache-2.0
def initialize(base_url, options = {}) @base_url = base_url @options = options @response_counter = 0 @from = nil end
Creates an expectation. @example Create expectation. Typhoeus::Expectation.new(base_url) @return [ Expectation ] The created expectation. @api private
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/expectation.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus/expectation.rb
Apache-2.0