class Shaf::ResourceDoc
Attributes
attributes[R]
curies[R]
embeds[R]
links[R]
name[R]
Public Class Methods
find(name)
click to toggle source
# 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)
click to toggle source
# File lib/shaf/resource_doc.rb, line 14 def find!(name) find(name) or raise(Errors::NotFoundError, "No documentation for #{name}") end
new(name, properties = {})
click to toggle source
# 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
Private Class Methods
docs()
click to toggle source
# File lib/shaf/resource_doc.rb, line 20 def docs @docs ||= {} end
load(name)
click to toggle source
# File lib/shaf/resource_doc.rb, line 24 def load(name) file = File.join(Settings.documents_dir, "#{name}.yml") return YAML.load(File.read(file)) if File.exist? file end
Public Instance Methods
attribute(attr)
click to toggle source
# 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)
click to toggle source
# File lib/shaf/resource_doc.rb, line 63 def embedded(name) embed_doc = embeds[name.to_s] return embed_doc if embed_doc raise Errors::NotFoundError, "No documentation for #{name} embedded '#{name}'" end
link(rel)
click to toggle source
# 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()
click to toggle source
# File lib/shaf/resource_doc.rb, line 40 def to_s JSON.pretty_generate( attributes: attributes, links: links, curies: curies, embeds: embeds, ) end