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



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

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



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

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

.when_used(schema) ⇒ Object



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

def self.when_used schema
  schema.extend ClassMethods
end