Sha256: f32be8e5c1af2956204d41e5d5aa6e9d2d683c607156e420f13303332922ebf6

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 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 modelize value
            new value
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_data-0.0.1 lib/active_data/model/collectionizable/proxy.rb