Class: Artifactory::Collection::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/artifactory/collections/base.rb

Direct Known Subclasses

Artifact, Build

Instance Method Summary collapse

Constructor Details

#initialize(klass, parent, options = {}, &block) ⇒ Base

Create a new collection object (proxy).

Parameters:

  • klass (Class)

    the child class object

  • parent (Object)

    the parent object who created the collection

  • options (Hash) (defaults to: {})

    the list of options given by the parent

  • block (Proc)

    the block to evaluate for the instance



31
32
33
34
35
36
# File 'lib/artifactory/collections/base.rb', line 31

def initialize(klass, parent, options = {}, &block)
  @klass   = klass
  @parent  = parent
  @options = options
  @block   = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

Use method missing to delegate methods to the class object or instance object.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/artifactory/collections/base.rb', line 42

def method_missing(m, *args, &block)
  if klass.respond_to?(m)
    if args.last.is_a?(Hash)
      args.last.merge(options)
    end

    klass.send(m, *args, &block)
  else
    instance.send(m, *args, &block)
  end
end