lib/rdf/json/extensions.rb in rdf-json-0.2.0 vs lib/rdf/json/extensions.rb in rdf-json-0.3.0.pre
- old
+ new
@@ -49,11 +49,11 @@
# @return [String]
def to_json
# Any RDF/JSON-compatible class must implement `#to_rdf_json`:
to_rdf_json.to_json
end
- end
+ end # Value
##
# RDF/JSON extensions for `RDF::Node`.
module Node
##
@@ -61,11 +61,11 @@
#
# @return [Hash]
def to_rdf_json
{:type => :bnode, :value => to_s}
end
- end
+ end # Node
##
# RDF/JSON extensions for `RDF::URI`.
module URI
##
@@ -73,11 +73,11 @@
#
# @return [Hash]
def to_rdf_json
{:type => :uri, :value => to_s}
end
- end
+ end # URI
##
# RDF/JSON extensions for `RDF::Literal`.
module Literal
##
@@ -92,11 +92,11 @@
{:type => :literal, :value => value.to_s, :lang => language.to_s}
else
{:type => :literal, :value => value.to_s}
end
end
- end
+ end # Literal
##
# RDF/JSON extensions for `RDF::Statement`.
module Statement
##
@@ -104,11 +104,11 @@
#
# @return [Hash]
def to_rdf_json
{subject.to_s => {predicate.to_s => [object.to_rdf_json]}}
end
- end
+ end # Statement
##
# RDF/JSON extensions for `RDF::Enumerable`.
module Enumerable
##
@@ -133,22 +133,40 @@
json[s][p] ||= []
json[s][p] << o.to_rdf_json
end
json
end
- end
+ end # Enumerable
##
# RDF/JSON extensions for `RDF::Graph`.
module Graph
include Enumerable
- end
+ end # Graph
##
# RDF/JSON extensions for `RDF::Repository`.
module Repository
include Enumerable
- end
- end # module Extensions
+ end # Repository
+ ##
+ # RDF/JSON extensions for `RDF::Transaction`.
+ module Transaction
+ ##
+ # Returns the serialized JSON representation of this object.
+ #
+ # @return [String]
+ def to_json
+ json = options.dup.to_hash rescue {}
+ json.merge!({
+ :graph => graph ? graph.to_uri.to_s : nil,
+ :delete => deletes.to_rdf_json,
+ :insert => inserts.to_rdf_json,
+ })
+ json.to_json
+ end
+ end # Transaction
+ end # Extensions
+
Extensions.install!
-end # module RDF::JSON
+end # RDF::JSON