Class: ActiveGraph::Core::Element
- Inherits:
 - 
      Object
      
        
- Object
 - ActiveGraph::Core::Element
 
 
- Defined in:
 - lib/active_graph/core/element.rb
 
Instance Attribute Summary collapse
- 
  
    
      #name  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute name.
 
Class Method Summary collapse
Instance Method Summary collapse
- #constraint?(property) ⇒ Boolean
 - #constraints(_options = {}) ⇒ Object
 - 
  
    
      #create_constraint(property, type: :key)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Creates a neo4j constraint on a property See docs.neo4j.org/chunked/stable/query-constraints.html.
 - #create_index(*properties, **options) ⇒ Object
 - 
  
    
      #drop_constraint(property, type: :key)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Drops a neo4j constraint on a property See docs.neo4j.org/chunked/stable/query-constraints.html.
 - #drop_index(property, options = {}) ⇒ Object
 - #drop_indexes ⇒ Object
 - #drop_uniqueness_constraint(property, options = {}) ⇒ Object
 - #index?(property) ⇒ Boolean
 - #indexes ⇒ Object
 - 
  
    
      #initialize(name)  ⇒ Element 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Element.
 - #uniqueness_constraint?(property) ⇒ Boolean
 - #uniqueness_constraints(_options = {}) ⇒ Object
 
Constructor Details
#initialize(name) ⇒ Element
Returns a new instance of Element.
      7 8 9  | 
    
      # File 'lib/active_graph/core/element.rb', line 7 def initialize(name) @name = name end  | 
  
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
      4 5 6  | 
    
      # File 'lib/active_graph/core/element.rb', line 4 def name @name end  | 
  
Class Method Details
.drop_constraints ⇒ Object
      99 100 101 102 103 104 105 106 107 108  | 
    
      # File 'lib/active_graph/core/element.rb', line 99 def drop_constraints result = ActiveGraph::Base.read_transaction do |tx| tx.run('SHOW CONSTRAINTS YIELD *').to_a end ActiveGraph::Base.write_transaction do |tx| result.each do |record| tx.run("DROP CONSTRAINT `#{record[:name]}`") end end end  | 
  
.drop_indexes ⇒ Object
      93 94 95 96 97  | 
    
      # File 'lib/active_graph/core/element.rb', line 93 def drop_indexes indexes.each do |definition| ActiveGraph::Base.query("DROP INDEX #{definition[:name]}") unless definition[:owningConstraint] end end  | 
  
.indexes ⇒ Object
      89 90 91  | 
    
      # File 'lib/active_graph/core/element.rb', line 89 def indexes ActiveGraph::Base.indexes end  | 
  
Instance Method Details
#constraint?(property) ⇒ Boolean
      78 79 80  | 
    
      # File 'lib/active_graph/core/element.rb', line 78 def constraint?(property) constraints.any? { |definition| definition[:properties] == [property.to_sym] } end  | 
  
#constraints(_options = {}) ⇒ Object
      66 67 68 69 70  | 
    
      # File 'lib/active_graph/core/element.rb', line 66 def constraints( = {}) ActiveGraph::Base.constraints.select do |definition| definition[:label] == @name.to_sym end end  | 
  
#create_constraint(property, type: :key) ⇒ Object
Creates a neo4j constraint on a property See docs.neo4j.org/chunked/stable/query-constraints.html
      31 32 33 34 35  | 
    
      # File 'lib/active_graph/core/element.rb', line 31 def create_constraint(property, type: :key) schema_query( "CREATE CONSTRAINT #{constraint_name(property, type:)} FOR #{pattern("n:`#{name}`")} REQUIRE n.`#{property}` IS #{constraint_type(type:)}" ) end  | 
  
#create_index(*properties, **options) ⇒ Object
      11 12 13 14 15  | 
    
      # File 'lib/active_graph/core/element.rb', line 11 def create_index(*properties, **) () properties = properties.map { |p| "l.#{p}" } schema_query("CREATE INDEX FOR (l:`#{@name}`) ON (#{properties.join('.')})") end  | 
  
#drop_constraint(property, type: :key) ⇒ Object
Drops a neo4j constraint on a property See docs.neo4j.org/chunked/stable/query-constraints.html
      44 45 46  | 
    
      # File 'lib/active_graph/core/element.rb', line 44 def drop_constraint(property, type: :key) schema_query("DROP CONSTRAINT #{constraint_name(property, type:)} IF EXISTS") end  | 
  
#drop_index(property, options = {}) ⇒ Object
      17 18 19 20 21 22 23  | 
    
      # File 'lib/active_graph/core/element.rb', line 17 def drop_index(property, = {}) () schema_query("SHOW INDEXES YIELD * WHERE labelsOrTypes = $labels AND properties = $properties", labels: [@name], properties: [property]).each do |record| schema_query("DROP INDEX #{record[:name]}") end end  | 
  
#drop_indexes ⇒ Object
      58 59 60  | 
    
      # File 'lib/active_graph/core/element.rb', line 58 def drop_indexes self.class.drop_indexes end  | 
  
#drop_uniqueness_constraint(property, options = {}) ⇒ Object
      48 49 50  | 
    
      # File 'lib/active_graph/core/element.rb', line 48 def drop_uniqueness_constraint(property, = {}) drop_constraint(property, type: :unique) end  | 
  
#index?(property) ⇒ Boolean
      62 63 64  | 
    
      # File 'lib/active_graph/core/element.rb', line 62 def index?(property) indexes.any? { |definition| definition[:properties] == [property.to_sym] } end  | 
  
#indexes ⇒ Object
      52 53 54 55 56  | 
    
      # File 'lib/active_graph/core/element.rb', line 52 def indexes self.class.indexes.select do |definition| definition[:label] == @name.to_sym end end  | 
  
#uniqueness_constraint?(property) ⇒ Boolean
      82 83 84  | 
    
      # File 'lib/active_graph/core/element.rb', line 82 def uniqueness_constraint?(property) uniqueness_constraints.include?([property]) end  | 
  
#uniqueness_constraints(_options = {}) ⇒ Object
      72 73 74 75 76  | 
    
      # File 'lib/active_graph/core/element.rb', line 72 def uniqueness_constraints( = {}) constraints.select do |definition| definition[:type] == :uniqueness end end  |