joffice 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/LICENSE-2.0.txt +202 -0
- data/README.md +0 -0
- data/Rakefile +25 -0
- data/lib/joffice.rb +28 -0
- data/lib/joffice/config.rb +37 -0
- data/lib/joffice/external_lazy_load.rb +21 -0
- data/lib/joffice/fiber_events_pool.rb +96 -0
- data/lib/joffice/fiber_extensions.rb +71 -0
- data/lib/joffice/http_headers.rb +73 -0
- data/lib/joffice/i18n.rb +2 -0
- data/lib/joffice/kernel.rb +23 -0
- data/lib/joffice/kernel/array.rb +39 -0
- data/lib/joffice/kernel/math.rb +28 -0
- data/lib/joffice/kernel/object.rb +29 -0
- data/lib/joffice/kernel/string.rb +23 -0
- data/lib/joffice/kernel/time.rb +34 -0
- data/lib/joffice/locales/ru.yml +12 -0
- data/lib/joffice/mysql_utf8.rb +43 -0
- metadata +83 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.svn
|
data/LICENSE-2.0.txt
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
$:.unshift File.join(File.absolute_path(File.dirname(__FILE__)), 'lib')
|
3
|
+
require File.join(File.absolute_path(File.dirname(__FILE__)), 'lib', 'joffice.rb')
|
4
|
+
|
5
|
+
require "rake"
|
6
|
+
require "base64"
|
7
|
+
|
8
|
+
begin
|
9
|
+
require "jeweler"
|
10
|
+
|
11
|
+
Jeweler::Tasks.new do |gemspec|
|
12
|
+
gemspec.name = "joffice"
|
13
|
+
gemspec.summary = "JOffice common classes"
|
14
|
+
gemspec.description = gemspec.summary
|
15
|
+
gemspec.email = Base64.decode64("bWNjb2Rlci1ub3NwYW1AeWEucnU=")
|
16
|
+
gemspec.homepage = "http://github.com/mccoder/joffice"
|
17
|
+
gemspec.authors = ['Kokorin Denis']
|
18
|
+
gemspec.required_ruby_version = ">= 1.9.1"
|
19
|
+
gemspec.version= JOffice::VERSION
|
20
|
+
end
|
21
|
+
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
25
|
+
end
|
data/lib/joffice.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
require 'joffice/kernel'
|
19
|
+
require 'joffice/fiber_extensions'
|
20
|
+
require 'joffice/external_lazy_load'
|
21
|
+
|
22
|
+
module JOffice
|
23
|
+
VERSION='0.1.0'
|
24
|
+
autoload :FiberEvents, 'joffice/fiber_events_pool'
|
25
|
+
autoload :BaseEmClient, 'joffice/base_em_client'
|
26
|
+
autoload :Boot, 'joffice/boot'
|
27
|
+
autoload :Config, 'joffice/config'
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
require 'socket'
|
19
|
+
require 'yaml'
|
20
|
+
|
21
|
+
module JOffice
|
22
|
+
class Config
|
23
|
+
class << self
|
24
|
+
|
25
|
+
def profiles
|
26
|
+
@@profiles||=[[Socket.gethostname,ENV['JOFFICE_ENV']], Socket.gethostname, 'default']
|
27
|
+
end
|
28
|
+
|
29
|
+
def load(name)
|
30
|
+
profiles.each do |host|
|
31
|
+
full_path=File.join(JOFFICE_CONFIG, host, "#{name}.yml")
|
32
|
+
return YAML::load(File.new(full_path)) if File.exists?(full_path)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
autoload :UnicodeUtils, "unicode_utils/downcase"
|
19
|
+
autoload :EM, 'eventmachine'
|
20
|
+
autoload :EventMachine, 'eventmachine'
|
21
|
+
autoload :Bitly, 'em-synchrony/em-bitly'
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
require 'fiber'
|
19
|
+
require 'never_block'
|
20
|
+
|
21
|
+
module JOffice
|
22
|
+
module FiberEvents
|
23
|
+
class << self
|
24
|
+
def logger
|
25
|
+
@@logger
|
26
|
+
end
|
27
|
+
|
28
|
+
def logger=(v)
|
29
|
+
@@logger=v
|
30
|
+
end
|
31
|
+
|
32
|
+
def class_fiber_pool
|
33
|
+
@@class_fiber_pool||={}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def logger
|
38
|
+
@@logger
|
39
|
+
end
|
40
|
+
|
41
|
+
def fiber_pool
|
42
|
+
@fiber_pool||=(FiberEvents.class_fiber_pool[self.class.name]||=NB::Pool::FiberPool.new(5))
|
43
|
+
end
|
44
|
+
private :fiber_pool
|
45
|
+
|
46
|
+
def fiber_queue
|
47
|
+
@fiber_queue||={}
|
48
|
+
end
|
49
|
+
private :fiber_queue
|
50
|
+
|
51
|
+
def fire_events(key, value)
|
52
|
+
queue=fiber_queue.delete(key)
|
53
|
+
queue.each do |o|
|
54
|
+
o.run_on_next_tick(value)
|
55
|
+
end if queue
|
56
|
+
end
|
57
|
+
protected :fire_events
|
58
|
+
|
59
|
+
def shedule_task_in_new_fiber(key, &block)
|
60
|
+
EM.next_tick do
|
61
|
+
fiber_pool.spawn do
|
62
|
+
|
63
|
+
begin
|
64
|
+
result=block.call
|
65
|
+
ensure
|
66
|
+
fire_events(key, result);
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
private :shedule_task_in_new_fiber
|
73
|
+
|
74
|
+
def register_fiber_and_shedule_task(key, &block)
|
75
|
+
(fiber_queue[key]||=[]) << Fiber.yield
|
76
|
+
shedule_task_in_new_fiber(key, &block)
|
77
|
+
Fiber.yield
|
78
|
+
end
|
79
|
+
protected :register_fiber_and_shedule_task
|
80
|
+
|
81
|
+
def register_fiber_and_singleton_task(key)
|
82
|
+
if (queue=fiber_queue[key])
|
83
|
+
queue << Fiber.current
|
84
|
+
result=Fiber.yield
|
85
|
+
else
|
86
|
+
fiber_queue[key]=[]
|
87
|
+
begin
|
88
|
+
result=yield
|
89
|
+
ensure
|
90
|
+
fire_events(key, result);
|
91
|
+
end
|
92
|
+
end
|
93
|
+
result
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
|
19
|
+
require 'fiber'
|
20
|
+
require 'eventmachine'
|
21
|
+
class Fiber
|
22
|
+
def run_on_next_tick(value)
|
23
|
+
EM.next_tick do
|
24
|
+
resume(value) if alive?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def subscriptions
|
29
|
+
@subscriptions||={}
|
30
|
+
end
|
31
|
+
|
32
|
+
class << self
|
33
|
+
def sleep_to_next_tick
|
34
|
+
current.run_on_next_tick(nil)
|
35
|
+
Fiber.yield
|
36
|
+
end
|
37
|
+
|
38
|
+
def sleep(timeout)
|
39
|
+
f=current
|
40
|
+
EventMachine::Timer.new(timeout) { f.resume }
|
41
|
+
Fiber.yield
|
42
|
+
end
|
43
|
+
|
44
|
+
def subscriptions
|
45
|
+
current.subscriptions
|
46
|
+
end
|
47
|
+
|
48
|
+
def subscription(node)
|
49
|
+
subscriptions[node]
|
50
|
+
end
|
51
|
+
|
52
|
+
def subscribed?(node)
|
53
|
+
subscriptions.has_key?(node)
|
54
|
+
end
|
55
|
+
|
56
|
+
def delete_subscription(node)
|
57
|
+
subscriptions.delete(node)
|
58
|
+
end
|
59
|
+
|
60
|
+
def delete_subscriptions
|
61
|
+
current.subscriptions.clear
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_subscription(node, value)
|
65
|
+
subscriptions[node]=value
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
|
19
|
+
ALL_HEADERS=['Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 GTB5 (.NET CLR 3.5.30729)',
|
20
|
+
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3) Gecko/20090305 Firefox/3.1b3 GTB5',
|
21
|
+
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; ko; rv:1.9.1b2) Gecko/20081201 Firefox/3.1b2',
|
22
|
+
'Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.9b5) Gecko/2008032620 Firefox/3.0b5',
|
23
|
+
'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.12) Gecko/20080214 Firefox/2.0.0.12',
|
24
|
+
'Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8',
|
25
|
+
'Mozilla/5.0 (X11; U; OpenBSD i386; en-US; rv:1.8.0.5) Gecko/20060819 Firefox/1.5.0.5',
|
26
|
+
'Mozilla/5.0 (Windows; U; Windows NT 5.0; es-ES; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3',
|
27
|
+
'Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.7.9) Gecko/20050711 Firefox/1.0.5',
|
28
|
+
|
29
|
+
'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2a2pre) Gecko/20090901 Ubuntu/9.10 (karmic) Namoroka/3.6a2pre',
|
30
|
+
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2a1) Gecko/20090806 Namoroka/3.6a1',
|
31
|
+
'Mozilla/5.0 (Windows; U; Windows NT 6.1; cs; rv:1.9.2a2pre) Gecko/20090912 Namoroka/3.6a2pre (.NET CLR 3.5.30729)',
|
32
|
+
'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090109 Shiretoko/3.1b3pre',
|
33
|
+
'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b4pre) Gecko/20090311 Shiretoko/3.1b4pre',
|
34
|
+
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko/2009033017 GranParadiso/3.0.8',
|
35
|
+
'Mozilla/5.0 (BeOS; U; Haiku BePC; en-US; rv:1.8.1.21pre) Gecko/20090227 BonEcho/2.0.0.21pre',
|
36
|
+
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.9) Gecko/20071113 BonEcho/2.0.0.9',
|
37
|
+
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061026 BonEcho/2.0',
|
38
|
+
|
39
|
+
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.53 Safari/525.19',
|
40
|
+
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.36 Safari/525.19',
|
41
|
+
|
42
|
+
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; MS-RTC LM 8; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; .NET CLR 3.0.30729)',
|
43
|
+
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.2)',
|
44
|
+
|
45
|
+
'Opera/5.11 (Windows 98; U) [en]',
|
46
|
+
'Mozilla/4.0 (compatible; MSIE 5.0; Windows 98) Opera 5.12 [en]',
|
47
|
+
'Opera/6.0 (Windows 2000; U) [fr]',
|
48
|
+
'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) Opera 6.01 [en]',
|
49
|
+
'Opera/7.03 (Windows NT 5.0; U) [en]',
|
50
|
+
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.10 [en]',
|
51
|
+
'Opera/9.02 (Windows XP; U; ru)',
|
52
|
+
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.24',
|
53
|
+
'Opera/9.51 (Macintosh; Intel Mac OS X; U; en)',
|
54
|
+
'Opera/9.70 (Linux i686 ; U; en) Presto/2.2.1',
|
55
|
+
'Opera/9.80 (Windows NT 5.1; U; cs) Presto/2.2.15 Version/10.00',
|
56
|
+
|
57
|
+
'Mozilla/5.0 (X11; Linux i686; U;rv: 1.7.13)',
|
58
|
+
'Mozilla/5.0 (X11; U; Linux 2.4.2-2 i586; en-US; m18)',
|
59
|
+
'Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.8.0.2)',
|
60
|
+
'Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.7.6)',
|
61
|
+
'Mozilla/5.0 (X11; U; Linux i686; en-US; Nautilus/1.0Final)',
|
62
|
+
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.3)',
|
63
|
+
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2b)',
|
64
|
+
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6)',
|
65
|
+
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7)',
|
66
|
+
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1)',
|
67
|
+
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1)',
|
68
|
+
'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9a8)',
|
69
|
+
'Mozilla/5.0 Galeon/1.0.2 (X11; Linux i686; U;)'].freeze
|
70
|
+
|
71
|
+
def get_random_header
|
72
|
+
ALL_HEADERS[rand(ALL_HEADERS.size)]
|
73
|
+
end
|
data/lib/joffice/i18n.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
|
19
|
+
require 'joffice/kernel/object'
|
20
|
+
require 'joffice/kernel/time'
|
21
|
+
require 'joffice/kernel/string'
|
22
|
+
require 'joffice/kernel/math'
|
23
|
+
require 'joffice/kernel/array'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
|
19
|
+
class Array
|
20
|
+
def to_ranges
|
21
|
+
array = self.compact.uniq.sort
|
22
|
+
ranges = []
|
23
|
+
if !array.empty?
|
24
|
+
# Initialize the left and right endpoints of the range
|
25
|
+
left, right = array.first, nil
|
26
|
+
array.each do |obj|
|
27
|
+
# If the right endpoint is set and obj is not equal to right's successor
|
28
|
+
# then we need to create a range.
|
29
|
+
if right && obj != right.succ
|
30
|
+
ranges << Range.new(left,right)
|
31
|
+
left = obj
|
32
|
+
end
|
33
|
+
right = obj
|
34
|
+
end
|
35
|
+
ranges << Range.new(left,right)
|
36
|
+
end
|
37
|
+
ranges
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
|
19
|
+
module Math
|
20
|
+
def self.max(a, b)
|
21
|
+
a > b ? a : b
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.min(a, b)
|
25
|
+
a < b ? a : b
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
|
19
|
+
class Object
|
20
|
+
def nil_or_empty(if_nil, &block)
|
21
|
+
return if_nil if nil? or empty?
|
22
|
+
return block.call(self) if block
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def nil_or_empty?
|
27
|
+
nil? or empty?
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
|
19
|
+
class String
|
20
|
+
def encode2utf8
|
21
|
+
self.respond_to?(:force_encoding) ? force_encoding("utf-8") : self
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
|
19
|
+
class Time
|
20
|
+
def truncate_utc
|
21
|
+
time=getutc
|
22
|
+
Time.utc(time.year, time.month, time.day, 0, 0, 0)
|
23
|
+
end
|
24
|
+
|
25
|
+
def append_gmt(gmt, dst=true)
|
26
|
+
t=self
|
27
|
+
time=(t.utc? ? t : Time.utc(t.year, t.month, t.day, t.hour, 0, 0))
|
28
|
+
return time.getlocal if gmt.nil?
|
29
|
+
|
30
|
+
(gmt+=1) if dst
|
31
|
+
|
32
|
+
(self + (3600*gmt) )
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Copyright 2010 Denis Kokorin <virkdi@mail.ru>
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
18
|
+
require 'mysql'
|
19
|
+
|
20
|
+
class Mysql::Result
|
21
|
+
def encode(value, encoding = "utf-8")
|
22
|
+
String === value ? value.force_encoding(encoding) : value
|
23
|
+
end
|
24
|
+
|
25
|
+
def each_utf8(&block)
|
26
|
+
each_orig do |row|
|
27
|
+
yield row.map {|col| encode(col) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
alias each_orig each
|
31
|
+
alias each each_utf8
|
32
|
+
|
33
|
+
def each_hash_utf8(&block)
|
34
|
+
each_hash_orig do |row|
|
35
|
+
row.each {|k, v| row[k] = encode(v) }
|
36
|
+
yield(row)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
alias each_hash_orig each_hash
|
40
|
+
alias each_hash each_hash_utf8
|
41
|
+
end
|
42
|
+
|
43
|
+
Encoding.default_internal, Encoding.default_external = ['utf-8'] * 2
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: joffice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kokorin Denis
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-05 00:00:00 +04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: JOffice common classes
|
22
|
+
email: mccoder-nospam@ya.ru
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE-2.0.txt
|
29
|
+
- README.md
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- LICENSE-2.0.txt
|
33
|
+
- README.md
|
34
|
+
- Rakefile
|
35
|
+
- lib/joffice.rb
|
36
|
+
- lib/joffice/config.rb
|
37
|
+
- lib/joffice/external_lazy_load.rb
|
38
|
+
- lib/joffice/fiber_events_pool.rb
|
39
|
+
- lib/joffice/fiber_extensions.rb
|
40
|
+
- lib/joffice/http_headers.rb
|
41
|
+
- lib/joffice/i18n.rb
|
42
|
+
- lib/joffice/kernel.rb
|
43
|
+
- lib/joffice/kernel/array.rb
|
44
|
+
- lib/joffice/kernel/math.rb
|
45
|
+
- lib/joffice/kernel/object.rb
|
46
|
+
- lib/joffice/kernel/string.rb
|
47
|
+
- lib/joffice/kernel/time.rb
|
48
|
+
- lib/joffice/locales/ru.yml
|
49
|
+
- lib/joffice/mysql_utf8.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/mccoder/joffice
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --charset=UTF-8
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 9
|
66
|
+
- 1
|
67
|
+
version: 1.9.1
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.3.6
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: JOffice common classes
|
82
|
+
test_files: []
|
83
|
+
|