class Shaf::Profile
Public Class Methods
attribute(*args, **kwargs, &block)
click to toggle source
# File lib/shaf/profile.rb, line 50 def attribute(*args, **kwargs, &block) evaluator.attribute(*args, **kwargs, &block) end
attributes()
click to toggle source
# File lib/shaf/profile.rb, line 38 def attributes @attributes ||= [] end
descriptor(id)
click to toggle source
# File lib/shaf/profile.rb, line 59 def descriptor(id) find_attribute(id) || find_relation(id) end
doc(str = nil)
click to toggle source
# File lib/shaf/profile.rb, line 20 def doc(str = nil) @doc = str if str @doc if defined? @doc end
example(str)
click to toggle source
# File lib/shaf/profile.rb, line 30 def example(str) examples << str end
examples()
click to toggle source
# File lib/shaf/profile.rb, line 46 def examples @examples ||= [] end
find_attribute(id)
click to toggle source
# File lib/shaf/profile.rb, line 63 def find_attribute(id) attributes.find { |attr| attr.id.to_sym == id.to_sym } end
find_relation(id)
click to toggle source
# File lib/shaf/profile.rb, line 67 def find_relation(id) relations.find { |rel| rel.id.to_sym == id.to_sym } end
inherited(child)
click to toggle source
# File lib/shaf/profile.rb, line 11 def inherited(child) Profiles.register child end
match?(str)
click to toggle source
# File lib/shaf/profile.rb, line 34 def match?(str) normalize(name) == normalize(str) end
name(str = nil)
click to toggle source
# File lib/shaf/profile.rb, line 15 def name(str = nil) @name = str if str @name if defined? @name end
relation(*args, **kwargs, &block)
click to toggle source
# File lib/shaf/profile.rb, line 54 def relation(*args, **kwargs, &block) evaluator.rel(*args, **kwargs, &block) end
Also aliased as: rel
relations()
click to toggle source
# File lib/shaf/profile.rb, line 42 def relations @relations ||= [] end
urn(value = nil)
click to toggle source
# File lib/shaf/profile.rb, line 25 def urn(value = nil) @urn = value if value @urn if defined? @urn end
use(*descriptors, from:, doc: nil)
click to toggle source
# File lib/shaf/profile.rb, line 71 def use(*descriptors, from:, doc: nil) descriptors.each do |id| desc = from.descriptor(id) href = profile_path(from.name, fragment_id: id) case desc when Relation kwargs = { doc: doc || desc&.doc, href: href, http_methods: desc.http_methods, payload_type: desc.payload_type, content_type: desc.content_type, } relation(id, **kwargs) when Attribute attribute(id, href: href, doc: doc) when NilClass raise "#{from.name} does not have a descriptor with id #{id}" else raise Errors::ServerError, "Unsupported descriptor: #{desc}" end end end
Private Class Methods
evaluator()
click to toggle source
# File lib/shaf/profile.rb, line 98 def evaluator Evaluator.new(parent: self) end
normalize(name)
click to toggle source
# File lib/shaf/profile.rb, line 102 def normalize(name) name.to_s.downcase.tr('-', '_') end
Public Instance Methods
name()
click to toggle source
# File lib/shaf/profile.rb, line 107 def name normalize(self.class.name) end
normalize(str)
click to toggle source
# File lib/shaf/profile.rb, line 111 def normalize(str) self.class.normalize(str) end