spira 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Changelog for Spira <http://github.com/datagraph/spira>
2
-
2
+
3
3
  ## untagged
4
+ * Small updates for RDF.rb 0.2.0 compatibility
5
+ * Add a Spira::Base class that can be inherited from for users who prefer to
6
+ inherit rather than include.
7
+ * Resource#new returns to the public API as a way to create a resource with a
8
+ new blank node subject.
9
+
10
+ ## 0.0.3
4
11
  * Bumped promise dependency to 0.1.1 to fix a Ruby 1.9 warning
5
12
  * Rework error handling when a repository is not configured; this should
6
13
  always now raise a Spira::NoRepositoryError regardless of what operation
data/README CHANGED
@@ -94,9 +94,12 @@ Then use your model classes, in a way more or less similar to any number of ORMs
94
94
  hits = CD.for 'queens-greatest-hits'
95
95
  hits.artist == artist == queen
96
96
 
97
- ### Absolute and Relative URIs
97
+ ### URIs and Blank Nodes
98
98
 
99
- A class with a base URI can reference objects by a short name:
99
+ Spira instances have a subject, which is either a URI or a blank node.
100
+
101
+ A class with a base URI can instantiate with a string (or anything, via to_s),
102
+ and it will have a URI representation:
100
103
 
101
104
  Artist.for('queen')
102
105
 
@@ -108,12 +111,25 @@ can always access classes with a full URI:
108
111
  If you have a URI that you would like to look at as a Spira resource, you can instantiate it from the URI:
109
112
 
110
113
  RDF::URI.new('http://example.org/my-hidden-cds/new-kids').as(Artist)
111
- # => <Artist @uri=http://example.org/my-hidden-cds/new-kids>
114
+ # => <Artist @subject=http://example.org/my-hidden-cds/new-kids>
112
115
 
113
116
  Any call to 'for' with a valid identifier will always return an object with nil
114
117
  fields. It's a way of looking at a given resource, not a closed-world mapping
115
118
  to one.
116
119
 
120
+ You can use also use blank nodes more or less as you would a URI:
121
+
122
+ remix_artist = Artist.for(RDF::Node.new)
123
+ # => <Artist @subject=#<RDF::Node:0xd1d314(_:g13751060)>>
124
+ RDF::Node.new.as(Artist)
125
+ # => <Artist @subject=#<RDF::Node:0xd1d314(_:g13751040)>>
126
+
127
+ Finally, you can create an instance of a Spira projection with #new, and you'll
128
+ get an instance with a shiny new blank node subject:
129
+
130
+ formerly_known_as_prince = Artist.new
131
+ # => <Artist @subject=#<RDF::Node:0xd1d314(_:g13747140)>>
132
+
117
133
  ### Class Options
118
134
 
119
135
  A number of options are available for Spira classes.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/lib/spira.rb CHANGED
@@ -110,6 +110,7 @@ module Spira
110
110
  module_function :type_alias
111
111
 
112
112
  autoload :Resource, 'spira/resource'
113
+ autoload :Base, 'spira/base'
113
114
  autoload :Type, 'spira/type'
114
115
  autoload :Types, 'spira/types'
115
116
  autoload :Errors, 'spira/errors'
data/lib/spira/base.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Spira
2
+
3
+ ##
4
+ # Spira::Base does nothing but include Spira::Resource, if it's more your
5
+ # style to do inheritance than module inclusion.
6
+ #
7
+ # @see Spira::Resource
8
+ class Base
9
+ include Spira::Resource
10
+ end
11
+ end
@@ -67,8 +67,8 @@ module Spira
67
67
  if !self.type.nil? && attributes[:type]
68
68
  raise TypeError, "#{self} has an RDF type, #{self.type}, and cannot accept one as an argument."
69
69
  end
70
- uri = id_for(identifier)
71
- self.new(uri, attributes)
70
+ subject = id_for(identifier)
71
+ self.new(attributes.merge(:_subject => subject))
72
72
  end
73
73
 
74
74
  ##
@@ -20,15 +20,17 @@ module Spira
20
20
  attr_reader :subject
21
21
 
22
22
  ##
23
- # Initialize a new Spira::Resource instance of this resource class. This
24
- # method should not be called directly, use
23
+ # Initialize a new Spira::Resource instance of this resource class using
24
+ # a new blank node subject. Accepts a hash of arguments for initial
25
+ # attributes. To use a URI or existing blank node as a subject, use
25
26
  # {Spira::Resource::ClassMethods#for} instead.
26
27
  #
27
- # @param [RDF::URI, RDF::Node] identifier The URI or URI fragment for this instance
28
28
  # @param [Hash] opts Default attributes for this instance
29
29
  # @see Spira::Resource::ClassMethods#for
30
- def initialize(identifier, opts = {})
31
- @subject = identifier
30
+ # @see RDF::URI#as
31
+ # @see RDF::Node#as
32
+ def initialize(opts = {})
33
+ @subject = opts[:_subject] || RDF::Node.new
32
34
  reload(opts)
33
35
  end
34
36
 
@@ -184,7 +186,7 @@ module Spira
184
186
  #
185
187
  # @private
186
188
  def inspect
187
- "<#{self.class}:#{self.object_id} uri: #{@subject}>"
189
+ "<#{self.class}:#{self.object_id} @subject: #{@subject}>"
188
190
  end
189
191
 
190
192
  ##
data/lib/spira/types.rb CHANGED
@@ -20,6 +20,7 @@ module Spira
20
20
  require 'spira/types/string'
21
21
  require 'spira/types/float'
22
22
  require 'spira/types/uri'
23
+ require 'spira/types/decimal'
23
24
 
24
25
 
25
26
  end
@@ -0,0 +1,29 @@
1
+ module Spira::Types
2
+
3
+ ##
4
+ # A {Spira::Type} for integer values. Values will be associated with the
5
+ # `XSD.integer` type.
6
+ #
7
+ # A {Spira::Resource} property can reference this type as
8
+ # `Spira::Types::Integer`, `Integer`, or `XSD.integer`.
9
+ #
10
+ # @see Spira::Type
11
+ # @see http://rdf.rubyforge.org/RDF/Literal.html
12
+ class Decimal
13
+ include Spira::Type
14
+
15
+ def self.unserialize(value)
16
+ require 'bigdecimal' unless defined?(BigDecimal)
17
+ object = value.object
18
+ object.is_a?(BigDecimal) ? object : BigDecimal.new(object.to_s)
19
+ end
20
+
21
+ def self.serialize(value)
22
+ require 'bigdecimal' unless defined?(BigDecimal)
23
+ RDF::Literal.new(value, :datatype => XSD.decimal)
24
+ end
25
+
26
+ register_alias XSD.decimal
27
+
28
+ end
29
+ end
data/lib/spira/version.rb CHANGED
@@ -2,7 +2,7 @@ module Spira
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 3
5
+ TINY = 4
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ben Lavender
@@ -15,7 +15,7 @@ bindir:
15
15
  - bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-07 00:00:00 +02:00
18
+ date: 2010-06-21 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -23,13 +23,13 @@ dependencies:
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 0
30
- - 1
31
- - 10
32
- version: 0.1.10
30
+ - 2
31
+ - 0
32
+ version: 0.2.0
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -65,13 +65,13 @@ dependencies:
65
65
  prerelease: false
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - ~>
69
69
  - !ruby/object:Gem::Version
70
70
  segments:
71
71
  - 0
72
- - 1
73
- - 10
74
- version: 0.1.10
72
+ - 2
73
+ - 0
74
+ version: 0.2.0
75
75
  type: :runtime
76
76
  version_requirements: *id004
77
77
  - !ruby/object:Gem::Dependency
@@ -116,6 +116,7 @@ files:
116
116
  - README
117
117
  - UNLICENSE
118
118
  - VERSION
119
+ - lib/spira/base.rb
119
120
  - lib/spira/errors.rb
120
121
  - lib/spira/exceptions.rb
121
122
  - lib/spira/resource/class_methods.rb
@@ -126,6 +127,7 @@ files:
126
127
  - lib/spira/type.rb
127
128
  - lib/spira/types/any.rb
128
129
  - lib/spira/types/boolean.rb
130
+ - lib/spira/types/decimal.rb
129
131
  - lib/spira/types/float.rb
130
132
  - lib/spira/types/integer.rb
131
133
  - lib/spira/types/string.rb