Module: Spider::DataType
- Included in:
- Spider::DataTypes::Decimal, Spider::DataTypes::FilePath, Spider::DataTypes::PK, Spider::DataTypes::Password, Spider::DataTypes::SerializedMixin, Spider::DataTypes::SerializedObject, Spider::DataTypes::TimeSpan, Spider::DataTypes::UUID
- Defined in:
- lib/spiderfw/model/data_type.rb
Overview
The DataType module, if included by a Class, allows to use it as an element type in a Model. The Class must be a subclass of a base type (see Spider::Model.base_types), and allow to be initialized passing the superclass instance as the only parameter; or, it must define maps_to, and override the from_value method.
Extends the including class with ClassMethods.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#attributes ⇒ Object
Returns the DataType attributes, as set in the Model Element.
-
#format(format = :normal) ⇒ Object
This method may be overridden by subclasses and provide different textual representation for named formats.
-
#map(mapper_type) ⇒ Object
Returns a representation of the DataType for storing.
-
#new(val = nil) ⇒ Object
Returns a new instance of the datatype for the value passed, copying any set attributes.
-
#prepare ⇒ Object
Is called after an object has acquired the value and finished setting the attributes; should should alter the value according to the attributes.
Class Method Details
.included(klass) ⇒ Object
13 14 15 |
# File 'lib/spiderfw/model/data_type.rb', line 13 def self.included(klass) klass.extend(ClassMethods) end |
Instance Method Details
#attributes ⇒ Object
Returns the DataType attributes, as set in the Model Element. (See ClassMethods.take_attributes).
82 83 84 |
# File 'lib/spiderfw/model/data_type.rb', line 82 def attributes @attributes ||= {} end |
#format(format = :normal) ⇒ Object
This method may be overridden by subclasses and provide different textual representation for named formats. Possible formats are :normal, :short, :medium, :long, :full. The default implementation ignores the format and just calls to_s.
94 95 96 |
# File 'lib/spiderfw/model/data_type.rb', line 94 def format(format = :normal) self.to_s end |
#map(mapper_type) ⇒ Object
Returns a representation of the DataType for storing.
87 88 89 |
# File 'lib/spiderfw/model/data_type.rb', line 87 def map(mapper_type) self end |
#new(val = nil) ⇒ Object
Returns a new instance of the datatype for the value passed, copying any set attributes
105 106 107 108 109 |
# File 'lib/spiderfw/model/data_type.rb', line 105 def new(val=nil) dt = self.class.new(val) attributes.each{ |k, v| dt.attributes[k] = v } dt end |
#prepare ⇒ Object
Is called after an object has acquired the value and finished setting the attributes; should should alter the value according to the attributes.
100 101 102 |
# File 'lib/spiderfw/model/data_type.rb', line 100 def prepare self end |