Class: AdequateExposure::Attribute
- Inherits:
-
Object
- Object
- AdequateExposure::Attribute
- Defined in:
- lib/adequate_exposure/attribute.rb
Instance Attribute Summary collapse
-
#fetch ⇒ Object
readonly
Returns the value of attribute fetch.
-
#ivar_name ⇒ Object
readonly
Returns the value of attribute ivar_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #expose!(klass) ⇒ Object
- #getter_method_name ⇒ Object
-
#initialize(options) ⇒ Attribute
constructor
A new instance of Attribute.
- #setter_method_name ⇒ Object
Constructor Details
#initialize(options) ⇒ Attribute
Returns a new instance of Attribute.
5 6 7 8 9 |
# File 'lib/adequate_exposure/attribute.rb', line 5 def initialize() @name = .fetch(:name) @fetch = .fetch(:fetch) @ivar_name = .fetch(:ivar_name) end |
Instance Attribute Details
#fetch ⇒ Object (readonly)
Returns the value of attribute fetch.
3 4 5 |
# File 'lib/adequate_exposure/attribute.rb', line 3 def fetch @fetch end |
#ivar_name ⇒ Object (readonly)
Returns the value of attribute ivar_name.
3 4 5 |
# File 'lib/adequate_exposure/attribute.rb', line 3 def ivar_name @ivar_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/adequate_exposure/attribute.rb', line 3 def name @name end |
Instance Method Details
#expose!(klass) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/adequate_exposure/attribute.rb', line 19 def expose!(klass) attribute = self klass.instance_eval do define_method attribute.getter_method_name do Context.new(self, attribute).get end define_method attribute.setter_method_name do |value| Context.new(self, attribute).set(value) end end end |
#getter_method_name ⇒ Object
11 12 13 |
# File 'lib/adequate_exposure/attribute.rb', line 11 def getter_method_name name.to_sym end |
#setter_method_name ⇒ Object
15 16 17 |
# File 'lib/adequate_exposure/attribute.rb', line 15 def setter_method_name "#{name}=".to_sym end |