nasty 0.0.1386739849 → 0.0.1388162472

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: d00aed6e79f442e75e8f6be52047ab8067078f76
4
- data.tar.gz: 04d300b4f50fab0ed04d7b236a7997e5f3f3db55
3
+ metadata.gz: 642033e0d0fe0194dbac76d15ea61ff8f4392445
4
+ data.tar.gz: 9bef2d7c6d40c6ffec26c1356ce0eff7db1996b7
5
5
  SHA512:
6
- metadata.gz: 978975665ee0f2524007922f20c151f6c5f3047008e1c43a5b94627c8ec3a68c0cb3c56231320efbe00ae87d2fdba080a8cfd4cc8f00763cacb5a4eb01d6ff0d
7
- data.tar.gz: c4d037599eb4e703370f0d6fee453a95585a1eb36f1d84d7e06dfdc023bd735bf284dc8da42978dd0a0a9169e2ed12db1e69a2cb88cd9656d60ddc4c490d96c2
6
+ metadata.gz: ef743b56cfb87efac47b67e2d0074f53354fe5be971f233a8c6ab9d442409edc8e972801edc0268fbd4352d711533ec15223460f721abc436e709365e79b45e3
7
+ data.tar.gz: f1304112fd741f6ea08d74d519374edf556b153654c70728c21a475143ff0ca73ab724e9ac2c1068beb36c78dfd4a69b511bfe01b26ec5879de6a74ae1063145
@@ -0,0 +1,20 @@
1
+ module Nasty
2
+ class BackgroundJob
3
+ def initialize(process)
4
+ @process = process
5
+ end
6
+
7
+ def run
8
+ @pid = fork do
9
+ exec @process
10
+ end
11
+ end
12
+
13
+ def stop(signal = "TERM")
14
+ if @pid
15
+ Process.kill(signal, @pid)
16
+ Process.wait(@pid)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ module Kernel
2
+ def using(resource, &block)
3
+ begin
4
+ block.call
5
+ ensure
6
+ resource.dispose
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Nasty
2
+ module LambdaBehaviours
3
+ def memoize(lambda_method)
4
+ lambda { |*args| @cache ||= lambda_method.call(*args) }
5
+ end
6
+ end
7
+ end
data/lib/nasty.rb CHANGED
@@ -1,5 +1,8 @@
1
+ require "nasty/background_job"
1
2
  require "nasty/command"
2
3
  require "nasty/composite_command"
4
+ require "nasty/kernel"
5
+ require "nasty/lambda_behaviours"
3
6
  require "nasty/version"
4
7
 
5
8
  module Nasty
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ module Nasty
4
+ describe LambdaBehaviours do
5
+ include LambdaBehaviours
6
+
7
+ it "memoizes the lambda" do
8
+ calculation = memoize(lambda { |x| x + rand(100) })
9
+ first_result = calculation.call(1)
10
+ calculation.call(1).should == first_result
11
+ calculation.call(1).should == first_result
12
+ calculation.call(1).should == first_result
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe "using" do
4
+ let(:item) { double("item", dispose: true) }
5
+
6
+ it "disposes the item" do
7
+ using(item) { }
8
+ item.should have_received(:dispose)
9
+ end
10
+
11
+ it "performs the action" do
12
+ ran = false
13
+ using(item) do
14
+ ran = true
15
+ end
16
+ ran.should be_true
17
+ end
18
+
19
+ it "always cleans up the resource" do
20
+ begin
21
+ using(item) { raise "heck" }
22
+ rescue
23
+ end
24
+ item.should have_received(:dispose)
25
+ end
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nasty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1386739849
4
+ version: 0.0.1388162472
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-11 00:00:00.000000000 Z
11
+ date: 2013-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,12 +80,17 @@ files:
80
80
  - README.md
81
81
  - Rakefile
82
82
  - lib/nasty.rb
83
+ - lib/nasty/background_job.rb
83
84
  - lib/nasty/command.rb
84
85
  - lib/nasty/composite_command.rb
86
+ - lib/nasty/kernel.rb
87
+ - lib/nasty/lambda_behaviours.rb
85
88
  - lib/nasty/version.rb
86
89
  - nasty.gemspec
87
90
  - spec/spec_helper.rb
88
91
  - spec/unit/command_spec.rb
92
+ - spec/unit/lambda_behaviours_spec.rb
93
+ - spec/unit/using_spec.rb
89
94
  homepage: http://github.com/mokhan/nasty
90
95
  licenses:
91
96
  - MIT
@@ -106,10 +111,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
111
  version: '0'
107
112
  requirements: []
108
113
  rubyforge_project:
109
- rubygems_version: 2.1.11
114
+ rubygems_version: 2.0.14
110
115
  signing_key:
111
116
  specification_version: 4
112
117
  summary: basicly it's a commons library
113
118
  test_files:
114
119
  - spec/spec_helper.rb
115
120
  - spec/unit/command_spec.rb
121
+ - spec/unit/lambda_behaviours_spec.rb
122
+ - spec/unit/using_spec.rb