Class: Waw::ResourceCollection::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/waw/resource_collection.rb

Overview

DSL for resources

Instance Method Summary collapse

Constructor Details

#initialize(resources) ⇒ DSL

Creates a DSL instance



9
10
11
# File 'lib/waw/resource_collection.rb', line 9

def initialize(resources)
  @resources = resources
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Adds a resource to the collection



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/waw/resource_collection.rb', line 14

def method_missing(name, *args, &block)
  if args.length==0 and block.nil?
    @resources.send(name)
  elsif args.length==1 and block.nil?
    @resources.send(:add_resource, name, args[0])
  elsif args.length==0 and block
    @resources.send(:add_resource, name, nil, &block)
  elsif block
    raise ArgumentError, "Bad resources usage on #{name} #{args.inspect} #{block.inspect}"
  end
end