Class: Shaf::DocModel
- Inherits:
-
Object
- Object
- Shaf::DocModel
- Defined in:
- lib/shaf/doc_model.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attribute(attr) ⇒ Object
- #embedded(name) ⇒ Object
-
#initialize(name) ⇒ DocModel
constructor
A new instance of DocModel.
- #link(rel) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ DocModel
Returns a new instance of DocModel.
24 25 26 |
# File 'lib/shaf/doc_model.rb', line 24 def initialize(name) @name = name end |
Class Method Details
.find(name) ⇒ Object
6 7 8 9 10 |
# File 'lib/shaf/doc_model.rb', line 6 def find(name) @@docs ||= {} @@docs[name] ||= load(name) new(name) if @@docs[name] end |
.find!(name) ⇒ Object
12 13 14 |
# File 'lib/shaf/doc_model.rb', line 12 def find!(name) find(name) or raise(Errors::NotFoundError, "No documentation for #{name}") end |
Instance Method Details
#attribute(attr) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/shaf/doc_model.rb', line 33 def attribute(attr) attr_doc = @@docs.dig(@name, 'attributes', attr.to_s) return attr_doc if attr_doc raise Errors::NotFoundError, "No documentation for #{@name} attribute '#{attr}'" end |
#embedded(name) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/shaf/doc_model.rb', line 47 def (name) = @@docs.dig(@name, 'embeds', name.to_s) return if raise Errors::NotFoundError, "No documentation for #{@name} embedded '#{name}'" end |
#link(rel) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/shaf/doc_model.rb', line 40 def link(rel) link_doc = @@docs.dig(@name, 'links', rel.to_s) return link_doc if link_doc raise Errors::NotFoundError, "No documentation for #{@name} link relation '#{rel}'" end |
#to_s ⇒ Object
28 29 30 31 |
# File 'lib/shaf/doc_model.rb', line 28 def to_s return "#{@name} not found" unless @@docs[@name] JSON.pretty_generate(@@docs[@name]) end |