Class: Related::Node::Query
- Inherits:
-
Object
- Object
- Related::Node::Query
- Includes:
- DistributedFallback, QueryMethods
- Defined in:
- lib/related/node.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
writeonly
Sets the attribute depth.
-
#destination ⇒ Object
writeonly
Sets the attribute destination.
-
#direction ⇒ Object
writeonly
Sets the attribute direction.
-
#include_start_node ⇒ Object
writeonly
Sets the attribute include_start_node.
-
#limit ⇒ Object
writeonly
Sets the attribute limit.
-
#options ⇒ Object
writeonly
Sets the attribute options.
-
#page ⇒ Object
writeonly
Sets the attribute page.
-
#relationship_type ⇒ Object
writeonly
Sets the attribute relationship_type.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#result_type ⇒ Object
writeonly
Sets the attribute result_type.
-
#search_algorithm ⇒ Object
writeonly
Sets the attribute search_algorithm.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #count ⇒ Object
- #diff(query) ⇒ Object
- #each(&block) ⇒ Object
- #find(node) ⇒ Object
- #include?(entity) ⇒ Boolean
-
#initialize(node) ⇒ Query
constructor
A new instance of Query.
- #intersect(query) ⇒ Object
- #map(&block) ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
- #to_json(options = {}) ⇒ Object
- #union(query) ⇒ Object
Methods included from QueryMethods
#depth, #include_start_node, #incoming, #limit, #nodes, #options, #outgoing, #page, #path_to, #per_page, #relationships, #shortest_path_to
Constructor Details
#initialize(node) ⇒ Query
Returns a new instance of Query.
128 129 130 131 132 133 |
# File 'lib/related/node.rb', line 128 def initialize(node) @node = node @result_type = :nodes @depth = 4 @options = {} end |
Instance Attribute Details
#depth=(value) ⇒ Object (writeonly)
Sets the attribute depth
122 123 124 |
# File 'lib/related/node.rb', line 122 def depth=(value) @depth = value end |
#destination=(value) ⇒ Object (writeonly)
Sets the attribute destination
124 125 126 |
# File 'lib/related/node.rb', line 124 def destination=(value) @destination = value end |
#direction=(value) ⇒ Object (writeonly)
Sets the attribute direction
119 120 121 |
# File 'lib/related/node.rb', line 119 def direction=(value) @direction = value end |
#include_start_node=(value) ⇒ Object (writeonly)
Sets the attribute include_start_node
123 124 125 |
# File 'lib/related/node.rb', line 123 def include_start_node=(value) @include_start_node = value end |
#limit=(value) ⇒ Object (writeonly)
Sets the attribute limit
120 121 122 |
# File 'lib/related/node.rb', line 120 def limit=(value) @limit = value end |
#options=(value) ⇒ Object (writeonly)
Sets the attribute options
126 127 128 |
# File 'lib/related/node.rb', line 126 def (value) @options = value end |
#page=(value) ⇒ Object (writeonly)
Sets the attribute page
121 122 123 |
# File 'lib/related/node.rb', line 121 def page=(value) @page = value end |
#relationship_type=(value) ⇒ Object (writeonly)
Sets the attribute relationship_type
118 119 120 |
# File 'lib/related/node.rb', line 118 def relationship_type=(value) @relationship_type = value end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
115 116 117 |
# File 'lib/related/node.rb', line 115 def result @result end |
#result_type=(value) ⇒ Object (writeonly)
Sets the attribute result_type
117 118 119 |
# File 'lib/related/node.rb', line 117 def result_type=(value) @result_type = value end |
#search_algorithm=(value) ⇒ Object (writeonly)
Sets the attribute search_algorithm
125 126 127 |
# File 'lib/related/node.rb', line 125 def search_algorithm=(value) @search_algorithm = value end |
Instance Method Details
#as_json(options = {}) ⇒ Object
207 208 209 |
# File 'lib/related/node.rb', line 207 def as_json( = {}) self.to_a end |
#count ⇒ Object
152 153 154 155 156 157 |
# File 'lib/related/node.rb', line 152 def count @count = @result_type == :nodes ? Related.redis.scard(key) : Related.redis.zcard(key) @limit && @count > @limit ? @limit : @count end |
#diff(query) ⇒ Object
195 196 197 198 199 |
# File 'lib/related/node.rb', line 195 def diff(query) @result_type = :nodes @result = Related.redis.sdiff(key, query.key) self end |
#each(&block) ⇒ Object
135 136 137 |
# File 'lib/related/node.rb', line 135 def each(&block) self.to_a.each(&block) end |
#find(node) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/related/node.rb', line 177 def find(node) if @result_type == :nodes if Related.redis.sismember(key, node.id) node_class.find(node.id, @options) end else if id = Related.redis.get(dir_key(node)) Related::Relationship.find(id, @options) end end end |
#include?(entity) ⇒ Boolean
163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/related/node.rb', line 163 def include?(entity) if @destination self.to_a.include?(entity) else if entity.is_a?(node_class) @result_type = :nodes Related.redis.sismember(key, entity.id) elsif entity.is_a?(Related::Relationship) @result_type = :relationships Related.redis.sismember(key, entity.id) end end end |
#intersect(query) ⇒ Object
201 202 203 204 205 |
# File 'lib/related/node.rb', line 201 def intersect(query) @result_type = :nodes @result = Related.redis.sinter(key, query.key) self end |
#map(&block) ⇒ Object
139 140 141 |
# File 'lib/related/node.rb', line 139 def map(&block) self.to_a.map(&block) end |
#size ⇒ Object
159 160 161 |
# File 'lib/related/node.rb', line 159 def size @count || count end |
#to_a ⇒ Object
143 144 145 146 147 148 149 150 |
# File 'lib/related/node.rb', line 143 def to_a perform_query unless @result if @result_type == :nodes node_class.find(@result, @options) else Related::Relationship.find(@result, @options) end end |
#to_json(options = {}) ⇒ Object
211 212 213 |
# File 'lib/related/node.rb', line 211 def to_json( = {}) self.as_json.to_json() end |