mementus 0.5.9 → 0.5.10

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: d72f23a450b59fac9738ab69fcd8b1897cb9fe50
4
- data.tar.gz: b30bbb72e5b3e23b02a0f7d26eb0de51728c18ab
3
+ metadata.gz: 51576e4f06689d15c0f10ecc7543bbf2135b7aa2
4
+ data.tar.gz: 8c681b2e0747301acb9febb7c15bc45b4fd1fedd
5
5
  SHA512:
6
- metadata.gz: f5c318c087e36b1f212c5b3a45afd2c8d38bfb9f44366b2a404a9fa98bf34a534ac8015e35c7a8d9d9474dc3ae9848b7eb777ad48ae9b85f306ff4564969b803
7
- data.tar.gz: 5e487bd68022e6fb6c8081e0563eb44e09869734e1b61bffda1f36274deecbf784fb0289332fa7008a3eb67ff9378585dd84919483cec29fe6157a6c7ab9f3b3
6
+ metadata.gz: 20fbeee9ae1f0abff80637fb97214c6366899c7d9788ef74e0fd2e1a5e6d9015b449e71d8168223e73abef598ae3dd29a651aea5d19c4ad6b77c4b62ea2bb269
7
+ data.tar.gz: 82587fa758d97b6217950ca795a4d557b020117d9d35251a042547ed1eed85e53beb92747bd0a18c5a8ea734aaf5d94d6674372d4fa48a602e12eef542f49bd8
@@ -0,0 +1,20 @@
1
+ module Mementus
2
+ class BindingDelegator
3
+ def initialize(instance, scope)
4
+ @instance = instance
5
+ @scope = scope.eval('self')
6
+ end
7
+
8
+ def method_missing(name, *args, &block)
9
+ if @instance.respond_to?(name)
10
+ @instance.send(name, *args, &block)
11
+ else
12
+ @scope.send(name, *args, &block)
13
+ end
14
+ end
15
+
16
+ def respond_to_missing?(name)
17
+ @scope.respond_to?(name) || @instance.respond_to?(name)
18
+ end
19
+ end
20
+ end
@@ -5,7 +5,7 @@ module Mementus
5
5
  def initialize(is_directed=true, &block)
6
6
  builder = GraphBuilder.new(is_directed)
7
7
 
8
- builder.instance_eval(&block) if block_given?
8
+ BindingDelegator.new(builder, block.binding).instance_eval(&block) if block_given?
9
9
 
10
10
  @structure = builder.graph
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module Mementus
2
- VERSION = '0.5.9'.freeze
2
+ VERSION = '0.5.10'.freeze
3
3
  end
data/lib/mementus.rb CHANGED
@@ -19,6 +19,7 @@ require 'mementus/depth_first_search'
19
19
  require 'mementus/breadth_first_search'
20
20
  require 'mementus/integer_id'
21
21
  require 'mementus/element_builder'
22
+ require 'mementus/binding_delegator'
22
23
  require 'mementus/graph_builder'
23
24
  require 'mementus/node_builder'
24
25
  require 'mementus/edge_builder'
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ class GraphWrapper
4
+ def one
5
+ 111
6
+ end
7
+
8
+ def two
9
+ 222
10
+ end
11
+
12
+ def build
13
+ Mementus::Graph.new do
14
+ add_edge(from: one, to: two)
15
+ end
16
+ end
17
+ end
18
+
19
+ describe Mementus::BindingDelegator do
20
+ it 'dispatches to methods in block scope' do
21
+ graph = GraphWrapper.new.build
22
+ expect(graph.n(111).first.outgoing.first.id).to eq(222)
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mementus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - maetl
@@ -65,6 +65,7 @@ files:
65
65
  - LICENSE.txt
66
66
  - README.md
67
67
  - lib/mementus.rb
68
+ - lib/mementus/binding_delegator.rb
68
69
  - lib/mementus/breadth_first_search.rb
69
70
  - lib/mementus/depth_first_search.rb
70
71
  - lib/mementus/direction.rb
@@ -94,6 +95,7 @@ files:
94
95
  - lib/mementus/structure/incidence_list.rb
95
96
  - lib/mementus/version.rb
96
97
  - mementus.gemspec
98
+ - spec/binding_delegator_spec.rb
97
99
  - spec/direction_spec.rb
98
100
  - spec/edge_proxy_spec.rb
99
101
  - spec/edge_spec.rb
@@ -136,6 +138,7 @@ signing_key:
136
138
  specification_version: 4
137
139
  summary: Graph data structure toolkit for Ruby applications.
138
140
  test_files:
141
+ - spec/binding_delegator_spec.rb
139
142
  - spec/direction_spec.rb
140
143
  - spec/edge_proxy_spec.rb
141
144
  - spec/edge_spec.rb