Sha256: 6d78c6878a243ac2274a9c87fdc289f3e73c462819060512df2305e55b03216c

Contents?: true

Size: 751 Bytes

Versions: 62

Compression:

Stored size: 751 Bytes

Contents

module Workarea
  # 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.
  #
  module Constants
    mattr_accessor :cache
    self.cache ||= {}

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

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

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

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

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.4.27 lib/workarea/constants.rb
workarea-core-3.5.4 lib/workarea/constants.rb
workarea-core-3.4.26 lib/workarea/constants.rb
workarea-core-3.5.3 lib/workarea/constants.rb
workarea-core-3.4.25 lib/workarea/constants.rb
workarea-core-3.5.2 lib/workarea/constants.rb
workarea-core-3.4.24 lib/workarea/constants.rb
workarea-core-3.5.1 lib/workarea/constants.rb
workarea-core-3.4.23 lib/workarea/constants.rb
workarea-core-3.4.22 lib/workarea/constants.rb
workarea-core-3.5.0 lib/workarea/constants.rb
workarea-core-3.4.21 lib/workarea/constants.rb
workarea-core-3.5.0.beta.1 lib/workarea/constants.rb
workarea-core-3.4.20 lib/workarea/constants.rb
workarea-core-3.4.19 lib/workarea/constants.rb
workarea-core-3.4.18 lib/workarea/constants.rb
workarea-core-3.4.17 lib/workarea/constants.rb
workarea-core-3.4.16 lib/workarea/constants.rb
workarea-core-3.4.15 lib/workarea/constants.rb
workarea-core-3.4.14 lib/workarea/constants.rb