class Halibut::Builder::RootContext
This is the root context of Halibut::Builder
.
Public Class Methods
# File lib/halibut/builder.rb, line 31 def initialize(resource, &resource_definition) @resource = resource instance_eval(&resource_definition) if block_given? end
Public Instance Methods
Adds a link to the respection relation of the resource.
@param [String] relation relation to which link will be added @param [String] href URI of the link @param [Hash] options Link optional parameters: templated, hreflang, etc @return [Halibut::Core::Resource] resource with the link added
# File lib/halibut/builder.rb, line 53 def link(relation, href, options={}) @resource.add_link relation, href, options end
Adds a namespace to the resource.
A namespace is a conceptual abstraction of CURIE links. Since the client of the library doesn't need to handle CURIE links directly because they're just for dereferencing link relations, no CURIE links are presented.
resource = Halibut::Builder.new do namespace :john, 'http://appleseed.com' end.resource resource.namespace(:john).href # => "http://appleseed.com"
@param [String,Symbol] name name of the namespace @param [String] href URI of the namespace
# File lib/halibut/builder.rb, line 72 def namespace(name, href) @resource.add_namespace(name, href) end
Sets a property on the resource. Will overwrite any same-named existing property.
@param [String] name name of the property @param [String] value value of the property @return [Halibut::Core::resource] resource with property set
# File lib/halibut/builder.rb, line 43 def property(name, value) @resource.set_property name, value end
Adds links or resources to a relation.
Relation allows the user to specify links, or resources, per relation, instead of individually. This feature was introduced as an attempt to reduce repeating the relation per link/resource, and thus reducing typos.
resource = Halibut::Builder.new do relation :john do link 'http://appleseed.com/john' end end.resource resource.links[:john].first.href
@param [String,Symbol] rel @param [Proc] blk Instructions to be executed in the relation
context
# File lib/halibut/builder.rb, line 104 def relation(rel, &relation_definition) RelationContext.new(@resource, rel, &relation_definition) end
Adds an embedded resource.
@param [String] rel Embedded resource relation to the parent resource @param [String] href URI to the resource itself @param [Proc] blk Instructions to construct the embedded resource
# File lib/halibut/builder.rb, line 81 def resource(rel, href=nil, &embedded_definition) embedded = Halibut::Builder.new(href, &embedded_definition) @resource.embed_resource(rel, embedded.resource) end