Class: DiviningRod::Mapper

Inherits:
Object
  • Object
show all
Includes:
Murge
Defined in:
lib/divining_rod/mapper.rb

Instance Method Summary collapse

Methods included from Murge

#murge

Constructor Details

#initialize(parent, default_opts = {}) ⇒ Mapper

Returns a new instance of Mapper.



5
6
7
8
# File 'lib/divining_rod/mapper.rb', line 5

def initialize(parent, default_opts = {})
  @parent = parent
  @default_opts = default_opts
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/divining_rod/mapper.rb', line 30

def method_missing(meth, *args, &blk)
  # Lets us use map.ua instead of map.pattern :ua
  if Matchers.respond_to?(meth.to_sym)
    self.pattern(meth, args[0], args[1,], &blk)
  else
    super
  end
end

Instance Method Details

#default(opts = {}) ⇒ Object



24
25
26
27
28
# File 'lib/divining_rod/mapper.rb', line 24

def default(opts = {})
  definition = Definition.new(opts) { true }
  append_to_parent(definition)
  definition
end

#pattern(type, pattern, opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/divining_rod/mapper.rb', line 10

def pattern(type, pattern, opts = {})
  opts = murge(default_options, opts)
  definition = Matchers.send(type.to_sym, pattern, opts)
  append_to_parent(definition)
  if block_given?
    yield self.class.new(definition)
  end
  definition
end

#with_options(opts) {|self.class.new(@parent, opts)| ... } ⇒ Object

Yields:

  • (self.class.new(@parent, opts))


20
21
22
# File 'lib/divining_rod/mapper.rb', line 20

def with_options(opts)
  yield self.class.new(@parent, opts)
end