elf 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in elf.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 fl00r
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Elf
2
+
3
+ Elves are creatures to manage background processes.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'elf'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install elf
18
+
19
+ ## Usage
20
+
21
+ Elves are creatures to manage background processes.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task :default => :spec
5
+
6
+ desc 'Tests'
7
+ Rake::TestTask.new(:spec) do |t|
8
+ t.libs << 'spec'
9
+ t.pattern = 'spec/**/*_spec.rb'
10
+ t.verbose = false
11
+ end
data/elf.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/elf/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Petr Yanovich"]
6
+ gem.email = ["fl00r@yandex.ru"]
7
+ gem.description = %q{Elves are creatures to manage background processes}
8
+ gem.summary = %q{Elves are creatures to manage background processes}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "elf"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Elf::VERSION
17
+ end
data/lib/elf.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "elf/version"
2
+ require "elf/process"
3
+ require "elf/child"
4
+ require "elf/fork"
5
+ require "elf/sync"
6
+
7
+ module Elf
8
+ # Your code goes here...
9
+ end
data/lib/elf/child.rb ADDED
@@ -0,0 +1,31 @@
1
+ module Elf
2
+ class Child
3
+ def initialize(cmd)
4
+ @cmd = cmd
5
+ fire
6
+ end
7
+
8
+ def success=(&blk)
9
+ @success = blk
10
+ success if @status.exitstatus == 0
11
+ end
12
+
13
+ def success
14
+ puts "Success: #{@cmd}"
15
+ @success.call if @success
16
+ end
17
+
18
+ def error
19
+ puts "Failed: #{@cmd}"
20
+ end
21
+
22
+ def fire
23
+ fork_pid = ::Process.fork do
24
+ puts "Fired: #{@cmd}"
25
+ exec @cmd
26
+ end
27
+ pid, @status = ::Process.waitpid2(fork_pid)
28
+ @status.exitstatus == 0 ? success : error
29
+ end
30
+ end
31
+ end
data/lib/elf/fork.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Elf
2
+ class Fork < Child
3
+ alias :sync_fire :fire
4
+
5
+ def fire
6
+ fork do
7
+ sync_fire
8
+ end
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module Elf
2
+ class Process
3
+ def initialize(&blk)
4
+ blk.call(self)
5
+ st = ::Process.waitall
6
+ end
7
+
8
+ def fork(cmd)
9
+ Elf::Fork.new(cmd)
10
+ end
11
+
12
+ def sync(cmd)
13
+ Elf::Sync.new(cmd)
14
+ end
15
+ end
16
+ end
data/lib/elf/sync.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Elf
2
+ class Sync < Child
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Elf
2
+ VERSION = "0.0.1.alpha"
3
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Elf::Process do
5
+ it "should run 3 parallel processes" do
6
+ start = Time.now
7
+ Elf::Process.new do |elf|
8
+ elf.fork("sleep 1")
9
+ elf.fork("sleep 2")
10
+ elf.fork("sleep 2")
11
+ end
12
+ (Time.now-start).to_i.must_equal(2)
13
+ end
14
+
15
+ it "should run 3 sequenced processes" do
16
+ start = Time.now
17
+ Elf::Process.new do |elf|
18
+ elf.sync("sleep 1")
19
+ elf.sync("sleep 2")
20
+ elf.sync("sleep 3")
21
+ end
22
+ (Time.now-start).to_i.must_equal(6)
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ require 'elf'
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Petr Yanovich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-18 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Elves are creatures to manage background processes
15
+ email:
16
+ - fl00r@yandex.ru
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - elf.gemspec
27
+ - lib/elf.rb
28
+ - lib/elf/child.rb
29
+ - lib/elf/fork.rb
30
+ - lib/elf/process.rb
31
+ - lib/elf/sync.rb
32
+ - lib/elf/version.rb
33
+ - spec/elf/process_spec.rb
34
+ - spec/spec_helper.rb
35
+ homepage: ''
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>'
51
+ - !ruby/object:Gem::Version
52
+ version: 1.3.1
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.15
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Elves are creatures to manage background processes
59
+ test_files:
60
+ - spec/elf/process_spec.rb
61
+ - spec/spec_helper.rb
62
+ has_rdoc: