locky 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05587a5dc71c458b45eefd9f60b3b577a1591449
4
+ data.tar.gz: 95c29c4d9b9f56655eaf6fccc7ac1dfcbedaefa1
5
+ SHA512:
6
+ metadata.gz: e682d4bbb1a5e2b317b30ffda730aa2cd4f10c4dfa0c054878052ad3b9e2396caa80a0009b208d364a22fe99bc498486207f853fcdff36cdc8d2867468d7178a
7
+ data.tar.gz: d69ddb0aa5aecc76faada8518c1ee9a048b001ad081846fb1e55e6a145e01317cd256b111e00091b5a427553a3c00c1eb14f25b96c60e7c30c99ae64f59d80c2
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: TavNNcaJ5eiV5iXH7m9tucrZBzBpQ3acf
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ locky
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby 2.1
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in locky.gemspec
4
+ gemspec
5
+
6
+ gem 'coveralls', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Gabriel Naiman
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,39 @@
1
+ # Locky
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/locky.png)](https://rubygems.org/gems/locky)
4
+ [![Build Status](https://travis-ci.org/gabynaiman/locky.png?branch=master)](https://travis-ci.org/gabynaiman/locky)
5
+ [![Coverage Status](https://coveralls.io/repos/gabynaiman/locky/badge.png?branch=master)](https://coveralls.io/r/gabynaiman/locky?branch=master)
6
+ [![Code Climate](https://codeclimate.com/github/gabynaiman/locky.png)](https://codeclimate.com/github/gabynaiman/locky)
7
+ [![Dependency Status](https://gemnasium.com/gabynaiman/locky.png)](https://gemnasium.com/gabynaiman/locky)
8
+
9
+ Mini locker
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'locky'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install locky
24
+
25
+ ## Usage
26
+
27
+ locker = Locky.new :name
28
+
29
+ locker.lock :process_name do
30
+ ...
31
+ end
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/gabynaiman/locky/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:spec) do |t|
5
+ t.libs << 'spec'
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ t.verbose = false
8
+ end
9
+
10
+ task :console do
11
+ require 'pry'
12
+ require 'locky'
13
+ ARGV.clear
14
+ Pry.start
15
+ end
16
+
17
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ class Locky
2
+ VERSION = '0.0.1'
3
+ end
data/lib/locky.rb ADDED
@@ -0,0 +1,32 @@
1
+ class Locky
2
+
3
+ Error = Class.new StandardError
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(name, adapter={})
8
+ @name = name
9
+ @adapter = adapter
10
+ end
11
+
12
+ def lock(process)
13
+ raise Error, "#{name} already locked by #{locked_by}" if locked?
14
+ adapter[name] = process
15
+ yield
16
+ ensure
17
+ adapter.delete name
18
+ end
19
+
20
+ def locked?
21
+ adapter.key? name
22
+ end
23
+
24
+ def locked_by
25
+ adapter[name]
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :adapter
31
+
32
+ end
data/locky.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'locky/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'locky'
8
+ spec.version = Locky::VERSION
9
+ spec.authors = ['Gabriel Naiman']
10
+ spec.email = ['gabynaiman@gmail.com']
11
+ spec.summary = 'Mini locker'
12
+ spec.description = 'Mini locker'
13
+ spec.homepage = 'https://github.com/gabynaiman/locky'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'minitest', '~> 4.7'
24
+ spec.add_development_dependency 'turn', '~> 0.9'
25
+ spec.add_development_dependency 'simplecov'
26
+ spec.add_development_dependency 'pry-nav'
27
+ end
@@ -0,0 +1,8 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
@@ -0,0 +1,22 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Locky do
4
+
5
+ let(:locker) { Locky.new :test }
6
+
7
+ it 'Test' do
8
+ locker.name.must_equal :test
9
+ locker.wont_be :locked?
10
+
11
+ locker.lock :process_1 do
12
+ locker.must_be :locked?
13
+ locker.locked_by.must_equal :process_1
14
+
15
+ error = proc { locker.lock :process_2 }.must_raise Locky::Error
16
+ error.message.must_equal 'test already locked by process_1'
17
+ end
18
+
19
+ locker.wont_be :locked?
20
+ end
21
+
22
+ end
@@ -0,0 +1,11 @@
1
+ require 'coverage_helper'
2
+ require 'locky'
3
+ require 'minitest/autorun'
4
+ require 'turn'
5
+ require 'pry-nav'
6
+
7
+ Turn.config do |c|
8
+ c.format = :pretty
9
+ c.natural = true
10
+ c.ansi = true
11
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locky
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Naiman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: turn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-nav
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Mini locker
98
+ email:
99
+ - gabynaiman@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".coveralls.yml"
105
+ - ".gitignore"
106
+ - ".ruby-gemset"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/locky.rb
114
+ - lib/locky/version.rb
115
+ - locky.gemspec
116
+ - spec/coverage_helper.rb
117
+ - spec/locky_spec.rb
118
+ - spec/minitest_helper.rb
119
+ homepage: https://github.com/gabynaiman/locky
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.2
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Mini locker
143
+ test_files:
144
+ - spec/coverage_helper.rb
145
+ - spec/locky_spec.rb
146
+ - spec/minitest_helper.rb