Skip to content
This repository
Browse code

Update readme with new instantiation syntax

  • Loading branch information...
commit 59a3713385fe732fc3678ec5ea7a32b6968f13ba 1 parent 15c4b2d
Ben Lavender bhuga authored

Showing 1 changed file with 23 additions and 13 deletions. Show diff stats Hide diff stats

  1. +23 13 README.md
36 README.md
Source Rendered
@@ -24,7 +24,7 @@ or to create a new store of RDF data based on simple defaults.
24 24
25 25 end
26 26
27   - bob = Person.create 'bob'
  27 + bob = Person.for('bob')
28 28 bob.age = 15
29 29 bob.name = "Bob Smith"
30 30 bob.save!
@@ -75,9 +75,9 @@ without the `RDF::` prefix. For example:
75 75
76 76 Then use your model classes, in a way more or less similar to any number of ORMs:
77 77
78   - cd = CD.create "queens-greatest-hits"
  78 + cd = CD.for("queens-greatest-hits")
79 79 cd.name = "Queen's greatest hits"
80   - artist = Artist.create "queen"
  80 + artist = Artist.for("queen")
81 81 artist.name = "Queen"
82 82
83 83 cd.artist = artist
@@ -85,21 +85,30 @@ Then use your model classes, in a way more or less similar to any number of ORMs
85 85 artist.cds = [cd]
86 86 artist.save!
87 87
88   - queen = Arist.find 'queen'
89   - hits = CD.find 'queens-greatest-hits'
  88 + queen = Arist.for('queen')
  89 + hits = CD.for 'queens-greatest-hits'
90 90 hits.artist == artist == queen
91 91
92 92 ### Absolute and Relative URIs
93 93
94 94 A class with a base URI can reference objects by a short name:
95 95
96   - Artist.find 'queen'
  96 + Artist.for('queen')
97 97
98 98 However, a class is not required to have a base URI, and even if it does, it
99 99 can always access classes with a full URI:
100 100
101   - nk = Artist.find RDF::URI.new('http://example.org/my-hidden-cds/new-kids')
102   -
  101 + nk = Artist.for(RDF::URI.new('http://example.org/my-hidden-cds/new-kids'))
  102 +
  103 +If you have a URI that you would like to look at as a Spira resource, you can instantiate it from the URI:
  104 +
  105 + RDF::URI.new('http://example.org/my-hidden-cds/new-kids').as(Artist)
  106 + # => <Artist @uri=http://example.org/my-hidden-cds/new-kids>
  107 +
  108 +Spira uses an open-world model. Any call to 'for' with a valid identifier will
  109 +always return an object with nil fields. It's a way of looking at a given
  110 +resource, not the definition of one.
  111 +
103 112 ### Class Options
104 113
105 114 A number of options are available for Spira classes.
@@ -107,11 +116,11 @@ A number of options are available for Spira classes.
107 116 #### base_uri
108 117
109 118 A class with a `base_uri` set (either an `RDF::URI` or a `String`) will
110   -use that URI as a base URI for non-absolute `create` and `find` calls.
  119 +use that URI as a base URI for non-absolute `for` calls.
111 120
112 121 Example
113   - CD.find 'queens-greatest-hits' # is the same as...
114   - CD.find RDF::URI.new('http://example.org/cds/queens-greatest-hits')
  122 + CD.for 'queens-greatest-hits' # is the same as...
  123 + CD.for RDF::URI.new('http://example.org/cds/queens-greatest-hits')
115 124
116 125 #### type
117 126
@@ -123,7 +132,7 @@ A class with a `type` set is assigned an `RDF.type` on creation and saving.
123 132 property :name, :predicate => DC.title
124 133 end
125 134
126   - rolling_stones = Album.create RDF::URI.new('http://example.org/cds/rolling-stones-hits')
  135 + rolling_stones = Album.for RDF::URI.new('http://example.org/cds/rolling-stones-hits')
127 136 # See RDF.rb for more information about #has_predicate?
128 137 rolling_stones.has_predicate?(RDF.type) #=> true
129 138 Album.type #=> RDF::URI('http://example.org/types/album')
@@ -152,9 +161,10 @@ A class with a `default_vocabulary` set will transparently create predicates for
152 161 property :author, :type => :artist
153 162 end
154 163
155   - dancing_queen = Song.create 'dancing-queen'
  164 + dancing_queen = Song.for 'dancing-queen'
156 165 dancing_queen.title = "Dancing Queen"
157 166 dancing_queen.artist = abba
  167 + # See RDF::Enumerable for #has_predicate?
158 168 dancing_queen.has_predicate?(RDF::URI.new('http://example.org/vocab/title')) #=> true
159 169 dancing_queen.has_predicate?(RDF::URI.new('http://example.org/vocab/artist')) #=> true
160 170

0 comments on commit 59a3713

Please sign in to comment.
Something went wrong with that request. Please try again.