Property type of a symbol

2 views
Skip to first unread message

Dmytrii Nagirniak

unread,
Dec 7, 2011, 12:02:02 AM12/7/11
to neo4jrb
Hi,

Is it possible to make sure that the property is always a symbol so that the spec below passes:

it "should allow string-ish status" do
u = User.new
u.status = 'invited'
u.status.should == :active
end


And the class:

class User < Neo4j::Model
property :status, :type => :ProbablySymbolIsNotAvailableButMustBeAWayToConvert, :default => :active
end


As the last resort, there must be some hook similar to ActiveRecord write_attribute/read_attribute?

Thanks,
Dmytrii

Vivek Prahlad

unread,
Dec 7, 2011, 12:13:34 AM12/7/11
to neo...@googlegroups.com
Hi,

I think you'll need to write a small convertor to handle symbols (it looks like symbols aren't supported out of the box, unfortunately). Once the convertor is registered (probably in a Rails initializer?), it will be available in all of your models.

Please take a look at https://github.com/andreasronge/neo4j/blob/master/spec/type_converters/type_converters_spec.rb and
https://github.com/andreasronge/neo4j/blob/master/lib/neo4j/type_converters/type_converters.rb

(The spec shows how to add a new converter)

Cheers,
Vivek


--
You received this message because you are subscribed to the Google Groups "neo4jrb" group.
To post to this group, send email to neo...@googlegroups.com.
To unsubscribe from this group, send email to neo4jrb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/neo4jrb?hl=en.


Dmytrii Nagirniak

unread,
Dec 7, 2011, 12:22:14 AM12/7/11
to neo...@googlegroups.com
Thanks a lot for that.
That's exactly what I need.

Another thing is that it seems the :type option is just ignored.

When I do:
class User < Neo4j::Model
  property :status, :type => :definitely_wrong_and_not_existing, :default => :active
end

The type value is obviously wrong but there no any error raised.
Why is that?

Vivek Prahlad

unread,
Dec 7, 2011, 12:34:45 AM12/7/11
to neo...@googlegroups.com
From what I can see, this is because there is a 'DefaultConvertor' that's used as a fallback in case a convertor is not found - but I agree, your example should raise an error instead. Could you please raise a bug?

Vivek

Dmytrii Nagirniak

unread,
Dec 7, 2011, 1:21:53 AM12/7/11
to neo...@googlegroups.com
On 07/12/2011, at 4:34 PM, Vivek Prahlad wrote:

From what I can see, this is because there is a 'DefaultConvertor' that's used as a fallback in case a convertor is not found - but I agree, your example should raise an error instead. Could you please raise a bug?

Dmytrii Nagirniak

unread,
Dec 7, 2011, 1:47:12 AM12/7/11
to neo...@googlegroups.com
On 07/12/2011, at 4:13 PM, Vivek Prahlad wrote:

Thanks for that.

Do you want to accept the Pull Request to support it natively?

Maybe you can also release the gem so I don't have to do the same thing in my app?
Reply all
Reply to author
Forward
0 new messages