module Neomirror::Relationship::ClassMethods
Attributes
neo_primary_key[W]
Public Instance Methods
mirror_neo_relationship(options, &block)
click to toggle source
# File lib/neomirror/relationship.rb, line 27 def mirror_neo_relationship(options, &block) m = Hash[options.map{ |k, v| [k.to_sym, v] }] raise ArgumentError, "Mirror with such options already defined" if rel_mirror(m) raise ArgumentError, "Options :start_node and :end_node are mandatory" unless m[:start_node] && m[:end_node] m[:start_node] = m[:start_node].to_sym m[:end_node] = m[:end_node].to_sym class_name = self.name.gsub(/^.*::/, '').gsub(/([a-z\d])([A-Z])/, '\1_\2') m[:type] = (m[:type] ? m[:type] : class_name.upcase).to_sym m[:properties] = Neomirror::PropertyCollector.new(&block).properties if block_given? m[:if] = m[:if].to_proc if m[:if] m[:index_name] = "#{m[:start_node] == :self ? class_name.downcase : m[:start_node]}_#{m[:type]}_#{m[:end_node] == :self ? class_name.downcase : m[:end_node]}" m[:complete] = true # indicates a completely filled rel mirror hash (not partial, that used for search) ::Neomirror.neo.create_relationship_index(m[:index_name]) rel_mirrors << m end
neo_primary_key()
click to toggle source
# File lib/neomirror/relationship.rb, line 43 def neo_primary_key @neo_primary_key ||= self.respond_to?(:primary_key) ? self.__send__(:primary_key) : :id end
rel_mirror(p)
click to toggle source
Find declaration by partial options.
# File lib/neomirror/relationship.rb, line 21 def rel_mirror(p) return rel_mirrors.first unless p.present? rel_mirrors.find { |m| (!p[:start_node] || p[:start_node] == m[:start_node]) && (!p[:end_node] || p[:end_node] == m[:end_node]) && (!p[:type] || p[:type] == m[:type]) } end
rel_mirrors()
click to toggle source
# File lib/neomirror/relationship.rb, line 10 def rel_mirrors @rel_mirrors ||= begin if a = self.ancestors.drop(1).find { |c| c.respond_to?(:rel_mirrors) && c.rel_mirrors.any? } a.rel_mirrors else [] end end end