nasty 0.0.1386739849 → 0.0.1388162472
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 +4 -4
- data/lib/nasty/background_job.rb +20 -0
- data/lib/nasty/kernel.rb +9 -0
- data/lib/nasty/lambda_behaviours.rb +7 -0
- data/lib/nasty.rb +3 -0
- data/spec/unit/lambda_behaviours_spec.rb +15 -0
- data/spec/unit/using_spec.rb +26 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 642033e0d0fe0194dbac76d15ea61ff8f4392445
|
4
|
+
data.tar.gz: 9bef2d7c6d40c6ffec26c1356ce0eff7db1996b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/nasty/kernel.rb
ADDED
data/lib/nasty.rb
CHANGED
@@ -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.
|
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
|
+
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.
|
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
|