ruby-ext 0.2.2 → 0.2.3
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/.git/COMMIT_EDITMSG +1 -1
- data/.git/index +0 -0
- data/.git/logs/HEAD +3 -0
- data/.git/logs/refs/heads/master +3 -0
- data/.git/logs/refs/remotes/origin/master +3 -0
- data/.git/objects/3a/5fe0dc6aaa6e41eb8dd865fa7d7100f4e68ced +0 -0
- data/.git/objects/49/3774d80093f4ec3c6c3bfad21e1c8c9eaf41ec +0 -0
- data/.git/objects/52/94913c6107b381d1378279e58551fa2be7cecb +0 -0
- data/.git/objects/57/ab6c10ddf4eff75d98b5770a2c2bf573b692cd +0 -0
- data/.git/objects/61/beeaa4bc6790a469babafbdc7395e9e19dcb5d +0 -0
- data/.git/objects/62/3a67b104c04e24316da21f3e229e1bc2ba9d31 +0 -0
- data/.git/objects/6d/1da4d8a2949a1a9714d5f9979c7ee9613d7cfd +0 -0
- data/.git/objects/7f/2c583d1fdcc5313140c57778be8b0d45824be9 +0 -0
- data/.git/objects/9f/e2acc9bded3dc0d29b1dfc7dc1b3bed5d72c8f +0 -0
- data/.git/objects/e1/3f643da891453763504616e4f5a8195b8ffdb9 +0 -0
- data/.git/objects/ee/69f9fad83c5b0668b62622037094e989d3c394 +0 -0
- data/.git/refs/heads/master +1 -1
- data/.git/refs/remotes/origin/master +1 -1
- data/Rakefile +2 -2
- data/lib/ruby_ext/should.rb +14 -0
- data/old/README +860 -0
- data/old/lib/RubyExt/ClassLoader.rb +142 -0
- data/old/lib/RubyExt/ExtraBlankSlate.rb +14 -0
- data/old/lib/RubyExt/ImportAll.rb +9 -0
- data/old/lib/RubyExt/Localization/Module.rb +12 -0
- data/old/lib/RubyExt/Localization/Object.rb +19 -0
- data/old/lib/RubyExt/Localization/require.rb +3 -0
- data/old/lib/RubyExt/Localization.rb +28 -0
- data/old/lib/RubyExt/Log.config.sample +57 -0
- data/old/lib/RubyExt/Log.rb +59 -0
- data/old/lib/RubyExt/Path.rb +91 -0
- data/old/lib/RubyExt/Resource/file_system_provider.rb +273 -0
- data/old/lib/RubyExt/StateMashine.rb +176 -0
- data/old/lib/RubyExt/array.rb +24 -0
- data/old/lib/RubyExt/class.rb +0 -0
- data/old/lib/RubyExt/debug.rb +71 -0
- data/old/lib/RubyExt/false_class.rb +5 -0
- data/old/lib/RubyExt/kernel.rb +3 -0
- data/old/lib/RubyExt/module.rb +26 -0
- data/old/lib/RubyExt/nil_class.rb +5 -0
- data/old/lib/RubyExt/observable.rb +25 -0
- data/old/lib/RubyExt/require.rb +1 -0
- data/old/lib/RubyExt/require_base.rb +1 -0
- data/old/lib/RubyExt/resource.rb +172 -0
- data/old/lib/RubyExt/true_class.rb +5 -0
- data/old/rakefile +52 -0
- data/old/require.rb +3 -0
- data/old/require_base.rb +3 -0
- data/old/spec/RubyExt/ForClassLoader/ClassA.rb +4 -0
- data/old/spec/RubyExt/ForClassLoader/LoadCount.rb +1 -0
- data/old/spec/RubyExt/ForClassLoader/ModuleA/ClassB.rb +3 -0
- data/old/spec/RubyExt/ForClassLoader/ModuleA/ClassInsideAnonymousClass.rb +3 -0
- data/old/spec/RubyExt/ForClassLoader/ModuleA/InfinityLoop.rb +3 -0
- data/old/spec/RubyExt/ForClassLoader/ModuleA/ModuleB/ClassC.rb +3 -0
- data/old/spec/RubyExt/ForClassLoader/ModuleA/SameName/SomeClass.rb +2 -0
- data/old/spec/RubyExt/ForClassLoader/ModuleA/SameName.rb +2 -0
- data/old/spec/RubyExt/ForClassLoader/Scope/ScopeA1.rb +3 -0
- data/old/spec/RubyExt/ForClassLoader/Scope/ScopeB1.rb +5 -0
- data/old/spec/RubyExt/ForKernel/Raise2.rb +5 -0
- data/old/spec/RubyExt/ForKernel/RaiseWithoutSelf.rb +9 -0
- data/old/spec/RubyExt/ForLocalization/NS/A.rb +3 -0
- data/old/spec/RubyExt/ForLocalization/NS/A.ru.localization.yaml +2 -0
- data/old/spec/RubyExt/ForLocalization/NS/B.rb +22 -0
- data/old/spec/RubyExt/ForLocalization/NS/B.ru.localization.yaml +3 -0
- data/old/spec/RubyExt/ForLocalization/NS.ru.localization.yaml +2 -0
- data/old/spec/RubyExt/ForModule/NS1/A.data +1 -0
- data/old/spec/RubyExt/ForModule/NS1/A.rb +1 -0
- data/old/spec/RubyExt/ForModule/NS1/A2.rb +1 -0
- data/old/spec/RubyExt/ForModule/NS1/B.rb +2 -0
- data/old/spec/RubyExt/ForModule/NS1/B2.rb +1 -0
- data/old/spec/RubyExt/ForModule/NS1.data +1 -0
- data/old/spec/RubyExt/ForModule/NS2/A.data +1 -0
- data/old/spec/RubyExt/ForModule/NS2/A.rb +3 -0
- data/old/spec/RubyExt/ForModule/NS2/B.rb +3 -0
- data/old/spec/RubyExt/ForModule/NS2/M.data +1 -0
- data/old/spec/RubyExt/ForModule/NS2/M.rb +3 -0
- data/old/spec/RubyExt/ForResource/ChangedClass.rb +1 -0
- data/old/spec/RubyExt/ForResource/ChangedClass.res/Text.txt +0 -0
- data/old/spec/RubyExt/ForResource/ChangedClass.txt +0 -0
- data/old/spec/RubyExt/ForResource/ProviderChaining/ProviderABaseDir/ChainTest.rb +3 -0
- data/old/spec/RubyExt/ForResource/ProviderChaining/ProviderABaseDir/ChainTest.resource +1 -0
- data/old/spec/RubyExt/ForResource/ProviderChaining/ProviderABaseDir/ClassExistOnlyInProviderA.rb +3 -0
- data/old/spec/RubyExt/ForResource/ProviderChaining/ProviderBBaseDir/ChainTest.rb +3 -0
- data/old/spec/RubyExt/ForResource/ProviderChaining/ProviderBBaseDir/ChainTest.resource +1 -0
- data/old/spec/RubyExt/ForResource/ResourceExtension.rb +1 -0
- data/old/spec/RubyExt/ForResource/ResourceExtension.res/Data.yaml +2 -0
- data/old/spec/RubyExt/ForResource/ResourceTest/Test.rb +11 -0
- data/old/spec/RubyExt/ForResource/ResourceTest/Test.res/Data.txt +1 -0
- data/old/spec/RubyExt/ForResource/ResourceTest/Test.res/txt +1 -0
- data/old/spec/array_spec.rb +27 -0
- data/old/spec/class_loader_spec.rb +94 -0
- data/old/spec/import_all_spec.rb +21 -0
- data/old/spec/kernel_spec.rb +29 -0
- data/old/spec/localization_spec.rb +49 -0
- data/old/spec/module_spec.rb +14 -0
- data/old/spec/object_spec.rb +8 -0
- data/old/spec/observable_spec.rb +44 -0
- data/old/spec/path_spec.rb +169 -0
- data/old/spec/resource_spec.rb +136 -0
- data/old/spec/state_machine_spec.rb +201 -0
- metadata +93 -2
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
module RubyExt
|
|
2
|
+
module ClassLoader
|
|
3
|
+
@monitor = Monitor.new
|
|
4
|
+
@loaded_classes = {}
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
include Observable
|
|
8
|
+
|
|
9
|
+
attr_accessor :error_on_defined_constant
|
|
10
|
+
|
|
11
|
+
def reload_class class_name
|
|
12
|
+
@monitor.synchronize do
|
|
13
|
+
class_name = class_name.sub(/^::/, "")
|
|
14
|
+
namespace = Module.namespace_for(class_name);
|
|
15
|
+
name = class_name.sub(/^#{namespace}::/, "")
|
|
16
|
+
return load_class namespace, name, true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def load_class namespace, const, reload = false
|
|
21
|
+
@monitor.synchronize do
|
|
22
|
+
namespace = nil if namespace == Object or namespace == Module
|
|
23
|
+
target_namespace = namespace
|
|
24
|
+
|
|
25
|
+
# Name hack (for anonymous classes)
|
|
26
|
+
namespace = eval "#{name_hack(namespace)}" if namespace
|
|
27
|
+
|
|
28
|
+
class_name = namespace ? "#{namespace.name}::#{const}" : const
|
|
29
|
+
simple_also_tried = false
|
|
30
|
+
begin
|
|
31
|
+
simple_also_tried = (namespace == nil)
|
|
32
|
+
|
|
33
|
+
if try_load class_name, const
|
|
34
|
+
defined_in_home_scope = namespace ? namespace.const_defined?(const) : \
|
|
35
|
+
Object.const_defined?(const)
|
|
36
|
+
|
|
37
|
+
raise_without_self NameError, "Class Name '#{class_name}' doesn't\
|
|
38
|
+
correspond to File Name '#{Resource.class_to_virtual_file(class_name)}'!", ClassLoader \
|
|
39
|
+
unless defined_in_home_scope
|
|
40
|
+
|
|
41
|
+
unless reload
|
|
42
|
+
if @loaded_classes.include? class_name
|
|
43
|
+
if error_on_defined_constant
|
|
44
|
+
raise_without_self NameError,
|
|
45
|
+
"Class '#{class_name}' is not defined in the '#{target_namespace}' Namespace!",
|
|
46
|
+
ClassLoader
|
|
47
|
+
else
|
|
48
|
+
warn "Warn: Class '#{class_name}' is not defined in the '#{target_namespace}' Namespace!"
|
|
49
|
+
puts caller
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
result = namespace ? namespace.const_get(const) : Object.const_get(const)
|
|
55
|
+
|
|
56
|
+
@loaded_classes[class_name] = target_namespace
|
|
57
|
+
notify_observers :update_class, result
|
|
58
|
+
return result
|
|
59
|
+
elsif namespace
|
|
60
|
+
namespace = Module.namespace_for(namespace.name)
|
|
61
|
+
class_name = namespace ? "#{namespace.name}::#{const}" : const
|
|
62
|
+
end
|
|
63
|
+
end until simple_also_tried
|
|
64
|
+
|
|
65
|
+
raise_without_self NameError, "uninitialized constant '#{class_name}'!",
|
|
66
|
+
ClassLoader
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def wrap_inside_namespace namespace, script
|
|
71
|
+
nesting = []
|
|
72
|
+
if namespace
|
|
73
|
+
current_scope = ""
|
|
74
|
+
namespace.name.split("::").each do |level|
|
|
75
|
+
current_scope += "::#{level}"
|
|
76
|
+
type = eval current_scope, TOPLEVEL_BINDING, __FILE__, __LINE__
|
|
77
|
+
nesting << [level, (type.class == Module ? "module" : "class")]
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
begining = nesting.collect{|l, t| "#{t} #{l};"}.join(' ')
|
|
81
|
+
ending = nesting.collect{"end"}.join('; ')
|
|
82
|
+
return "#{begining}#{script} \n#{ending}"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
protected
|
|
86
|
+
|
|
87
|
+
def try_load class_name, const
|
|
88
|
+
if Resource.class_exist? class_name
|
|
89
|
+
script = Resource.class_get class_name
|
|
90
|
+
script = wrap_inside_namespace Module.namespace_for(class_name), script
|
|
91
|
+
eval script, TOPLEVEL_BINDING, Resource.class_to_virtual_file(class_name)
|
|
92
|
+
# elsif Resource.class_namespace_exist? class_name
|
|
93
|
+
# script = "#{begining} module #{const}; end; #{ending}"
|
|
94
|
+
# eval script, TOPLEVEL_BINDING, __FILE__, __LINE__
|
|
95
|
+
else
|
|
96
|
+
return false
|
|
97
|
+
end
|
|
98
|
+
return true
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def name_hack namespace
|
|
102
|
+
if namespace
|
|
103
|
+
namespace.to_s.gsub("#<Class:", "").gsub(">", "")
|
|
104
|
+
else
|
|
105
|
+
""
|
|
106
|
+
end
|
|
107
|
+
# Namespace Hack description
|
|
108
|
+
# Module.name doesn't works correctly for Anonymous classes.
|
|
109
|
+
# try to execute this code:
|
|
110
|
+
#
|
|
111
|
+
#class Module
|
|
112
|
+
# def const_missing const
|
|
113
|
+
# p self.to_s
|
|
114
|
+
# end
|
|
115
|
+
#end
|
|
116
|
+
#
|
|
117
|
+
#class A
|
|
118
|
+
# class << self
|
|
119
|
+
# def a
|
|
120
|
+
# p self
|
|
121
|
+
# MissingConst
|
|
122
|
+
# end
|
|
123
|
+
# end
|
|
124
|
+
#end
|
|
125
|
+
#
|
|
126
|
+
#A.a
|
|
127
|
+
#
|
|
128
|
+
# the output will be:
|
|
129
|
+
# A
|
|
130
|
+
# "#<Class:A>"
|
|
131
|
+
#
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
class Module
|
|
138
|
+
# alias_method :old_const_missing, :const_missing
|
|
139
|
+
def const_missing const
|
|
140
|
+
return RubyExt::ClassLoader.load_class self, const.to_s
|
|
141
|
+
end
|
|
142
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class ExtraBlankSlate < BlankSlate
|
|
2
|
+
CUSTOM_UNDEFINE = [:p, :select, :puts]
|
|
3
|
+
|
|
4
|
+
undefine = Kernel.instance_methods + Object.instance_methods + CUSTOM_UNDEFINE
|
|
5
|
+
BlankSlate.instance_methods.each{|m| undefine.delete m}
|
|
6
|
+
|
|
7
|
+
undefine.each do |m|
|
|
8
|
+
script = %{\
|
|
9
|
+
def #{m} *p, &b
|
|
10
|
+
method_missing :#{m}, *p, &b
|
|
11
|
+
end}
|
|
12
|
+
class_eval script, __FILE__, __LINE__
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class Module
|
|
2
|
+
def localization lang
|
|
3
|
+
list, resource = [], "#{lang}.#{RubyExt::Localization::RESOURCE_EXTENSION}"
|
|
4
|
+
self_ancestors_and_namespaces do |klass|
|
|
5
|
+
if RubyExt::Resource.resource_exist? klass, resource
|
|
6
|
+
list << RubyExt::Resource.resource_get(klass, resource)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
return list.reverse.inject(:merge)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
DeclarativeCache.cached_with_params :class, Module, :localization
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class Object
|
|
2
|
+
def to_l string, binding = nil
|
|
3
|
+
lang = RubyExt::Localization.language
|
|
4
|
+
unless lang == RubyExt::Localization::DEFAULT_LANGUAGE
|
|
5
|
+
aself = self.respond_to(:localization_self) || self
|
|
6
|
+
aclass = (aself.class == Class or aself.class == Module) ? aself : aself.class
|
|
7
|
+
|
|
8
|
+
localization = aclass.localization lang
|
|
9
|
+
if localization and localization.include? string
|
|
10
|
+
string = localization[string]
|
|
11
|
+
else
|
|
12
|
+
RubyExt::Localization.log.warn("Not localized: '#{aclass.name}' '#{string}'!")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
string = string.interpolate binding if binding
|
|
17
|
+
return string
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Localization
|
|
2
|
+
extend Log
|
|
3
|
+
DEFAULT_LANGUAGE = :en
|
|
4
|
+
RESOURCE_EXTENSION = "localization.yaml"
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def default_language= lang
|
|
8
|
+
@default_language = lang
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def default_language
|
|
12
|
+
@default_language ||= DEFAULT_LANGUAGE
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def language= block
|
|
16
|
+
@language = block
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def language
|
|
20
|
+
if @language
|
|
21
|
+
lang = @language.call
|
|
22
|
+
return lang || default_language
|
|
23
|
+
else
|
|
24
|
+
return default_language
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<log4r_config>
|
|
2
|
+
<pre_config>
|
|
3
|
+
<global level="DEBUG"/>
|
|
4
|
+
|
|
5
|
+
<parameter name="serverlog" value="./logs/server.log"/>
|
|
6
|
+
</pre_config>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<outputter type="FileOutputter" name="server">
|
|
10
|
+
<filename>#{serverlog}</filename>
|
|
11
|
+
<trunc>false</trunc>
|
|
12
|
+
</outputter>
|
|
13
|
+
<outputter type="FileOutputter" name="client"
|
|
14
|
+
filename="./../logs/client.log"/>
|
|
15
|
+
<outputter type="FileOutputter" name="gui"
|
|
16
|
+
filename="./../logs/guidebug.log"/>
|
|
17
|
+
<outputter type="StderrOutputter" name="console" level="ERROR"/>
|
|
18
|
+
|
|
19
|
+
<logger name="server" level="ERROR" outputters="server, console"/>
|
|
20
|
+
<logger name="client" level="INFO" outputters="client, console"/>
|
|
21
|
+
<logger name="client::gui" trace="true">
|
|
22
|
+
<level>DEBUG</level>
|
|
23
|
+
<outputter>gui</outputter>
|
|
24
|
+
</logger>
|
|
25
|
+
|
|
26
|
+
</log4r_config>
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
<log4r_config>
|
|
32
|
+
<pre_config>
|
|
33
|
+
<global level="ALL"/>
|
|
34
|
+
</pre_config>
|
|
35
|
+
|
|
36
|
+
<outputter type="StderrOutputter" name="default" level="ALL"/>
|
|
37
|
+
<logger name="Default" level="ALL" outputters="default"/>
|
|
38
|
+
|
|
39
|
+
<outputter type="StderrOutputter" name="console" level="WARN"/>
|
|
40
|
+
<outputter type="StderrOutputter" name="console_all" level="ALL"/>
|
|
41
|
+
<outputter type="FileOutputter" name="microcontainer" filename="./../logs/microcontainer.log"/>
|
|
42
|
+
<outputter type="FileOutputter" name="rubyext" filename="./../logs/rubyext.log"/>
|
|
43
|
+
<outputter type="FileOutputter" name="wgui" filename="./../logs/wgui.log"/>
|
|
44
|
+
<outputter type="FileOutputter" name="howt" filename="./../logs/howt.log"/>
|
|
45
|
+
<outputter type="FileOutputter" name="log" filename="./../logs/log.log"/>
|
|
46
|
+
<outputter type="FileOutputter" name="localization" filename="./../logs/localization.log"/>
|
|
47
|
+
<outputter type="FileOutputter" name="object_model" filename="./../logs/object_model.log" level="ALL"/>
|
|
48
|
+
|
|
49
|
+
<logger name="MicroContainer" level="ALL" outputters="console, microcontainer"/>
|
|
50
|
+
<logger name="HOWT" level="ALL" outputters="console, howt"/>
|
|
51
|
+
<logger name="WGUI" level="ALL" outputters="console, wgui"/>
|
|
52
|
+
<logger name="RubyExt" level="ALL" outputters="console, rubyext"/>
|
|
53
|
+
<logger name="Localization" level="ALL" outputters="localization"/>
|
|
54
|
+
<logger name="Log" level="ALL" outputters="console, log"/>
|
|
55
|
+
<logger name="ClassLoader" level="ALL" outputters="console_all"/>
|
|
56
|
+
<logger name="ObjectModel" level="ALL" outputters="object_model, console_all"/>
|
|
57
|
+
</log4r_config>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'log4r'
|
|
2
|
+
require 'log4r/configurator'
|
|
3
|
+
|
|
4
|
+
module Log
|
|
5
|
+
@loggers = Hash.new do |hash, klass|
|
|
6
|
+
# Such complex initialization because I don't know how it exactly work.
|
|
7
|
+
# For example: Log.new for WGUI::SomeClass will works, but Log.new for WGUI will not.
|
|
8
|
+
logger = begin
|
|
9
|
+
Log4r::Logger.get(klass.name)
|
|
10
|
+
rescue
|
|
11
|
+
Log4r::Logger.new(klass.name) rescue Log4r::Logger.get("Default")
|
|
12
|
+
end
|
|
13
|
+
hash[klass] = logger
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
module ClassMethods
|
|
17
|
+
def log
|
|
18
|
+
Log.loggers[(self.class == Class or self.class == Module) ? self : self.class]
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def log
|
|
23
|
+
Log.loggers[(self.class == Class or self.class == Module) ? self : self.class]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class << self
|
|
27
|
+
attr_reader :loggers
|
|
28
|
+
|
|
29
|
+
def info *s
|
|
30
|
+
log.info *s
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def error *s
|
|
34
|
+
log.error *s
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def warn *s
|
|
38
|
+
log.warn *s
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def log
|
|
42
|
+
Log.loggers[Log]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
# configure %{\
|
|
46
|
+
#<log4r_config>
|
|
47
|
+
# <pre_config>
|
|
48
|
+
# <global level="ALL"/>
|
|
49
|
+
# </pre_config>
|
|
50
|
+
#
|
|
51
|
+
# <outputter type="StderrOutputter" name="default" level="ALL"/>
|
|
52
|
+
# <logger name="Default" level="ALL" outputters="default"/>
|
|
53
|
+
#</log4r_config>}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
module Log
|
|
57
|
+
config = Dir.getwd + "/config/log.xml"
|
|
58
|
+
Log4r::Configurator.load_xml_string(File.read(config)) if File.exist? config
|
|
59
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
class Path < String
|
|
2
|
+
def initialize path = ''
|
|
3
|
+
super path.chomp
|
|
4
|
+
raise "Invalid Path '#{path}' (ends with the '/' sign)" if (self =~ /\/$/ ) && !empty?
|
|
5
|
+
raise "Tnvalid Path '#{path}' (the '/' sign encounters multiple times in a row)" if self =~ /\/{2,}/
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def absolute?;
|
|
9
|
+
(self =~ /^\//) ? true : false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def relative?;
|
|
13
|
+
!absolute?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def empty?; self == '' || self == '/' end
|
|
17
|
+
|
|
18
|
+
def simple?;
|
|
19
|
+
self =~ /^\/?[^\/]*$/ ? true : false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def after part
|
|
23
|
+
raise "There is no Part '#{part}' in the Path '#{self}'" unless include? part
|
|
24
|
+
Path.new((absolute? ? '/' : '') + sub(/.*#{part}\/*/, ""))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def before part
|
|
28
|
+
raise "There is no Part '#{part}' in the Path '#{self}'" unless include? part
|
|
29
|
+
Path.new((absolute? ? '/' : '') + to_relative.sub(/\/*#{part}.*/, ""))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def previous;
|
|
33
|
+
return nil if empty?
|
|
34
|
+
p = sub(/[^\/]+?$/, "" )
|
|
35
|
+
p = p[0..p.string_size-2] if p.string_size > 1
|
|
36
|
+
return p
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def next;
|
|
40
|
+
p = sub(/[^\/]+\/?/, "")
|
|
41
|
+
return p.empty? ? nil : p
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def first;
|
|
45
|
+
Path.new(scan(/^\/?[^\/]*/)[0])
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def last;
|
|
49
|
+
Path.new(sub(/[^\/].+\//, ""))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def last_name
|
|
53
|
+
list = scan(/[^\/]+$/)
|
|
54
|
+
return list.size > 0 ? list[0] : nil
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def first_name
|
|
58
|
+
list = scan(/[^\/]+/)
|
|
59
|
+
return list.size > 0 ? list[0] : nil
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def add path
|
|
63
|
+
path = Path.new(path) unless path.is_a? Path
|
|
64
|
+
return Path.new((absolute? ? "/" : "") + path.to_relative) if empty?
|
|
65
|
+
return Path.new(self) if path.empty?
|
|
66
|
+
return Path.new(self.string_plus((path.absolute? ? '' : '/')) + path)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
alias_method :string_plus, :+
|
|
70
|
+
def + o
|
|
71
|
+
add(o)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def to_absolute; Path.new(absolute? ? self : "/#{self}") end
|
|
75
|
+
|
|
76
|
+
def to_relative; Path.new sub(/^\//, "") end
|
|
77
|
+
|
|
78
|
+
alias_method :string_each, :each
|
|
79
|
+
def each &block
|
|
80
|
+
to_a.each(&block)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
alias_method :string_size, :size
|
|
84
|
+
def size() to_a.size end
|
|
85
|
+
|
|
86
|
+
def to_a; @elements ||= to_relative.split('/') end
|
|
87
|
+
|
|
88
|
+
def to_s
|
|
89
|
+
return String.new(self)
|
|
90
|
+
end
|
|
91
|
+
end
|