Module: DatGretel::Crumbs

Extended by:
Resettable
Defined in:
lib/dat_gretel/crumbs.rb

Class Method Summary collapse

Methods included from Resettable

reset!

Class Method Details

List of breadcrumb configuration files.



53
54
55
# File 'lib/dat_gretel/crumbs.rb', line 53

def breadcrumb_files
  Dir[*DatGretel.breadcrumb_paths]
end

.crumb(key, &block) ⇒ Object

Stores the supplied block for later use.



7
8
9
# File 'lib/dat_gretel/crumbs.rb', line 7

def crumb(key, &block)
  crumbs[key] = block
end

.crumb_defined?(key) ⇒ Boolean

Returns true if a crumb with the given key has been set.

Returns:

  • (Boolean)


17
18
19
# File 'lib/dat_gretel/crumbs.rb', line 17

def crumb_defined?(key)
  crumbs.has_key?(key)
end

.crumbsObject

Returns a hash of all stored crumb blocks.



12
13
14
# File 'lib/dat_gretel/crumbs.rb', line 12

def crumbs
  @crumbs ||= {}
end

.load_breadcrumbsObject

Loads the breadcrumb configuration files.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dat_gretel/crumbs.rb', line 22

def load_breadcrumbs
  @crumbs = {}

  loaded_file_mtimes.clear
  breadcrumb_files.each do |file|
    instance_eval open(file).read, file
    loaded_file_mtimes << File.mtime(file)
  end

  @loaded = true
end

.loaded?Boolean

Returns true if the breadcrumb configuration files have been loaded.

Returns:

  • (Boolean)


48
49
50
# File 'lib/dat_gretel/crumbs.rb', line 48

def loaded?
  !!@loaded if defined? @loaded
end

.reload?Boolean

Returns true if a breadcrumbs reload is needed based on configuration file changes.

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/dat_gretel/crumbs.rb', line 40

def reload?
  return true unless loaded?
  return false unless DatGretel.reload_environments.include?(Rails.env)

  loaded_file_mtimes != breadcrumb_files.map { |file| File.mtime(file) }
end

.reload_if_neededObject

Reloads the breadcrumb configuration files if they have changed.



35
36
37
# File 'lib/dat_gretel/crumbs.rb', line 35

def reload_if_needed
  load_breadcrumbs if reload?
end