Class: Toggly::EntityContext

Inherits:
Struct
  • Object
show all
Defined in:
lib/toggly/entity_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes

Returns:

  • (Object)

    the current value of attributes



9
10
11
# File 'lib/toggly/entity_context.rb', line 9

def attributes
  @attributes
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



9
10
11
# File 'lib/toggly/entity_context.rb', line 9

def key
  @key
end

#kindObject

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



9
10
11
# File 'lib/toggly/entity_context.rb', line 9

def kind
  @kind
end

Instance Method Details

#attribute(name) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/toggly/entity_context.rb', line 10

def attribute(name)
  return nil unless attributes.is_a?(Hash)

  return attributes[name] if attributes.key?(name)
  return attributes[name.to_s] if attributes.key?(name.to_s)

  attributes.each { |k, v| return v if k.to_s.casecmp?(name.to_s) }
  nil
end

#attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/toggly/entity_context.rb', line 20

def attribute?(name)
  return false unless attributes.is_a?(Hash)

  attributes.key?(name) || attributes.key?(name.to_s) ||
    attributes.keys.any? { |k| k.to_s.casecmp?(name.to_s) }
end