Class: PersistentEnum::EnumSpec

Inherits:
Struct
  • Object
show all
Defined in:
lib/persistent_enum.rb

Overview

Closes over the arguments to ‘acts_as_enum` so that it can be reloaded.

Defined Under Namespace

Classes: ConstantEvaluator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(constant_block, constant_hash, name_attr, sql_enum_type) ⇒ EnumSpec



63
64
65
66
67
68
69
70
# File 'lib/persistent_enum.rb', line 63

def initialize(constant_block, constant_hash, name_attr, sql_enum_type)
  unless constant_block.nil? ^ constant_hash.nil?
    raise ArgumentError.new('Constants must be provided by exactly one of hash argument or builder block')
  end

  super(constant_block, constant_hash, name_attr.to_s, sql_enum_type)
  freeze
end

Instance Attribute Details

#constant_blockObject

Returns the value of attribute constant_block



62
63
64
# File 'lib/persistent_enum.rb', line 62

def constant_block
  @constant_block
end

#constant_hashObject

Returns the value of attribute constant_hash



62
63
64
# File 'lib/persistent_enum.rb', line 62

def constant_hash
  @constant_hash
end

#name_attrObject

Returns the value of attribute name_attr



62
63
64
# File 'lib/persistent_enum.rb', line 62

def name_attr
  @name_attr
end

#sql_enum_typeObject

Returns the value of attribute sql_enum_type



62
63
64
# File 'lib/persistent_enum.rb', line 62

def sql_enum_type
  @sql_enum_type
end

Instance Method Details

#required_membersObject



72
73
74
# File 'lib/persistent_enum.rb', line 72

def required_members
  constant_hash || ConstantEvaluator.new.evaluate(&constant_block)
end