Module: Tripod::Links::ClassMethods

Defined in:
lib/tripod/links.rb

Instance Method Summary collapse

Instance Method Details

#linked_from(name, incoming_field_name, options = {}) ⇒ LinkedTo

Define that another resource links to this one. Creates a getter with the name you specify. For this to work, the incoming class needs to define a linked_to relationship. Just creates the relevant getter which always return an array of objects.

  linked_from :dogs, :owner

  linked_from :doggies, :person, class_name: ‘Dog’

 @option options [ String ] class_name The name of the class that links to this resource, if we can’t guess it from the link name

Examples:

make a method called people which returns Dog objects, via the linked_to :owner field on Dog. We guess the class name based on the linked_from name.

make a method called doggies which returns Dog objects, via the linked_to :person field on Dog.

Parameters:

  • name (Symbol)

    The name of the link.

  • incoming_field_name (Symbol)

    The name of the linked_to relationship on the other class

  • options (Hash) (defaults to: {})

    The options to pass to the field.

Returns:



60
61
62
# File 'lib/tripod/links.rb', line 60

def linked_from(name, incoming_field_name, options = {})
  add_linked_from(name, incoming_field_name, options)
end

#linked_to(name, predicate, options = {}) ⇒ LinkedTo

Define a link to another resource. Creates relevant fields and getter/setter methods. Note that the getter only retrives saved resources from the db.

Examples:

Define a link away from resources of this class to resources of class Organisation

linked_to :organisation, 'http://example.com/name'

Define a multivalued link away from resources of this class (can be combined with other options)

linked_to :organisations, 'http://example.com/modified_at',  multivalued: true

Define a link away from resources of this class, specifying the class and the field name that will be generated

linked_to :org, 'http://example.com/modified_at', class_name: 'Organisation', field: my_field

Parameters:

  • name (Symbol)

    The name of the link.

  • predicate (String, RDF::URI)

    The predicate for the field.

  • options (Hash) (defaults to: {})

    The options to pass to the field.

Options Hash (options):

  • multivalued (Boolean)

    Is this a multi-valued field? Default is false.

  • class_name (String)

    The name of the class of resource which we’re linking to (normally will derive this from the link name)

  • field_name (Symbol)

    the symbol of the field that will be generated (normally will just add _uri or _uris to the link name)

Returns:



38
39
40
# File 'lib/tripod/links.rb', line 38

def linked_to(name, predicate, options = {})
  add_linked_to(name, predicate, options)
end