Module: Xail::DSL

Defined in:
lib/xail/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/xail/config.rb', line 66

def method_missing(name, *args, &block)
  abort "internal error #{name} #{args} #{block}" unless name

  filterClass = FilterRegistry::get_filter(name.downcase)
  filter_scope(filterClass.new(*args), &block)

rescue StreamLineStop => stop
  # short circuit the stream line stop exception so we can catch it
  # in xail main
  raise stop

rescue UnknownFilter => error
  abort error.to_s

rescue => error
  abort "#{filter_in_scope} will not accept #{name} as subfilter: #{error}"
end

Instance Attribute Details

#has_finalObject (readonly)

Returns the value of attribute has_final.



49
50
51
# File 'lib/xail/config.rb', line 49

def has_final
  @has_final
end

Instance Method Details

#filter(&block) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/xail/config.rb', line 36

def filter(&block)
  filter_in_scope << Class.new(AbstractFilter) do
    def streamLine(line)
      block(line)
    end
  end
end

#filter_in_scopeObject



61
62
63
64
# File 'lib/xail/config.rb', line 61

def filter_in_scope
  @filter_stack ||= [FilterCascade.new]
  @filter_stack.last
end

#filter_scope(compound) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/xail/config.rb', line 25

def filter_scope(compound)
  # add this compound filter to the filter currently in scope
  filter_in_scope << compound

  if block_given?
    @filter_stack << compound
    yield
    @filter_stack.pop
  end
end

#get_bindingObject



21
22
23
# File 'lib/xail/config.rb', line 21

def get_binding
  binding
end

#group(name, &filters) ⇒ Object



44
45
46
47
# File 'lib/xail/config.rb', line 44

def group(name, &filters)
  # TODO intergrate with UX
  filter_scope(FilterComposition.new, &filters)
end

#rest(&filters) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/xail/config.rb', line 50

def rest(&filters)
  if @has_final
    raise "rest may only be specified once"
  end

  @has_final = true
  filter_scope(FilterComposition.new) {
    filters.yield
  }
end