Class: EnoughFields::Attributes

Inherits:
ActiveSupport::HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/enough_fields/attributes.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.klassObject

Returns the value of attribute klass.



4
5
6
# File 'lib/enough_fields/attributes.rb', line 4

def klass
  @klass
end

Class Method Details

.[](attributes) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/enough_fields/attributes.rb', line 11

def [](attributes)
  return super unless Thread.current[:monit_set]

  hash = super
  hash.each do |key, value|
    next if key.is_a?(Array) || [:_id, :_type].include?(key.to_sym)
    attribute_value = AttributeValue.new(value, @klass, key, caller.find_all { |c| c.index Rails.root })
    hash[ key ] = attribute_value
    Thread.current[:monit_set] << attribute_value
  end
  hash
end

.build(klass, attributes) ⇒ Object



6
7
8
9
# File 'lib/enough_fields/attributes.rb', line 6

def build(klass, attributes)
  @klass = klass
  self[attributes]
end

Instance Method Details

#[](key) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/enough_fields/attributes.rb', line 25

def [](key)
  return super unless Thread.current[:monit_set]

  if super && super.is_a?(AttributeValue)
    super.used = true
    super.to_value
  else
    super
  end
end