Class: Jschematic::Attributes::Dependencies
- Inherits:
-
Object
- Object
- Jschematic::Attributes::Dependencies
- Includes:
- Element
- Defined in:
- lib/jschematic/attributes/dependencies.rb
Instance Attribute Summary
Attributes included from Element
Instance Method Summary collapse
- #accepts?(instance) ⇒ Boolean
-
#initialize(dependencies) ⇒ Dependencies
constructor
A new instance of Dependencies.
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
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 |