RubyExt 0.1.1 → 0.1.2
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/README +16 -2
- data/lib/RubyExt/Config.rb +23 -0
- data/lib/RubyExt/Log.rb +1 -1
- data/lib/RubyExt/Resource/file_system_provider.rb +111 -82
- data/lib/RubyExt/_require.rb +56 -0
- data/lib/RubyExt/_require_base.rb +35 -0
- data/lib/RubyExt/require.rb +1 -56
- data/lib/RubyExt/require_base.rb +1 -35
- data/lib/RubyExt/resource.rb +1 -27
- data/rakefile +5 -2
- data/spec/RubyExt/ForResource/ResourceTest/Test.rb +11 -1
- data/spec/config_spec.rb +37 -0
- data/spec/resource_spec.rb +5 -4
- metadata +17 -5
- data/lib/RubyExt/ideas.txt +0 -17
data/README
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
=== Readme ===
|
2
|
-
|
3
|
-
|
2
|
+
For docs go to spec.
|
3
|
+
|
4
|
+
Most usefull classes are: ClassLoader, Cache, Localization, Synchronizer, Path,
|
5
|
+
module.rb, assert.rb.
|
6
|
+
|
7
|
+
=== Memo ====
|
8
|
+
I'm new to Git and this is shome memo for me :).
|
9
|
+
ssh-add axyd
|
10
|
+
git remote add origin git@github.com:alexeypetrushin/RubyExt.git
|
11
|
+
git pull origin master
|
12
|
+
git push origin master
|
13
|
+
http://jonas.nitro.dk/git/quick-reference.html
|
14
|
+
|
15
|
+
=== Copyright ===
|
16
|
+
Copyright (c) 2009, Alexey Petrushin
|
17
|
+
All rights reserved.
|
4
18
|
|
5
19
|
=== License (LGPL) ===
|
6
20
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Config
|
2
|
+
attr_reader :runtime, :config, :default
|
3
|
+
|
4
|
+
def initialize runtime, config, default
|
5
|
+
@runtime, @config, @default = runtime, config, default
|
6
|
+
end
|
7
|
+
|
8
|
+
def [] key
|
9
|
+
value = @runtime[key]
|
10
|
+
value = @config[key] if value.equal? nil
|
11
|
+
value = @default[key] if value.equal? nil
|
12
|
+
raise "There is no key #{key}!" if value.equal? nil
|
13
|
+
return value
|
14
|
+
end
|
15
|
+
|
16
|
+
def []= key, value
|
17
|
+
@runtime[key] = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def include? key
|
21
|
+
(@runtime[key] != nil) or (@config[key] != nil) or (@default[key] != nil)
|
22
|
+
end
|
23
|
+
end
|
data/lib/RubyExt/Log.rb
CHANGED
@@ -3,7 +3,7 @@ module RubyExt
|
|
3
3
|
attr_accessor :directories
|
4
4
|
|
5
5
|
def initialize directories = lambda{[File.expand_path('.')]}
|
6
|
-
@directories
|
6
|
+
@directories = directories
|
7
7
|
end
|
8
8
|
|
9
9
|
def class_get class_name
|
@@ -33,7 +33,7 @@ module RubyExt
|
|
33
33
|
end
|
34
34
|
|
35
35
|
length = File.write(path, data)
|
36
|
-
remember_file path
|
36
|
+
FileSystemProvider.remember_file path
|
37
37
|
return length
|
38
38
|
end
|
39
39
|
|
@@ -81,7 +81,7 @@ module RubyExt
|
|
81
81
|
end
|
82
82
|
|
83
83
|
length = File.write path, data
|
84
|
-
remember_file path
|
84
|
+
FileSystemProvider.remember_file path
|
85
85
|
return length
|
86
86
|
end
|
87
87
|
|
@@ -90,43 +90,7 @@ module RubyExt
|
|
90
90
|
raise Resource::NotExist unless class_path
|
91
91
|
|
92
92
|
real_resource_path(class_name, resource_name) != nil
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
def check_for_changed_files
|
97
|
-
changed = []
|
98
|
-
v = @directories.call
|
99
|
-
@directories.call.inject([]){|list, dir| list + Dir.glob("#{dir}/**/**")}.each do |path|
|
100
|
-
if file_changed? path
|
101
|
-
remember_file path
|
102
|
-
changed << file_changed(path)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
return changed
|
106
|
-
end
|
107
|
-
|
108
|
-
def reset_changed_files
|
109
|
-
@files = {}
|
110
|
-
@directories.call.inject([]){|list, dir| list + Dir.glob("#{dir}/**/**")}.each do |path|
|
111
|
-
remember_file path
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Different Providers can use different class path interpretation.
|
116
|
-
# So we return virtual path only if this path really exist.
|
117
|
-
def class_to_virtual_file class_name
|
118
|
-
path = nil
|
119
|
-
if @cache.include? class_name
|
120
|
-
path = @cache[class_name]
|
121
|
-
else
|
122
|
-
path = real_class_path class_name
|
123
|
-
raise Resource::NotExist, "Class '#{class_name}' doesn't Exist!" unless path
|
124
|
-
|
125
|
-
@cache[class_name] = path
|
126
|
-
end
|
127
|
-
|
128
|
-
File.expand_path path
|
129
|
-
end
|
93
|
+
end
|
130
94
|
|
131
95
|
# def class_to_virtual_path class_name
|
132
96
|
# result = nil
|
@@ -158,6 +122,112 @@ module RubyExt
|
|
158
122
|
# end
|
159
123
|
# end
|
160
124
|
|
125
|
+
# Different Providers can use different class path interpretation.
|
126
|
+
# So we return virtual path only if this path really exist.
|
127
|
+
def class_to_virtual_file class_name
|
128
|
+
path = nil
|
129
|
+
if FileSystemProvider.cache.include? class_name
|
130
|
+
path = FileSystemProvider.cache[class_name]
|
131
|
+
else
|
132
|
+
path = real_class_path class_name
|
133
|
+
raise Resource::NotExist, "Class '#{class_name}' doesn't Exist!" unless path
|
134
|
+
|
135
|
+
FileSystemProvider.cache[class_name] = path
|
136
|
+
end
|
137
|
+
|
138
|
+
File.expand_path path
|
139
|
+
end
|
140
|
+
|
141
|
+
# Reloading
|
142
|
+
@files, @cache = {}, {}
|
143
|
+
class << self
|
144
|
+
attr_reader :cache
|
145
|
+
|
146
|
+
def start_watching interval = 2, directories = Dir.glob("**/lib")
|
147
|
+
stop_watching
|
148
|
+
@watch_thread = Thread.new do
|
149
|
+
reset_changed_files directories
|
150
|
+
while true
|
151
|
+
sleep interval
|
152
|
+
begin
|
153
|
+
check_for_changed_files(directories).each do |type, klass, res|
|
154
|
+
Resource.notify_observers :update_resource, type, klass, res
|
155
|
+
end
|
156
|
+
rescue Exception => e
|
157
|
+
warn e
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def stop_watching
|
164
|
+
if @watch_thread
|
165
|
+
@watch_thread.kill
|
166
|
+
@watch_thread = nil
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def remember_file path
|
171
|
+
@files[path] = File.mtime(path)
|
172
|
+
end
|
173
|
+
|
174
|
+
protected
|
175
|
+
def check_for_changed_files directories
|
176
|
+
changed = []
|
177
|
+
directories.inject([]){|list, dir| list + Dir.glob("#{dir}/**/**")}.each do |path|
|
178
|
+
if file_changed? path, directories
|
179
|
+
remember_file path
|
180
|
+
changed << file_changed(path, directories)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
return changed
|
184
|
+
end
|
185
|
+
|
186
|
+
def reset_changed_files directories
|
187
|
+
@files = {}
|
188
|
+
directories.inject([]){|list, dir| list + Dir.glob("#{dir}/**/**")}.each do |path|
|
189
|
+
remember_file path
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def file_changed? path, directories
|
194
|
+
old_time = @files[path]
|
195
|
+
old_time == nil or old_time != File.mtime(path)
|
196
|
+
end
|
197
|
+
|
198
|
+
def file_changed path, directories
|
199
|
+
begin
|
200
|
+
if path =~ /\.rb$/
|
201
|
+
path = path.sub(/\.rb$/, "")
|
202
|
+
class_name = path_to_class(path, directories)
|
203
|
+
|
204
|
+
# ClassLoader.reload_class()
|
205
|
+
klass = eval class_name, TOPLEVEL_BINDING, __FILE__, __LINE__
|
206
|
+
cache.delete class_name
|
207
|
+
return :class, klass, nil
|
208
|
+
else
|
209
|
+
if path =~ /\.res/
|
210
|
+
class_path = path.sub(/\.res.+/, "")
|
211
|
+
resource_name3 = path.sub("#{class_path}.res/", "")
|
212
|
+
class_name = path_to_class class_path, directories
|
213
|
+
else
|
214
|
+
resource_name3 = path.sub(/.+\./, "")
|
215
|
+
class_name = path_to_class path.sub(/\.#{resource_name3}$/, ""), directories
|
216
|
+
end
|
217
|
+
klass = eval class_name, TOPLEVEL_BINDING, __FILE__, __LINE__
|
218
|
+
return :resource, klass, resource_name3
|
219
|
+
end
|
220
|
+
rescue Exception => e
|
221
|
+
warn "Can't reload file '#{path}' #{e.message}!"
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def path_to_class path, directories
|
226
|
+
base_dir = directories.select{|f| path.include? f}.max{|a, b| a.size <=> b.size}
|
227
|
+
path.gsub(/^#{base_dir}\//, "").gsub("/", "::")
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
161
231
|
protected
|
162
232
|
def real_class_path class_name
|
163
233
|
path = class_to_files(class_name).find{|f| File.exist? f}
|
@@ -180,48 +250,7 @@ module RubyExt
|
|
180
250
|
def class_to_basefiles class_name
|
181
251
|
relative = class_name.gsub("::", "/")
|
182
252
|
return @directories.call.collect{|dir| "#{dir}/#{relative}"}
|
183
|
-
end
|
184
|
-
|
185
|
-
def remember_file path
|
186
|
-
@files[path] = File.mtime(path)
|
187
|
-
end
|
188
|
-
|
189
|
-
def file_changed? path
|
190
|
-
old_time = @files[path]
|
191
|
-
old_time == nil or old_time != File.mtime(path)
|
192
|
-
end
|
193
|
-
|
194
|
-
def file_changed path
|
195
|
-
begin
|
196
|
-
if path =~ /\.rb$/
|
197
|
-
path = path.sub(/\.rb$/, "")
|
198
|
-
class_name = path_to_class(path)
|
199
|
-
|
200
|
-
# ClassLoader.reload_class()
|
201
|
-
klass = eval class_name, TOPLEVEL_BINDING, __FILE__, __LINE__
|
202
|
-
@cache.delete class_name
|
203
|
-
return :class, klass, nil
|
204
|
-
else
|
205
|
-
if path =~ /\.res/
|
206
|
-
class_path = path.sub(/\.res.+/, "")
|
207
|
-
resource_name = path.sub("#{class_path}.res/", "")
|
208
|
-
class_name = path_to_class class_path
|
209
|
-
else
|
210
|
-
resource_name = path.sub(/.+\./, "")
|
211
|
-
class_name = path_to_class path.sub(/\.#{resource_name}$/, "")
|
212
|
-
end
|
213
|
-
klass = eval class_name, TOPLEVEL_BINDING, __FILE__, __LINE__
|
214
|
-
return :resource, klass, resource_name
|
215
|
-
end
|
216
|
-
rescue Exception => e
|
217
|
-
warn "Can't reload file '#{path}' #{e.message}!"
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
def path_to_class path
|
222
|
-
base_dir = @directories.call.select{|f| path.include? f}.max{|a, b| a.size <=> b.size}
|
223
|
-
path.gsub(/^#{base_dir}\//, "").gsub("/", "::")
|
224
|
-
end
|
253
|
+
end
|
225
254
|
|
226
255
|
# Doesn't make Sense for Virtual Resource System
|
227
256
|
# def resource_path class_name, resource_name
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'RubyExt/require_base'
|
2
|
+
|
3
|
+
# Ruby Classes extensions
|
4
|
+
%w{
|
5
|
+
symbol string array false_class true_class nil_class
|
6
|
+
}.each{|n| require "RubyExt/#{n}"}
|
7
|
+
|
8
|
+
Path = RubyExt::Path
|
9
|
+
Log = RubyExt::Log
|
10
|
+
Observable = RubyExt::Observable
|
11
|
+
OpenConstructor = RubyExt::OpenConstructor
|
12
|
+
Cache = RubyExt::Cache
|
13
|
+
|
14
|
+
# Facets
|
15
|
+
require 'facets/elementor'
|
16
|
+
require 'facets/blankslate'
|
17
|
+
# Dictionary, Crypt, BiCrypt, Duration, LRUCache, LinkedList, Timer, Memoizer,
|
18
|
+
# Recorder, attr_validator
|
19
|
+
# "TreeTop" - cool Ruby Parser DSL.
|
20
|
+
|
21
|
+
# ResourceProcessing
|
22
|
+
require 'yaml'
|
23
|
+
module RubyExt
|
24
|
+
Resource.register_resource_extension(
|
25
|
+
".yaml",
|
26
|
+
lambda{|data, klass, name| YAML.load(data)},
|
27
|
+
lambda{|data, klass, name| YAML.dump(data)}
|
28
|
+
)
|
29
|
+
|
30
|
+
Resource.register_resource_extension(
|
31
|
+
".rb",
|
32
|
+
lambda{|data, klass, name|
|
33
|
+
script = ClassLoader.wrap_inside_namespace(klass, data)
|
34
|
+
eval script, TOPLEVEL_BINDING, "#{klass.name}/#{name}"
|
35
|
+
},
|
36
|
+
lambda{|data, klass, name| raise "Writing '.rb' Resource isn't supported!"}
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Cache
|
41
|
+
Cache.cached_with_params :class, Module, :resource_exist?, :[]
|
42
|
+
|
43
|
+
# Others
|
44
|
+
require 'fileutils'
|
45
|
+
# Undef
|
46
|
+
#[
|
47
|
+
#:select, :autoload, :autoload?, :chomp, :chomp!, :chop, :chop!, :fail, :format, :gsub,
|
48
|
+
#:gsub!, :iterator?, :open, :print, :printf, :puts, :putc, :readline, :readlines, :scan,
|
49
|
+
#:split, :sub, :sub!, :test, :trap, :warn
|
50
|
+
#].each do |m|
|
51
|
+
# Kernel.send :undef_method, m
|
52
|
+
#end
|
53
|
+
|
54
|
+
# select
|
55
|
+
|
56
|
+
require 'RubyExt/debug'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'monitor'
|
2
|
+
require 'singleton'
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
class NotDefined; end
|
6
|
+
|
7
|
+
# Core Classes, can't be excluded.
|
8
|
+
%w{
|
9
|
+
kernel module object class file
|
10
|
+
}.each{|n| require "RubyExt/#{n}"}
|
11
|
+
|
12
|
+
require 'RubyExt/assert'
|
13
|
+
require 'RubyExt/observable'
|
14
|
+
|
15
|
+
require 'RubyExt/resource'
|
16
|
+
require 'RubyExt/Resource/file_system_provider'
|
17
|
+
|
18
|
+
# Need this complex loading for correct work of 'raise_without_self''
|
19
|
+
module RubyExt
|
20
|
+
# libraries_in_working_dir = Dir.glob("*/**/lib").select{|f| File.directory? f}.collect{|f| File.expand_path f}
|
21
|
+
# specs_in_working_dir = Dir.glob("*/**/spec").select{|f| File.directory? f}.collect{|f| File.expand_path f}
|
22
|
+
directories = lambda do
|
23
|
+
$LOAD_PATH.select{|f| ![/site_ruby/, /vendor_ruby/, /bin$/].any?{|re| f =~ re}}\
|
24
|
+
.collect{|f| File.expand_path f}
|
25
|
+
# $LOAD_PATH.select{|dir| dir =~ /gems.+lib/}
|
26
|
+
# $LOAD_PATH.select{|dir| dir =~ /gems.+spec/} +
|
27
|
+
# [Dir.getwd] +
|
28
|
+
# libraries_in_working_dir
|
29
|
+
# specs_in_working_dir
|
30
|
+
end
|
31
|
+
Resource.add_resource_provider FileSystemProvider.new(directories)
|
32
|
+
|
33
|
+
script = Resource.class_get "RubyExt::ClassLoader"
|
34
|
+
eval script, TOPLEVEL_BINDING, Resource.class_to_virtual_file("RubyExt::ClassLoader")
|
35
|
+
end
|
data/lib/RubyExt/require.rb
CHANGED
@@ -1,56 +1 @@
|
|
1
|
-
require 'RubyExt/
|
2
|
-
|
3
|
-
# Ruby Classes extensions
|
4
|
-
%w{
|
5
|
-
symbol string array false_class true_class nil_class
|
6
|
-
}.each{|n| require "RubyExt/#{n}"}
|
7
|
-
|
8
|
-
Path = RubyExt::Path
|
9
|
-
Log = RubyExt::Log
|
10
|
-
Observable = RubyExt::Observable
|
11
|
-
OpenConstructor = RubyExt::OpenConstructor
|
12
|
-
Cache = RubyExt::Cache
|
13
|
-
|
14
|
-
# Facets
|
15
|
-
require 'facets/elementor'
|
16
|
-
require 'facets/blankslate'
|
17
|
-
# Dictionary, Crypt, BiCrypt, Duration, LRUCache, LinkedList, Timer, Memoizer,
|
18
|
-
# Recorder, attr_validator
|
19
|
-
# "TreeTop" - cool Ruby Parser DSL.
|
20
|
-
|
21
|
-
# ResourceProcessing
|
22
|
-
require 'yaml'
|
23
|
-
module RubyExt
|
24
|
-
Resource.register_resource_extension(
|
25
|
-
".yaml",
|
26
|
-
lambda{|data, klass, name| YAML.load(data)},
|
27
|
-
lambda{|data, klass, name| YAML.dump(data)}
|
28
|
-
)
|
29
|
-
|
30
|
-
Resource.register_resource_extension(
|
31
|
-
".rb",
|
32
|
-
lambda{|data, klass, name|
|
33
|
-
script = ClassLoader.wrap_inside_namespace(klass, data)
|
34
|
-
eval script, TOPLEVEL_BINDING, "#{klass.name}/#{name}"
|
35
|
-
},
|
36
|
-
lambda{|data, klass, name| raise "Writing '.rb' Resource isn't supported!"}
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Cache
|
41
|
-
Cache.cached_with_params :class, Module, :resource_exist?, :[]
|
42
|
-
|
43
|
-
# Others
|
44
|
-
require 'fileutils'
|
45
|
-
# Undef
|
46
|
-
#[
|
47
|
-
#:select, :autoload, :autoload?, :chomp, :chomp!, :chop, :chop!, :fail, :format, :gsub,
|
48
|
-
#:gsub!, :iterator?, :open, :print, :printf, :puts, :putc, :readline, :readlines, :scan,
|
49
|
-
#:split, :sub, :sub!, :test, :trap, :warn
|
50
|
-
#].each do |m|
|
51
|
-
# Kernel.send :undef_method, m
|
52
|
-
#end
|
53
|
-
|
54
|
-
# select
|
55
|
-
|
56
|
-
require 'RubyExt/debug'
|
1
|
+
require 'RubyExt/_require'
|
data/lib/RubyExt/require_base.rb
CHANGED
@@ -1,35 +1 @@
|
|
1
|
-
require '
|
2
|
-
require 'singleton'
|
3
|
-
require 'set'
|
4
|
-
|
5
|
-
class NotDefined; end
|
6
|
-
|
7
|
-
# Core Classes, can't be excluded.
|
8
|
-
%w{
|
9
|
-
kernel module object class file
|
10
|
-
}.each{|n| require "RubyExt/#{n}"}
|
11
|
-
|
12
|
-
require 'RubyExt/assert'
|
13
|
-
require 'RubyExt/observable'
|
14
|
-
|
15
|
-
require 'RubyExt/resource'
|
16
|
-
require 'RubyExt/Resource/file_system_provider'
|
17
|
-
|
18
|
-
# Need this complex loading for correct work of 'raise_without_self''
|
19
|
-
module RubyExt
|
20
|
-
# libraries_in_working_dir = Dir.glob("*/**/lib").select{|f| File.directory? f}.collect{|f| File.expand_path f}
|
21
|
-
# specs_in_working_dir = Dir.glob("*/**/spec").select{|f| File.directory? f}.collect{|f| File.expand_path f}
|
22
|
-
directories = lambda do
|
23
|
-
$LOAD_PATH.select{|f| ![/site_ruby/, /vendor_ruby/, /bin$/].any?{|re| f =~ re}}\
|
24
|
-
.collect{|f| File.expand_path f}
|
25
|
-
# $LOAD_PATH.select{|dir| dir =~ /gems.+lib/}
|
26
|
-
# $LOAD_PATH.select{|dir| dir =~ /gems.+spec/} +
|
27
|
-
# [Dir.getwd] +
|
28
|
-
# libraries_in_working_dir
|
29
|
-
# specs_in_working_dir
|
30
|
-
end
|
31
|
-
Resource.add_resource_provider FileSystemProvider.new(directories)
|
32
|
-
|
33
|
-
script = Resource.class_get "RubyExt::ClassLoader"
|
34
|
-
eval script, TOPLEVEL_BINDING, Resource.class_to_virtual_file("RubyExt::ClassLoader")
|
35
|
-
end
|
1
|
+
require 'RubyExt/_require_base'
|
data/lib/RubyExt/resource.rb
CHANGED
@@ -142,33 +142,7 @@ module RubyExt
|
|
142
142
|
p.resource_exist? klass.name, resource_name
|
143
143
|
end
|
144
144
|
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def start_watching interval = 2
|
148
|
-
stop_watching
|
149
|
-
@watch_thread = Thread.new do
|
150
|
-
providers.each{|p| p.reset_changed_files}
|
151
|
-
while true
|
152
|
-
sleep interval
|
153
|
-
begin
|
154
|
-
providers.each do |p|
|
155
|
-
p.check_for_changed_files.each do |type, klass, res|
|
156
|
-
notify_observers :update_resource, type, klass, res
|
157
|
-
end
|
158
|
-
end
|
159
|
-
rescue Exception => e
|
160
|
-
warn e
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def stop_watching
|
167
|
-
if @watch_thread
|
168
|
-
@watch_thread.kill
|
169
|
-
@watch_thread = nil
|
170
|
-
end
|
171
|
-
end
|
145
|
+
end
|
172
146
|
|
173
147
|
def class_to_virtual_file class_name
|
174
148
|
@monitor.synchronize do
|
data/rakefile
CHANGED
@@ -3,6 +3,7 @@ require 'spec/rake/spectask'
|
|
3
3
|
|
4
4
|
Dir.chdir File.dirname(__FILE__)
|
5
5
|
|
6
|
+
# Specs
|
6
7
|
task :default => :spec
|
7
8
|
|
8
9
|
Spec::Rake::SpecTask.new('spec') do |t|
|
@@ -10,13 +11,14 @@ Spec::Rake::SpecTask.new('spec') do |t|
|
|
10
11
|
t.libs = ["lib", "spec"]
|
11
12
|
end
|
12
13
|
|
14
|
+
# Gem
|
13
15
|
require 'rake/clean'
|
14
16
|
require 'rake/gempackagetask'
|
15
17
|
require 'fileutils'
|
16
18
|
|
17
19
|
spec = Gem::Specification.new do |s|
|
18
20
|
s.name = "RubyExt"
|
19
|
-
s.version = "0.1.
|
21
|
+
s.version = "0.1.2"
|
20
22
|
s.summary = "A set of Ruby language extensions, mainly for ActivePoint Project"
|
21
23
|
s.description = "A set of Ruby language extensions, mainly for ActivePoint Project"
|
22
24
|
s.author = "Alexey Petrushin"
|
@@ -32,13 +34,14 @@ spec = Gem::Specification.new do |s|
|
|
32
34
|
.select{|f| f !~ /^\./}
|
33
35
|
# s.executables = ['restclient']
|
34
36
|
# s.add_dependency("BlueCloth", ">= 0.0.4")
|
37
|
+
s.add_dependency "facets"
|
35
38
|
|
36
39
|
s.require_path = "lib"
|
37
40
|
end
|
38
41
|
|
39
42
|
Rake::GemPackageTask.new(spec) do |p|
|
40
43
|
package_dir = "#{File.expand_path File.dirname(__FILE__)}/../build"
|
41
|
-
FileUtils.mkdir package_dir unless File.exist? package_dir
|
44
|
+
# FileUtils.mkdir package_dir unless File.exist? package_dir
|
42
45
|
p.need_tar = true if RUBY_PLATFORM !~ /mswin/
|
43
46
|
p.need_zip = true
|
44
47
|
p.package_dir = package_dir
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'RubyExt/require'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
module RubyExt
|
5
|
+
describe 'Config' do
|
6
|
+
it "Use Case" do
|
7
|
+
runtime = {1 => 1}
|
8
|
+
config = {1 => 2, 2 => 2}
|
9
|
+
default = {1 => 3, 2 => 3, 3 => 3}
|
10
|
+
|
11
|
+
c = RubyExt::Config.new runtime, config, default
|
12
|
+
c[1].should == 1
|
13
|
+
c[2].should == 2
|
14
|
+
c[3].should == 3
|
15
|
+
|
16
|
+
lambda{c[:unknown]}.should raise_error(/key/)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "set runtime key" do
|
20
|
+
c = RubyExt::Config.new({}, {}, {})
|
21
|
+
lambda{c[:key]}.should raise_error(/key/)
|
22
|
+
c[:key] = :value
|
23
|
+
c[:key].should == :value
|
24
|
+
end
|
25
|
+
|
26
|
+
it "shouold correct works with false" do
|
27
|
+
runtime = {1 => false, 2 => false}
|
28
|
+
config = {2 => true}
|
29
|
+
|
30
|
+
c = RubyExt::Config.new runtime, config, {}
|
31
|
+
c.should include(1)
|
32
|
+
c.should include(2)
|
33
|
+
c[1].should == false
|
34
|
+
c[2].should == false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/resource_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'RubyExt/require_base'
|
2
|
+
require 'fileutils'
|
2
3
|
require 'spec'
|
3
4
|
Thread.abort_on_exception=true
|
4
5
|
|
@@ -97,7 +98,7 @@ module RubyExt
|
|
97
98
|
Resource.add_observer obs
|
98
99
|
|
99
100
|
begin
|
100
|
-
|
101
|
+
FileSystemProvider.start_watching(1, [File.dirname __FILE__])
|
101
102
|
|
102
103
|
sleep 0.1
|
103
104
|
base = "#{File.dirname(__FILE__)}/RubyExt/ForResource"
|
@@ -106,8 +107,8 @@ module RubyExt
|
|
106
107
|
File.write("#{base}/ChangedClass.res/Text.txt", "")
|
107
108
|
sleep 1.5
|
108
109
|
ensure
|
109
|
-
|
110
|
-
end
|
110
|
+
FileSystemProvider.stop_watching
|
111
|
+
end
|
111
112
|
|
112
113
|
obs.classes.size.should == 3
|
113
114
|
obs.classes.all?{|k| k == ForResource::ChangedClass}.should be_true
|
@@ -126,7 +127,7 @@ end}
|
|
126
127
|
end
|
127
128
|
|
128
129
|
it "ResourceExtension" do
|
129
|
-
require "
|
130
|
+
require "RubyExt/require"
|
130
131
|
Resource.resource_set RubyExt::ForResource::ResourceExtension, "Data.yaml", {:value => true}
|
131
132
|
res = Resource.resource_get RubyExt::ForResource::ResourceExtension, "Data.yaml"
|
132
133
|
res.should == {:value => true}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RubyExt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Petrushin
|
@@ -9,10 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-15 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: facets
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
16
25
|
description: A set of Ruby language extensions, mainly for ActivePoint Project
|
17
26
|
email:
|
18
27
|
executables: []
|
@@ -43,8 +52,10 @@ files:
|
|
43
52
|
- lib/RubyExt/kernel.rb
|
44
53
|
- lib/RubyExt/debug.rb
|
45
54
|
- lib/RubyExt/class.rb
|
55
|
+
- lib/RubyExt/_require.rb
|
46
56
|
- lib/RubyExt/ExtraBlankSlate.rb
|
47
57
|
- lib/RubyExt/observable.rb
|
58
|
+
- lib/RubyExt/_require_base.rb
|
48
59
|
- lib/RubyExt/Cache.res
|
49
60
|
- lib/RubyExt/Cache.res/single_version_with_args.txt
|
50
61
|
- lib/RubyExt/Cache.res/multiple_version_without_args.txt
|
@@ -59,7 +70,7 @@ files:
|
|
59
70
|
- lib/RubyExt/nil_class.rb
|
60
71
|
- lib/RubyExt/ImportAll.rb
|
61
72
|
- lib/RubyExt/true_class
|
62
|
-
- lib/RubyExt/
|
73
|
+
- lib/RubyExt/Config.rb
|
63
74
|
- lib/RubyExt/StateMashine.rb
|
64
75
|
- lib/RubyExt/false_class.rb
|
65
76
|
- lib/RubyExt/require_base.rb
|
@@ -144,6 +155,7 @@ files:
|
|
144
155
|
- spec/synchronizer_spec.rb
|
145
156
|
- spec/localization_spec.rb
|
146
157
|
- spec/path_spec.rb
|
158
|
+
- spec/config_spec.rb
|
147
159
|
has_rdoc: true
|
148
160
|
homepage: http://www.bos-tec.com
|
149
161
|
post_install_message:
|
data/lib/RubyExt/ideas.txt
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
CRITICAL
|
2
|
-
- Reloading resourses in ClassXXX.res folder doesn't works.
|
3
|
-
- Change 'raise_without_self' to caller.delete(SomePackage)
|
4
|
-
|
5
|
-
MEDIUM
|
6
|
-
|
7
|
-
LOW
|
8
|
-
- Add macros functionality to Ruby. (for example replace all '!=' with 'not_equal')
|
9
|
-
- Create project 'Flawless Ruby' (macros != to not_equal, and so on)
|
10
|
-
- Automatically evaluate extension for resources, use Class["res"] instead of Class["res.yaml"]
|
11
|
-
|
12
|
-
DONE
|
13
|
-
- Add resource providers chaining.
|
14
|
-
- Resource providers should be abstract (also for ObjectModel storage).
|
15
|
-
- Cashe implementation
|
16
|
-
- Resource reloading doesn't works (fix and add spec).
|
17
|
-
- Add raise_withoud_self 'bla-bla', [excludeAclass, excludeBclass]
|