class AbstractDummyModel
Attributes
attributes[R]
enum_constant[R]
id[R]
ordinal[R]
Public Class Methods
for_name(name_attr)
click to toggle source
# File lib/persistent_enum.rb, line 418 def self.for_name(name_attr) Class.new(self) do define_singleton_method(:name_attr, -> { name_attr }) alias_method name_attr, :enum_constant end end
new(id, name, attributes = {})
click to toggle source
# File lib/persistent_enum.rb, line 365 def initialize(id, name, attributes = {}) @ordinal = id @enum_constant = name @attributes = attributes.with_indifferent_access freeze end
Public Instance Methods
freeze()
click to toggle source
Calls superclass method
# File lib/persistent_enum.rb, line 407 def freeze @ordinal.freeze @enum_constant.freeze @attributes.freeze @attributes.each do |k, v| k.freeze v.freeze end super end
method_missing(meth, *args)
click to toggle source
Calls superclass method
# File lib/persistent_enum.rb, line 391 def method_missing(meth, *args) if attributes.has_key?(meth) unless args.empty? raise ArgumentError.new("wrong number of arguments (#{args.size} for 0)") end attributes[meth] else super end end
read_attribute(attr)
click to toggle source
# File lib/persistent_enum.rb, line 378 def read_attribute(attr) case attr.to_s when 'id' ordinal when self.class.name_attr.to_s enum_constant else @attributes[attr] end end
Also aliased as: []
respond_to_missing?(meth, include_private = false)
click to toggle source
Calls superclass method
# File lib/persistent_enum.rb, line 403 def respond_to_missing?(meth, include_private = false) attributes.has_key?(meth) || super end
to_sym()
click to toggle source
# File lib/persistent_enum.rb, line 372 def to_sym enum_constant.to_sym end