Class: Swift::Attribute
- Inherits:
-
Object
- Object
- Swift::Attribute
- Defined in:
- lib/swift/attribute.rb,
ext/attribute.cc
Overview
– NOTE: Default method is defined in the extension.
Direct Known Subclasses
Type::BigDecimal, Type::Boolean, Type::Date, 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_scheme_methods(scheme) ⇒ Object
-
#initialize(scheme, name, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(scheme, name, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
7 8 9 10 11 12 13 14 |
# File 'lib/swift/attribute.rb', line 7 def initialize scheme, name, = {} @name = name @default = .fetch(:default, nil) @field = .fetch(:field, name) @key = .fetch(:key, false) @serial = .fetch(:serial, false) define_scheme_methods(scheme) end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
5 6 7 |
# File 'lib/swift/attribute.rb', line 5 def field @field end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/swift/attribute.rb', line 5 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/swift/attribute.rb', line 5 def name @name end |
#serial ⇒ Object (readonly)
Returns the value of attribute serial.
5 6 7 |
# File 'lib/swift/attribute.rb', line 5 def serial @serial end |
Instance Method Details
#default ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'ext/attribute.cc', line 5
VALUE attribute_default(VALUE self) {
VALUE value = rb_iv_get(self, "@default");
if (NIL_P(value) || rb_special_const_p(value))
return value;
else if (rb_respond_to(value, fcall))
return rb_funcall(value, fcall, 0);
else
return rb_obj_dup(value);
}
|
#define_scheme_methods(scheme) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/swift/attribute.rb', line 16 def define_scheme_methods scheme scheme.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{name}; tuple.fetch(:#{field}, nil) end def #{name}= value; tuple.store(:#{field}, value) end RUBY end |