Class: AdequateExposure::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/adequate_exposure/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @name = options.fetch(:name)
  @fetch = options.fetch(:fetch)
  @ivar_name = options.fetch(:ivar_name)
end

Instance Attribute Details

#fetchObject (readonly)

Returns the value of attribute fetch.



3
4
5
# File 'lib/adequate_exposure/attribute.rb', line 3

def fetch
  @fetch
end

#ivar_nameObject (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

#nameObject (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_nameObject



11
12
13
# File 'lib/adequate_exposure/attribute.rb', line 11

def getter_method_name
  name.to_sym
end

#setter_method_nameObject



15
16
17
# File 'lib/adequate_exposure/attribute.rb', line 15

def setter_method_name
  "#{name}=".to_sym
end