Class: Yori::SchemaBase

Inherits:
Hash
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/yori/schema_base.rb

Overview

Yori::SchemaBase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

Returns the value of attribute id.



22
23
24
# File 'lib/yori/schema_base.rb', line 22

def id
  @id
end

Class Method Details

.eval_class!(klass, id, &block) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/yori/schema_base.rb', line 50

def eval_class!(klass, id, &block)
  klass.new.tap do |c|
    raise 'must inherit SchemaBase class' unless c.is_a?(SchemaBase)
    c.id = id
    c.instance_eval(&block)
    c.validate!
  end
end

.eval_hash!(klass, id, value) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/yori/schema_base.rb', line 42

def eval_hash!(klass, id, value)
  klass[value].tap do |c|
    raise 'must inherit SchemaBase class' unless c.is_a?(SchemaBase)
    c.id = id
    c.validate!
  end
end

.eval_input!(klass, id, value = nil, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yori/schema_base.rb', line 29

def eval_input!(klass, id, value = nil, &block)
  return eval_class!(klass, id, &block) unless value

  case value
  when String, FalseClass
    value # pass as a runtime expression
  when Hash
    eval_hash!(klass, id, value)
  else
    raise 'direct assignment value must be a Hash'
  end
end

Instance Method Details

#ref(value) ⇒ Object



24
25
26
# File 'lib/yori/schema_base.rb', line 24

def ref(value)
  self['$ref'] = value
end

#validate!Object



20
# File 'lib/yori/schema_base.rb', line 20

def validate!; end

#validatorObject



16
17
18
# File 'lib/yori/schema_base.rb', line 16

def validator
  @validator ||= Yori::SchemaValidator.new(self)
end