Class: Msgr::Routes
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #<<(file) ⇒ Object
- #blocks ⇒ Object
- #configure(&block) ⇒ Object
- #files ⇒ Object
- #files=(files) ⇒ Object
-
#initialize ⇒ Routes
constructor
A new instance of Routes.
- #load(file) ⇒ Object
- #reload ⇒ Object
- #route(key, opts = {}) ⇒ Object
Methods included from Logging
Constructor Details
#initialize ⇒ Routes
Returns a new instance of Routes.
11 12 13 |
# File 'lib/msgr/routes.rb', line 11 def initialize @routes = [] end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
7 8 9 |
# File 'lib/msgr/routes.rb', line 7 def routes @routes end |
Instance Method Details
#<<(file) ⇒ Object
32 33 34 |
# File 'lib/msgr/routes.rb', line 32 def <<(file) files << file end |
#blocks ⇒ Object
24 25 26 |
# File 'lib/msgr/routes.rb', line 24 def blocks @blocks ||= [] end |
#configure(&block) ⇒ Object
15 16 17 18 |
# File 'lib/msgr/routes.rb', line 15 def configure(&block) blocks << block instance_eval(&block) end |
#files ⇒ Object
20 21 22 |
# File 'lib/msgr/routes.rb', line 20 def files @files ||= [] end |
#files=(files) ⇒ Object
28 29 30 |
# File 'lib/msgr/routes.rb', line 28 def files=(files) @files = Array files end |
#load(file) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/msgr/routes.rb', line 49 def load(file) unless File.exist?(file) raise ArgumentError.new "File `#{file}` does not exists." end instance_eval File.read file end |
#reload ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/msgr/routes.rb', line 36 def reload routes.clear blocks.each {|block| instance_eval(&block) } files.uniq! files.each do |file| if File.exist? file load file else log(:warn) { "Routes file `#{file}` does not exists (anymore)." } end end end |