Class: Lab419::Config::Reader

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/lab419/config/reader.rb

Overview

TODO: code @handler setters, @handler is a dead variable right now

no specs imply its usage yet

Constant Summary

Constants included from Parser

Parser::SyntaxError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

#parse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



15
16
17
# File 'lib/lab419/config/reader.rb', line 15

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/lab419/config/reader.rb', line 15

def name
  @name
end

Instance Method Details

#handle(trigger_rgx, message_name = nil, &blk) ⇒ Object



19
20
21
22
23
24
# File 'lib/lab419/config/reader.rb', line 19

def handle trigger_rgx, message_name = nil, &blk
  if message_name && blk || blk.nil? && message_name.nil?
    raise ArgumentError, "please specify a message_name *or* a block, not both or none"
  end
  @handlers.update( trigger_rgx => message_name || blk )
end

#parsed?Boolean

Returns:

  • (Boolean)


17
# File 'lib/lab419/config/reader.rb', line 17

def parsed?; @parsed end

#with_file(filename, &blk) ⇒ Object



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

def with_file filename, &blk
  File.open( filename ) do | f |
    init_source f, filename
  end
  blk[self] if blk
  self
rescue Errno::ENOENT
  raise DataError, "hmm file: '#{filename}' does not seem to be readable!"
end

#with_string(string, &blk) ⇒ Object



35
36
37
38
39
# File 'lib/lab419/config/reader.rb', line 35

def with_string string, &blk
  init_source string
  blk[self] if blk
  self
end