Class: Jschematic::Attributes::Extends
- Inherits:
-
Object
- Object
- Jschematic::Attributes::Extends
- Includes:
- Element
- Defined in:
- lib/jschematic/attributes/extends.rb
Instance Attribute Summary
Attributes included from Element
Instance Method Summary collapse
- #accepts?(instance) ⇒ Boolean
-
#initialize(id_or_schema_or_array_of_schemas) ⇒ Extends
constructor
A new instance of Extends.
Methods included from Element
#required?, #schema_for, #title, #to_s
Constructor Details
#initialize(id_or_schema_or_array_of_schemas) ⇒ Extends
Returns a new instance of Extends.
10 11 12 |
# File 'lib/jschematic/attributes/extends.rb', line 10 def initialize(id_or_schema_or_array_of_schemas) @schema = id_or_schema_or_array_of_schemas end |
Instance Method Details
#accepts?(instance) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jschematic/attributes/extends.rb', line 14 def accepts?(instance) case @schema when String uri = Addressable::URI.parse(@schema) schema = schema_for(uri) schema.accepts?(instance) when Hash Schema.new(@schema).accepts?(instance) when Array @schema.all? do |schema| extends = Extends.new(schema) extends.parent = self extends.accepts?(instance) end end || fail_validation!(@schema, instance) end |