Module: Model::DSL
- Included in:
- Engineering::Builder::Model
- Defined in:
- lib/model/dsl.rb
Overview
Extensions to Model::DSL
Instance Method Summary collapse
-
#attr_accessor(name, value = nil, &block) ⇒ Object
(also: #attribute)
Define a new read-write Model attribute.
-
#attr_reader(name, value = nil, &block) ⇒ Object
Define a new read-only Model attribute.
-
#attr_writer(name) ⇒ Object
Define a new write-only Model attribute.
-
#method_missing(method, *args, &block) ⇒ Object
If the missing method happens to be the same as a known subclass of Model, then pass the call to the push method.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
If the missing method happens to be the same as a known subclass of
{Model}, then pass the call to the push method.
30 31 32 33 34 35 36 37 |
# File 'lib/model/dsl.rb', line 30 def method_missing(method, *args, &block) klass = Object.const_get(method) if klass <= Model push klass, *args, &block end rescue super end |
Instance Method Details
#attr_accessor(name, value = nil, &block) ⇒ Object Also known as: attribute
Define a new read-write Model attribute. An optional default value can be supplied as either an argument, or as a block. The block will be evaluated the first time the attribute is accessed.
9 10 11 12 |
# File 'lib/model/dsl.rb', line 9 def attr_accessor(name, value=nil, &block) define_attribute_reader name, value, &block define_attribute_writer name end |
#attr_reader(name, value = nil, &block) ⇒ Object
Define a new read-only Model attribute. An optional default value can be supplied as either an argument, or as a block. The block will be evaluated the first time the attribute is accessed.
18 19 20 |
# File 'lib/model/dsl.rb', line 18 def attr_reader(name, value=nil, &block) define_attribute_reader(name, value, &block) end |
#attr_writer(name) ⇒ Object
Define a new write-only Model attribute
24 25 26 |
# File 'lib/model/dsl.rb', line 24 def attr_writer(name) define_attribute_writer(name) end |