Class: YAS::DuplicateExt
- Inherits:
-
Object
- Object
- YAS::DuplicateExt
- Defined in:
- lib/yas/ext/duplicate.rb
Overview
Duplicate value of a key
Usage:
duplicate :mykey => [:other_key, :another_key]
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
- .apply(schema, hash) ⇒ Object
- .when_schema_inherited(superschema, subschema) ⇒ Object
- .when_used(schema) ⇒ Object
Class Method Details
.apply(schema, hash) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/yas/ext/duplicate.rb', line 33 def self.apply schema, hash schema.duplicate_keys.each do |from, to| if hash.has_key?(from) to = Array(to) to.each { |t| hash[t] = hash[from] } end end end |
.when_schema_inherited(superschema, subschema) ⇒ Object
26 27 28 29 30 |
# File 'lib/yas/ext/duplicate.rb', line 26 def self.when_schema_inherited superschema, subschema superschema.duplicate_keys.each do |from, to| subschema.duplicate_keys[key] = to end end |
.when_used(schema) ⇒ Object
21 22 23 |
# File 'lib/yas/ext/duplicate.rb', line 21 def self.when_used schema schema.extend ClassMethods end |