elasticsearch-model-extensions 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91592da0d915c072cdaa65f2a805d94edab055e9
4
- data.tar.gz: c9b8c32829eb32ca15d9971fe5dc967b2947b740
3
+ metadata.gz: 230f4b0043c57c9df059dbf2e374a04f4d1c664d
4
+ data.tar.gz: ed147cfd9c46fd23479c3c172669a30c9f4cb55d
5
5
  SHA512:
6
- metadata.gz: 0900f09019a5451ba338c7b619a3ad23cda124624f9aa902865289f27164c6f7245d2235b77b9ffce6beda2a927cc02e7a26426d2235339bd6ddefb3a0fa44bb
7
- data.tar.gz: 523697b1b2836f2033941899db7077edc6ea2c7302b8d317f54745d3339e86bf3286e96065ae9155f1522e1c95ca4d5e095997954b94b7c86e337def1686a54b
6
+ metadata.gz: ccfbe7336e23b8b8ce8c50127181cbbe3c44cbd66ef165a7a58a777c23e84c84540ab17b54d755b3d65a2cc8b2896ce7efe0751672a11432c716664965d06dc6
7
+ data.tar.gz: ff730a3b4d8de0ee4350f3fbb5d8fabc34dd8c77105d0f2182b1042e38d92e659a524392c6c2bb0b0cb2c1e280a8d892800db0ce55188afe1750118865e962c3
@@ -1,4 +1,4 @@
1
- require 'shortest_path'
1
+ require_relative 'shortest_path'
2
2
 
3
3
  module Elasticsearch
4
4
  module Model
@@ -0,0 +1,98 @@
1
+ module Elasticsearch
2
+ module Model
3
+ module Extensions
4
+ class ShortestPath
5
+ class Node
6
+ include Enumerable
7
+
8
+ def each(&block)
9
+ raise "A required method #{self.class}#each is not implemented."
10
+ end
11
+
12
+ def name
13
+ raise "A required method #{self.class}#name is not implemented."
14
+ end
15
+
16
+ def each_with_name(&block)
17
+ iterator = each.lazy.map do |edge|
18
+ [edge, edge.name]
19
+ end
20
+
21
+ if block.nil?
22
+ iterator
23
+ else
24
+ iterator.each(&block)
25
+ end
26
+ end
27
+
28
+ def hash
29
+ name.hash
30
+ end
31
+
32
+ def eql?(other)
33
+ self.class == other.class && (name.eql? other.name)
34
+ end
35
+
36
+ def edge_class
37
+ ShortestPath::Edge
38
+ end
39
+
40
+ def breadth_first_search(&block)
41
+ ShortestPath.breadth_first_search self, &block
42
+ end
43
+ end
44
+
45
+ class Edge
46
+ def initialize(name:, destination:)
47
+ @name = name
48
+ @destination = destination
49
+ end
50
+
51
+ def name
52
+ @name
53
+ end
54
+
55
+ def destination
56
+ @destination
57
+ end
58
+ end
59
+
60
+ module ClassMethods
61
+ def breadth_first_search(node, &block)
62
+ paths = node.each.map { |e| [e] }
63
+
64
+ loop {
65
+ a = paths.select { |p|
66
+ if block.call(p.last)
67
+ p
68
+ end
69
+ }
70
+
71
+ return a if a.size != 0
72
+
73
+ paths = paths.flat_map { |p|
74
+ p.last.destination.each.map { |e|
75
+ p + [e]
76
+ }
77
+ }
78
+ }
79
+ end
80
+
81
+ def depth_first_search(node, &block)
82
+ node.each.select do |edge|
83
+ if block.call(edge)
84
+ [[edge]]
85
+ else
86
+ depth_first_search(edge.destination, &block).map do |path|
87
+ [edge] + path
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ extend ClassMethods
95
+ end
96
+ end
97
+ end
98
+ end
@@ -1,7 +1,7 @@
1
1
  module Elasticsearch
2
2
  module Model
3
3
  module Extensions
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-model-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke KUOKA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -63,6 +63,7 @@ files:
63
63
  - lib/elasticsearch/model/extensions/mapping_reflection.rb
64
64
  - lib/elasticsearch/model/extensions/outer_document_updating.rb
65
65
  - lib/elasticsearch/model/extensions/partial_updating.rb
66
+ - lib/elasticsearch/model/extensions/shortest_path.rb
66
67
  - lib/elasticsearch/model/extensions/update_callback.rb
67
68
  - lib/elasticsearch/model/extensions/version.rb
68
69
  homepage: https://github.com/crowdworks/elasticsearch-model-extensions