Sha256: 272fbf684a2bf4fc05243369deffea1955e56fd2c4c520a4e495354dbfb1b742

Contents?: true

Size: 1.89 KB

Versions: 4

Compression:

Stored size: 1.89 KB

Contents

require 'parliament/grom/decorator/version'
require 'parliament/grom/decorator/helpers'
require 'parliament/grom/decorator/constituency_area'
require 'parliament/grom/decorator/constituency_group'
require 'parliament/grom/decorator/contact_point'
require 'parliament/grom/decorator/gender'
require 'parliament/grom/decorator/gender_identity'
require 'parliament/grom/decorator/house'
require 'parliament/grom/decorator/house_incumbency'
require 'parliament/grom/decorator/house_seat'
require 'parliament/grom/decorator/incumbency'
require 'parliament/grom/decorator/party'
require 'parliament/grom/decorator/party_membership'
require 'parliament/grom/decorator/person'
require 'parliament/grom/decorator/postal_address'
require 'parliament/grom/decorator/seat_incumbency'
require 'parliament/grom/decorator/parliaments'
require 'parliament/grom/decorator/member_image'

# Namespace for classes and modules that handle connections to, and processing of data from the parliamentary API.
# @since 0.1.0
module Parliament
  module Grom
    # Namespace for Grom decorators.
    #
    # @since 0.1.0
    module Decorator
      # Gets the root directory of the gem
      def self.gem_path
        File.expand_path '../../../../', __FILE__
      end

      # Loads the translation file into the I18n gem
      I18n.load_path += Dir[File.join(gem_path, 'config', 'locales', '*.yml')]
      I18n.backend.load_translations

      # Decorates objects with alias methods extended from its decorator module.
      #
      # @param [Grom::Node] object the object to be decorated.
      def self.decorate(object)
        return object unless object.respond_to?(:type)

        object_type = ::Grom::Helper.get_id(object.type)

        return object unless constants.include?(object_type.to_sym)

        decorator_module = Object.const_get("Parliament::Grom::Decorator::#{object_type}")
        object.extend(decorator_module)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
parliament-grom-decorators-0.2.8 lib/parliament/grom/decorator.rb
parliament-grom-decorators-0.2.7 lib/parliament/grom/decorator.rb
parliament-grom-decorators-0.2.6.pre lib/parliament/grom/decorator.rb
parliament-grom-decorators-0.2.5.pre lib/parliament/grom/decorator.rb