RubyExt 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +846 -0
- data/lib/RubyExt/Cache.rb +101 -0
- data/lib/RubyExt/Cache.res/multiple_version_with_args.txt +12 -0
- data/lib/RubyExt/Cache.res/multiple_version_without_args.txt +11 -0
- data/lib/RubyExt/Cache.res/single_version_with_args.txt +11 -0
- data/lib/RubyExt/Cache.res/single_version_without_args.txt +10 -0
- data/lib/RubyExt/ClassLoader.rb +142 -0
- data/lib/RubyExt/Debug.rb +24 -0
- data/lib/RubyExt/ExtraBlankSlate.rb +14 -0
- data/lib/RubyExt/ImportAll.rb +9 -0
- data/lib/RubyExt/Localization/Module.rb +12 -0
- data/lib/RubyExt/Localization/Object.rb +19 -0
- data/lib/RubyExt/Localization/require.rb +3 -0
- data/lib/RubyExt/Localization.rb +28 -0
- data/lib/RubyExt/Log.config.sample +57 -0
- data/lib/RubyExt/Log.rb +59 -0
- data/lib/RubyExt/OpenConstructor.rb +51 -0
- data/lib/RubyExt/Path.rb +91 -0
- data/lib/RubyExt/Resource/file_system_provider.rb +244 -0
- data/lib/RubyExt/StateMashine.rb +176 -0
- data/lib/RubyExt/Synchronizer.rb +29 -0
- data/lib/RubyExt/array.rb +24 -0
- data/lib/RubyExt/assert.rb +111 -0
- data/lib/RubyExt/class.rb +0 -0
- data/lib/RubyExt/debug.rb +71 -0
- data/lib/RubyExt/false_class.rb +5 -0
- data/lib/RubyExt/file.rb +23 -0
- data/lib/RubyExt/ideas.txt +17 -0
- data/lib/RubyExt/kernel.rb +61 -0
- data/lib/RubyExt/module.rb +102 -0
- data/lib/RubyExt/nil_class.rb +5 -0
- data/lib/RubyExt/object.rb +7 -0
- data/lib/RubyExt/observable.rb +25 -0
- data/lib/RubyExt/require.rb +56 -0
- data/lib/RubyExt/require_base.rb +35 -0
- data/lib/RubyExt/resource.rb +198 -0
- data/lib/RubyExt/string.rb +21 -0
- data/lib/RubyExt/symbol.rb +21 -0
- data/lib/RubyExt/true_class +0 -0
- data/lib/RubyExt/true_class.rb +5 -0
- data/rakefile +49 -0
- data/spec/RubyExt/ForClassLoader/ClassA.rb +4 -0
- data/spec/RubyExt/ForClassLoader/LoadCount.rb +1 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/ClassB.rb +3 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/ClassInsideAnonymousClass.rb +3 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/InfinityLoop.rb +3 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/ModuleB/ClassC.rb +3 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/SameName/SomeClass.rb +2 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/SameName.rb +2 -0
- data/spec/RubyExt/ForClassLoader/Scope/ScopeA1.rb +3 -0
- data/spec/RubyExt/ForClassLoader/Scope/ScopeB1.rb +5 -0
- data/spec/RubyExt/ForKernel/Raise2.rb +5 -0
- data/spec/RubyExt/ForKernel/RaiseWithoutSelf.rb +9 -0
- data/spec/RubyExt/ForLocalization/NS/A.rb +3 -0
- data/spec/RubyExt/ForLocalization/NS/A.ru.localization.yaml +2 -0
- data/spec/RubyExt/ForLocalization/NS/B.rb +22 -0
- data/spec/RubyExt/ForLocalization/NS/B.ru.localization.yaml +3 -0
- data/spec/RubyExt/ForLocalization/NS.ru.localization.yaml +2 -0
- data/spec/RubyExt/ForModule/NS1/A.data +1 -0
- data/spec/RubyExt/ForModule/NS1/A.rb +1 -0
- data/spec/RubyExt/ForModule/NS1/A2.rb +1 -0
- data/spec/RubyExt/ForModule/NS1/B.rb +2 -0
- data/spec/RubyExt/ForModule/NS1/B2.rb +1 -0
- data/spec/RubyExt/ForModule/NS1.data +1 -0
- data/spec/RubyExt/ForModule/NS2/A.data +1 -0
- data/spec/RubyExt/ForModule/NS2/A.rb +3 -0
- data/spec/RubyExt/ForModule/NS2/B.rb +3 -0
- data/spec/RubyExt/ForModule/NS2/M.data +1 -0
- data/spec/RubyExt/ForModule/NS2/M.rb +3 -0
- data/spec/RubyExt/ForResource/ChangedClass.rb +1 -0
- data/spec/RubyExt/ForResource/ChangedClass.res/Text.txt +0 -0
- data/spec/RubyExt/ForResource/ChangedClass.txt +0 -0
- data/spec/RubyExt/ForResource/ProviderChaining/ProviderABaseDir/ChainTest.rb +3 -0
- data/spec/RubyExt/ForResource/ProviderChaining/ProviderABaseDir/ChainTest.resource +1 -0
- data/spec/RubyExt/ForResource/ProviderChaining/ProviderABaseDir/ClassExistOnlyInProviderA.rb +3 -0
- data/spec/RubyExt/ForResource/ProviderChaining/ProviderBBaseDir/ChainTest.rb +3 -0
- data/spec/RubyExt/ForResource/ProviderChaining/ProviderBBaseDir/ChainTest.resource +1 -0
- data/spec/RubyExt/ForResource/ResourceExtension.rb +1 -0
- data/spec/RubyExt/ForResource/ResourceExtension.res/Data.yaml +2 -0
- data/spec/RubyExt/ForResource/ResourceTest/Test.rb +1 -0
- data/spec/RubyExt/ForResource/ResourceTest/Test.res/Data.txt +1 -0
- data/spec/RubyExt/ForResource/ResourceTest/Test.res/txt +1 -0
- data/spec/array_spec.rb +27 -0
- data/spec/assert_spec.rb +18 -0
- data/spec/cache_spec.rb +95 -0
- data/spec/class_loader_spec.rb +94 -0
- data/spec/import_all_spec.rb +21 -0
- data/spec/kernel_spec.rb +38 -0
- data/spec/localization_spec.rb +49 -0
- data/spec/module_spec.rb +135 -0
- data/spec/object_spec.rb +8 -0
- data/spec/observable_spec.rb +44 -0
- data/spec/open_constructor_spec.rb +38 -0
- data/spec/path_spec.rb +169 -0
- data/spec/resource_spec.rb +135 -0
- data/spec/state_machine_spec.rb +201 -0
- data/spec/synchronizer_spec.rb +66 -0
- metadata +130 -10
- data/lib/RubyExt.rb +0 -1
- data/lib/hello_gem.rb +0 -5
@@ -0,0 +1,61 @@
|
|
1
|
+
module Kernel
|
2
|
+
def raise_without_self *args
|
3
|
+
error, message, the_self = nil
|
4
|
+
if args.size == 1
|
5
|
+
error = RuntimeError
|
6
|
+
message = args[0]
|
7
|
+
the_self = self
|
8
|
+
elsif args.size == 2
|
9
|
+
message, the_self = args
|
10
|
+
error = RuntimeError
|
11
|
+
elsif args.size == 3
|
12
|
+
error, message, the_self = args
|
13
|
+
else
|
14
|
+
raise RuntimeError, "Invalid arguments!", caller
|
15
|
+
end
|
16
|
+
|
17
|
+
the_self = the_self.is_a?(Array) ? the_self : [the_self]
|
18
|
+
|
19
|
+
list = []
|
20
|
+
the_self.each do |s|
|
21
|
+
klass = (s.class == Class or s.class == Module) ? s : s.class
|
22
|
+
klass.ancestors.each do |a|
|
23
|
+
next if a == Object or a == Module
|
24
|
+
name = a.name
|
25
|
+
path = nil
|
26
|
+
if RubyExt::Resource.class_exist?(name)
|
27
|
+
path = RubyExt::Resource.class_to_virtual_file(name)
|
28
|
+
path.sub!(".rb", "")
|
29
|
+
else
|
30
|
+
path = name.gsub("::", "/")
|
31
|
+
end
|
32
|
+
list << /#{path}/
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
stack = caller
|
37
|
+
stack = stack.delete_if do |line|
|
38
|
+
list.any?{|re| line =~ re} and line !~ /\/spec\// # Do not exclude Spec stacktrace.
|
39
|
+
end
|
40
|
+
raise error, message, stack
|
41
|
+
end
|
42
|
+
|
43
|
+
def respond_to sym, *args
|
44
|
+
return nil if not respond_to? sym
|
45
|
+
send sym, *args
|
46
|
+
end
|
47
|
+
|
48
|
+
# def _ &b
|
49
|
+
# raise "Block isn't provided!" unless b
|
50
|
+
# return b
|
51
|
+
# end
|
52
|
+
|
53
|
+
def singleton_class(&block)
|
54
|
+
if block_given?
|
55
|
+
(class << self; self; end).class_eval(&block)
|
56
|
+
self
|
57
|
+
else
|
58
|
+
(class << self; self; end)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
class Module
|
2
|
+
def namespace
|
3
|
+
if @module_namespace_defined
|
4
|
+
@module_namespace
|
5
|
+
else
|
6
|
+
@module_namespace_defined = true
|
7
|
+
@module_namespace = Module.namespace_for name
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def each_namespace &block
|
12
|
+
current = namespace
|
13
|
+
while current do
|
14
|
+
block.call current
|
15
|
+
current = current.namespace
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def each_ancestor include_standard = false, &block
|
20
|
+
if include_standard
|
21
|
+
ancestors.each{|a| block.call a unless a == self}
|
22
|
+
else
|
23
|
+
exclude = [self, Object, Kernel]
|
24
|
+
ancestors.each do |a|
|
25
|
+
block.call a unless exclude.include? a
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self_ancestors_and_namespaces &b
|
31
|
+
b.call self
|
32
|
+
each_ancestor &b
|
33
|
+
each_namespace &b
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.namespace_for class_name
|
37
|
+
list = class_name.split("::")
|
38
|
+
if list.size > 1
|
39
|
+
list.pop
|
40
|
+
return eval list.join("::"), TOPLEVEL_BINDING, __FILE__, __LINE__
|
41
|
+
else
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def wrap_method( sym, prefix = "old_", &blk )
|
47
|
+
old_method = "#{prefix}_#{sym}".to_sym
|
48
|
+
alias_method old_method, sym
|
49
|
+
define_method(sym) do |*args|
|
50
|
+
instance_exec(old_method, *args, &blk)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def is?(base)
|
55
|
+
ancestors.include?(base)
|
56
|
+
end
|
57
|
+
|
58
|
+
def resource_exist? resource_name
|
59
|
+
self_ancestors_and_namespaces do |klass|
|
60
|
+
return true if RubyExt::Resource.resource_exist? klass, resource_name
|
61
|
+
end
|
62
|
+
return false
|
63
|
+
end
|
64
|
+
|
65
|
+
def [] resource_name
|
66
|
+
self_ancestors_and_namespaces do |klass|
|
67
|
+
if RubyExt::Resource.resource_exist? klass, resource_name
|
68
|
+
return RubyExt::Resource.resource_get(klass, resource_name)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
raise RubyExt::Resource::NotExist, "Resource '#{resource_name}' for Class '#{self.name}' doesn't exist!", caller
|
72
|
+
end
|
73
|
+
|
74
|
+
def []= resource_name, value
|
75
|
+
RubyExt::Resource.resource_set self.name, resource_name, value
|
76
|
+
end
|
77
|
+
|
78
|
+
def inherited_instance_methods
|
79
|
+
im = Set.new
|
80
|
+
ancestors.each do |a|
|
81
|
+
next if a == self
|
82
|
+
im.merge a.instance_methods
|
83
|
+
end
|
84
|
+
return im.to_a
|
85
|
+
end
|
86
|
+
|
87
|
+
def inherit *modules
|
88
|
+
modules.each do |amodule|
|
89
|
+
include amodule
|
90
|
+
|
91
|
+
processed = []
|
92
|
+
amodule.ancestors.each do |a|
|
93
|
+
if a.const_defined? :ClassMethods
|
94
|
+
class_methods = a.const_get :ClassMethods
|
95
|
+
next if processed.include? class_methods
|
96
|
+
processed << class_methods
|
97
|
+
extend class_methods
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RubyExt
|
2
|
+
module Observable
|
3
|
+
def add_observer observer
|
4
|
+
@observable_observers ||= []
|
5
|
+
@observable_observers << observer unless @observable_observers.include? observer
|
6
|
+
end
|
7
|
+
|
8
|
+
def notify_observers method, *args
|
9
|
+
method.should! :be_a, Symbol
|
10
|
+
@observable_observers.each{|observer| observer.respond_to method, *args} if @observable_observers
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete_observer observer
|
14
|
+
@observable_observers.delete observer if @observable_observers
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete_observers
|
18
|
+
@observable_observers.clear if @observable_observers
|
19
|
+
end
|
20
|
+
|
21
|
+
def observers_count
|
22
|
+
@observable_observers ? @observable_observers.size : 0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -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
|
@@ -0,0 +1,198 @@
|
|
1
|
+
module RubyExt
|
2
|
+
module Resource
|
3
|
+
@monitor = Monitor.new
|
4
|
+
@providers = []
|
5
|
+
@resource_extensions = {}
|
6
|
+
|
7
|
+
class NotExist < RuntimeError
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
include Observable
|
13
|
+
|
14
|
+
def add_resource_provider provider
|
15
|
+
@providers.unshift provider
|
16
|
+
end
|
17
|
+
|
18
|
+
def providers
|
19
|
+
raise "There's no any Resource Provider!" if @providers.empty?
|
20
|
+
@providers
|
21
|
+
end
|
22
|
+
|
23
|
+
def register_resource_extension extension, load, save
|
24
|
+
@monitor.synchronize do
|
25
|
+
@resource_extensions[extension] = load, save
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def unregister_resource_extension extension
|
30
|
+
@monitor.synchronize do
|
31
|
+
@resource_extensions.delete extension
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns from first Provider that contains this Class.
|
36
|
+
def class_get class_name
|
37
|
+
@monitor.synchronize do
|
38
|
+
providers.each do |p|
|
39
|
+
begin
|
40
|
+
return p.class_get(class_name)
|
41
|
+
rescue NotExist;
|
42
|
+
end
|
43
|
+
end
|
44
|
+
raise "Class '#{class_name}' doesn't exist!"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Search for first Provider that contains Class Namespace and creates Class in it, then exits.
|
49
|
+
def class_set class_name, data, *args
|
50
|
+
@monitor.synchronize do
|
51
|
+
namespace = Module.namespace_for class_name
|
52
|
+
namespace = namespace ? namespace.to_s : nil
|
53
|
+
found = true
|
54
|
+
providers.each do |p|
|
55
|
+
next unless !namespace or p.class_exist?(namespace)
|
56
|
+
p.class_set class_name, data, *args
|
57
|
+
break
|
58
|
+
end
|
59
|
+
raise "Namespace '#{namespace}' doesn't exist!" unless found
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def class_exist? class_name
|
64
|
+
@monitor.synchronize do
|
65
|
+
providers.any?{|p| p.class_exist? class_name}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Deletes in each Providers.
|
70
|
+
def class_delete class_name
|
71
|
+
@monitor.synchronize do
|
72
|
+
providers.each{|p| p.class_delete class_name}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# def class_namespace_exist? namespace_name
|
77
|
+
# @monitor.synchronize do
|
78
|
+
# providers.any?{|p| p.class_namespace_exist? namespace_name}
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
|
82
|
+
# Search each Provider that contains this Class and returns first found Resource.
|
83
|
+
def resource_get klass, resource_name
|
84
|
+
@monitor.synchronize do
|
85
|
+
providers.each do |p|
|
86
|
+
next unless p.class_exist?(klass.name)
|
87
|
+
begin
|
88
|
+
data = p.resource_get(klass.name, resource_name)
|
89
|
+
|
90
|
+
if data
|
91
|
+
extension = File.extname(resource_name)
|
92
|
+
if @resource_extensions.include? extension
|
93
|
+
load, save = @resource_extensions[extension]
|
94
|
+
data = load.call data, klass, resource_name
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
return data
|
99
|
+
rescue NotExist;
|
100
|
+
end
|
101
|
+
end
|
102
|
+
raise "Resource '#{resource_name}' for Class '#{klass.name}' doesn't exist!"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Deletes Resource in all Providers.
|
107
|
+
def resource_delete klass, resource_name
|
108
|
+
@monitor.synchronize do
|
109
|
+
providers.each do |p|
|
110
|
+
next unless p.class_exist?(klass.name)
|
111
|
+
p.resource_delete klass.name, resource_name
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Set Resource in fist Provider that contains this Class.
|
117
|
+
def resource_set klass, resource_name, data
|
118
|
+
@monitor.synchronize do
|
119
|
+
extension = File.extname(resource_name)
|
120
|
+
if @resource_extensions.include? extension
|
121
|
+
load, save = @resource_extensions[extension]
|
122
|
+
data = save.call data, klass, resource_name
|
123
|
+
end
|
124
|
+
|
125
|
+
found = false
|
126
|
+
providers.each do |p|
|
127
|
+
next unless p.class_exist?(klass.name)
|
128
|
+
p.resource_set klass.name, resource_name, data
|
129
|
+
found = true
|
130
|
+
break
|
131
|
+
end
|
132
|
+
|
133
|
+
raise "Class '#{klass.name}' doesn't exist!" unless found
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Check also for Class existence.
|
138
|
+
def resource_exist? klass, resource_name
|
139
|
+
@monitor.synchronize do
|
140
|
+
providers.any? do |p|
|
141
|
+
next unless p.class_exist?(klass.name)
|
142
|
+
p.resource_exist? klass.name, resource_name
|
143
|
+
end
|
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
|
172
|
+
|
173
|
+
def class_to_virtual_file class_name
|
174
|
+
@monitor.synchronize do
|
175
|
+
providers.each do |p|
|
176
|
+
begin
|
177
|
+
return p.class_to_virtual_file class_name
|
178
|
+
rescue NotExist;
|
179
|
+
end
|
180
|
+
end
|
181
|
+
raise "Class '#{class_name}' doesn't exist!"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# def class_to_virtual_path class_name
|
186
|
+
# @monitor.synchronize do
|
187
|
+
# providers.each do |p|
|
188
|
+
# begin
|
189
|
+
# return p.class_to_virtual_path class_name
|
190
|
+
# rescue NotExist;
|
191
|
+
# end
|
192
|
+
# end
|
193
|
+
# raise "Class '#{class_name}' doesn't exist!"
|
194
|
+
# end
|
195
|
+
# end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class String
|
2
|
+
def to_reader
|
3
|
+
self.to_sym
|
4
|
+
end
|
5
|
+
|
6
|
+
def to_writer
|
7
|
+
"#{self}=".to_sym
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_iv
|
11
|
+
"@#{self}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def substitute binding
|
15
|
+
binding.should! :be_a, Binding
|
16
|
+
return gsub(/\#\{.+?\}/) do |term|
|
17
|
+
identifier = term.slice(2 .. term.size-2)
|
18
|
+
binding.eval identifier
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Symbol
|
2
|
+
def <=> other
|
3
|
+
self.to_s <=> other.to_s
|
4
|
+
end
|
5
|
+
|
6
|
+
def to_reader
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_writer
|
11
|
+
"#{self}=".to_sym
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_iv
|
15
|
+
"@#{self}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def + other
|
19
|
+
(self.to_s + other.to_s).to_sym
|
20
|
+
end
|
21
|
+
end
|
File without changes
|
data/rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
Dir.chdir File.dirname(__FILE__)
|
5
|
+
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
9
|
+
t.spec_files = FileList["spec/**/*_spec.rb"]
|
10
|
+
t.libs = ["lib", "spec"]
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rake/clean'
|
14
|
+
require 'rake/gempackagetask'
|
15
|
+
require 'fileutils'
|
16
|
+
|
17
|
+
spec = Gem::Specification.new do |s|
|
18
|
+
s.name = "RubyExt"
|
19
|
+
s.version = "0.1.1"
|
20
|
+
s.summary = "A set of Ruby language extensions, mainly for ActivePoint Project"
|
21
|
+
s.description = "A set of Ruby language extensions, mainly for ActivePoint Project"
|
22
|
+
s.author = "Alexey Petrushin"
|
23
|
+
# s.email = ""
|
24
|
+
s.homepage = "http://www.bos-tec.com"
|
25
|
+
s.rubyforge_project = "RubyExt"
|
26
|
+
|
27
|
+
s.platform = Gem::Platform::RUBY
|
28
|
+
s.has_rdoc = true
|
29
|
+
s.extra_rdoc_files = ["README"]
|
30
|
+
|
31
|
+
s.files = (%w{rakefile README} + Dir.glob("{lib,spec}/**/*"))\
|
32
|
+
.select{|f| f !~ /^\./}
|
33
|
+
# s.executables = ['restclient']
|
34
|
+
# s.add_dependency("BlueCloth", ">= 0.0.4")
|
35
|
+
|
36
|
+
s.require_path = "lib"
|
37
|
+
end
|
38
|
+
|
39
|
+
Rake::GemPackageTask.new(spec) do |p|
|
40
|
+
package_dir = "#{File.expand_path File.dirname(__FILE__)}/../build"
|
41
|
+
FileUtils.mkdir package_dir unless File.exist? package_dir
|
42
|
+
p.need_tar = true if RUBY_PLATFORM !~ /mswin/
|
43
|
+
p.need_zip = true
|
44
|
+
p.package_dir = package_dir
|
45
|
+
end
|
46
|
+
|
47
|
+
CLEAN.include [ 'pkg', '*.gem']
|
48
|
+
|
49
|
+
task :release => [:gem, :clean]
|
@@ -0,0 +1 @@
|
|
1
|
+
class LoadCount; end
|