Sha256: 822b002d5791fa6cb1f4754a2c715fc15f122a6e70c01509d082b1eb899ddd49

Contents?: true

Size: 862 Bytes

Versions: 50

Compression:

Stored size: 862 Bytes

Contents

module Arrest
  class ChildCollection #< BasicObject
    def initialize parent, clazz_name
      @parent = parent
      @clazz_name = clazz_name
      @children = nil
    end

    def build attributes = {}
      resolved_class.new(@parent.context, @parent, attributes)
    end

    def method_missing(*args, &block)
     if resolved_class.respond_to?(args[0])
       sub_args = [@parent]
       sub_args += args.drop(1)
       resolved_class.send(args[0], *sub_args)
     else
       children.send(*args, &block)
     end
    end

    def inspect
      children.inspect
    end

    private


    def children
      if @children == nil
        @children = resolved_class.all_for(@parent)
      end
      @children
    end

    def resolved_class
      if @clazz == nil
        @clazz = Source.mod.const_get(@clazz_name)
      end
      @clazz
    end

  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
arrest-0.0.58 lib/arrest/helper/child_collection.rb
arrest-0.0.57 lib/arrest/helper/child_collection.rb
arrest-0.0.56 lib/arrest/helper/child_collection.rb
arrest-0.0.54 lib/arrest/helper/child_collection.rb
arrest-0.0.53 lib/arrest/helper/child_collection.rb
arrest-0.0.52 lib/arrest/helper/child_collection.rb
arrest-0.0.51 lib/arrest/helper/child_collection.rb
arrest-0.0.50 lib/arrest/helper/child_collection.rb
arrest-0.0.49 lib/arrest/helper/child_collection.rb
arrest-0.0.48 lib/arrest/helper/child_collection.rb
arrest-0.0.47 lib/arrest/helper/child_collection.rb
arrest-0.0.46 lib/arrest/helper/child_collection.rb
arrest-0.0.44 lib/arrest/helper/child_collection.rb
arrest-0.0.43 lib/arrest/helper/child_collection.rb
arrest-0.0.42 lib/arrest/helper/child_collection.rb
arrest-0.0.41 lib/arrest/helper/child_collection.rb
arrest-0.0.40 lib/arrest/helper/child_collection.rb
arrest-0.0.39 lib/arrest/helper/child_collection.rb
arrest-0.0.38 lib/arrest/helper/child_collection.rb
arrest-0.0.37 lib/arrest/helper/child_collection.rb