Class: Buoys::Loader
- Inherits:
-
Object
- Object
- Buoys::Loader
- Defined in:
- lib/buoys/loader.rb
Class Method Summary collapse
-
.buoy(key, &block) ⇒ Object
(also: crumb)
buoy :account do link 'Account', account_path end.
- .buoy_files ⇒ Object
- .buoys ⇒ Object
- .load_buoys_files ⇒ Object
- .loaded_times ⇒ Object
- .need_reload? ⇒ Boolean
Class Method Details
.buoy(key, &block) ⇒ Object Also known as: crumb
buoy :account do
link 'Account', account_path
end
buoy :account_edit do |account|
link 'Account Edit', edit_account_path(account)
pre_buoy :account
end
15 16 17 |
# File 'lib/buoys/loader.rb', line 15 def buoy(key, &block) buoys[key] = block end |
.buoy_files ⇒ Object
40 41 42 |
# File 'lib/buoys/loader.rb', line 40 def buoy_files Dir[*Buoys.buoy_file_paths] end |
.buoys ⇒ Object
20 21 22 |
# File 'lib/buoys/loader.rb', line 20 def buoys @buoys ||= {} end |
.load_buoys_files ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/buoys/loader.rb', line 28 def load_buoys_files return unless need_reload? buoys.clear loaded_times.clear buoy_files.each do |file| instance_eval File.read(file), file loaded_times << File.mtime(file) end end |
.loaded_times ⇒ Object
24 25 26 |
# File 'lib/buoys/loader.rb', line 24 def loaded_times @loaded_times ||= [] end |
.need_reload? ⇒ Boolean
44 45 46 47 48 |
# File 'lib/buoys/loader.rb', line 44 def need_reload? return true if buoys.empty? Rails.env.development? && loaded_times != buoy_files.map {|f| File.mtime(f) } end |