classx 0.0.4 → 0.0.5
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.
- data/ChangeLog +114 -0
- data/Rakefile +2 -2
- data/bench/attribute_set.rb +10 -0
- data/bench/define_attribute.rb +18 -0
- data/bench/initialize.rb +8 -0
- data/example/commandable.rb +3 -3
- data/lib/classx.rb +17 -12
- data/lib/classx/attribute.rb +34 -5
- data/lib/classx/attributes.rb +10 -6
- data/lib/classx/commandable.rb +2 -2
- data/lib/classx/role/logger.rb +42 -10
- data/spec/classx/handles_spec.rb +13 -2
- data/spec/classx/with_coerce_spec.rb +20 -0
- data/spec/classx/with_trigger_spec.rb +61 -0
- data/spec/classx_class_attributes/with_coerce_spec.rb +35 -8
- data/spec/classx_class_attributes/with_trigger_spec.rb +59 -0
- data/tasks/basic_config.rake +1 -0
- metadata +18 -16
- data/doc/output/coverage/index.html +0 -414
- data/doc/output/coverage/lib-classx-attribute_rb.html +0 -896
- data/doc/output/coverage/lib-classx-attributes_rb.html +0 -768
- data/doc/output/coverage/lib-classx-bracketable_rb.html +0 -671
- data/doc/output/coverage/lib-classx-class_attributes_rb.html +0 -775
- data/doc/output/coverage/lib-classx-commandable_rb.html +0 -727
- data/doc/output/coverage/lib-classx-declare_rb.html +0 -659
- data/doc/output/coverage/lib-classx-validate_rb.html +0 -650
- data/doc/output/coverage/lib-classx_rb.html +0 -815
data/ChangeLog
CHANGED
|
@@ -1,3 +1,117 @@
|
|
|
1
|
+
commit de3b716466a8c30e31f75483977bfcd9f19f871a
|
|
2
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
3
|
+
Date: Mon Oct 27 00:00:14 2008 +0900
|
|
4
|
+
|
|
5
|
+
oops. spec message fixed.
|
|
6
|
+
|
|
7
|
+
commit 8c892fc051bba7175cbaa02dd9d29cdd3bab7d51
|
|
8
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
9
|
+
Date: Sun Oct 26 23:00:20 2008 +0900
|
|
10
|
+
|
|
11
|
+
update benchmark result.
|
|
12
|
+
|
|
13
|
+
commit ad6a1e8be27e44d38b2a357f060086053572ecb2
|
|
14
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
15
|
+
Date: Sun Oct 26 18:53:28 2008 +0900
|
|
16
|
+
|
|
17
|
+
fixed bug. when you handle some methods that use with block, it not worked.
|
|
18
|
+
|
|
19
|
+
commit ad34cf6a7f3d119379a2bc78b4060504b404db9e
|
|
20
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
21
|
+
Date: Fri Sep 19 08:59:34 2008 +0900
|
|
22
|
+
|
|
23
|
+
added coerce to log_rotate.
|
|
24
|
+
|
|
25
|
+
commit 8b4cc50e9395bb801beafd60afc579e279e7604d
|
|
26
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
27
|
+
Date: Fri Sep 19 08:52:38 2008 +0900
|
|
28
|
+
|
|
29
|
+
added CoerceWithProc.
|
|
30
|
+
|
|
31
|
+
commit cc2917b5b7f1088428936f9065932c7d630ae356
|
|
32
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
33
|
+
Date: Fri Sep 19 08:37:39 2008 +0900
|
|
34
|
+
|
|
35
|
+
added validate to log_rotate.
|
|
36
|
+
|
|
37
|
+
commit ef422314b28c741950a04e4a9d75a532c4f4a0ab
|
|
38
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
39
|
+
Date: Fri Sep 19 08:29:22 2008 +0900
|
|
40
|
+
|
|
41
|
+
fixed bug: ClassX::Commandable with none kind_of specified attribute does not output :desc to help.
|
|
42
|
+
|
|
43
|
+
commit 62217b9347f6470db829ef66de116a9bdab04c7c
|
|
44
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
45
|
+
Date: Fri Sep 19 08:20:01 2008 +0900
|
|
46
|
+
|
|
47
|
+
added more shortcut.
|
|
48
|
+
|
|
49
|
+
commit 497ac5c854faa719a90eabcabeb5fbecdd25997f
|
|
50
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
51
|
+
Date: Fri Sep 19 08:11:18 2008 +0900
|
|
52
|
+
|
|
53
|
+
added log_rotate attribute.
|
|
54
|
+
|
|
55
|
+
commit b06e8dac0d7084623426f37568369ca251cf6550
|
|
56
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
57
|
+
Date: Fri Sep 19 08:01:23 2008 +0900
|
|
58
|
+
|
|
59
|
+
trigger is not neeed.
|
|
60
|
+
|
|
61
|
+
commit 343c1efcb9c8fe4c6ccb7674edefeeacf64740e9
|
|
62
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
63
|
+
Date: Fri Sep 19 07:55:14 2008 +0900
|
|
64
|
+
|
|
65
|
+
tweak for rdoc.
|
|
66
|
+
|
|
67
|
+
commit 51dcdd598cfac6d432494dede4427589dcefb665
|
|
68
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
69
|
+
Date: Wed Sep 17 08:59:48 2008 +0900
|
|
70
|
+
|
|
71
|
+
change #before_init to class method and change name process_init_args.
|
|
72
|
+
|
|
73
|
+
commit 6437f8ca6ef3cb443d3e1ced0a7a7d2b61062edb
|
|
74
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
75
|
+
Date: Wed Sep 17 08:42:13 2008 +0900
|
|
76
|
+
|
|
77
|
+
adding document.
|
|
78
|
+
|
|
79
|
+
commit b9bdffc8f2146ef793a0c03e63182d5a4388ad07
|
|
80
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
81
|
+
Date: Tue Sep 16 09:00:40 2008 +0900
|
|
82
|
+
|
|
83
|
+
added document.
|
|
84
|
+
|
|
85
|
+
commit 4a2807b839fe7c9e4d2989e025cf94d415c92e69
|
|
86
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
87
|
+
Date: Tue Sep 16 08:52:28 2008 +0900
|
|
88
|
+
|
|
89
|
+
trigger should take array as default.
|
|
90
|
+
|
|
91
|
+
commit 0171feab3293523d26f70220d8501de1ac6f518d
|
|
92
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
93
|
+
Date: Tue Sep 16 08:14:18 2008 +0900
|
|
94
|
+
|
|
95
|
+
update benchmark.
|
|
96
|
+
|
|
97
|
+
commit d85fa7ded08434e5300e434996eb63686a5753bf
|
|
98
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
99
|
+
Date: Tue Sep 16 08:07:34 2008 +0900
|
|
100
|
+
|
|
101
|
+
trigger option support.
|
|
102
|
+
|
|
103
|
+
commit 355ede71dc0b98f78ebb40b616945f2e192abdc8
|
|
104
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
105
|
+
Date: Mon Sep 15 15:54:03 2008 +0900
|
|
106
|
+
|
|
107
|
+
refactering
|
|
108
|
+
|
|
109
|
+
commit 723cffd4439723f9533c8e681a9202ca5836d3c5
|
|
110
|
+
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
111
|
+
Date: Sat Sep 13 00:38:06 2008 +0900
|
|
112
|
+
|
|
113
|
+
released 0.0.4
|
|
114
|
+
|
|
1
115
|
commit c27d76a9e41d7f1d6f02160c6c0b555c6cd68206
|
|
2
116
|
Author: Keiji, Yoshimi <walf443@gmail.com>
|
|
3
117
|
Date: Sat Sep 13 00:28:06 2008 +0900
|
data/Rakefile
CHANGED
|
@@ -17,7 +17,7 @@ DESCRIPTION = <<-"END_DESCRIPTION"
|
|
|
17
17
|
Meta Framework extending and flexible attribute like Moose ( perl )
|
|
18
18
|
END_DESCRIPTION
|
|
19
19
|
BIN_FILES = %w( )
|
|
20
|
-
VERS = "0.0.
|
|
20
|
+
VERS = "0.0.5"
|
|
21
21
|
|
|
22
22
|
EXTRA_RDOC_FILES = []
|
|
23
23
|
HECKLE_ROOT_MODULES = ["Classx"]
|
|
@@ -28,7 +28,7 @@ SPEC = Gem::Specification.new do |s|
|
|
|
28
28
|
s.platform = Gem::Platform::RUBY
|
|
29
29
|
s.has_rdoc = true
|
|
30
30
|
s.extra_rdoc_files = DEFAULT_EXTRA_RDOC_FILES + EXTRA_RDOC_FILES
|
|
31
|
-
s.rdoc_options += RDOC_OPTS + ['--title', "#{NAME} documentation"]
|
|
31
|
+
s.rdoc_options += RDOC_OPTS + ['--title', "#{NAME} documentation", ]
|
|
32
32
|
s.summary = DESCRIPTION
|
|
33
33
|
s.description = DESCRIPTION
|
|
34
34
|
s.author = AUTHOR
|
data/bench/attribute_set.rb
CHANGED
|
@@ -55,6 +55,16 @@ end
|
|
|
55
55
|
# On my environment( MacBook1.1 Intel Core Duo 1.83 GHz, 2GB), result is like that. TOOOOO SLOOOW classX!!!!.
|
|
56
56
|
#
|
|
57
57
|
# ----------------------------------------------------------
|
|
58
|
+
# result after 0171feab
|
|
59
|
+
# classx with attr_name = val 0.030000 0.000000 0.030000 ( 0.035114)
|
|
60
|
+
# classx with attr_name(val) 0.040000 0.000000 0.040000 ( 0.053949)
|
|
61
|
+
# normal class 0.010000 0.000000 0.010000 ( 0.001969)
|
|
62
|
+
# ----------------------------------------------------------
|
|
63
|
+
# result after d85fa7ded
|
|
64
|
+
# classx with attr_name = val 0.020000 0.010000 0.030000 ( 0.031880)
|
|
65
|
+
# classx with attr_name(val) 0.040000 0.000000 0.040000 ( 0.049979)
|
|
66
|
+
# normal class 0.000000 0.000000 0.000000 ( 0.002021)
|
|
67
|
+
# ----------------------------------------------------------
|
|
58
68
|
# result after 92ed088b ( before 0.0.4 )
|
|
59
69
|
# user system total real
|
|
60
70
|
# classx with attr_name = val 0.020000 0.010000 0.030000 ( 0.029100)
|
data/bench/define_attribute.rb
CHANGED
|
@@ -156,7 +156,25 @@ end
|
|
|
156
156
|
# On my environment( MacBook1.1 Intel Core Duo 1.83 GHz, 2GB), result is like that. TOOOOO SLOOOW classX!!!!.
|
|
157
157
|
#
|
|
158
158
|
# ----------------------------------------------------------
|
|
159
|
+
# result after ad6a1e8be27
|
|
160
|
+
# user system total real
|
|
161
|
+
# attr_reader 0.010000 0.000000 0.010000 ( 0.009723)
|
|
162
|
+
# simple define 0.220000 0.010000 0.230000 ( 0.284162)
|
|
163
|
+
# with declare 0.230000 0.020000 0.250000 ( 0.296754)
|
|
164
|
+
# with writable 0.180000 0.020000 0.200000 ( 0.216788)
|
|
165
|
+
# with optional 0.260000 0.020000 0.280000 ( 0.296184)
|
|
166
|
+
# with default 0.200000 0.010000 0.210000 ( 0.234367)
|
|
167
|
+
# with default Proc 0.270000 0.020000 0.290000 ( 0.321229)
|
|
168
|
+
# with default Proc lazy 0.210000 0.010000 0.220000 ( 0.238869)
|
|
169
|
+
# with validate Proc 0.310000 0.030000 0.340000 ( 0.358173)
|
|
170
|
+
# with validate Regexp 0.200000 0.010000 0.210000 ( 0.236095)
|
|
171
|
+
# with handles Array 0.240000 0.020000 0.260000 ( 0.278163)
|
|
172
|
+
# with handles Hash 0.380000 0.020000 0.400000 ( 0.433075)
|
|
173
|
+
# with include 0.210000 0.010000 0.220000 ( 0.237816)
|
|
174
|
+
# with extend 0.200000 0.020000 0.220000 ( 0.246489)
|
|
175
|
+
# ----------------------------------------------------------
|
|
159
176
|
# result after 92ed088b ( before 0.0.4 )
|
|
177
|
+
# user system total real
|
|
160
178
|
# attr_reader 0.010000 0.000000 0.010000 ( 0.011373)
|
|
161
179
|
# simple define 0.190000 0.020000 0.210000 ( 0.245375)
|
|
162
180
|
# with declare 0.210000 0.020000 0.230000 ( 0.269984)
|
data/bench/initialize.rb
CHANGED
|
@@ -41,6 +41,14 @@ end
|
|
|
41
41
|
# On my environment( MacBook1.1 Intel Core Duo 1.83 GHz, 2GB), result is like that. TOOOOO SLOOOW classX!!!!.
|
|
42
42
|
#
|
|
43
43
|
# ----------------------------------------------------------
|
|
44
|
+
# result after 0171feab
|
|
45
|
+
# classx 0.080000 0.000000 0.080000 ( 0.099778)
|
|
46
|
+
# normal class 0.000000 0.000000 0.000000 ( 0.005175)
|
|
47
|
+
# ----------------------------------------------------------
|
|
48
|
+
# result after d85fa7de
|
|
49
|
+
# classx 0.070000 0.000000 0.070000 ( 0.094902)
|
|
50
|
+
# normal class 0.010000 0.000000 0.010000 ( 0.004398)
|
|
51
|
+
# ----------------------------------------------------------
|
|
44
52
|
# result after 92ed088b ( before 0.0.4 )
|
|
45
53
|
# classx 0.060000 0.010000 0.070000 ( 0.083939)
|
|
46
54
|
# normal class 0.010000 0.000000 0.010000 ( 0.004305)
|
data/example/commandable.rb
CHANGED
|
@@ -23,10 +23,10 @@ class YourApp
|
|
|
23
23
|
|
|
24
24
|
def run
|
|
25
25
|
# do something!!
|
|
26
|
-
|
|
26
|
+
info 'starting your_app'
|
|
27
27
|
attribute_of
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
debug attribute_of.pretty_inspect
|
|
29
|
+
info 'end your app'
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
data/lib/classx.rb
CHANGED
|
@@ -50,7 +50,11 @@ module ClassX
|
|
|
50
50
|
# This method checking required value is setted and taking value is valid to attribute.
|
|
51
51
|
#
|
|
52
52
|
def initialize *args
|
|
53
|
-
|
|
53
|
+
if respond_to? :before_init
|
|
54
|
+
warn 'before_init is deprecated. please define process_init_args class method'
|
|
55
|
+
else
|
|
56
|
+
hash = self.class.process_init_args(*args)
|
|
57
|
+
end
|
|
54
58
|
|
|
55
59
|
unless hash && hash.kind_of?(Hash)
|
|
56
60
|
raise ArgumentError, "#{hash.inspect} was wrong as arguments. please specify kind of Hash instance"
|
|
@@ -101,17 +105,6 @@ module ClassX
|
|
|
101
105
|
@__attribute_of
|
|
102
106
|
end
|
|
103
107
|
|
|
104
|
-
# processing initialize argument to hash
|
|
105
|
-
# you can override this method for not taking initializer your classx based class.
|
|
106
|
-
def before_init *args
|
|
107
|
-
raise ArgumentError if args.size > 1
|
|
108
|
-
|
|
109
|
-
hash = args.first
|
|
110
|
-
hash.nil? ? {} : hash
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
alias process_init_args before_init
|
|
114
|
-
|
|
115
108
|
# automatically called this method on last of #initialize.
|
|
116
109
|
# you can override this method.
|
|
117
110
|
def after_init
|
|
@@ -196,10 +189,22 @@ module ClassX
|
|
|
196
189
|
end
|
|
197
190
|
end
|
|
198
191
|
|
|
192
|
+
module ClassMethods
|
|
193
|
+
# processing initialize argument to hash
|
|
194
|
+
# you can override this method for not taking initializer your classx based class.
|
|
195
|
+
def process_init_args *args
|
|
196
|
+
raise ArgumentError if args.size > 1
|
|
197
|
+
|
|
198
|
+
hash = args.first
|
|
199
|
+
hash.nil? ? {} : hash
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
199
203
|
private
|
|
200
204
|
|
|
201
205
|
def self.included klass
|
|
202
206
|
klass.extend(Attributes)
|
|
207
|
+
klass.extend(ClassMethods)
|
|
203
208
|
end
|
|
204
209
|
|
|
205
210
|
end
|
data/lib/classx/attribute.rb
CHANGED
|
@@ -78,6 +78,12 @@ module ClassX
|
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
+
module CoerceWithProc #:nodoc:
|
|
82
|
+
def coerce val
|
|
83
|
+
config[:coerce].call(val)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
81
87
|
module CoerceNothing #:nodoc:
|
|
82
88
|
def coerce val
|
|
83
89
|
val
|
|
@@ -91,11 +97,9 @@ module ClassX
|
|
|
91
97
|
end
|
|
92
98
|
module DefaultWithNoProc #:nodoc:
|
|
93
99
|
def default parent
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
config[:default]
|
|
98
|
-
end
|
|
100
|
+
config[:default].dup
|
|
101
|
+
rescue Exception
|
|
102
|
+
config[:default]
|
|
99
103
|
end
|
|
100
104
|
end
|
|
101
105
|
|
|
@@ -152,6 +156,14 @@ module ClassX
|
|
|
152
156
|
true
|
|
153
157
|
end
|
|
154
158
|
end
|
|
159
|
+
|
|
160
|
+
module TriggerArrayProc #:nodoc:
|
|
161
|
+
def trigger parent, val
|
|
162
|
+
config[:trigger].each do |trg|
|
|
163
|
+
trg.call(parent, val)
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
155
167
|
end
|
|
156
168
|
|
|
157
169
|
module InstanceMethods #:nodoc:
|
|
@@ -171,6 +183,9 @@ module ClassX
|
|
|
171
183
|
val = self.class.coerce(val)
|
|
172
184
|
raise ClassX::InvalidAttrArgument unless self.class.validate? val
|
|
173
185
|
@data = val
|
|
186
|
+
|
|
187
|
+
self.class.trigger(@parent, val)
|
|
188
|
+
@data
|
|
174
189
|
end
|
|
175
190
|
|
|
176
191
|
def inspect
|
|
@@ -210,6 +225,8 @@ module ClassX
|
|
|
210
225
|
klass.extend(ClassX::AttributeMethods::ClassMethods::CoerceWithHash)
|
|
211
226
|
when Array
|
|
212
227
|
klass.extend(ClassX::AttributeMethods::ClassMethods::CoerceWithArray)
|
|
228
|
+
when Proc
|
|
229
|
+
klass.extend(ClassX::AttributeMethods::ClassMethods::CoerceWithProc)
|
|
213
230
|
end
|
|
214
231
|
else
|
|
215
232
|
klass.extend(ClassX::AttributeMethods::ClassMethods::CoerceNothing)
|
|
@@ -244,6 +261,18 @@ module ClassX
|
|
|
244
261
|
klass.extend(ClassX::AttributeMethods::ClassMethods::ValidateNothing)
|
|
245
262
|
end
|
|
246
263
|
|
|
264
|
+
# you can specify :trigger option for invoking event on setting value to attribute.
|
|
265
|
+
# :trigger should take Proc or multi Proc Array.
|
|
266
|
+
if args[:trigger]
|
|
267
|
+
unless args[:trigger].kind_of?(Array)
|
|
268
|
+
args[:trigger] = [ args[:trigger] ]
|
|
269
|
+
end
|
|
270
|
+
klass.extend(ClassX::AttributeMethods::ClassMethods::TriggerArrayProc)
|
|
271
|
+
else
|
|
272
|
+
args[:trigger] = []
|
|
273
|
+
klass.extend(ClassX::AttributeMethods::ClassMethods::TriggerArrayProc)
|
|
274
|
+
end
|
|
275
|
+
|
|
247
276
|
# for extending attribute point.
|
|
248
277
|
if args[:include]
|
|
249
278
|
case args[:include]
|
data/lib/classx/attributes.rb
CHANGED
|
@@ -131,15 +131,19 @@ module ClassX
|
|
|
131
131
|
case attr_class.config[:handles]
|
|
132
132
|
when Hash
|
|
133
133
|
attr_class.config[:handles].each do |before, after|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
class_eval <<-CLASS_EVAL
|
|
135
|
+
def #{before} *args, &block
|
|
136
|
+
__send__("#{name}").__send__ "#{after}", *args, &block
|
|
137
|
+
end
|
|
138
|
+
CLASS_EVAL
|
|
137
139
|
end
|
|
138
140
|
when Array
|
|
139
141
|
attr_class.config[:handles].each do |meth|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
class_eval <<-CLASS_EVAL
|
|
143
|
+
def #{meth} *args, &block
|
|
144
|
+
__send__("#{name}").__send__ "#{meth}", *args, &block
|
|
145
|
+
end
|
|
146
|
+
CLASS_EVAL
|
|
143
147
|
end
|
|
144
148
|
end
|
|
145
149
|
end
|
data/lib/classx/commandable.rb
CHANGED
|
@@ -96,9 +96,9 @@ module ClassX
|
|
|
96
96
|
end
|
|
97
97
|
else
|
|
98
98
|
if short_option_of[short_option] == key
|
|
99
|
-
opt.on("-#{short_option}", "--#{key} #{val_format}") {|v| value_of[key] = v }
|
|
99
|
+
opt.on("-#{short_option}", "--#{key} #{val_format}", val.desc ) {|v| value_of[key] = v }
|
|
100
100
|
else
|
|
101
|
-
opt.on("--#{key} #{val_format}") {|v| value_of[key] = v }
|
|
101
|
+
opt.on("--#{key} #{val_format}", val.desc ) {|v| value_of[key] = v }
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
end
|
data/lib/classx/role/logger.rb
CHANGED
|
@@ -38,22 +38,28 @@ module ClassX
|
|
|
38
38
|
alias to_i to_log_level
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
# dummy method for rdoc
|
|
42
|
-
def logger; end
|
|
41
|
+
def logger; end # dummy method for rdoc
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
# you can use #debug, #info, #warn, #error, #fatal method
|
|
44
|
+
# shortcut for logger.debug, logger.info, logger.warn, logger.error, logger.fatal.
|
|
45
|
+
# default output is $stderr.
|
|
46
|
+
# see also Logger
|
|
47
|
+
has :logger, {
|
|
45
48
|
:optional => true,
|
|
46
49
|
:no_cmd_option => true,
|
|
47
|
-
:lazy => true,
|
|
50
|
+
:lazy => true,
|
|
48
51
|
:default => proc {|mine|
|
|
49
|
-
logger = ::Logger.new(mine.logfile)
|
|
52
|
+
logger = ::Logger.new(mine.logfile, mine.log_rotate)
|
|
50
53
|
logger.level = mine.attribute_of['log_level'].to_i
|
|
51
54
|
logger.progname = $0
|
|
52
55
|
|
|
53
56
|
logger
|
|
54
|
-
}
|
|
57
|
+
},
|
|
58
|
+
:handles => [:debug, :info, :warn, :error, :fatal ],
|
|
59
|
+
}
|
|
55
60
|
|
|
56
|
-
|
|
61
|
+
# log_level (debug|info|warn|error|fatal) ( default info )
|
|
62
|
+
has :log_level, {
|
|
57
63
|
:kind_of => String,
|
|
58
64
|
:desc => 'log_level (debug|info|warn|error|fatal) (default info)',
|
|
59
65
|
:optional => true,
|
|
@@ -61,13 +67,39 @@ module ClassX
|
|
|
61
67
|
:include => ToLogLevel,
|
|
62
68
|
:validate => proc {|val|
|
|
63
69
|
val && ::Logger::Severity.const_defined?(val.to_s.upcase)
|
|
64
|
-
}
|
|
70
|
+
},
|
|
71
|
+
}
|
|
65
72
|
|
|
66
|
-
|
|
73
|
+
# output logfile ( default STDERR ).
|
|
74
|
+
has :logfile, {
|
|
67
75
|
:kind_of => String,
|
|
68
76
|
:desc => 'output logfile. (default STDERR)',
|
|
69
77
|
:optional => true,
|
|
70
|
-
:default => $stderr # hmm, is name bad?
|
|
78
|
+
:default => $stderr, # hmm, is name bad?
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# size or (daily|weekly|monthly) (default nil)
|
|
82
|
+
has :log_rotate, {
|
|
83
|
+
:desc => "size or (daily|weekly|monthly) (default nil)",
|
|
84
|
+
:optional => true,
|
|
85
|
+
:validate => proc {|val|
|
|
86
|
+
return true if val =~ /^(daily|weekly|monthly)$/
|
|
87
|
+
return true if val.to_i > 0
|
|
88
|
+
|
|
89
|
+
false
|
|
90
|
+
},
|
|
91
|
+
# convert for ClassX::Commandable
|
|
92
|
+
:coerce => proc {|val|
|
|
93
|
+
return val if val.kind_of? Integer
|
|
94
|
+
return val if val =~ /^(daily|weekly|monthly)$/
|
|
95
|
+
|
|
96
|
+
if val.respond_to?(:to_i) && val.to_i > 0
|
|
97
|
+
val.to_i
|
|
98
|
+
else
|
|
99
|
+
val
|
|
100
|
+
end
|
|
101
|
+
},
|
|
102
|
+
}
|
|
71
103
|
|
|
72
104
|
end
|
|
73
105
|
end
|