Class: Tutor::Attributes::Attribute
- Inherits:
-
Object
- Object
- Tutor::Attributes::Attribute
- Defined in:
- lib/tutor/attributes/attribute.rb
Instance Attribute Summary collapse
-
#alias ⇒ Object
Returns the value of attribute alias.
-
#get ⇒ Object
Returns the value of attribute get.
-
#name ⇒ Object
Returns the value of attribute name.
-
#override ⇒ Object
Returns the value of attribute override.
-
#reader_method ⇒ Object
Returns the value of attribute reader_method.
-
#set ⇒ Object
Returns the value of attribute set.
-
#writer_method ⇒ Object
Returns the value of attribute writer_method.
Attributes included from Type
Attributes included from Default
Instance Method Summary collapse
- #add_attribute_methods(klass) ⇒ Object
- #add_reader_method(klass) ⇒ Object
- #add_writer_method(klass) ⇒ Object
-
#initialize(name, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
Methods included from Type
#check_value_type!, #valid_value_type?
Methods included from Default
Constructor Details
#initialize(name, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tutor/attributes/attribute.rb', line 15 def initialize(name, = {}) self.name = name.to_sym self.type = [:type] self.nullable = .has_key?(:nullable) ? [:nullable] : true self.default = [:default] self.override = .has_key?(:override) ? [:override] : false self.alias = [:alias] self.get = .has_key?(:get) ? [:get] && Tutor::Attributes::Block.new(&[:get]) : get_default self.set = .has_key?(:set) ? [:set] && Tutor::Attributes::Block.new(&[:set]) : set_default end |
Instance Attribute Details
#alias ⇒ Object
Returns the value of attribute alias.
6 7 8 |
# File 'lib/tutor/attributes/attribute.rb', line 6 def alias @alias end |
#get ⇒ Object
Returns the value of attribute get.
6 7 8 |
# File 'lib/tutor/attributes/attribute.rb', line 6 def get @get end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/tutor/attributes/attribute.rb', line 6 def name @name end |
#override ⇒ Object
Returns the value of attribute override.
6 7 8 |
# File 'lib/tutor/attributes/attribute.rb', line 6 def override @override end |
#reader_method ⇒ Object
Returns the value of attribute reader_method.
6 7 8 |
# File 'lib/tutor/attributes/attribute.rb', line 6 def reader_method @reader_method end |
#set ⇒ Object
Returns the value of attribute set.
6 7 8 |
# File 'lib/tutor/attributes/attribute.rb', line 6 def set @set end |
#writer_method ⇒ Object
Returns the value of attribute writer_method.
6 7 8 |
# File 'lib/tutor/attributes/attribute.rb', line 6 def writer_method @writer_method end |
Instance Method Details
#add_attribute_methods(klass) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/tutor/attributes/attribute.rb', line 26 def add_attribute_methods(klass) [ add_reader_method(klass), add_writer_method(klass) ].compact end |
#add_reader_method(klass) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/tutor/attributes/attribute.rb', line 33 def add_reader_method(klass) return if !self.get self.reader_method = add_method( klass, self.name, body: self.get ) end |
#add_writer_method(klass) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/tutor/attributes/attribute.rb', line 42 def add_writer_method(klass) return if !self.set self.writer_method = add_method( klass, "#{self.name}=".to_sym, pre_execute: lambda { |object, value| self.check_value_type!(value) }, body: self.set ) end |