Class: ActiveData::Model::Attributes::Represents

Inherits:
Attribute
  • Object
show all
Defined in:
lib/active_data/model/attributes/represents.rb

Instance Attribute Summary

Attributes inherited from Base

#name, #owner

Instance Method Summary collapse

Methods inherited from Attribute

#default, #defaultize, #enum, #enumerize, #normalize

Methods inherited from Base

#came_from_default?, #came_from_user?, #initialize, #inspect_attribute, #pollute, #query, #readonly?, #reflection, #typecast, #value_present?, #write_value

Constructor Details

This class inherits a constructor from ActiveData::Model::Attributes::Base

Instance Method Details

#readObject



20
21
22
23
24
25
# File 'lib/active_data/model/attributes/represents.rb', line 20

def read
  reset if cached_value != read_value
  variable_cache(:value) do
    normalize(enumerize(defaultize(cached_value, read_before_type_cast)))
  end
end

#read_before_type_castObject



27
28
29
30
31
32
# File 'lib/active_data/model/attributes/represents.rb', line 27

def read_before_type_cast
  reset if cached_value_before_type_cast != read_value_before_type_cast
  variable_cache(:value_before_type_cast) do
    defaultize(cached_value_before_type_cast)
  end
end

#resetObject



15
16
17
18
# File 'lib/active_data/model/attributes/represents.rb', line 15

def reset
  super
  remove_variable(:cached_value, :cached_value_before_type_cast)
end

#write(value) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/active_data/model/attributes/represents.rb', line 7

def write(value)
  return if readonly?
  pollute do
    reset
    reference.send(writer, value)
  end
end