Sha256: 45e1e2d9ffa7ed1988ec777bc08d60b4a67de8c5a83b372a3be57312e0e63366

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

module ChartMogul
  module Concerns
    module Entries
      def self.included(base)
        base.extend ClassMethods

        base.instance_eval do
          @resource_root_key = :entries if @resource_root_key.nil?
          readonly_attr @resource_root_key, default: []

          include API::Actions::All

          include Enumerable
          def_delegators @resource_root_key, :each, :[], :<<, :size, :length, :empty?, :first, :last

          resource_root_key = @resource_root_key.to_s
          base.send :define_method, 'set_' + resource_root_key do |entries|
            objects = entries.map do |entity|
              self.class.get_entry_class.new_from_json(entity)
            end
            instance_variable_set "@#{resource_root_key}", objects
          end
        end
      end

      module ClassMethods
        def set_entry_class(klass)
          instance_variable_set('@entry_class', klass)
        end

        def get_entry_class
          instance_variable_get('@entry_class')
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
chartmogul-ruby-1.5.1 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.5.0 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.4.1 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.4.0 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.3.3 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.3.2 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.3.1 lib/chartmogul/concerns/entries.rb