Class: Swift::Attribute
- Inherits:
-
Object
- Object
- Swift::Attribute
- Defined in:
- lib/swift/attribute.rb
Overview
An attribute (column) definition. – NOTE: Default method is defined in the extension.
Direct Known Subclasses
Type::BigDecimal, Type::Boolean, Type::Date, Type::DateTime, Type::Float, Type::IO, Type::Integer, Type::String, Type::Time
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#serial ⇒ Object
readonly
Returns the value of attribute serial.
Instance Method Summary collapse
- #default ⇒ Object
-
#define_record_methods(record) ⇒ Object
Evals attribute accessors for this attribute into the record.
-
#initialize(record, name, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
-
#to_s ⇒ String
The attributes field.
Constructor Details
#initialize(record, name, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
23 24 25 26 27 28 29 30 |
# File 'lib/swift/attribute.rb', line 23 def initialize record, name, = {} @name = name @default = .fetch(:default, nil) @field = .fetch(:field, name).to_sym @key = .fetch(:key, false) @serial = .fetch(:serial, false) define_record_methods(record) end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
7 8 9 |
# File 'lib/swift/attribute.rb', line 7 def field @field end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/swift/attribute.rb', line 7 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/swift/attribute.rb', line 7 def name @name end |
#serial ⇒ Object (readonly)
Returns the value of attribute serial.
7 8 9 |
# File 'lib/swift/attribute.rb', line 7 def serial @serial end |
Instance Method Details
#default ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/swift/attribute.rb', line 32 def default case @default when Numeric, Symbol, true, false, nil @default when Proc @default.call else @default.dup end end |
#define_record_methods(record) ⇒ Object
Evals attribute accessors for this attribute into the record.
51 52 53 54 55 56 |
# File 'lib/swift/attribute.rb', line 51 def define_record_methods record record.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{name}; tuple.fetch(:#{field}, nil) end def #{name}= value; tuple.store(:#{field}, value) end RUBY end |
#to_s ⇒ String
The attributes field.
46 47 48 |
# File 'lib/swift/attribute.rb', line 46 def to_s field.to_s end |