Module: Gretel::Crumbs

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

Defined Under Namespace

Classes: Builder

Class Method Summary collapse

Methods included from Resettable

reset!

Class Method Details

List of breadcrumb configuration files.



49
50
51
# File 'lib/gretel/crumbs.rb', line 49

def breadcrumb_files
  Dir[*Gretel.breadcrumb_paths]
end

.crumb_defined?(key) ⇒ Boolean

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

Returns:

  • (Boolean)


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

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

.crumbsObject

Returns a hash of all stored crumb blocks.



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

def crumbs
  @crumbs ||= {}
end

.load_breadcrumbsObject

Loads the breadcrumb configuration files.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gretel/crumbs.rb', line 17

def load_breadcrumbs
  builder = Builder.new

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

  @crumbs = builder.crumbs
  @loaded = true
end

.loaded?Boolean

Returns true if the breadcrumb configuration files have been loaded.

Returns:

  • (Boolean)


44
45
46
# File 'lib/gretel/crumbs.rb', line 44

def loaded?
  !!@loaded
end

.reload?Boolean

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

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/gretel/crumbs.rb', line 36

def reload?
  return true unless loaded?
  return false unless Gretel.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.



31
32
33
# File 'lib/gretel/crumbs.rb', line 31

def reload_if_needed
  load_breadcrumbs if reload?
end