-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
530d83e
commit f8689b5
Showing
7 changed files
with
115 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Neo4j | ||
module Shared | ||
module Typecaster | ||
def self.included(other) | ||
Neo4j::Shared::TypeConverters.register_converter(other) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
describe 'custom type conversion' do | ||
class RangeConverter | ||
class << self | ||
def primitive_type | ||
String | ||
end | ||
|
||
def convert_type | ||
Range | ||
end | ||
|
||
def to_db(value) | ||
value.to_s | ||
end | ||
|
||
def to_ruby(value) | ||
ends = value.to_s.split('..').map { |d| Integer(d) } | ||
ends[0]..ends[1] | ||
end | ||
alias_method :call, :to_ruby | ||
end | ||
|
||
include Neo4j::Shared::Typecaster | ||
end | ||
|
||
class RangeConvertPerson | ||
include Neo4j::ActiveNode | ||
property :my_range, type: Range | ||
end | ||
|
||
it 'registers the typecaster' do | ||
expect(Neo4j::Shared::TypeConverters.converters).to have_key(Range) | ||
end | ||
|
||
it 'uses the custom typecaster' do | ||
r = RangeConvertPerson.new | ||
r.my_range = 1..30 | ||
r.save | ||
r.reload | ||
expect(r.my_range).to be_a(Range) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters