fattr 2.1.0 → 2.2.0
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/LICENSE +1 -0
- data/Rakefile +155 -36
- data/lib/fattr.rb +12 -3
- data/test/{fattr.rb → fattr_test.rb} +10 -3
- metadata +19 -11
- data/a.rb +0 -42
- data/fattr.gemspec +0 -29
data/LICENSE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
same as Ruby's
|
data/Rakefile
CHANGED
@@ -1,23 +1,67 @@
|
|
1
|
+
This.rubyforge_project = 'codeforpeople'
|
1
2
|
This.author = "Ara T. Howard"
|
2
3
|
This.email = "ara.t.howard@gmail.com"
|
3
4
|
This.homepage = "http://github.com/ahoward/#{ This.lib }/tree/master"
|
4
|
-
|
5
|
+
|
5
6
|
|
6
7
|
task :default do
|
7
|
-
puts(Rake::Task.tasks.map{|task| task.name} - ['default'])
|
8
|
+
puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
|
9
|
+
end
|
10
|
+
|
11
|
+
task :test do
|
12
|
+
run_tests!
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :test do
|
16
|
+
task(:unit){ run_tests!(:unit) }
|
17
|
+
task(:functional){ run_tests!(:functional) }
|
18
|
+
task(:integration){ run_tests!(:integration) }
|
8
19
|
end
|
9
20
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
21
|
+
def run_tests!(which = nil)
|
22
|
+
which ||= '**'
|
23
|
+
test_dir = File.join(This.dir, "test")
|
24
|
+
test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
|
25
|
+
test_rbs = Dir.glob(test_glob).sort
|
26
|
+
|
27
|
+
div = ('=' * 119)
|
28
|
+
line = ('-' * 119)
|
29
|
+
helper = "-r ./test/helper.rb" if test(?e, "./test/helper.rb")
|
30
|
+
|
31
|
+
test_rbs.each_with_index do |test_rb, index|
|
32
|
+
testno = index + 1
|
33
|
+
command = "#{ This.ruby } -I ./lib -I ./test/lib #{ helper } #{ test_rb }"
|
34
|
+
|
35
|
+
puts
|
36
|
+
say(div, :color => :cyan, :bold => true)
|
37
|
+
say("@#{ testno } => ", :bold => true, :method => :print)
|
38
|
+
say(command, :color => :cyan, :bold => true)
|
39
|
+
say(line, :color => :cyan, :bold => true)
|
40
|
+
|
41
|
+
system(command)
|
42
|
+
|
43
|
+
say(line, :color => :cyan, :bold => true)
|
44
|
+
|
45
|
+
status = $?.exitstatus
|
46
|
+
|
47
|
+
if status.zero?
|
48
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
49
|
+
say("SUCCESS", :color => :green, :bold => true)
|
50
|
+
else
|
51
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
52
|
+
say("FAILURE", :color => :red, :bold => true)
|
53
|
+
end
|
54
|
+
say(line, :color => :cyan, :bold => true)
|
55
|
+
|
56
|
+
exit(status) unless status.zero?
|
14
57
|
end
|
15
58
|
end
|
16
59
|
|
60
|
+
|
17
61
|
task :gemspec do
|
18
62
|
ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
|
19
|
-
ignore_directories =
|
20
|
-
ignore_files =
|
63
|
+
ignore_directories = %w[ pkg ]
|
64
|
+
ignore_files = %w[ test/log ]
|
21
65
|
|
22
66
|
shiteless =
|
23
67
|
lambda do |list|
|
@@ -39,14 +83,18 @@ task :gemspec do
|
|
39
83
|
end
|
40
84
|
|
41
85
|
lib = This.lib
|
86
|
+
object = This.object
|
42
87
|
version = This.version
|
43
88
|
files = shiteless[Dir::glob("**/**")]
|
44
89
|
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
|
45
90
|
has_rdoc = true #File.exist?('doc')
|
46
91
|
test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
|
92
|
+
summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
|
93
|
+
description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
|
47
94
|
|
48
|
-
|
49
|
-
|
95
|
+
if This.extensions.nil?
|
96
|
+
This.extensions = []
|
97
|
+
extensions = This.extensions
|
50
98
|
%w( Makefile configure extconf.rb ).each do |ext|
|
51
99
|
extensions << ext if File.exists?(ext)
|
52
100
|
end
|
@@ -64,22 +112,20 @@ task :gemspec do
|
|
64
112
|
|
65
113
|
Gem::Specification::new do |spec|
|
66
114
|
spec.name = #{ lib.inspect }
|
67
|
-
spec.description = 'fattr.rb is a "fatter attr" for ruby'
|
68
115
|
spec.version = #{ version.inspect }
|
69
116
|
spec.platform = Gem::Platform::RUBY
|
70
117
|
spec.summary = #{ lib.inspect }
|
118
|
+
spec.description = #{ description.inspect }
|
71
119
|
|
72
120
|
spec.files = #{ files.inspect }
|
73
121
|
spec.executables = #{ executables.inspect }
|
74
122
|
|
75
|
-
<% if test(?d, 'lib') %>
|
76
123
|
spec.require_path = "lib"
|
77
|
-
<% end %>
|
78
124
|
|
79
125
|
spec.has_rdoc = #{ has_rdoc.inspect }
|
80
126
|
spec.test_files = #{ test_files.inspect }
|
81
|
-
|
82
|
-
|
127
|
+
|
128
|
+
# spec.add_dependency 'lib', '>= version'
|
83
129
|
|
84
130
|
spec.extensions.push(*#{ extensions.inspect })
|
85
131
|
|
@@ -92,12 +138,13 @@ task :gemspec do
|
|
92
138
|
}
|
93
139
|
end
|
94
140
|
|
95
|
-
|
96
|
-
This.gemspec = "
|
141
|
+
Fu.mkdir_p(This.pkgdir)
|
142
|
+
This.gemspec = File.join(This.pkgdir, "gemspec.rb")
|
143
|
+
open("#{ This.gemspec }", "w"){|fd| fd.puts(template)}
|
97
144
|
end
|
98
145
|
|
99
146
|
task :gem => [:clean, :gemspec] do
|
100
|
-
Fu.mkdir_p
|
147
|
+
Fu.mkdir_p(This.pkgdir)
|
101
148
|
before = Dir['*.gem']
|
102
149
|
cmd = "gem build #{ This.gemspec }"
|
103
150
|
`#{ cmd }`
|
@@ -123,7 +170,7 @@ task :readme do
|
|
123
170
|
cmd = "ruby #{ sample }"
|
124
171
|
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
125
172
|
|
126
|
-
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -
|
173
|
+
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
|
127
174
|
samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
|
128
175
|
end
|
129
176
|
|
@@ -170,44 +217,62 @@ end
|
|
170
217
|
|
171
218
|
|
172
219
|
BEGIN {
|
220
|
+
# support for this rakefile
|
221
|
+
#
|
173
222
|
$VERBOSE = nil
|
174
223
|
|
175
224
|
require 'ostruct'
|
176
225
|
require 'erb'
|
177
226
|
require 'fileutils'
|
227
|
+
require 'rbconfig'
|
178
228
|
|
229
|
+
# fu shortcut
|
230
|
+
#
|
179
231
|
Fu = FileUtils
|
180
232
|
|
233
|
+
# cache a bunch of stuff about this rakefile/environment
|
234
|
+
#
|
181
235
|
This = OpenStruct.new
|
182
236
|
|
183
237
|
This.file = File.expand_path(__FILE__)
|
184
238
|
This.dir = File.dirname(This.file)
|
185
239
|
This.pkgdir = File.join(This.dir, 'pkg')
|
186
240
|
|
241
|
+
# grok lib
|
242
|
+
#
|
187
243
|
lib = ENV['LIB']
|
188
244
|
unless lib
|
189
|
-
lib = File.basename(Dir.pwd)
|
245
|
+
lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
|
190
246
|
end
|
191
247
|
This.lib = lib
|
192
248
|
|
249
|
+
# grok version
|
250
|
+
#
|
193
251
|
version = ENV['VERSION']
|
194
252
|
unless version
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
require library
|
200
|
-
version = eval(name).send(:version)
|
201
|
-
elsif test(?e, program)
|
202
|
-
version = `#{ program } --version`.strip
|
203
|
-
end
|
204
|
-
abort('no version') if(version.nil? or version.empty?)
|
253
|
+
require "./lib/#{ This.lib }"
|
254
|
+
This.name = lib.capitalize
|
255
|
+
This.object = eval(This.name)
|
256
|
+
version = This.object.send(:version)
|
205
257
|
end
|
206
258
|
This.version = version
|
207
259
|
|
260
|
+
# we need to know the name of the lib an it's version
|
261
|
+
#
|
208
262
|
abort('no lib') unless This.lib
|
209
263
|
abort('no version') unless This.version
|
210
264
|
|
265
|
+
# discover full path to this ruby executable
|
266
|
+
#
|
267
|
+
c = Config::CONFIG
|
268
|
+
bindir = c["bindir"] || c['BINDIR']
|
269
|
+
ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
|
270
|
+
ruby_ext = c['EXEEXT'] || ''
|
271
|
+
ruby = File.join(bindir, (ruby_install_name + ruby_ext))
|
272
|
+
This.ruby = ruby
|
273
|
+
|
274
|
+
# some utils
|
275
|
+
#
|
211
276
|
module Util
|
212
277
|
def indent(s, n = 2)
|
213
278
|
s = unindent(s)
|
@@ -217,18 +282,20 @@ BEGIN {
|
|
217
282
|
|
218
283
|
def unindent(s)
|
219
284
|
indent = nil
|
220
|
-
s.
|
221
|
-
|
222
|
-
|
285
|
+
s.each_line do |line|
|
286
|
+
next if line =~ %r/^\s*$/
|
287
|
+
indent = line[%r/^\s*/] and break
|
288
|
+
end
|
289
|
+
indent ? s.gsub(%r/^#{ indent }/, "") : s
|
223
290
|
end
|
224
|
-
indent ? s.gsub(%r/^#{ indent }/, "") : s
|
225
|
-
end
|
226
291
|
extend self
|
227
292
|
end
|
228
293
|
|
294
|
+
# template support
|
295
|
+
#
|
229
296
|
class Template
|
230
297
|
def initialize(&block)
|
231
|
-
@block = block
|
298
|
+
@block = block.binding
|
232
299
|
@template = block.call.to_s
|
233
300
|
end
|
234
301
|
def expand(b=nil)
|
@@ -238,5 +305,57 @@ BEGIN {
|
|
238
305
|
end
|
239
306
|
def Template(*args, &block) Template.new(*args, &block) end
|
240
307
|
|
308
|
+
# colored console output support
|
309
|
+
#
|
310
|
+
This.ansi = {
|
311
|
+
:clear => "\e[0m",
|
312
|
+
:reset => "\e[0m",
|
313
|
+
:erase_line => "\e[K",
|
314
|
+
:erase_char => "\e[P",
|
315
|
+
:bold => "\e[1m",
|
316
|
+
:dark => "\e[2m",
|
317
|
+
:underline => "\e[4m",
|
318
|
+
:underscore => "\e[4m",
|
319
|
+
:blink => "\e[5m",
|
320
|
+
:reverse => "\e[7m",
|
321
|
+
:concealed => "\e[8m",
|
322
|
+
:black => "\e[30m",
|
323
|
+
:red => "\e[31m",
|
324
|
+
:green => "\e[32m",
|
325
|
+
:yellow => "\e[33m",
|
326
|
+
:blue => "\e[34m",
|
327
|
+
:magenta => "\e[35m",
|
328
|
+
:cyan => "\e[36m",
|
329
|
+
:white => "\e[37m",
|
330
|
+
:on_black => "\e[40m",
|
331
|
+
:on_red => "\e[41m",
|
332
|
+
:on_green => "\e[42m",
|
333
|
+
:on_yellow => "\e[43m",
|
334
|
+
:on_blue => "\e[44m",
|
335
|
+
:on_magenta => "\e[45m",
|
336
|
+
:on_cyan => "\e[46m",
|
337
|
+
:on_white => "\e[47m"
|
338
|
+
}
|
339
|
+
def say(phrase, *args)
|
340
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
341
|
+
options[:color] = args.shift.to_s.to_sym unless args.empty?
|
342
|
+
keys = options.keys
|
343
|
+
keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
|
344
|
+
|
345
|
+
color = options[:color]
|
346
|
+
bold = options.has_key?(:bold)
|
347
|
+
|
348
|
+
parts = [phrase]
|
349
|
+
parts.unshift(This.ansi[color]) if color
|
350
|
+
parts.unshift(This.ansi[:bold]) if bold
|
351
|
+
parts.push(This.ansi[:clear]) if parts.size > 1
|
352
|
+
|
353
|
+
method = options[:method] || :puts
|
354
|
+
|
355
|
+
Kernel.send(method, parts.join)
|
356
|
+
end
|
357
|
+
|
358
|
+
# always run out of the project dir
|
359
|
+
#
|
241
360
|
Dir.chdir(This.dir)
|
242
361
|
}
|
data/lib/fattr.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Fattr
|
2
|
-
Fattr::Version = '2.
|
2
|
+
Fattr::Version = '2.2.0' unless Fattr.const_defined?(:Version)
|
3
3
|
def self.version() Fattr::Version end
|
4
4
|
|
5
5
|
class List < ::Array
|
@@ -72,7 +72,7 @@ module Fattr
|
|
72
72
|
|
73
73
|
initialize = (
|
74
74
|
if inheritable
|
75
|
-
lambda do
|
75
|
+
lambda do |*ignored|
|
76
76
|
parents = ancestors[1..-1]
|
77
77
|
catch(:value) do
|
78
78
|
parents.each do |parent|
|
@@ -82,7 +82,7 @@ module Fattr
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
else
|
85
|
-
block || lambda{ default }
|
85
|
+
block || lambda{|*ignored| default }
|
86
86
|
end
|
87
87
|
)
|
88
88
|
|
@@ -123,6 +123,7 @@ module Fattr
|
|
123
123
|
compile[code]
|
124
124
|
|
125
125
|
# bang method re-calls any initializer given at declaration time
|
126
|
+
=begin
|
126
127
|
code = <<-code
|
127
128
|
def #{ name }!
|
128
129
|
initializer = ObjectSpace._id2ref #{ initializer_id }
|
@@ -131,6 +132,14 @@ module Fattr
|
|
131
132
|
end
|
132
133
|
code
|
133
134
|
compile[code]
|
135
|
+
=end
|
136
|
+
|
137
|
+
module_eval do
|
138
|
+
define_method :"#{ name }!" do
|
139
|
+
self.send :"#{ name }=", initializer.call(self)
|
140
|
+
self.instance_variable_get :"@#{name}"
|
141
|
+
end
|
142
|
+
end
|
134
143
|
|
135
144
|
# query simply defers to getter - cast to bool
|
136
145
|
code = <<-code
|
@@ -10,6 +10,7 @@ Testing Fattr do
|
|
10
10
|
|
11
11
|
testing 'that the basic usage works' do
|
12
12
|
o = Class.new{ fattr :a }.new
|
13
|
+
p o.a
|
13
14
|
assert{ o.a==nil }
|
14
15
|
assert{ o.a=42 }
|
15
16
|
assert{ o.a(42.0) }
|
@@ -123,10 +124,16 @@ BEGIN {
|
|
123
124
|
words.join('-').downcase
|
124
125
|
end
|
125
126
|
|
126
|
-
|
127
|
-
|
127
|
+
def self.testing_subclass_count
|
128
|
+
@testing_subclass_count ||= 0
|
129
|
+
end
|
130
|
+
def self.testing_subclass_count=(value)
|
131
|
+
@testing_subclass_count = value
|
132
|
+
end
|
133
|
+
|
134
|
+
self.testing_subclass_count += 1
|
128
135
|
slug = slug_for(*args).gsub(%r/-/,'_')
|
129
|
-
name = ['TESTING', '%03d' %
|
136
|
+
name = ['TESTING', '%03d' % self.testing_subclass_count, slug].delete_if{|part| part.empty?}.join('_')
|
130
137
|
name = name.upcase!
|
131
138
|
const_set(:Name, name)
|
132
139
|
def self.name() const_get(:Name) end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fattr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 2
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 2.2.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Ara T. Howard
|
@@ -9,11 +14,11 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-11-08 00:00:00 -07:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
16
|
-
description: fattr
|
21
|
+
description: "description: fattr kicks the ass"
|
17
22
|
email: ara.t.howard@gmail.com
|
18
23
|
executables: []
|
19
24
|
|
@@ -22,9 +27,8 @@ extensions: []
|
|
22
27
|
extra_rdoc_files: []
|
23
28
|
|
24
29
|
files:
|
25
|
-
- a.rb
|
26
|
-
- fattr.gemspec
|
27
30
|
- lib/fattr.rb
|
31
|
+
- LICENSE
|
28
32
|
- Rakefile
|
29
33
|
- README
|
30
34
|
- README.erb
|
@@ -36,7 +40,7 @@ files:
|
|
36
40
|
- samples/f.rb
|
37
41
|
- samples/g.rb
|
38
42
|
- samples/h.rb
|
39
|
-
- test/
|
43
|
+
- test/fattr_test.rb
|
40
44
|
has_rdoc: true
|
41
45
|
homepage: http://github.com/ahoward/fattr/tree/master
|
42
46
|
licenses: []
|
@@ -47,23 +51,27 @@ rdoc_options: []
|
|
47
51
|
require_paths:
|
48
52
|
- lib
|
49
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
50
55
|
requirements:
|
51
56
|
- - ">="
|
52
57
|
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
53
60
|
version: "0"
|
54
|
-
version:
|
55
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
56
63
|
requirements:
|
57
64
|
- - ">="
|
58
65
|
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
59
68
|
version: "0"
|
60
|
-
version:
|
61
69
|
requirements: []
|
62
70
|
|
63
71
|
rubyforge_project: codeforpeople
|
64
|
-
rubygems_version: 1.3.
|
72
|
+
rubygems_version: 1.3.7
|
65
73
|
signing_key:
|
66
74
|
specification_version: 3
|
67
75
|
summary: fattr
|
68
|
-
test_files:
|
69
|
-
|
76
|
+
test_files: []
|
77
|
+
|
data/a.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'fattr'
|
3
|
-
|
4
|
-
class A
|
5
|
-
class << A
|
6
|
-
fattr(:x, :inheritable => true){ 42 }
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class B < A; end
|
11
|
-
|
12
|
-
class C < B; end
|
13
|
-
|
14
|
-
|
15
|
-
p C.x
|
16
|
-
p B.x
|
17
|
-
p A.x
|
18
|
-
puts
|
19
|
-
|
20
|
-
B.x = 42.0
|
21
|
-
|
22
|
-
p C.x
|
23
|
-
p B.x
|
24
|
-
p A.x
|
25
|
-
puts
|
26
|
-
|
27
|
-
C.x! # force re-initialization from parent(s)
|
28
|
-
|
29
|
-
p C.x
|
30
|
-
p B.x
|
31
|
-
p A.x
|
32
|
-
puts
|
33
|
-
|
34
|
-
|
35
|
-
class K
|
36
|
-
end
|
37
|
-
module M
|
38
|
-
fattr(:x, :inheritable => true){ 42 }
|
39
|
-
end
|
40
|
-
K.extend(M)
|
41
|
-
|
42
|
-
p K.x
|
data/fattr.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
## fattr.gemspec
|
2
|
-
#
|
3
|
-
|
4
|
-
Gem::Specification::new do |spec|
|
5
|
-
spec.name = "fattr"
|
6
|
-
spec.description = 'fattr.rb is a "fatter attr" for ruby'
|
7
|
-
spec.version = "2.1.0"
|
8
|
-
spec.platform = Gem::Platform::RUBY
|
9
|
-
spec.summary = "fattr"
|
10
|
-
|
11
|
-
spec.files = ["a.rb", "fattr.gemspec", "lib", "lib/fattr.rb", "Rakefile", "README", "README.erb", "samples", "samples/a.rb", "samples/b.rb", "samples/c.rb", "samples/d.rb", "samples/e.rb", "samples/f.rb", "samples/g.rb", "samples/h.rb", "test", "test/fattr.rb"]
|
12
|
-
spec.executables = []
|
13
|
-
|
14
|
-
|
15
|
-
spec.require_path = "lib"
|
16
|
-
|
17
|
-
|
18
|
-
spec.has_rdoc = true
|
19
|
-
spec.test_files = "test/fattr.rb"
|
20
|
-
#spec.add_dependency 'lib', '>= version'
|
21
|
-
#spec.add_dependency 'fattr'
|
22
|
-
|
23
|
-
spec.extensions.push(*[])
|
24
|
-
|
25
|
-
spec.rubyforge_project = "codeforpeople"
|
26
|
-
spec.author = "Ara T. Howard"
|
27
|
-
spec.email = "ara.t.howard@gmail.com"
|
28
|
-
spec.homepage = "http://github.com/ahoward/fattr/tree/master"
|
29
|
-
end
|