Class: AdequateExposure::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, attribute) ⇒ Context

Public: Initialize a context.

context - The Class where the attribute is defined. attribute - The attribute that will be accessed by a getter

and setter.


10
11
12
# File 'lib/adequate_exposure/context.rb', line 10

def initialize(context, attribute)
  @context, @attribute = context, attribute
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



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

def attribute
  @attribute
end

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

Instance Method Details

#getObject

Public: Read an attribute on the context Class.

Get an attribute’s value. If the attribute’s instance variable is not defined, it will create one, execute attribute#fetch, and assign the result to the instance variable.

Returns the attribute’s value.



22
23
24
# File 'lib/adequate_exposure/context.rb', line 22

def get
  ivar_defined?? ivar_get : set(fetch_value)
end

#set(value) ⇒ Object

Public: Write to an attribute on the context Class.

value - The value that will be set to the attribute’s

instance variable.

Returns the attribute’s value.



32
33
34
# File 'lib/adequate_exposure/context.rb', line 32

def set(value)
  ivar_set(value)
end