Class: V
- Inherits:
-
ActiveOrient::Model
- Object
- ActiveOrient::Base
- ActiveOrient::Model
- V
- Defined in:
- lib/model/vertex.rb
Constant Summary
Constants included from OrientDB
OrientDB::DocumentDatabase, OrientDB::DocumentDatabasePool, OrientDB::DocumentDatabasePooled, OrientDB::GraphDatabase, OrientDB::IndexType, OrientDB::OClassImpl, OrientDB::OTraverse, OrientDB::PropertyImpl, OrientDB::RemoteStorage, OrientDB::SQLCommand, OrientDB::SQLSynchQuery, OrientDB::Schema, OrientDB::SchemaProxy, OrientDB::SchemaType, OrientDB::ServerAdmin, OrientDB::User, OrientDB::UsingJava
Instance Attribute Summary
Attributes inherited from ActiveOrient::Model
Attributes inherited from ActiveOrient::Base
Class Method Summary collapse
-
.delete(where:) ⇒ Object
Vertex#delete fires a “delete edge” command to the database.
Instance Method Summary collapse
-
#detect_inherent_edge(kind, edge_name) ⇒ Object
:nodoc:.
-
#edges(kind = :all) ⇒ Object
retrieves connected edges.
-
#in(edge_name = nil) ⇒ Object
»in« and »out« provide the main access to edges.
-
#in_edges ⇒ Object
»in_edges« and »out_edges« are shortcuts to »edges :in« and »edges :out«.
- #out(edge_name = nil) ⇒ Object
- #out_edges ⇒ Object
- #remove ⇒ Object
Methods inherited from ActiveOrient::Model
autoload_object, delete_class, #document, #to_ary
Methods included from ModelClass
#add_edge_link, #all, #alter_property, #classname, #count, #create, #create_index, #create_properties, #create_property, #custom_where, #delete_property, #delete_record, #delete_records, #first, #get, #get_model_class, #get_properties, #get_records, #last, #match, #naming_convention, #orientdb_class, #print_class_properties, #query_database, #require_model_file, #update_all, #update_or_create_records, #upsert, #where
Methods included from ModelRecord
#add_item_to_property, classname, #find, #from_orient, #increment_version, #is_edge?, #method_missing, #query, #reload!, #remove_item_from_property, #remove_position_from_property, #rid, #rrid, #save, #set_item_to_property, #to_or, #update, #update_attribute, #update_attributes, #update_item_property, #version, #version=
Methods included from ActiveOrient::BaseProperties
#==, #content_attributes, #default_attributes, #set_attribute_defaults, #to_human, #update_missing
Methods inherited from ActiveOrient::Base
#[], #[]=, attr_accessible, attr_protected, #attributes, #attributes=, belongs_to, display_rid, #document, get_rid, has_many, has_one, #initialize, #my_metadata, remove_rid, reset_rid_store, serialize, store_rid, #to_model, #update_attribute
Constructor Details
This class inherits a constructor from ActiveOrient::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ModelRecord
Class Method Details
.delete(where:) ⇒ Object
Vertex#delete fires a “delete edge” command to the database. The where statement can be empty ( “” or {}“), then all vertices are removed
The rid-cache is reseted, too
10 11 12 13 |
# File 'lib/model/vertex.rb', line 10 def self.delete where: db.execute { "delete vertex #{ref_name} #{db.compose_where(where)}" } reset_rid_store end |
Instance Method Details
#detect_inherent_edge(kind, edge_name) ⇒ Object
:nodoc:
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/model/vertex.rb', line 15 def detect_inherent_edge kind, edge_name # :nodoc: ## returns a list of inherented classes get_superclass = ->(e) do n = ORD.get_db_superclass(e) n =='E' ? e : e + ',' + get_superclass[n] end if edge_name.present? e_name = edge_name.is_a?( Class) ? edge_name.ref_name : edge_name.to_s the_edge = @metadata[:edges][kind].detect{|y| get_superclass[y].split(',').detect{|x| x == edge_name } } candidate= attributes["#{kind.to_s}_#{the_edge}"] candidate.present? ? candidate.map( &:from_orient ) : [] else edges(kind).map &:from_orient end end |
#edges(kind = :all) ⇒ Object
retrieves connected edges
The basic ussage is to fetch all/ incomming/ outgoing edges
Model-Instance.edges :in # :out | :all
One can filter specific edges by providing parts of the edge-name
Model-Instance.edges 'in_sector'
Model-Instance.edges /sector/
returns an array of rid’s
example:
Industry.first.attributes.keys
=> ["in_sector_classification", "k", "name", "created_at", "updated_at"] # edge--> in ...
Industry.first.edges :out
=> []
Industry.first.edges :in
=> ["#61:0", "#61:9", "#61:21", "#61:33", "#61:39", "#61:93", "#61:120", "#61:150", "#61:240", "#61:252", "#61:264", "#61:279", "#61:303", "#61:339" ...]
To fetch the associated records use the ActiveOrient::Model.autoload_object method
ActiveOrient::Model.autoload_object Industry.first.edges( :in).first
# or
Industry.autoload_object Industry.first.edges( /sector/ ).first
=> #<SectorClassification:0x00000002daad20 @metadata={"type"=>"d", "class"=>"sector_classification", "version"=>1, "fieldTypes"=>"out=x,in=x", "cluster"=>61, "record"=>0},(...)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/model/vertex.rb', line 84 def edges kind=:all # :all, :in, :out expression = case kind when :all /^in|^out/ when :in /^in/ when :out /^out/ when String /#{kind}/ when Regexp kind else return [] end edges = attributes.keys.find_all{ |x| x =~ expression } edges.map{|x| attributes[x]}.flatten end |
#in(edge_name = nil) ⇒ Object
»in« and »out« provide the main access to edges.
If called without a parameter, all edges connected are displayed.
If called with a string, symbol or class, the edge-class is resolved and even inherented edges are retrieved.
41 42 43 |
# File 'lib/model/vertex.rb', line 41 def in edge_name= nil detect_inherent_edge :in, edge_name end |
#in_edges ⇒ Object
»in_edges« and »out_edges« are shortcuts to »edges :in« and »edges :out«
Its easy to expand the result:
tg.out( :ohlc).out.out_edges
=> [["#102:11032", "#121:0"]]
tg.out( :ohlc).out.out_edges.from_orient
=> [[#<TG::GRID_OF:0x00000002620e38
this displays the out-edges correctly
whereas tg.out( :ohlc).out.edges( :out)
=> [["#101:11032", "#102:11032", "#94:10653", "#121:0"]]
returns all edges. The parameter (:out) is not recognized, because out is already a nested array.
this
tg.out( :ohlc).first.out.edges( :out)
is a walkaround, but using in_- and out_edges is more elegant.
125 126 127 |
# File 'lib/model/vertex.rb', line 125 def in_edges edges :in end |
#out(edge_name = nil) ⇒ Object
45 46 47 |
# File 'lib/model/vertex.rb', line 45 def out edge_name = nil detect_inherent_edge :out, edge_name end |
#out_edges ⇒ Object
128 129 130 |
# File 'lib/model/vertex.rb', line 128 def out_edges edges :out end |
#remove ⇒ Object
132 133 134 |
# File 'lib/model/vertex.rb', line 132 def remove db.delete_vertex self end |