Class: Lab419::Config::Reader
- Inherits:
-
Object
- Object
- Lab419::Config::Reader
- 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
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #handle(trigger_rgx, message_name = nil, &blk) ⇒ Object
- #parsed? ⇒ Boolean
- #with_file(filename, &blk) ⇒ Object
- #with_string(string, &blk) ⇒ Object
Methods included from Parser
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/lab419/config/reader.rb', line 15 def config @config end |
#name ⇒ Object (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, = nil, &blk if && blk || blk.nil? && .nil? raise ArgumentError, "please specify a message_name *or* a block, not both or none" end @handlers.update( trigger_rgx => || blk ) end |
#parsed? ⇒ 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 |