Class: ActiveRecordUuid::Config
- Inherits:
-
Object
- Object
- ActiveRecordUuid::Config
- Defined in:
- lib/active_record_uuid/config.rb
Constant Summary collapse
- METHODS =
[:column, :primary_key, :association, :generator, :store_as, :hook]
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #to_hash ⇒ Object
- #validate_options! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/active_record_uuid/config.rb', line 3 def initialize( = {}) = { :column => :uuid, :primary_key => false, :association => false, :generator => :timestamp, :store_as => :string, :hook => :before_validation } = .merge() .each_pair do |key, value| send(key.to_sym, value) end end |
Instance Method Details
#to_hash ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/active_record_uuid/config.rb', line 27 def to_hash METHODS.inject({}) do |result, key| result[key] = send(key) result end end |
#validate_options! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/active_record_uuid/config.rb', line 35 def default_generators = [:timestamp, :random] raise ArgumentError, "Expected :timestamp or :random, got #{@generator}." \ unless default_generators.include?(@generator) default_stores = [:binary, :base64, :hexdigest, :string] raise ArgumentError, "Expected :binary, :base64, :hexdigest, or :string, got #{@store_as}." \ unless default_stores.include?(@store_as) default_hooks = [:before_validation, :after_initialize, :before_create] raise ArgumentError, "Expected :before_validation, :after_initialize, or :before_create, got #{hook}." \ unless default_hooks.include?(@hook) end |