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



15
16
17
# File 'lib/buoys/loader.rb', line 15

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

.buoy_filesObject



40
41
42
# File 'lib/buoys/loader.rb', line 40

def buoy_files
  Dir[*Buoys.buoy_file_paths]
end

.buoysObject



20
21
22
# File 'lib/buoys/loader.rb', line 20

def buoys
  @buoys ||= {}
end

.load_buoys_filesObject



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.open(file).read, file
    loaded_times << File.mtime(file)
  end
end

.loaded_timesObject



24
25
26
# File 'lib/buoys/loader.rb', line 24

def loaded_times
  @loaded_times ||= []
end

.need_reload?Boolean

Returns:

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