Sha256: 85894f990755ed48a0f188198159c882253593243729e990cbba3ddbc66b6479

Contents?: true

Size: 952 Bytes

Versions: 3

Compression:

Stored size: 952 Bytes

Contents

module Mobility
=begin

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.

=end
  class Wrapper < SimpleDelegator
    # @return [Array<Attributes>]
    attr_reader :modules
    alias :model_class :__getobj__

    # @param [Class] model_class Model class
    def initialize(model_class)
      super
      @modules = []
    end

    # @return [Array<String>] Translated attributes defined on model
    def translated_attribute_names
      modules.map(&:attributes).flatten
    end

    # Appends backend module to +modules+ array for later reference.
    # @param [Attributes] backend_module Attributes module
    def << backend_module
      modules << backend_module
    end

    def initialize_dup(other)
      @modules = other.modules.dup
      super
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mobility-0.1.20 lib/mobility/wrapper.rb
mobility-0.1.19 lib/mobility/wrapper.rb
mobility-0.1.18 lib/mobility/wrapper.rb