cordawyn / spira

Fork of Spira with experimental branches, occasionally merged upstream.
http://blog.datagraph.org/2010/05/spira
The Unlicense
8 stars 2 forks source link

Property with class as object #8

Closed phlegx closed 12 years ago

phlegx commented 12 years ago

I have my vocabulary http://example.com/foo. This vocabulary has a property http://example.com/foo#has_area. The object of foo#has_area is an instance of class http://example.com/foo#area in my vocabulary.

How can I code it in spira?

# app/models/foo.rb
class foo < Spira::Base
   ...
   property :has_area, :predicate => RDF::URI.new('http://example.com/foo#has_area'), :type => :area
end

# app/models/area.rb
class area < Spira::Base
   ...
end

Spira return the error: "Could not find relation class area (referenced as area by #Foo:0x00000004b11008)"

cordawyn commented 12 years ago

You cannot have class names in Ruby in lower case. A class name in ruby must be a constant, starting with a capital letter. Doesn't your ruby interpreter issue errors for your code?

Here's your code, with my adjustments. Works for me.

class Foo < Spira::Base

...

property :has_area, :predicate => RDF::URI.new('http://example.com/foo#has_area'), :type => :Area end

class Area < Spira::Base

...

end

phlegx commented 12 years ago

Very cool man! Thx.

In Rails, symbols has : at the beginning and all in lowercase. Why don't use symbols that are converted into regular class names with methods capitalize, humanize and/or classify?

http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html

cordawyn commented 12 years ago

Spira wasn't initially a part of Rails ecosystem and it didn't have a dependency on ActiveSupport and the like. It has been using some home-brewn methods for many things that are available in ActiveSupport. It was the choice of the original author, not mine. I'm getting rid of the legacy code, but all in its good time.