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.78 lib/arrest/helper/child_collection.rb
arrest-0.0.77 lib/arrest/helper/child_collection.rb
arrest-0.0.76 lib/arrest/helper/child_collection.rb
arrest-0.0.75 lib/arrest/helper/child_collection.rb
arrest-0.0.74 lib/arrest/helper/child_collection.rb
arrest-0.0.73 lib/arrest/helper/child_collection.rb
arrest-0.0.72 lib/arrest/helper/child_collection.rb
arrest-0.0.71 lib/arrest/helper/child_collection.rb
arrest-0.0.70 lib/arrest/helper/child_collection.rb
arrest-0.0.69 lib/arrest/helper/child_collection.rb
arrest-0.0.68 lib/arrest/helper/child_collection.rb
arrest-0.0.67 lib/arrest/helper/child_collection.rb
arrest-0.0.66 lib/arrest/helper/child_collection.rb
arrest-0.0.65 lib/arrest/helper/child_collection.rb
arrest-0.0.64 lib/arrest/helper/child_collection.rb
arrest-0.0.63 lib/arrest/helper/child_collection.rb
arrest-0.0.62 lib/arrest/helper/child_collection.rb
arrest-0.0.61 lib/arrest/helper/child_collection.rb
arrest-0.0.60 lib/arrest/helper/child_collection.rb
arrest-0.0.59 lib/arrest/helper/child_collection.rb