Class: Buoys::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/buoys/loader.rb

Class Method Summary collapse

Class Method Details

.buoy(key, &block) ⇒ Object Also known as: crumb

buoy :account do

link 'Account', 

end

buoy :account_edit do |account|

link 'Account Edit', ()
pre_buoy :account

end



13
14
15
# File 'lib/buoys/loader.rb', line 13

def buoy(key, &block)
  buoys[key] = block
end

.buoy_filesObject



38
39
40
# File 'lib/buoys/loader.rb', line 38

def buoy_files
  Dir[*Buoys.buoy_file_paths]
end

.buoysObject



18
19
20
# File 'lib/buoys/loader.rb', line 18

def buoys
  @buoys ||= {}
end

.load_buoys_filesObject



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_timesObject



22
23
24
# File 'lib/buoys/loader.rb', line 22

def loaded_times
  @loaded_times ||= []
end

.need_reload?Boolean

Returns:

  • (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