Class: Jschematic::Attributes::Dependencies

Inherits:
Object
  • Object
show all
Includes:
Element
Defined in:
lib/jschematic/attributes/dependencies.rb

Instance Attribute Summary

Attributes included from Element

#id, #parent

Instance Method Summary collapse

Methods included from Element

#required?, #schema_for, #title, #to_s

Constructor Details

#initialize(dependencies) ⇒ Dependencies

Returns a new instance of Dependencies.



8
9
10
# File 'lib/jschematic/attributes/dependencies.rb', line 8

def initialize(dependencies)
  @dependencies = dependencies
end

Instance Method Details

#accepts?(instance) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jschematic/attributes/dependencies.rb', line 12

def accepts?(instance)
  instance.keys.all? do |property|
    case deps = @dependencies[property]
    when String, Array
      [deps].flatten.all?{ |req| instance.keys.include?(req) }
    when Hash
      Schema.new(deps).accepts?(instance)
    else
      true
    end
  end
end