Class: ActiveData::Model::Attributes::Reflections::Attribute

Inherits:
Base
  • Object
show all
Defined in:
lib/active_data/model/attributes/reflections/attribute.rb

Direct Known Subclasses

Collection, Dictionary, Localized, Represents

Instance Attribute Summary

Attributes inherited from Base

#name, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attribute_class, #build_attribute, #initialize, #inspect_reflection, #readonly, #type, #typecaster

Constructor Details

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

Class Method Details

.build(target, generated_methods, name, *args, &block) ⇒ Object



6
7
8
9
10
# File 'lib/active_data/model/attributes/reflections/attribute.rb', line 6

def self.build(target, generated_methods, name, *args, &block)
  attribute = super(target, generated_methods, name, *args, &block)
  generate_methods name, generated_methods
  attribute
end

.generate_methods(name, target) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_data/model/attributes/reflections/attribute.rb', line 12

def self.generate_methods(name, target)
  target.class_eval "    def \#{name}\n      attribute('\#{name}').read\n    end\n\n    def \#{name}= value\n      attribute('\#{name}').write(value)\n    end\n\n    def \#{name}?\n      attribute('\#{name}').query\n    end\n\n    def \#{name}_before_type_cast\n      attribute('\#{name}').read_before_type_cast\n    end\n\n    def \#{name}_came_from_user?\n      attribute('\#{name}').came_from_user?\n    end\n\n    def \#{name}_default\n      attribute('\#{name}').default\n    end\n\n    def \#{name}_values\n      attribute('\#{name}').enum.to_a\n    end\n  RUBY\nend\n", __FILE__, __LINE__ + 1

Instance Method Details

#defaultizerObject



44
45
46
# File 'lib/active_data/model/attributes/reflections/attribute.rb', line 44

def defaultizer
  @defaultizer ||= options[:default]
end

#enumerizerObject



48
49
50
# File 'lib/active_data/model/attributes/reflections/attribute.rb', line 48

def enumerizer
  @enumerizer ||= options[:enum] || options[:in]
end

#normalizersObject



52
53
54
# File 'lib/active_data/model/attributes/reflections/attribute.rb', line 52

def normalizers
  @normalizers ||= Array.wrap(options[:normalize] || options[:normalizer] || options[:normalizers])
end