Module: Ladder::Resource
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveTriples::Identifiable, Mongoid::Document
- Defined in:
- lib/ladder/resource.rb
Defined Under Namespace
Modules: ClassMethods, Dynamic
Instance Method Summary collapse
-
#as_jsonld(opts = {}) ⇒ Object
Return JSON-LD representation.
-
#rdf_label ⇒ Object
Overload ActiveTriples #rdf_label.
-
#update_resource(opts = {}) ⇒ Object
Populate resource properties from ActiveModel.
Instance Method Details
#as_jsonld(opts = {}) ⇒ Object
Return JSON-LD representation
21 22 23 |
# File 'lib/ladder/resource.rb', line 21 def as_jsonld(opts = {}) JSON.parse update_resource(opts.slice :related).dump(:jsonld, {standard_prefixes: true}.merge(opts)) end |
#rdf_label ⇒ Object
Overload ActiveTriples #rdf_label
29 30 31 32 |
# File 'lib/ladder/resource.rb', line 29 def rdf_label update_resource resource.rdf_label end |
#update_resource(opts = {}) ⇒ Object
Populate resource properties from ActiveModel
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ladder/resource.rb', line 36 def update_resource(opts = {}) resource_class.properties.each do |name, property| value = update_from_field(name) if fields[name] value = update_from_relation(name, opts) if relations[name] cast_uri = RDF::URI.new(value) resource.set_value(property.predicate, cast_uri.valid? ? cast_uri : value) if value end resource end |