noicycle 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rvmrc +48 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +7 -0
- data/lib/noicycle.rb +74 -0
- data/lib/noicycle/version.rb +3 -0
- data/noicycle.gemspec +24 -0
- data/spec/lib/noicycle_spec.rb +44 -0
- data/spec/spec_helper.rb +2 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 60aa6d9277caeac5964fbcfbe4829c3cd3bd69c0
|
4
|
+
data.tar.gz: 8fe3ef0bd93e30895584d4c00a155a81da266dd8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e03f0f758dcca553be78cbfbce7b0e1977607d6db08aa9395d74f15b50d380bd4461b388b1b46cdde3096db15ca370cb61185a34f132c8b5d3334d659ce987e7
|
7
|
+
data.tar.gz: 127428a0775cff3b125b4e77e3501367069aae9b82a639fb0d37484efe6892504bc71cc1c4104c3c2f950ee0736f06adc23363a3865b5d58a14c1a220e40911b
|
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 2.0.0" > .rvmrc
|
9
|
+
environment_id="ruby-2.0.0-p0@noicycle"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.18.20 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Mickaël Floc'hlay
|
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,44 @@
|
|
1
|
+
# Noicycle
|
2
|
+
|
3
|
+
Utility gem to calculate dates involved in a Tower of Hanoi backup rotation method.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'noicycle'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install noicycle
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To get the dates of a 7-tape backup from a give reference date:
|
22
|
+
|
23
|
+
ref_date = Date.parse("5th May 2013")
|
24
|
+
noicycle.tapes(ref_date, 7)
|
25
|
+
|
26
|
+
The result is a Hash that contains tape-keys and date values. For instance, on 24th september 2013, the upper code returned the following hash:
|
27
|
+
|
28
|
+
{
|
29
|
+
2=>#<Date: 2013-09-24 ((2456560j,0s,0n),+0s,2299161j)>,
|
30
|
+
1=>#<Date: 2013-09-23 ((2456559j,0s,0n),+0s,2299161j)>,
|
31
|
+
3=>#<Date: 2013-09-22 ((2456558j,0s,0n),+0s,2299161j)>,
|
32
|
+
4=>#<Date: 2013-09-18 ((2456554j,0s,0n),+0s,2299161j)>,
|
33
|
+
7=>#<Date: 2013-09-10 ((2456546j,0s,0n),+0s,2299161j)>,
|
34
|
+
5=>#<Date: 2013-08-25 ((2456530j,0s,0n),+0s,2299161j)>,
|
35
|
+
6=>#<Date: 2013-08-09 ((2456514j,0s,0n),+0s,2299161j)>
|
36
|
+
}
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/noicycle.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "noicycle/version"
|
2
|
+
|
3
|
+
module Noicycle
|
4
|
+
class Noicycle
|
5
|
+
def tapes(ref_date, nb_tapes = 3, cur_date = nil, weekly = false, weekly_ref_day = 0)
|
6
|
+
result = Hash.new
|
7
|
+
function = function_for_nb_of_tapes(nb_tapes)
|
8
|
+
Date.today
|
9
|
+
|
10
|
+
# Change the starting date if we're weekly so that it coincides with the desired weekly_ref_day
|
11
|
+
l_date = cur_date
|
12
|
+
l_date ||= Date.today
|
13
|
+
if weekly
|
14
|
+
while l_date.wday != weekly_ref_day do
|
15
|
+
l_date = l_date - 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
nb_of_tapes_found = 0
|
20
|
+
nb_of_days = (l_date - ref_date).to_i
|
21
|
+
nb_of_days = (nb_of_days / 7).to_i if weekly
|
22
|
+
for i in 0..nb_of_days
|
23
|
+
i_date = (weekly ? (l_date - 7*i) : (l_date - i))
|
24
|
+
i_tape = tape_for(i_date, ref_date, function, weekly)
|
25
|
+
if result[i_tape].nil?
|
26
|
+
result[i_tape] = i_date
|
27
|
+
nb_of_tapes_found = nb_of_tapes_found + 1
|
28
|
+
if nb_of_tapes_found == 7
|
29
|
+
return result
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
result
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def pretty_function(function)
|
40
|
+
function.sort.map do |key,value|
|
41
|
+
puts "function(#{key}) = #{value}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def function_for_nb_of_tapes(nb_of_tapes)
|
46
|
+
raise "There must be at least 2 tapes" unless nb_of_tapes > 1
|
47
|
+
|
48
|
+
# Fill the function
|
49
|
+
elements = 2 ** (nb_of_tapes - 1)
|
50
|
+
function = Hash.new
|
51
|
+
for i in 1..nb_of_tapes
|
52
|
+
index = 2 ** (i - 1)
|
53
|
+
while (index <= elements) do
|
54
|
+
function[index] = i
|
55
|
+
index = index + 2 ** i
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Create 0 value with last value:
|
60
|
+
# - This will allow the first backup (ie index 0) to be available the longest possible time
|
61
|
+
# - Will make further modulo operations much easier to achieve
|
62
|
+
function[0] = function[elements]
|
63
|
+
function.delete(elements)
|
64
|
+
function
|
65
|
+
end
|
66
|
+
|
67
|
+
def tape_for(date, ref_date, function, weekly = false)
|
68
|
+
nb_of_days = (date - ref_date).to_i
|
69
|
+
nb_of_days = (nb_of_days / 7).to_i if weekly
|
70
|
+
modulo = nb_of_days % function.length
|
71
|
+
function[modulo]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/noicycle.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'noicycle/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "noicycle"
|
8
|
+
spec.version = Noicycle::VERSION
|
9
|
+
spec.authors = ["Mickaël Floc'hlay"]
|
10
|
+
spec.email = ["dirtyhenry@gmail.com"]
|
11
|
+
spec.description = %q{Provide Tower of Hanoi backup rotation method dates"}
|
12
|
+
spec.summary = %q{Utility gem to calculate dates involved in a Tower of Hanoi backup rotation method}
|
13
|
+
spec.homepage = "http://dirtyhenry.github.io/noicycle/"
|
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 = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Noicycle do
|
4
|
+
it "returns a hash with as many results as requested when the reference date is old enough" do
|
5
|
+
noicycle = Noicycle::Noicycle.new
|
6
|
+
ref_date = Date.parse("5th May 2013")
|
7
|
+
for i in 3..5
|
8
|
+
tapes = noicycle.tapes(ref_date, i)
|
9
|
+
tapes.size.should eq(i)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the right result for a given example DAILY" do
|
14
|
+
noicycle = Noicycle::Noicycle.new
|
15
|
+
ref_date = Date.parse("5th May 2013")
|
16
|
+
cur_date = Date.parse("24th September 2013")
|
17
|
+
tapes = noicycle.tapes(ref_date, 7, cur_date)
|
18
|
+
|
19
|
+
tapes.size.should eq(7)
|
20
|
+
tapes[1].should == Date.parse("23rd September 2013")
|
21
|
+
tapes[2].should == Date.parse("24th September 2013")
|
22
|
+
tapes[3].should == Date.parse("22nd September 2013")
|
23
|
+
tapes[4].should == Date.parse("18th September 2013")
|
24
|
+
tapes[5].should == Date.parse("25th August 2013")
|
25
|
+
tapes[6].should == Date.parse("9th August 2013")
|
26
|
+
tapes[7].should == Date.parse("10th September 2013")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns the right result for a given example WEEKLY" do
|
30
|
+
noicycle = Noicycle::Noicycle.new
|
31
|
+
ref_date = Date.parse("5th May 2013")
|
32
|
+
cur_date = Date.parse("24th September 2013")
|
33
|
+
tapes = noicycle.tapes(ref_date, 7, cur_date, true)
|
34
|
+
|
35
|
+
tapes.size.should eq(6)
|
36
|
+
tapes[1].should == Date.parse("15th September 2013")
|
37
|
+
tapes[2].should == Date.parse("8th September 2013")
|
38
|
+
tapes[3].should == Date.parse("22nd September 2013")
|
39
|
+
tapes[4].should == Date.parse("30th June 2013")
|
40
|
+
tapes[5].should == Date.parse("25th August 2013")
|
41
|
+
tapes[6].should == nil
|
42
|
+
tapes[7].should == Date.parse("5th May 2013")
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: noicycle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mickaël Floc'hlay
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-24 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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Provide Tower of Hanoi backup rotation method dates"
|
56
|
+
email:
|
57
|
+
- dirtyhenry@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rvmrc
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/noicycle.rb
|
69
|
+
- lib/noicycle/version.rb
|
70
|
+
- noicycle.gemspec
|
71
|
+
- spec/lib/noicycle_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage: http://dirtyhenry.github.io/noicycle/
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Utility gem to calculate dates involved in a Tower of Hanoi backup rotation
|
97
|
+
method
|
98
|
+
test_files:
|
99
|
+
- spec/lib/noicycle_spec.rb
|
100
|
+
- spec/spec_helper.rb
|