Dahistory 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +14 -0
- data/lib/Dahistory.rb +11 -3
- data/lib/Dahistory/version.rb +1 -1
- data/spec/tests/Dashistory.rb +18 -0
- metadata +3 -2
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 da99
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -46,3 +46,17 @@ Both **def Dahistory** and **class Dahistory** are defined.
|
|
46
46
|
All the code is in one file and less than 150 lines:
|
47
47
|
[lib/Dahistory.rb](https://github.com/da99/Dahistory/blob/master/lib/Dahistory.rb)
|
48
48
|
|
49
|
+
Run Tests
|
50
|
+
---------
|
51
|
+
|
52
|
+
git clone git@github.com:da99/Dahistory.git
|
53
|
+
cd Dahistory
|
54
|
+
bundle update
|
55
|
+
bundle exec bacon spec/main.rb
|
56
|
+
|
57
|
+
"I hate writing."
|
58
|
+
-----------------------------
|
59
|
+
|
60
|
+
If you know of existing software that makes the above redundant,
|
61
|
+
please tell me. The last thing I want to do is maintain code.
|
62
|
+
|
data/lib/Dahistory.rb
CHANGED
@@ -21,6 +21,7 @@ class Dahistory
|
|
21
21
|
file!(file_path) if file_path
|
22
22
|
dirs './history'
|
23
23
|
pending_dir './pending'
|
24
|
+
@on_raise_pending = nil
|
24
25
|
yield(self) if block_given?
|
25
26
|
end
|
26
27
|
|
@@ -38,6 +39,10 @@ class Dahistory
|
|
38
39
|
@pending_dir = File.expand_path(dir)
|
39
40
|
end
|
40
41
|
|
42
|
+
def on_raise_pending &blok
|
43
|
+
@on_raise_pending = blok
|
44
|
+
end
|
45
|
+
|
41
46
|
#
|
42
47
|
# My alternative to :attr_accessors:
|
43
48
|
#
|
@@ -52,7 +57,7 @@ class Dahistory
|
|
52
57
|
eval %~
|
53
58
|
def #{name} *args, &blok
|
54
59
|
|
55
|
-
if args.empty?
|
60
|
+
if args.empty? && !block_given?
|
56
61
|
|
57
62
|
unless instance_variable_defined?(:@#{name})
|
58
63
|
raise ArgumentError, "Instance variable not set: @#{name}"
|
@@ -88,6 +93,7 @@ class Dahistory
|
|
88
93
|
|
89
94
|
if !old
|
90
95
|
File.write(backup_file, content) unless self.class.find_file_copy(file, pending_dir)
|
96
|
+
on_raise_pending.call if on_raise_pending
|
91
97
|
raise Pending, backup_file
|
92
98
|
end
|
93
99
|
|
@@ -97,7 +103,7 @@ class Dahistory
|
|
97
103
|
|
98
104
|
include Base
|
99
105
|
|
100
|
-
|
106
|
+
module Class_Methods
|
101
107
|
|
102
108
|
def find_file_copy file, *raw_dirs
|
103
109
|
standard = File.read(file).gsub("\r", "")
|
@@ -119,7 +125,9 @@ class Dahistory
|
|
119
125
|
found
|
120
126
|
end # === def
|
121
127
|
|
122
|
-
end # ===
|
128
|
+
end # === module Class_Methods
|
129
|
+
|
130
|
+
extend Class_Methods
|
123
131
|
|
124
132
|
end # === class Dahistory
|
125
133
|
|
data/lib/Dahistory/version.rb
CHANGED
data/spec/tests/Dashistory.rb
CHANGED
@@ -46,6 +46,24 @@ describe "Dahistory: pending file" do
|
|
46
46
|
Dir.glob("pending/*").size.should == 1
|
47
47
|
}
|
48
48
|
end
|
49
|
+
|
50
|
+
it "executes :on_raise_pending" do
|
51
|
+
file = "files/#{rand 1000}.txt"
|
52
|
+
content = rand(1000).to_s
|
53
|
+
target = nil
|
54
|
+
|
55
|
+
chdir {
|
56
|
+
File.write(file, content)
|
57
|
+
begin
|
58
|
+
Dahistory { |o|
|
59
|
+
o.file file
|
60
|
+
o.on_raise_pending { target = "done" }
|
61
|
+
}
|
62
|
+
rescue Dahistory::Pending => e
|
63
|
+
end
|
64
|
+
target.should == "done"
|
65
|
+
}
|
66
|
+
end
|
49
67
|
|
50
68
|
end # === Dahistory: pending file
|
51
69
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Dahistory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bacon
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- .gitignore
|
87
87
|
- Dahistory.gemspec
|
88
88
|
- Gemfile
|
89
|
+
- LICENSE
|
89
90
|
- README.md
|
90
91
|
- Rakefile
|
91
92
|
- lib/Dahistory.rb
|