Class: Ceres::Reader
- Inherits:
-
Object
- Object
- Ceres::Reader
- Defined in:
- lib/ceres/reader.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
Instance Method Summary collapse
- #apply(klass) ⇒ Object
- #cache? ⇒ Boolean
-
#initialize(attribute, cache: false, &block) ⇒ Reader
constructor
A new instance of Reader.
- #name ⇒ Object
- #target ⇒ Object
- #to_proc ⇒ Object
- #variable ⇒ Object
Constructor Details
#initialize(attribute, cache: false, &block) ⇒ Reader
Returns a new instance of Reader.
6 7 8 9 10 |
# File 'lib/ceres/reader.rb', line 6 def initialize(attribute, cache: false, &block) @attribute = attribute @cache = cache @block = block end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
3 4 5 |
# File 'lib/ceres/reader.rb', line 3 def attribute @attribute end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
4 5 6 |
# File 'lib/ceres/reader.rb', line 4 def block @block end |
Instance Method Details
#apply(klass) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ceres/reader.rb', line 32 def apply(klass) name = self.name if allow_reader_optimisation? klass.instance_exec { attr_reader name } else reader = self.to_proc klass.instance_exec { define_method(name, &reader) } end end |
#cache? ⇒ Boolean
12 13 14 |
# File 'lib/ceres/reader.rb', line 12 def cache? @cache end |
#name ⇒ Object
16 17 18 |
# File 'lib/ceres/reader.rb', line 16 def name @attribute.name end |
#target ⇒ Object
20 21 22 |
# File 'lib/ceres/reader.rb', line 20 def target @attribute.target end |
#to_proc ⇒ Object
28 29 30 |
# File 'lib/ceres/reader.rb', line 28 def to_proc self.cache? ? to_cached_proc : to_uncached_proc end |
#variable ⇒ Object
24 25 26 |
# File 'lib/ceres/reader.rb', line 24 def variable @attribute.variable end |