Sha256: 797234acc650a4e07b2279461e857268e0fcb4e21ddef4ed53cf10510db14e3b

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 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

          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.3.0 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.2.2 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.2.1 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.2.0 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.1.9 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.1.8 lib/chartmogul/concerns/entries.rb
chartmogul-ruby-1.1.7 lib/chartmogul/concerns/entries.rb