monotone 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b1e8905b4361d5e3c6594b88d41202a03e9233f
4
+ data.tar.gz: 5f5a2df2321c041fbc43cefc681d9d2d2988068f
5
+ SHA512:
6
+ metadata.gz: e4adbdd3e55274c66864150d0a12138ba60a77d929afd3b8eb5c5cc74f138a5039b0b0b0c36281f52fa513ee270107497a8d796454dc670f367612899bfee969
7
+ data.tar.gz: e837f13a23ea54a33fc2c201999d497d0fef34c1ccad7abc4a1cb9956ae8182e236cf489323baebccff1460801f9f3cd1fdbc504bc5da39d482e0f954bb46609
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ .idea
2
+ .vendor
3
+ *.gem
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in monotone.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Michael Shea
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,46 @@
1
+ # Monotone
2
+
3
+ Gem to generate increasing numbers. Numbers are stored on the local filesystem, in ~/.monotone.
4
+ Also includes a CLI. I use it for generating BUILD_NUMBER-like numbers outside of the context of Jenkins jobs.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'monotone'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install monotone
19
+
20
+ ## Usage
21
+ ### Ruby
22
+ ```ruby
23
+ require 'monotone'
24
+ Monotone.next 'key' # Returns 0
25
+ Monotone.next 'key' # Returns 1
26
+ Monotone.set 'key', 0 # Returns 0
27
+ Monotone.next 'key' # Returns 1
28
+ ```
29
+
30
+ ### CLI
31
+ ```bash
32
+ mon-next key # Returns 0
33
+ mon-next key # Returns 1
34
+ mon-set key 0 # Returns 0
35
+ mon-next key # Returns 1
36
+ ```
37
+
38
+
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/mon-next ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require 'monotone'
3
+ unless ARGV.size == 1
4
+ puts 'Usage: mon-next [KEY]'
5
+ exit 1
6
+ end
7
+ puts Monotone.next ARGV[0]
data/bin/mon-set ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require 'monotone'
3
+ unless ARGV.size == 2
4
+ puts 'Usage: mon-set [KEY] [VALUE]'
5
+ exit 1
6
+ end
7
+ puts Monotone.set ARGV[0], ARGV[1].to_i
@@ -0,0 +1,3 @@
1
+ module Monotone
2
+ VERSION = '0.0.1'
3
+ end
data/lib/monotone.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'fileutils'
2
+ require 'monitor'
3
+ require 'monotone/version'
4
+
5
+ module Monotone
6
+
7
+ extend MonitorMixin
8
+
9
+ class << self
10
+
11
+ def initialize
12
+ super
13
+ end
14
+
15
+ def next( name )
16
+ file(name) do |f|
17
+ value = File.read(f).to_i
18
+ value += 1
19
+ File.write(f, value.to_s )
20
+ value
21
+ end
22
+ end
23
+
24
+ def set( name , value )
25
+ file(name) do |f|
26
+ File.write(f, value.to_s)
27
+ end
28
+ value
29
+ end
30
+
31
+ private
32
+
33
+ def file( name, &block )
34
+ synchronize do
35
+ file = File.join(root_dir, name).tap do |file|
36
+ unless File.file?(file)
37
+ File.write(file, '0')
38
+ end
39
+ end
40
+ block.yield(file)
41
+ end
42
+ end
43
+
44
+ def root_dir
45
+ @dir ||= File.join(ENV['HOME'], '.monotone').tap do |dir|
46
+ unless File.directory? dir
47
+ FileUtils.mkdir_p dir
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
data/monotone.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'monotone/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'monotone'
8
+ spec.version = Monotone::VERSION
9
+ spec.authors = ['Michael Shea']
10
+ spec.email = ['mike.shea@gmail.com']
11
+ spec.description = %q{Generates increasing numbers, stored on the filesystem.}
12
+ spec.summary = ''
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
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 = %w'lib'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monotone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Shea
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-08 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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
+ description: Generates increasing numbers, stored on the filesystem.
42
+ email:
43
+ - mike.shea@gmail.com
44
+ executables:
45
+ - mon-next
46
+ - mon-set
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/mon-next
56
+ - bin/mon-set
57
+ - lib/monotone.rb
58
+ - lib/monotone/version.rb
59
+ - monotone.gemspec
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.0.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: ''
84
+ test_files: []