Sha256: 7e91ade6e73166697f36478df022825794c8c6ca4b8498e74f6404029f928ec3

Contents?: true

Size: 1.18 KB

Versions: 11

Compression:

Stored size: 1.18 KB

Contents

require "rails"
require 'testing/rspec'

class PowerEnum < Rails::Engine
  config.autoload_paths << File.expand_path(File.join(__FILE__, "../"))

  initializer 'power_enum' do
    ActiveSupport.on_load(:active_record) do
      include PowerEnum::Enumerated
      include PowerEnum::HasEnumerated
      include PowerEnum::Reflection

      ActiveRecord::ConnectionAdapters.module_eval do
        include PowerEnum::Schema::SchemaStatements
      end

      if defined?(ActiveRecord::Migration::CommandRecorder)
        ActiveRecord::Migration::CommandRecorder.class_eval do
          include PowerEnum::Migration::CommandRecorder
        end
      end

      # patch Module to support VirtualEnumerations
      ::Module.module_eval do

        alias_method :enumerations_original_const_missing, :const_missing

        # Override const_missing to see if VirtualEnumerations can create it.
        def const_missing(const_id)
          # let rails have a go at loading it
          enumerations_original_const_missing(const_id)
        rescue NameError
          # now it's our turn
          ActiveRecord::VirtualEnumerations.synthesize_if_defined(const_id) or raise
        end

      end
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
power_enum-1.1.0 lib/power_enum.rb
power_enum-1.0.2 lib/power_enum.rb
power_enum-1.0.1 lib/power_enum.rb
power_enum-1.0.0 lib/power_enum.rb
power_enum-0.11.1 lib/power_enum.rb
power_enum-0.11.0 lib/power_enum.rb
power_enum-0.10.0 lib/power_enum.rb
power_enum-0.9.4 lib/power_enum.rb
power_enum-0.9.3 lib/power_enum.rb
power_enum-0.9.2 lib/power_enum.rb
power_enum-0.9.1 lib/power_enum.rb