Class: Aries::Schema
- Inherits:
-
Object
- Object
- Aries::Schema
- Defined in:
- lib/aries/schema.rb
Instance Method Summary collapse
-
#base_url ⇒ String
Find base url of api.
-
#initialize(schema) ⇒ Schema
constructor
A new instance of Schema.
- #inspect ⇒ Object
- #property_by(href) ⇒ JsonSchema::Schema
-
#resources ⇒ Object
Resources of json schema.
-
#root_link ⇒ JsonSchema::Schema::Link?
Finds link that has “self” rel to resolve API base URL.
Constructor Details
#initialize(schema) ⇒ Schema
Returns a new instance of Schema.
9 10 11 |
# File 'lib/aries/schema.rb', line 9 def initialize schema @schema = ::JsonSchema.parse!(schema).tap(&:expand_references!) end |
Instance Method Details
#base_url ⇒ String
Find base url of api
24 25 26 |
# File 'lib/aries/schema.rb', line 24 def base_url root_link.try(:href) or raise BaseUrlNotFound end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/aries/schema.rb', line 49 def inspect "#<Aries::Schema base_url=#{base_url}>" end |
#property_by(href) ⇒ JsonSchema::Schema
40 41 42 43 44 45 46 47 |
# File 'lib/aries/schema.rb', line 40 def property_by href accessor = href.gsub(/([a-zA-Z0-9\-\_]+)/).to_a result = @schema accessor.each_with_index do |a, i| result = (i % 2) == 0 ? result.send(a.to_sym) : result[a] end result end |
#resources ⇒ Object
Resources of json schema
15 16 17 18 19 |
# File 'lib/aries/schema.rb', line 15 def resources @resources ||= @schema.properties.map do |name, schema| Resource.new name, schema, self end end |
#root_link ⇒ JsonSchema::Schema::Link?
Finds link that has “self” rel to resolve API base URL
30 31 32 33 34 |
# File 'lib/aries/schema.rb', line 30 def root_link @schema.links.find do |link| link.rel == "self" end end |