Module: Proscenium::Utils

Defined in:
lib/proscenium/utils.rb

Class Method Summary collapse

Class Method Details

.digest(value) ⇒ String

Returns digest of the given value.

Parameters:

  • value (#to_s)

    The value to create the digest from. This will usually be a ‘Pathname`.

Returns:

  • (String)

    digest of the given value.



9
10
11
# File 'lib/proscenium/utils.rb', line 9

def digest(value)
  Digest::SHA1.hexdigest(value.to_s)[..7]
end

.merge_bang_attributes!(names, kw_attributes, allowed) ⇒ Object

Merges the given array of attribute ‘name`’s into the ‘kw_arguments`. A bang attribute is one that ends with an exclamation mark or - in Ruby parlance - a “bang”, and has a boolean value. Modifies the given `kw_attributes`, and only attribute names in `allowed` will be merged.

Example:

def tab(name, *args, href:, **attributes)
  Hue::Utils.merge_bang_attributes!(args, attributes, [:current])
end

Allowing you to use either of the following API’s:

tab 'Tab 1', required: true
tab 'Tab 1', :required!

Parameters:

  • names (Array(Symbol))

    of argument names

  • kw_attributes (Hash)

    attributes to be merged with

  • allowed (Array(Symbol))

    attribute names allowed to be merged as bang attributes



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/proscenium/utils.rb', line 32

def merge_bang_attributes!(names, kw_attributes, allowed)
  allowed.each do |name|
    sym_name = name.to_sym
    bang_name = :"#{sym_name}!"

    next unless names.include?(bang_name)

    names.delete(bang_name)

    # Keyword arguments should override the bang.
    kw_attributes[sym_name] = true unless kw_attributes.key?(sym_name)
  end
end