nasty 0.0.1388165564 → 0.0.1388166636

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03ada69e453d4784d6c93304dd6396d362c4752e
4
- data.tar.gz: 3f5a3775b57439efd2d05738600b8845f265ff6b
3
+ metadata.gz: 6a199b39461b16ea3634bf8b2f5d539cf68ca1bd
4
+ data.tar.gz: ab5aff2b9257964399a87247f5726ad5a959561e
5
5
  SHA512:
6
- metadata.gz: a5648fb4ea8c638d2cd2f5d82f4bb8d55ab3120d2f75e753b87c0b54041489e0ea1874a808afa36900343830b6ca37703b9ade2553cbacee3b50dab8fb394bbe
7
- data.tar.gz: 287f5678b2baab3c9fe90e58f37414e46d411fe14e04227f45d8347fd92267538955cea51b1b06d0af7b3ebdc242a508260868699266673613c5697ccbd2c6ea
6
+ metadata.gz: 8ae5b30bbca156ce1bfcbb317daf24a8ecf03e787f453f4b792574404f026f4951d0f6ba4b1fbe9b96fae6867e8853077c7fab5c8c4361b00612629c72847640
7
+ data.tar.gz: 9ceddeb796de7c33fc0b756476fd666147f5d8a19ff77e255c40f92578b4f8d802c1e33726f43c07b2a96b1d35920684a46d79710bb525f6b42a2e111aecf50d
@@ -5,6 +5,7 @@ require "nasty/composite_command"
5
5
  require "nasty/expose_binding"
6
6
  require "nasty/kernel"
7
7
  require "nasty/lambda_behaviours"
8
+ require "nasty/lazy"
8
9
  require "nasty/log"
9
10
  require "nasty/object"
10
11
  require "nasty/version"
@@ -0,0 +1,23 @@
1
+ module Nasty
2
+ class Lazy
3
+ def initialize(factory = ->(key) { key.new }, *arguments)
4
+ @factory = factory
5
+ @arguments = arguments
6
+ end
7
+
8
+ def method_missing(name, *args, &block)
9
+ @target ||= @factory.call(*@arguments)
10
+ @target.send(name, args, &block)
11
+ end
12
+
13
+ class << self
14
+ def bind_resolver(&block)
15
+ @@factory = block
16
+ end
17
+
18
+ def load(key, factory = @@factory)
19
+ Lazy.new(factory, key)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ module Nasty
4
+ describe Lazy do
5
+ context "when lazy loading an item from a factory" do
6
+ context "when invoking a method on the proxy" do
7
+ let(:factory) { double }
8
+ let(:blackbook) { double }
9
+
10
+ before :each do
11
+ blackbook.stub(:find).and_return("nasty")
12
+ Lazy.bind_factory do |key|
13
+ blackbook if key == :blackbook
14
+ end
15
+ end
16
+
17
+ it "should invoke the target" do
18
+ Lazy.load(:blackbook).find(:booty).should == "nasty"
19
+ end
20
+ end
21
+
22
+ context "before invocation" do
23
+ let(:factory) { ->(*args) { @called = true } }
24
+
25
+ before :each do
26
+ Lazy.load(:blackbook, factory)
27
+ end
28
+
29
+ it "does not resolve the component from the factory" do
30
+ @called.should be_false
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nasty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1388165564
4
+ version: 0.0.1388166636
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan
@@ -87,6 +87,7 @@ files:
87
87
  - lib/nasty/expose_binding.rb
88
88
  - lib/nasty/kernel.rb
89
89
  - lib/nasty/lambda_behaviours.rb
90
+ - lib/nasty/lazy.rb
90
91
  - lib/nasty/log.rb
91
92
  - lib/nasty/object.rb
92
93
  - lib/nasty/version.rb
@@ -96,6 +97,7 @@ files:
96
97
  - spec/unit/command_spec.rb
97
98
  - spec/unit/expose_binding_spec.rb
98
99
  - spec/unit/lambda_behaviours_spec.rb
100
+ - spec/unit/lazy_spec.rb
99
101
  - spec/unit/log_spec.rb
100
102
  - spec/unit/using_spec.rb
101
103
  homepage: http://github.com/mokhan/nasty
@@ -128,5 +130,6 @@ test_files:
128
130
  - spec/unit/command_spec.rb
129
131
  - spec/unit/expose_binding_spec.rb
130
132
  - spec/unit/lambda_behaviours_spec.rb
133
+ - spec/unit/lazy_spec.rb
131
134
  - spec/unit/log_spec.rb
132
135
  - spec/unit/using_spec.rb