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
13 14 15 |
# File 'lib/buoys/loader.rb', line 13 def buoy(key, &block) buoys[key] = block end |
.buoy_files ⇒ Object
38 39 40 |
# File 'lib/buoys/loader.rb', line 38 def buoy_files Dir[*Buoys.buoy_file_paths] end |
.buoys ⇒ Object
18 19 20 |
# File 'lib/buoys/loader.rb', line 18 def buoys @buoys ||= {} end |
.load_buoys_files ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/buoys/loader.rb', line 26 def load_buoys_files return unless need_reload? buoys.clear loaded_times.clear buoy_files.each do |file| instance_eval open(file).read, file loaded_times << File.mtime(file) end end |
.loaded_times ⇒ Object
22 23 24 |
# File 'lib/buoys/loader.rb', line 22 def loaded_times @loaded_times ||= [] end |
.need_reload? ⇒ Boolean
42 43 44 45 46 |
# File 'lib/buoys/loader.rb', line 42 def need_reload? return true if buoys.empty? Rails.env.development? && loaded_times != buoy_files.map {|f| File.mtime(f) } end |