Module: Workarea::Constants

Defined in:
lib/workarea/constants.rb

Overview

This module exists to help track constants for reflection at runtime. This is necessary because Rails’ autoloading will erase values stored in class or module accessors. This module must be loaded manually with ‘require`, for the same reason.

Class Method Summary collapse

Class Method Details

.exists?(type, constant) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/workarea/constants.rb', line 21

def self.exists?(type, constant)
  (cache[type] || []).map(&:name).include?(constant.name)
end

.find(type) ⇒ Object



17
18
19
# File 'lib/workarea/constants.rb', line 17

def self.find(type)
  cache[type.to_sym] || []
end

.register(type, constant) ⇒ Object



11
12
13
14
15
# File 'lib/workarea/constants.rb', line 11

def self.register(type, constant)
  type = type.to_sym
  cache[type] ||= []
  cache[type] << constant unless exists?(type, constant)
end

.reset!(type) ⇒ Object



25
26
27
# File 'lib/workarea/constants.rb', line 25

def self.reset!(type)
  cache[type.to_sym] = []
end