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.5.27 lib/workarea/constants.rb
workarea-core-3.5.26 lib/workarea/constants.rb
workarea-core-3.4.45 lib/workarea/constants.rb
workarea-core-3.5.25 lib/workarea/constants.rb
workarea-core-3.5.23 lib/workarea/constants.rb
workarea-core-3.4.44 lib/workarea/constants.rb
workarea-core-3.5.22 lib/workarea/constants.rb
workarea-core-3.4.43 lib/workarea/constants.rb
workarea-core-3.5.21 lib/workarea/constants.rb
workarea-core-3.4.42 lib/workarea/constants.rb
workarea-core-3.5.20 lib/workarea/constants.rb
workarea-core-3.4.41 lib/workarea/constants.rb
workarea-core-3.5.19 lib/workarea/constants.rb
workarea-core-3.4.40 lib/workarea/constants.rb
workarea-core-3.5.18 lib/workarea/constants.rb
workarea-core-3.4.39 lib/workarea/constants.rb
workarea-core-3.5.17 lib/workarea/constants.rb
workarea-core-3.4.38 lib/workarea/constants.rb
workarea-core-3.5.16 lib/workarea/constants.rb
workarea-core-3.4.37 lib/workarea/constants.rb