Class: Cyrel::Pattern::Relationship
- Inherits:
-
Object
- Object
- Cyrel::Pattern::Relationship
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, Cyrel::Parameterizable
- Defined in:
- lib/cyrel/pattern/relationship.rb
Instance Method Summary collapse
-
#initialize(types:, direction: Cyrel::Direction::BOTH, **kw) ⇒ Relationship
constructor
A new instance of Relationship.
- #render(query) ⇒ Object
Constructor Details
#initialize(types:, direction: Cyrel::Direction::BOTH, **kw) ⇒ Relationship
Returns a new instance of Relationship.
16 17 18 19 |
# File 'lib/cyrel/pattern/relationship.rb', line 16 def initialize(types:, direction: Cyrel::Direction::BOTH, **kw) # Accept string or array for :types just like the old API super({ types: Array(types) }.merge(kw).merge(direction: direction)) end |
Instance Method Details
#render(query) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cyrel/pattern/relationship.rb', line 21 def render(query) # For anonymous relationships (no alias, no types, no properties, no length) # we don't render brackets at all if alias_name.nil? && types.empty? && properties.empty? && length.nil? case direction in Direction::OUT then '-->' in Direction::IN then '<--' else '--' end else # Regular relationship with brackets core = +'[' core << alias_name.to_s if alias_name core << ':' << Array(types).join('|') unless types.empty? core << length_spec core << " #{prop_string(query)}" unless properties.empty? core << ']' case direction in Direction::OUT then "-#{core}->" in Direction::IN then "<-#{core}-" else "-#{core}-" end end end |