Class: YAS::AttributeExt

Inherits:
Object
  • Object
show all
Defined in:
lib/yas/ext/attribute.rb

Overview

Defines specific rules for keys

Defined Under Namespace

Modules: ClassMethods Classes: Attribute

Class Method Summary collapse

Class Method Details

.apply(schema, hash) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/yas/ext/attribute.rb', line 36

def self.apply schema, hash
  schema.attributes.each do |key, attr|
    raise YAS::ValidationError, "Key #{key} is required" if attr.required? && !hash.has_key?(key)
    hash.has_key?(key) and
      hash[key] = attr.validate(hash[key])
  end
end

.when_schema_inherited(superschema, subschema) ⇒ Object



29
30
31
32
33
# File 'lib/yas/ext/attribute.rb', line 29

def self.when_schema_inherited superschema, subschema
  superschema.attributes.each do |key, attr|
    subschema.attributes[key] = attr
  end
end

.when_used(schema) ⇒ Object



24
25
26
# File 'lib/yas/ext/attribute.rb', line 24

def self.when_used schema
  schema.extend ClassMethods
end