Class: Mobility::Wrapper

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/mobility/wrapper.rb

Overview

Class to access Mobility across backends. In particular, keeps a record of which Attributes modules have been included on the model class. It is also a simple delegator, so any missing method will be delegated to the model class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class) ⇒ Wrapper

Returns a new instance of Wrapper.

Parameters:

  • model_class (Class)

    Model class



15
16
17
18
# File 'lib/mobility/wrapper.rb', line 15

def initialize(model_class)
  super
  @modules = []
end

Instance Attribute Details

#modulesArray<Attributes> (readonly)

Returns:



11
12
13
# File 'lib/mobility/wrapper.rb', line 11

def modules
  @modules
end

Instance Method Details

#<<(backend_module) ⇒ Object

Appends backend module to modules array for later reference.

Parameters:

  • backend_module (Attributes)

    Attributes module



27
28
29
# File 'lib/mobility/wrapper.rb', line 27

def << backend_module
  modules << backend_module
end

#translated_attribute_namesArray<String>

Returns Translated attributes defined on model.

Returns:

  • (Array<String>)

    Translated attributes defined on model



21
22
23
# File 'lib/mobility/wrapper.rb', line 21

def translated_attribute_names
  modules.map(&:attributes).flatten
end