Module: PolymorphicEnumType

Defined in:
lib/polymorphic_enum_type.rb,
lib/polymorphic_enum_type/config.rb,
lib/polymorphic_enum_type/version.rb

Defined Under Namespace

Classes: Config

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject



24
25
26
# File 'lib/polymorphic_enum_type.rb', line 24

def config
  @config ||= PolymorphicEnumType::Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



20
21
22
# File 'lib/polymorphic_enum_type.rb', line 20

def configure
  yield(config)
end

Instance Method Details

#belongs_to(name, scope = nil, **options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/polymorphic_enum_type.rb', line 7

def belongs_to(name, scope = nil, **options)
  if options.delete(:enum_type)
    if ActiveRecord::VERSION::MAJOR >= 7
      enum("#{name}_type", PolymorphicEnumType.config.enum_hash(name), scopes: false, instance_methods: false)
    else
      enum("#{name}_type".to_sym => PolymorphicEnumType.config.enum_hash(name), _scopes: false)
    end
  end

  super(name, scope, **options)
end