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.
8 9 10 |
# File 'lib/msgr/routes.rb', line 8 def initialize @routes = [] end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
5 6 7 |
# File 'lib/msgr/routes.rb', line 5 def routes @routes end |
Instance Method Details
#<<(file) ⇒ Object
29 30 31 |
# File 'lib/msgr/routes.rb', line 29 def <<(file) files << file end |
#blocks ⇒ Object
21 22 23 |
# File 'lib/msgr/routes.rb', line 21 def blocks @blocks ||= [] end |
#configure(&block) ⇒ Object
12 13 14 15 |
# File 'lib/msgr/routes.rb', line 12 def configure(&block) blocks << block instance_eval &block end |
#files ⇒ Object
17 18 19 |
# File 'lib/msgr/routes.rb', line 17 def files @files ||= [] end |
#files=(files) ⇒ Object
25 26 27 |
# File 'lib/msgr/routes.rb', line 25 def files=(files) @files = Array files end |
#load(file) ⇒ Object
46 47 48 49 |
# File 'lib/msgr/routes.rb', line 46 def load(file) raise ArgumentError.new "File `#{file}` does not exists." unless File.exists? file instance_eval File.read file end |
#reload ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/msgr/routes.rb', line 33 def reload routes.clear blocks.each { |block| instance_eval(&block) } files.uniq! files.each do |file| if File.exists? file load file else log(:warn) { "Routes file `#{file}` does not exists (anymore)." } end end end |