Module: Hashie::Extensions::Dash::PredefinedValues

Defined in:
lib/hashie/extensions/dash/predefined_values.rb

Overview

Extends a Dash with the ability to accept only predefined values on a property.

== Example

class PersonHash < Hashie::Dash include Hashie::Extensions::Dash::PredefinedValues

property :gender, values: [:male, :female, :prefer_not_to_say]
property :age, values: (0..150) # a Range

end

person = PersonHash.new(gender: :male, age: -1) # => ArgumentError: The value '-1' is not accepted for property 'age'

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



18
19
20
21
22
# File 'lib/hashie/extensions/dash/predefined_values.rb', line 18

def self.included(base)
  base.instance_variable_set(:@values_for_properties, {})
  base.extend(ClassMethods)
  base.include(InstanceMethods)
end