Class: Shaf::ResourceDoc
- Inherits:
-
Object
- Object
- Shaf::ResourceDoc
- Defined in:
- lib/shaf/resource_doc.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#curies ⇒ Object
readonly
Returns the value of attribute curies.
-
#embeds ⇒ Object
readonly
Returns the value of attribute embeds.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #attribute(attr) ⇒ Object
- #embedded(name) ⇒ Object
-
#initialize(name, properties = {}) ⇒ ResourceDoc
constructor
A new instance of ResourceDoc.
- #link(rel) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, properties = {}) ⇒ ResourceDoc
Returns a new instance of ResourceDoc.
32 33 34 35 36 37 38 |
# File 'lib/shaf/resource_doc.rb', line 32 def initialize(name, properties = {}) @name = name @attributes = properties.fetch('attributes', {}) @links = properties.fetch('links', {}) @curies = properties.fetch('curies', {}) @embeds = properties.fetch('embeds', {}) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
30 31 32 |
# File 'lib/shaf/resource_doc.rb', line 30 def attributes @attributes end |
#curies ⇒ Object (readonly)
Returns the value of attribute curies.
30 31 32 |
# File 'lib/shaf/resource_doc.rb', line 30 def curies @curies end |
#embeds ⇒ Object (readonly)
Returns the value of attribute embeds.
30 31 32 |
# File 'lib/shaf/resource_doc.rb', line 30 def @embeds end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
30 31 32 |
# File 'lib/shaf/resource_doc.rb', line 30 def links @links end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/shaf/resource_doc.rb', line 30 def name @name end |
Class Method Details
.find(name) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/shaf/resource_doc.rb', line 6 def find(name) unless docs[name] properties = load(name) or return docs[name] = new(name, properties) end docs[name] end |
.find!(name) ⇒ Object
14 15 16 |
# File 'lib/shaf/resource_doc.rb', line 14 def find!(name) find(name) or raise(Errors::NotFoundError, "No documentation for #{name}") end |
Instance Method Details
#attribute(attr) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/shaf/resource_doc.rb', line 49 def attribute(attr) attr_doc = attributes[attr.to_s] return attr_doc if attr_doc raise Errors::NotFoundError, "No documentation for #{name} attribute '#{attr}'" end |
#embedded(name) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/shaf/resource_doc.rb', line 63 def (name) = [name.to_s] return if raise Errors::NotFoundError, "No documentation for #{name} embedded '#{name}'" end |
#link(rel) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/shaf/resource_doc.rb', line 56 def link(rel) link_doc = links[rel.to_s] return link_doc if link_doc raise Errors::NotFoundError, "No documentation for #{name} link relation '#{rel}'" end |
#to_s ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/shaf/resource_doc.rb', line 40 def to_s JSON.pretty_generate( attributes: attributes, links: links, curies: curies, embeds: , ) end |