Skip to content

Commit

Permalink
Merge pull request maxdemarzi#19 from kamranjon/relations
Browse files Browse the repository at this point in the history
changing :as and :reverse arguments to :out and :in
  • Loading branch information
kamranjon committed Aug 21, 2013
2 parents 983f42f + ba25103 commit 1c7bedc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions lib/deja/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ class << self
attr_reader :relationship_names

def relationship(name, opts = {})
raise StandardError, "'as' alias must be specified" unless opts.is_a? Hash and opts[:as]
raise StandardError, "'out' or 'in' aliases must be specified" unless opts.is_a? Hash and (opts[:out] or opts[:in])
@relationship_names ||= {}
if opts[:reverse] then
@relationship_names[name] = {
:out_singular => opts[:as].to_s.singularize,
:out_plural => opts[:as].to_s.pluralize,
:in_singular => opts[:reverse].to_s.singularize,
:in_plural => opts[:reverse].to_s.pluralize
:out_singular => opts[:out].to_s.singularize,
:out_plural => opts[:out].to_s.pluralize,
:in_singular => opts[:in].to_s.singularize,
:in_plural => opts[:in].to_s.pluralize
}
else
@relationship_names[name] = {
:out_singular => opts[:as].to_s.singularize,
:out_plural => opts[:as].to_s.pluralize
:out_singular => opts[:out].to_s.singularize,
:out_plural => opts[:out].to_s.pluralize
}
end
attr_writer name
Expand Down
8 changes: 4 additions & 4 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ class Company < Deja::Node
attribute :permalink, String, :index => true
attribute :type, String

relationship :invested_in, :as => :investment, :reverse => :investor
relationship :invested_in, :out => :investment, :in => :investor
end

class Person < Deja::Node
attribute :name, String
attribute :permalink, String, :index => true
attribute :type, String

relationship :invested_in, :as => :investment
relationship :friends_with, :as => :friends
relationship :has_hate, :as => :hates
relationship :invested_in, :out => :investment
relationship :friends_with, :out => :friends
relationship :has_hate, :out => :hates
end


Expand Down

0 comments on commit 1c7bedc

Please sign in to comment.