Sha256: 193ee4600303cfdad9e5374214ff42a55d5975666c1db375b0fe00518a1b3667

Contents?: true

Size: 933 Bytes

Versions: 6

Compression:

Stored size: 933 Bytes

Contents

module Support
  module Constants
    extend ActiveSupport::Concern

    module ClassMethods
      def uses_constants(*constants)
        before { create_constants *constants }
      end
    end

    def create_constants(*constants)
      constants.each { |constant| create_constant constant }
    end

    def remove_constants(*constants)
      constants.each { |constant| remove_constant constant }
    end

    def create_constant(constant)
      remove_constant constant
      Object.const_set constant, ToyStore(constant)
    end

    def remove_constant(constant)
      if Object.const_defined?(constant)
        Object.send :remove_const, constant
      end
    end

    def ToyStore(name = nil)
      Class.new.tap do |object|
        object.class_eval """
          def self.name; '#{name}' end
          def self.to_s; '#{name}' end
        """ if name
        object.send(:include, Toy::Store)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
toystore-0.13.2 spec/support/constants.rb
toystore-0.13.1 spec/support/constants.rb
toystore-0.13.0 spec/support/constants.rb
toystore-0.12.0 spec/support/constants.rb
toystore-0.11.0 spec/support/constants.rb
toystore-0.10.4 spec/support/constants.rb