Module: Tripod::Fields::ClassMethods
- Defined in:
- lib/tripod/fields.rb
Instance Method Summary collapse
-
#field(name, predicate, options = {}) ⇒ Field
Defines all the fields that are accessible on the Resource For each field that is defined, a getter and setter will be added as an instance method to the Resource.
-
#fields ⇒ Object
Return all of the fields on a
Resource
in a manner that respects Ruby’s inheritance rules. -
#get_field(name) ⇒ Object
Return the field object on a
Resource
associated with the given name.
Instance Method Details
#field(name, predicate, options = {}) ⇒ Field
Defines all the fields that are accessible on the Resource For each field that is defined, a getter and setter will be added as an instance method to the Resource.
@option options [ String, RDF::URI ] datatype The uri of the datatype for the field (will be used to create an RDF::Literal of the right type on the way in only).
45 46 47 48 |
# File 'lib/tripod/fields.rb', line 45 def field(name, predicate, = {}) @fields ||= {} add_field(name, predicate, ) end |
#fields ⇒ Object
Return all of the fields on a Resource
in a manner that respects Ruby’s inheritance rules. i.e. subclass fields should override superclass fields with the same
66 67 68 69 70 |
# File 'lib/tripod/fields.rb', line 66 def fields tripod_superclasses.map { |c| c.instance_variable_get(:@fields) }.reduce do |acc,class_fields| class_fields.merge(acc) end end |
#get_field(name) ⇒ Object
Return the field object on a Resource
associated with the given name.
56 57 58 59 60 61 |
# File 'lib/tripod/fields.rb', line 56 def get_field(name) @fields ||= {} field = fields[name] raise Tripod::Errors::FieldNotPresent.new unless field field end |