Class: Sortah::Parser

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/sortah/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



21
22
23
# File 'lib/sortah/parser.rb', line 21

def initialize
  clear!
end

Instance Attribute Details

#destinationsObject (readonly)

object-level interaction



13
14
15
# File 'lib/sortah/parser.rb', line 13

def destinations
  @destinations
end

#lensesObject (readonly)

object-level interaction



13
14
15
# File 'lib/sortah/parser.rb', line 13

def lenses
  @lenses
end

#routersObject (readonly)

object-level interaction



13
14
15
# File 'lib/sortah/parser.rb', line 13

def routers
  @routers
end

Class Method Details

.clear!Object



8
9
10
# File 'lib/sortah/parser.rb', line 8

def self.clear!
  self.instance.clear!
end

Instance Method Details

#clear!Object



15
16
17
18
19
# File 'lib/sortah/parser.rb', line 15

def clear!
  @destinations = Destinations.new
  @lenses = Lenses.new
  @routers = Routers.new
end

#destination(name, args) ⇒ Object

language elements



57
58
59
# File 'lib/sortah/parser.rb', line 57

def destination(name, args)
  @destinations << Destination.new(name, args)
end

#error_dest(dest = nil) ⇒ Object

double-duty getter/setter



45
46
47
48
# File 'lib/sortah/parser.rb', line 45

def error_dest(dest = nil)
  @error_dest = dest if dest
  @error_dest
end

#handle(&block) ⇒ Object



25
26
27
28
# File 'lib/sortah/parser.rb', line 25

def handle(&block)
  self.instance_eval &block
  valid?
end

#lens(name, opts = {}, &block) ⇒ Object



61
62
63
# File 'lib/sortah/parser.rb', line 61

def lens(name, opts = {}, &block)
  @lenses << Lens.new(name, opts, block)
end

#maildir(maildir_path = nil) ⇒ Object

double-duty getter/setter



39
40
41
42
# File 'lib/sortah/parser.rb', line 39

def maildir(maildir_path = nil)
  @maildir = maildir_path if maildir_path
  @maildir
end

#router(name = :root, opts = {}, &block) ⇒ Object



65
66
67
# File 'lib/sortah/parser.rb', line 65

def router(name = :root, opts = {}, &block)
  @routers << Router.new(name, opts, block)
end

#type(type = nil) ⇒ Object

double-duty getter/setter



51
52
53
54
# File 'lib/sortah/parser.rb', line 51

def type(type = nil)
  @type = type if type
  @type
end

#valid?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/sortah/parser.rb', line 30

def valid?
  @lenses.valid?
  @routers.valid?
  @destinations.valid?
end