Sha256: c2e1763855701ae7f0e1ca08120baeb1af46d4f5258f06c0e475da619bddaa1d

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module ActiveData
  module Model
    module Collectionizable
      module Proxy
        extend ActiveSupport::Concern

        included do
          class_attribute :collectible

          def initialize source = nil
            source ||= self.class.superclass.new
            super source.map { |entity| collectible.instantiate(entity) }
          end
        end

        def respond_to? method
          super || collectible.respond_to?(method)
        end

        def method_missing method, *args, &block
          result = with_scope { collectible.send(method, *args, &block) }
          result = self.class.new result if result.instance_of? self.class.superclass
          result
        end

        def with_scope
          previous_scope = collectible.current_scope
          collectible.current_scope = self
          result = yield
          collectible.current_scope = previous_scope
          result
        end

        module ClassMethods
          def active_data_type_cast value
            new value
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_data-0.3.0 lib/active_data/model/collectionizable/proxy.rb
active_data-0.2.0 lib/active_data/model/collectionizable/proxy.rb
active_data-0.1.0 lib/active_data/model/collectionizable/proxy.rb