Module: Spider::DataType::ClassMethods
- Defined in:
- lib/spiderfw/model/data_type.rb
Instance Method Summary collapse
-
#auto?(element) ⇒ Boolean
Returns whether the given element is autogenerated.
-
#autogenerated ⇒ Object
Tells the class that this type generates the element’s value automatically.
-
#force_wrap? ⇒ Boolean
Returns whether values need to be wrapped in this DataType when they are set on models instances.
-
#from_value(value) ⇒ Object
This method will be called when instantiating the DataType from a base type.
-
#mapper_dependant ⇒ Object
Indicates that the actual type of this DataType depends on the mapper (e.g. PK).
-
#mapper_dependant? ⇒ Boolean
Returns whether this DataTypes is mapper dependant.
-
#maps_back_to(val = nil) ⇒ Object
Sets and/or returns a base type the DataType will be converted to when loaded by the Mapper.
-
#maps_to(val = nil) ⇒ Object
Sets and/or returns the base type the DataType is converted to by the Mapper when storing.
-
#set_element_attributes(attributes) ⇒ Object
Is called by the BaseModel when creating an element of this type.
-
#take_attributes(*list) ⇒ Object
Defines a list of Element attributes the DataType will use.
Instance Method Details
#auto?(element) ⇒ Boolean
Returns whether the given element is autogenerated
54 55 56 |
# File 'lib/spiderfw/model/data_type.rb', line 54 def auto?(element) @autogenerated && element.attributes[:auto] end |
#autogenerated ⇒ Object
Tells the class that this type generates the element’s value automatically
49 50 51 |
# File 'lib/spiderfw/model/data_type.rb', line 49 def autogenerated @autogenerated = true end |
#force_wrap? ⇒ Boolean
Returns whether values need to be wrapped in this DataType when they are set on models instances.
64 65 66 |
# File 'lib/spiderfw/model/data_type.rb', line 64 def force_wrap? true end |
#from_value(value) ⇒ Object
This method will be called when instantiating the DataType from a base type. The default implementation calls the DataType constructor passing it the value.
21 22 23 24 |
# File 'lib/spiderfw/model/data_type.rb', line 21 def from_value(value) return nil if value.nil? return self.new(value) end |
#mapper_dependant ⇒ Object
Indicates that the actual type of this DataType depends on the mapper (e.g. PK)
69 70 71 |
# File 'lib/spiderfw/model/data_type.rb', line 69 def mapper_dependant @mapper_dependant = true end |
#mapper_dependant? ⇒ Boolean
Returns whether this DataTypes is mapper dependant
74 75 76 |
# File 'lib/spiderfw/model/data_type.rb', line 74 def mapper_dependant? @mapper_dependant end |
#maps_back_to(val = nil) ⇒ Object
Sets and/or returns a base type the DataType will be converted to when loaded by the Mapper.
33 34 35 36 |
# File 'lib/spiderfw/model/data_type.rb', line 33 def maps_back_to(val=nil) @maps_back_to = val if val @maps_back_to end |
#maps_to(val = nil) ⇒ Object
Sets and/or returns the base type the DataType is converted to by the Mapper when storing.
27 28 29 30 |
# File 'lib/spiderfw/model/data_type.rb', line 27 def maps_to(val=nil) @maps_to = val if val @maps_to end |
#set_element_attributes(attributes) ⇒ Object
Is called by the BaseModel when creating an element of this type. Can modify the element’s attributes.
59 60 61 |
# File 'lib/spiderfw/model/data_type.rb', line 59 def set_element_attributes(attributes) attributes[:auto] = true if @autogenerated && attributes[:auto] != false end |
#take_attributes(*list) ⇒ Object
Defines a list of Element attributes the DataType will use. They will be available in the @attributes instance variable.
40 41 42 43 44 45 46 |
# File 'lib/spiderfw/model/data_type.rb', line 40 def take_attributes(*list) if (list && !list.empty?) @take_attributes = list else @take_attributes || [] end end |