Class: Endymion::FieldSpec
- Inherits:
-
Object
- Object
- Endymion::FieldSpec
- Defined in:
- lib/endymion/field_spec.rb
Instance Attribute Summary collapse
-
#db_name ⇒ Object
readonly
Returns the value of attribute db_name.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, opts = {}) ⇒ FieldSpec
constructor
A new instance of FieldSpec.
- #pack(value) ⇒ Object
- #unpack(value) ⇒ Object
Constructor Details
#initialize(name, opts = {}) ⇒ FieldSpec
Returns a new instance of FieldSpec.
8 9 10 11 12 13 14 15 16 |
# File 'lib/endymion/field_spec.rb', line 8 def initialize(name, opts={}) @name = name @default = opts[:default] @type = opts[:type] @packer = opts[:packer] @unpacker = opts[:unpacker] @db_name = opts[:db_name] ? Format.format_field(opts[:db_name]) : name @api = opts[:api] end |
Instance Attribute Details
#db_name ⇒ Object (readonly)
Returns the value of attribute db_name.
6 7 8 |
# File 'lib/endymion/field_spec.rb', line 6 def db_name @db_name end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/endymion/field_spec.rb', line 6 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/endymion/field_spec.rb', line 6 def name @name end |
Instance Method Details
#pack(value) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/endymion/field_spec.rb', line 18 def pack(value) if @packer && @packer.respond_to?(:call) @packer.call(value) elsif @type type_packer = @api.packer_for(@type) type_packer ? type_packer.call(value) : value else value end end |
#unpack(value) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/endymion/field_spec.rb', line 29 def unpack(value) if @unpacker && @unpacker.respond_to?(:call) @unpacker.call(value) elsif @type type_packer = @api.unpacker_for(@type) type_packer ? type_packer.call(value) : value else value end end |