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



71
72
73
74
75
76
77
78
# File 'lib/persistent_enum.rb', line 71

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



70
71
72
# File 'lib/persistent_enum.rb', line 70

def constant_block
  @constant_block
end

#constant_hashObject

Returns the value of attribute constant_hash



70
71
72
# File 'lib/persistent_enum.rb', line 70

def constant_hash
  @constant_hash
end

#name_attrObject

Returns the value of attribute name_attr



70
71
72
# File 'lib/persistent_enum.rb', line 70

def name_attr
  @name_attr
end

#sql_enum_typeObject

Returns the value of attribute sql_enum_type



70
71
72
# File 'lib/persistent_enum.rb', line 70

def sql_enum_type
  @sql_enum_type
end

Instance Method Details

#required_membersObject



80
81
82
# File 'lib/persistent_enum.rb', line 80

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