libciel 0.0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +246 -0
- data/LICENSE.txt +1 -0
- data/README.md +10 -0
- data/Rakefile +38 -0
- data/lib/libciel.rb +136 -0
- data/libciel.gemspec +27 -0
- data/spec/libciel_spec.rb +100 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/test.sqlite +0 -0
- metadata +102 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: ecfd08c9e6800e2102d7b8a058da4a426677df8e
|
|
4
|
+
data.tar.gz: f959f67faead363cc2ff029b16d0d4ba166d37ad
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3071c7789ea15ffaabb5084652a114cc90e1c956a6e680233c5d357735fdba98be8e53466941ee851b743ee96365ecaacd6d801455778f8310d7a2f5810ddedc
|
|
7
|
+
data.tar.gz: fbc43c31094de75444a6d7ae7ad0b059fd1be105c051de30b126129bd2f488e37f7c2af394f2eb40fb892e84b46462c607dd80d31d2d61df1b994f8d228e6c91
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
language: ruby
|
|
2
|
+
before_install:
|
|
3
|
+
- gem update --system 2.1.11
|
|
4
|
+
- gem --version
|
|
5
|
+
rvm:
|
|
6
|
+
- 1.8.7
|
|
7
|
+
- ree
|
|
8
|
+
- 1.9.2
|
|
9
|
+
- 1.9.3
|
|
10
|
+
- 2.0.0
|
|
11
|
+
- 2.1.0
|
|
12
|
+
- ruby-head
|
|
13
|
+
- jruby-18mode
|
|
14
|
+
- jruby-19mode
|
|
15
|
+
- jruby-20mode
|
|
16
|
+
- jruby-21mode
|
|
17
|
+
- jruby-head
|
|
18
|
+
- rbx-2.1.1
|
|
19
|
+
- rbx-2.2.3
|
|
20
|
+
matrix:
|
|
21
|
+
allow_failures:
|
|
22
|
+
- rvm: ruby-head
|
|
23
|
+
- rvm: jruby-head
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
source "http://rubygems.org"
|
|
2
|
+
|
|
3
|
+
platforms :rbx do
|
|
4
|
+
gem 'rubysl'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
group :test do
|
|
8
|
+
gem 'backports'
|
|
9
|
+
platforms :ruby do
|
|
10
|
+
gem 'dbi'
|
|
11
|
+
gem 'dbd-sqlite3'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
group :development, :test do
|
|
16
|
+
gem 'bundler', '>= 1.0'
|
|
17
|
+
gem 'rake'
|
|
18
|
+
gem 'rspec'
|
|
19
|
+
gem 'simplecov'
|
|
20
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: http://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
backports (3.4.0)
|
|
5
|
+
dbd-sqlite3 (1.2.5)
|
|
6
|
+
dbi (>= 0.4.0)
|
|
7
|
+
sqlite3-ruby
|
|
8
|
+
dbi (0.4.5)
|
|
9
|
+
deprecated (= 2.0.1)
|
|
10
|
+
deprecated (2.0.1)
|
|
11
|
+
diff-lcs (1.2.5)
|
|
12
|
+
docile (1.1.1)
|
|
13
|
+
ffi2-generators (0.1.1)
|
|
14
|
+
multi_json (1.8.2)
|
|
15
|
+
rake (10.1.1)
|
|
16
|
+
rspec (2.14.1)
|
|
17
|
+
rspec-core (~> 2.14.0)
|
|
18
|
+
rspec-expectations (~> 2.14.0)
|
|
19
|
+
rspec-mocks (~> 2.14.0)
|
|
20
|
+
rspec-core (2.14.7)
|
|
21
|
+
rspec-expectations (2.14.4)
|
|
22
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
23
|
+
rspec-mocks (2.14.4)
|
|
24
|
+
rubysl (2.0.15)
|
|
25
|
+
rubysl-abbrev (~> 2.0)
|
|
26
|
+
rubysl-base64 (~> 2.0)
|
|
27
|
+
rubysl-benchmark (~> 2.0)
|
|
28
|
+
rubysl-bigdecimal (~> 2.0)
|
|
29
|
+
rubysl-cgi (~> 2.0)
|
|
30
|
+
rubysl-cgi-session (~> 2.0)
|
|
31
|
+
rubysl-cmath (~> 2.0)
|
|
32
|
+
rubysl-complex (~> 2.0)
|
|
33
|
+
rubysl-continuation (~> 2.0)
|
|
34
|
+
rubysl-coverage (~> 2.0)
|
|
35
|
+
rubysl-csv (~> 2.0)
|
|
36
|
+
rubysl-curses (~> 2.0)
|
|
37
|
+
rubysl-date (~> 2.0)
|
|
38
|
+
rubysl-delegate (~> 2.0)
|
|
39
|
+
rubysl-digest (~> 2.0)
|
|
40
|
+
rubysl-drb (~> 2.0)
|
|
41
|
+
rubysl-e2mmap (~> 2.0)
|
|
42
|
+
rubysl-english (~> 2.0)
|
|
43
|
+
rubysl-enumerator (~> 2.0)
|
|
44
|
+
rubysl-erb (~> 2.0)
|
|
45
|
+
rubysl-etc (~> 2.0)
|
|
46
|
+
rubysl-expect (~> 2.0)
|
|
47
|
+
rubysl-fcntl (~> 2.0)
|
|
48
|
+
rubysl-fiber (~> 2.0)
|
|
49
|
+
rubysl-fileutils (~> 2.0)
|
|
50
|
+
rubysl-find (~> 2.0)
|
|
51
|
+
rubysl-forwardable (~> 2.0)
|
|
52
|
+
rubysl-getoptlong (~> 2.0)
|
|
53
|
+
rubysl-gserver (~> 2.0)
|
|
54
|
+
rubysl-io-console (~> 2.0)
|
|
55
|
+
rubysl-io-nonblock (~> 2.0)
|
|
56
|
+
rubysl-io-wait (~> 2.0)
|
|
57
|
+
rubysl-ipaddr (~> 2.0)
|
|
58
|
+
rubysl-irb (~> 2.0)
|
|
59
|
+
rubysl-logger (~> 2.0)
|
|
60
|
+
rubysl-mathn (~> 2.0)
|
|
61
|
+
rubysl-matrix (~> 2.0)
|
|
62
|
+
rubysl-mkmf (~> 2.0)
|
|
63
|
+
rubysl-monitor (~> 2.0)
|
|
64
|
+
rubysl-mutex_m (~> 2.0)
|
|
65
|
+
rubysl-net-ftp (~> 2.0)
|
|
66
|
+
rubysl-net-http (~> 2.0)
|
|
67
|
+
rubysl-net-imap (~> 2.0)
|
|
68
|
+
rubysl-net-pop (~> 2.0)
|
|
69
|
+
rubysl-net-protocol (~> 2.0)
|
|
70
|
+
rubysl-net-smtp (~> 2.0)
|
|
71
|
+
rubysl-net-telnet (~> 2.0)
|
|
72
|
+
rubysl-nkf (~> 2.0)
|
|
73
|
+
rubysl-observer (~> 2.0)
|
|
74
|
+
rubysl-open-uri (~> 2.0)
|
|
75
|
+
rubysl-open3 (~> 2.0)
|
|
76
|
+
rubysl-openssl (~> 2.0)
|
|
77
|
+
rubysl-optparse (~> 2.0)
|
|
78
|
+
rubysl-ostruct (~> 2.0)
|
|
79
|
+
rubysl-pathname (~> 2.0)
|
|
80
|
+
rubysl-prettyprint (~> 2.0)
|
|
81
|
+
rubysl-prime (~> 2.0)
|
|
82
|
+
rubysl-profile (~> 2.0)
|
|
83
|
+
rubysl-profiler (~> 2.0)
|
|
84
|
+
rubysl-pstore (~> 2.0)
|
|
85
|
+
rubysl-pty (~> 2.0)
|
|
86
|
+
rubysl-rational (~> 2.0)
|
|
87
|
+
rubysl-readline (~> 2.0)
|
|
88
|
+
rubysl-resolv (~> 2.0)
|
|
89
|
+
rubysl-rexml (~> 2.0)
|
|
90
|
+
rubysl-rinda (~> 2.0)
|
|
91
|
+
rubysl-rss (~> 2.0)
|
|
92
|
+
rubysl-scanf (~> 2.0)
|
|
93
|
+
rubysl-securerandom (~> 2.0)
|
|
94
|
+
rubysl-set (~> 2.0)
|
|
95
|
+
rubysl-shellwords (~> 2.0)
|
|
96
|
+
rubysl-singleton (~> 2.0)
|
|
97
|
+
rubysl-socket (~> 2.0)
|
|
98
|
+
rubysl-stringio (~> 2.0)
|
|
99
|
+
rubysl-strscan (~> 2.0)
|
|
100
|
+
rubysl-sync (~> 2.0)
|
|
101
|
+
rubysl-syslog (~> 2.0)
|
|
102
|
+
rubysl-tempfile (~> 2.0)
|
|
103
|
+
rubysl-thread (~> 2.0)
|
|
104
|
+
rubysl-thwait (~> 2.0)
|
|
105
|
+
rubysl-time (~> 2.0)
|
|
106
|
+
rubysl-timeout (~> 2.0)
|
|
107
|
+
rubysl-tmpdir (~> 2.0)
|
|
108
|
+
rubysl-tsort (~> 2.0)
|
|
109
|
+
rubysl-un (~> 2.0)
|
|
110
|
+
rubysl-uri (~> 2.0)
|
|
111
|
+
rubysl-weakref (~> 2.0)
|
|
112
|
+
rubysl-webrick (~> 2.0)
|
|
113
|
+
rubysl-xmlrpc (~> 2.0)
|
|
114
|
+
rubysl-yaml (~> 2.0)
|
|
115
|
+
rubysl-zlib (~> 2.0)
|
|
116
|
+
rubysl-abbrev (2.0.4)
|
|
117
|
+
rubysl-base64 (2.0.0)
|
|
118
|
+
rubysl-benchmark (2.0.1)
|
|
119
|
+
rubysl-bigdecimal (2.0.2)
|
|
120
|
+
rubysl-cgi (2.0.1)
|
|
121
|
+
rubysl-cgi-session (2.0.1)
|
|
122
|
+
rubysl-cmath (2.0.0)
|
|
123
|
+
rubysl-complex (2.0.0)
|
|
124
|
+
rubysl-continuation (2.0.0)
|
|
125
|
+
rubysl-coverage (2.0.3)
|
|
126
|
+
rubysl-csv (2.0.2)
|
|
127
|
+
rubysl-english (~> 2.0)
|
|
128
|
+
rubysl-curses (2.0.1)
|
|
129
|
+
rubysl-date (2.0.6)
|
|
130
|
+
rubysl-delegate (2.0.1)
|
|
131
|
+
rubysl-digest (2.0.3)
|
|
132
|
+
rubysl-drb (2.0.1)
|
|
133
|
+
rubysl-e2mmap (2.0.0)
|
|
134
|
+
rubysl-english (2.0.0)
|
|
135
|
+
rubysl-enumerator (2.0.0)
|
|
136
|
+
rubysl-erb (2.0.1)
|
|
137
|
+
rubysl-etc (2.0.3)
|
|
138
|
+
ffi2-generators (~> 0.1)
|
|
139
|
+
rubysl-expect (2.0.0)
|
|
140
|
+
rubysl-fcntl (2.0.4)
|
|
141
|
+
ffi2-generators (~> 0.1)
|
|
142
|
+
rubysl-fiber (2.0.0)
|
|
143
|
+
rubysl-fileutils (2.0.3)
|
|
144
|
+
rubysl-find (2.0.1)
|
|
145
|
+
rubysl-forwardable (2.0.1)
|
|
146
|
+
rubysl-getoptlong (2.0.0)
|
|
147
|
+
rubysl-gserver (2.0.0)
|
|
148
|
+
rubysl-socket (~> 2.0)
|
|
149
|
+
rubysl-thread (~> 2.0)
|
|
150
|
+
rubysl-io-console (2.0.0)
|
|
151
|
+
rubysl-io-nonblock (2.0.0)
|
|
152
|
+
rubysl-io-wait (2.0.0)
|
|
153
|
+
rubysl-ipaddr (2.0.0)
|
|
154
|
+
rubysl-irb (2.0.4)
|
|
155
|
+
rubysl-e2mmap (~> 2.0)
|
|
156
|
+
rubysl-mathn (~> 2.0)
|
|
157
|
+
rubysl-readline (~> 2.0)
|
|
158
|
+
rubysl-thread (~> 2.0)
|
|
159
|
+
rubysl-logger (2.0.0)
|
|
160
|
+
rubysl-mathn (2.0.0)
|
|
161
|
+
rubysl-matrix (2.1.0)
|
|
162
|
+
rubysl-e2mmap (~> 2.0)
|
|
163
|
+
rubysl-mkmf (2.0.1)
|
|
164
|
+
rubysl-fileutils (~> 2.0)
|
|
165
|
+
rubysl-shellwords (~> 2.0)
|
|
166
|
+
rubysl-monitor (2.0.0)
|
|
167
|
+
rubysl-mutex_m (2.0.0)
|
|
168
|
+
rubysl-net-ftp (2.0.1)
|
|
169
|
+
rubysl-net-http (2.0.4)
|
|
170
|
+
rubysl-cgi (~> 2.0)
|
|
171
|
+
rubysl-erb (~> 2.0)
|
|
172
|
+
rubysl-singleton (~> 2.0)
|
|
173
|
+
rubysl-net-imap (2.0.1)
|
|
174
|
+
rubysl-net-pop (2.0.1)
|
|
175
|
+
rubysl-net-protocol (2.0.1)
|
|
176
|
+
rubysl-net-smtp (2.0.1)
|
|
177
|
+
rubysl-net-telnet (2.0.0)
|
|
178
|
+
rubysl-nkf (2.0.1)
|
|
179
|
+
rubysl-observer (2.0.0)
|
|
180
|
+
rubysl-open-uri (2.0.0)
|
|
181
|
+
rubysl-open3 (2.0.0)
|
|
182
|
+
rubysl-openssl (2.0.5)
|
|
183
|
+
rubysl-optparse (2.0.1)
|
|
184
|
+
rubysl-shellwords (~> 2.0)
|
|
185
|
+
rubysl-ostruct (2.0.4)
|
|
186
|
+
rubysl-pathname (2.0.0)
|
|
187
|
+
rubysl-prettyprint (2.0.2)
|
|
188
|
+
rubysl-prime (2.0.1)
|
|
189
|
+
rubysl-profile (2.0.0)
|
|
190
|
+
rubysl-profiler (2.0.1)
|
|
191
|
+
rubysl-pstore (2.0.0)
|
|
192
|
+
rubysl-pty (2.0.2)
|
|
193
|
+
rubysl-rational (2.0.1)
|
|
194
|
+
rubysl-readline (2.0.2)
|
|
195
|
+
rubysl-resolv (2.0.0)
|
|
196
|
+
rubysl-rexml (2.0.2)
|
|
197
|
+
rubysl-rinda (2.0.0)
|
|
198
|
+
rubysl-rss (2.0.0)
|
|
199
|
+
rubysl-scanf (2.0.0)
|
|
200
|
+
rubysl-securerandom (2.0.0)
|
|
201
|
+
rubysl-set (2.0.1)
|
|
202
|
+
rubysl-shellwords (2.0.0)
|
|
203
|
+
rubysl-singleton (2.0.0)
|
|
204
|
+
rubysl-socket (2.0.1)
|
|
205
|
+
rubysl-stringio (2.0.0)
|
|
206
|
+
rubysl-strscan (2.0.0)
|
|
207
|
+
rubysl-sync (2.0.0)
|
|
208
|
+
rubysl-syslog (2.0.1)
|
|
209
|
+
ffi2-generators (~> 0.1)
|
|
210
|
+
rubysl-tempfile (2.0.1)
|
|
211
|
+
rubysl-thread (2.0.2)
|
|
212
|
+
rubysl-thwait (2.0.0)
|
|
213
|
+
rubysl-time (2.0.3)
|
|
214
|
+
rubysl-timeout (2.0.0)
|
|
215
|
+
rubysl-tmpdir (2.0.0)
|
|
216
|
+
rubysl-tsort (2.0.1)
|
|
217
|
+
rubysl-un (2.0.0)
|
|
218
|
+
rubysl-fileutils (~> 2.0)
|
|
219
|
+
rubysl-optparse (~> 2.0)
|
|
220
|
+
rubysl-uri (2.0.0)
|
|
221
|
+
rubysl-weakref (2.0.0)
|
|
222
|
+
rubysl-webrick (2.0.0)
|
|
223
|
+
rubysl-xmlrpc (2.0.0)
|
|
224
|
+
rubysl-yaml (2.0.4)
|
|
225
|
+
rubysl-zlib (2.0.1)
|
|
226
|
+
simplecov (0.8.2)
|
|
227
|
+
docile (~> 1.1.0)
|
|
228
|
+
multi_json
|
|
229
|
+
simplecov-html (~> 0.8.0)
|
|
230
|
+
simplecov-html (0.8.0)
|
|
231
|
+
sqlite3 (1.3.8)
|
|
232
|
+
sqlite3-ruby (1.3.3)
|
|
233
|
+
sqlite3 (>= 1.3.3)
|
|
234
|
+
|
|
235
|
+
PLATFORMS
|
|
236
|
+
ruby
|
|
237
|
+
|
|
238
|
+
DEPENDENCIES
|
|
239
|
+
backports
|
|
240
|
+
bundler (>= 1.0)
|
|
241
|
+
dbd-sqlite3
|
|
242
|
+
dbi
|
|
243
|
+
rake
|
|
244
|
+
rspec
|
|
245
|
+
rubysl
|
|
246
|
+
simplecov
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
blank currently
|
data/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# libciel
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/cielavenir/ruby_libciel) [](https://codeclimate.com/github/cielavenir/ruby_libciel)
|
|
4
|
+
|
|
5
|
+
## Supported Ruby versions
|
|
6
|
+
* Ruby 1.8.7 or later
|
|
7
|
+
* jruby
|
|
8
|
+
* rubinius 2.1.1 or 2.2.3 (or later, maybe)
|
|
9
|
+
* 2.2.1 and 2.2.2 are not working.
|
|
10
|
+
* (Possibly) ironruby / macruby / topaz etc
|
data/Rakefile
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
2
|
+
require './lib/libciel'
|
|
3
|
+
|
|
4
|
+
### below are copied from jeweler ###
|
|
5
|
+
|
|
6
|
+
require 'rake'
|
|
7
|
+
# Clean up after gem building
|
|
8
|
+
require 'rake/clean'
|
|
9
|
+
CLEAN.include('pkg/*.gem')
|
|
10
|
+
CLOBBER.include('coverage')
|
|
11
|
+
|
|
12
|
+
require 'rspec/core'
|
|
13
|
+
require 'rspec/core/rake_task'
|
|
14
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
15
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
19
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
20
|
+
spec.rcov = true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
task :default => :spec
|
|
24
|
+
|
|
25
|
+
begin
|
|
26
|
+
require 'rdoc/task'
|
|
27
|
+
Rake::RDocTask.new do |rdoc|
|
|
28
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
29
|
+
rdoc.title = 'libciel '+LibCiel::VERSION
|
|
30
|
+
rdoc.main = 'README.md'
|
|
31
|
+
rdoc.rdoc_files.include('README.*')
|
|
32
|
+
rdoc.rdoc_files.include('LICENSE.*')
|
|
33
|
+
rdoc.rdoc_files.include('CHANGELOG.*')
|
|
34
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
35
|
+
end
|
|
36
|
+
rescue Exception #LoadError # Thus rdoc generation is limited to Ruby 1.9.3+...
|
|
37
|
+
#Ruby 1.9.2 gives another Exception. I cannot limit to LoadError...
|
|
38
|
+
end
|
data/lib/libciel.rb
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
module LibCiel
|
|
2
|
+
#Version string
|
|
3
|
+
VERSION='0.0.0.1'
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class Object
|
|
7
|
+
#PHPic extract(). Hash will be injected into self as instance variables (@var).
|
|
8
|
+
def extract(h,overwrite=false)
|
|
9
|
+
h.each{|k,v|
|
|
10
|
+
if overwrite || !self.instance_variable_defined?('@'+k) then
|
|
11
|
+
self.instance_variable_set('@'+k,v) #k should always be String
|
|
12
|
+
end
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
module Kernel
|
|
18
|
+
#Pythonic zip. The same as a.shift.zip(*a).
|
|
19
|
+
def zip(a) a.shift.zip(*a) end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module Enumerable
|
|
23
|
+
#Squeezes the same element. This behaves like C++ unique().
|
|
24
|
+
#To get the similar result to Array#uniq, you need to sort it prior.
|
|
25
|
+
# Calculation order is O(n).
|
|
26
|
+
def squeeze
|
|
27
|
+
r=[]
|
|
28
|
+
cur=nil
|
|
29
|
+
self.each{|e|
|
|
30
|
+
if r.empty?||cur!=e
|
|
31
|
+
r<<e
|
|
32
|
+
cur=e
|
|
33
|
+
end
|
|
34
|
+
}
|
|
35
|
+
r
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class Enumerator
|
|
40
|
+
begin
|
|
41
|
+
Lazy.class_eval{
|
|
42
|
+
#Enumerator.Lazy version of Enumerable#squeeze.
|
|
43
|
+
#Enumerator.Lazy is evaluated as Enumerable::Lazy on Ruby 1.9 + enumerable/lazy, otherwise Enumerator::Lazy.
|
|
44
|
+
# To use this method, on Ruby <2.0, you need to require enumerable/lazy or backports before requiring libciel.
|
|
45
|
+
def squeeze
|
|
46
|
+
first=true
|
|
47
|
+
cur=nil
|
|
48
|
+
self.class.new(self){|y,v|
|
|
49
|
+
if first||cur!=v
|
|
50
|
+
y<<v
|
|
51
|
+
first=false
|
|
52
|
+
cur=v
|
|
53
|
+
end
|
|
54
|
+
}
|
|
55
|
+
end
|
|
56
|
+
}
|
|
57
|
+
rescue NameError=>e; end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class Array
|
|
61
|
+
#Enumerates permutation of Array.
|
|
62
|
+
#Unlike Array#permutation, there are no duplicates in generated permutations.
|
|
63
|
+
#Instead, elements must be comparable.
|
|
64
|
+
def permutation2(n=self.size)
|
|
65
|
+
return to_enum(:permutation2,n) unless block_given?
|
|
66
|
+
return if n<0||self.size<n
|
|
67
|
+
a=self.sort
|
|
68
|
+
yield a.dup[0,n]
|
|
69
|
+
loop{
|
|
70
|
+
a=a[0,n]+a[n..-1].reverse
|
|
71
|
+
k=(a.size-2).downto(0).find{|i|a[i]<a[i+1]}
|
|
72
|
+
break if !k
|
|
73
|
+
l=(a.size-1).downto(k+1).find{|i|a[k]<a[i]}
|
|
74
|
+
a[k],a[l]=a[l],a[k]
|
|
75
|
+
a=a[0,k+1]+a[k+1..-1].reverse
|
|
76
|
+
yield a.dup[0,n]
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class String
|
|
82
|
+
#Rotate string to the left with count.
|
|
83
|
+
#Specifying negative number indicates rotation to the right.
|
|
84
|
+
def rotate(count=1)
|
|
85
|
+
count+=self.length if count<0
|
|
86
|
+
self.slice(count,self.length-count)+self.slice(0,count)
|
|
87
|
+
end
|
|
88
|
+
#Destructive version of String#rotate
|
|
89
|
+
def rotate!(count=1) self.replace(self.rotate(count)) end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
class Hash
|
|
93
|
+
#nil safe version of Hash#[].
|
|
94
|
+
# h.exists_rec?(['hello','world']) is the same as h['hello'].try.send(:[],'world').
|
|
95
|
+
def exists_rec?(a)
|
|
96
|
+
#if a.length<1 then return false
|
|
97
|
+
if !self.include?(a[0]) then return nil end #if not found
|
|
98
|
+
if a.length==1 then return self[a[0]] end #if found and last
|
|
99
|
+
if !self[a[0]].is_a?(Hash) then return nil end #if not last and child not hash
|
|
100
|
+
return self[a[0]].exists_rec?(a[1..-1]) #check child
|
|
101
|
+
end
|
|
102
|
+
#Returns self.dup with overwriting par.
|
|
103
|
+
def patch(par)
|
|
104
|
+
h=self.dup
|
|
105
|
+
par.each{|k,v|h[k]=v}
|
|
106
|
+
return h
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
module DBI
|
|
111
|
+
#connect-transaction-disconnect triplet.
|
|
112
|
+
# To use this method, you need to require dbi before requiring libciel.
|
|
113
|
+
def self.connect_transaction(driver_url, user=nil, auth=nil, params=nil, &block)
|
|
114
|
+
x=connect(driver_url, user, auth, params)
|
|
115
|
+
begin
|
|
116
|
+
x.transaction(&block)
|
|
117
|
+
ensure
|
|
118
|
+
x.disconnect
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
class DatabaseHandle
|
|
123
|
+
#execute-map,count-finish triplet.
|
|
124
|
+
# To use this method, you need to require dbi before requiring libciel.
|
|
125
|
+
def execute_immediate(stmt,*bindvars,&block)
|
|
126
|
+
sth=execute(stmt,*bindvars)
|
|
127
|
+
ret=0
|
|
128
|
+
begin
|
|
129
|
+
if block then ret=sth.map(&block).count end
|
|
130
|
+
ensure
|
|
131
|
+
sth.finish
|
|
132
|
+
end
|
|
133
|
+
ret
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
data/libciel.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
require './lib/libciel'
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |spec|
|
|
5
|
+
spec.name = "libciel"
|
|
6
|
+
spec.version = LibCiel::VERSION
|
|
7
|
+
spec.authors = ["cielavenir"]
|
|
8
|
+
spec.email = ["cielartisan@gmail.com"]
|
|
9
|
+
spec.description = "ciel's useful libraries of Ruby"
|
|
10
|
+
spec.summary = "ciel's useful libraries of Ruby"
|
|
11
|
+
spec.homepage = "http://github.com/cielavenir/libciel"
|
|
12
|
+
spec.license = "Ruby License (2-clause BSDL or Artistic)"
|
|
13
|
+
|
|
14
|
+
spec.files = `git ls-files`.split($/) + [
|
|
15
|
+
"LICENSE.txt",
|
|
16
|
+
"README.md",
|
|
17
|
+
"CHANGELOG.md",
|
|
18
|
+
]
|
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
21
|
+
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", ">= 1.0"
|
|
25
|
+
spec.add_development_dependency "rake"
|
|
26
|
+
spec.add_development_dependency "rspec"
|
|
27
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)+'/spec_helper')
|
|
2
|
+
|
|
3
|
+
describe Object do
|
|
4
|
+
specify 'extract' do
|
|
5
|
+
a=Class.new{
|
|
6
|
+
def greet() @message end
|
|
7
|
+
}.new
|
|
8
|
+
a.extract({'message'=>'hello'})
|
|
9
|
+
a.greet.should eq 'hello'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe Kernel do
|
|
14
|
+
specify 'zip' do
|
|
15
|
+
zip([[1,2],[3,4]]).should eq [[1,3],[2,4]]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe Enumerable do
|
|
20
|
+
specify 'squeeze' do
|
|
21
|
+
[1,2,2,3,3,2,1].squeeze.should eq [1,2,3,2,1]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe Enumerator::Lazy do
|
|
26
|
+
specify 'squeeze' do
|
|
27
|
+
[1,2,2,3,3,2,1].lazy.squeeze.select(&:odd?).to_a.should eq [1,3,1]
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe Array do
|
|
32
|
+
specify 'permutation2' do
|
|
33
|
+
[1,1,2,3].permutation2.to_a.should_not eq [1,1,2,3].permutation.to_a
|
|
34
|
+
[1,1,2,3].permutation2.to_a.should eq [1,1,2,3].permutation.to_a.uniq
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe String do
|
|
39
|
+
context 'rotate' do
|
|
40
|
+
it 'rotates left' do
|
|
41
|
+
'abcdefgh'.rotate(2).should eq 'cdefghab'
|
|
42
|
+
end
|
|
43
|
+
it 'rotates right' do
|
|
44
|
+
'abcdefgh'.rotate(-2).should eq 'ghabcdef'
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
context 'rotate!' do
|
|
48
|
+
it 'rotates left' do
|
|
49
|
+
s='abcdefgh'
|
|
50
|
+
s.rotate!(2)
|
|
51
|
+
s.should eq 'cdefghab'
|
|
52
|
+
end
|
|
53
|
+
it 'rotates right' do
|
|
54
|
+
s='abcdefgh'
|
|
55
|
+
s.rotate!(-2)
|
|
56
|
+
s.should eq 'ghabcdef'
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe Hash do
|
|
62
|
+
context 'safe case' do
|
|
63
|
+
h={'hello'=>{'world'=>42}}
|
|
64
|
+
specify 'usual search' do
|
|
65
|
+
h['hello']['world'].should eq 42
|
|
66
|
+
end
|
|
67
|
+
specify 'exists_rec?' do
|
|
68
|
+
h.exists_rec?(['hello','world']).should eq 42
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
context 'dangerous case' do
|
|
72
|
+
h={}
|
|
73
|
+
specify 'usual search' do
|
|
74
|
+
lambda{h['hello']['world']}.should raise_error
|
|
75
|
+
end
|
|
76
|
+
specify 'exists_rec?' do
|
|
77
|
+
h.exists_rec?(['hello','world']).should eq nil
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
specify 'patch' do
|
|
81
|
+
h={'hello'=>1,'world'=>2}
|
|
82
|
+
h_dup=h.dup
|
|
83
|
+
answer={'hello'=>1,'world'=>42}
|
|
84
|
+
h.patch({'world'=>42}).should eq answer
|
|
85
|
+
h_dup.should eq h
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe DBI do
|
|
90
|
+
specify 'connect and execute' do
|
|
91
|
+
pending 'dbd-sqlite3 seems stopped working from Ruby 2.0' if RUBY_VERSION>='2.0'
|
|
92
|
+
pending 'dbd-sqlite3 is not supported by jruby' if defined?(RUBY_ENGINE)&&RUBY_ENGINE=='jruby'
|
|
93
|
+
DBI.connect('DBI:SQLite3:'+File.dirname(__FILE__)+'/test.sqlite',nil,nil,'AutoCommit'=>false){|dbi|
|
|
94
|
+
#dbi.execute_immediate("create table test ( message varchar )")
|
|
95
|
+
dbi.execute_immediate("select * from test"){|e|
|
|
96
|
+
e.should eq ['hello']
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
end
|
|
100
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'rspec'
|
|
2
|
+
RSpec.configure{|config|
|
|
3
|
+
config.color=true
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
if !defined?(RUBY_ENGINE)||RUBY_ENGINE=='ruby'
|
|
7
|
+
require 'simplecov'
|
|
8
|
+
SimpleCov.start do
|
|
9
|
+
add_filter 'spec'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
if !defined?(Enumerator::Lazy)
|
|
14
|
+
require 'backports'
|
|
15
|
+
end
|
|
16
|
+
require 'dbi' if !defined?(RUBY_ENGINE)||RUBY_ENGINE!='jruby'
|
|
17
|
+
|
|
18
|
+
require File.expand_path(File.dirname(__FILE__)+'/../lib/libciel')
|
data/spec/test.sqlite
ADDED
|
Binary file
|
metadata
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: libciel
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- cielavenir
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: ciel's useful libraries of Ruby
|
|
56
|
+
email:
|
|
57
|
+
- cielartisan@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- .gitignore
|
|
63
|
+
- .travis.yml
|
|
64
|
+
- CHANGELOG.md
|
|
65
|
+
- Gemfile
|
|
66
|
+
- Gemfile.lock
|
|
67
|
+
- LICENSE.txt
|
|
68
|
+
- README.md
|
|
69
|
+
- Rakefile
|
|
70
|
+
- lib/libciel.rb
|
|
71
|
+
- libciel.gemspec
|
|
72
|
+
- spec/libciel_spec.rb
|
|
73
|
+
- spec/spec_helper.rb
|
|
74
|
+
- spec/test.sqlite
|
|
75
|
+
homepage: http://github.com/cielavenir/libciel
|
|
76
|
+
licenses:
|
|
77
|
+
- Ruby License (2-clause BSDL or Artistic)
|
|
78
|
+
metadata: {}
|
|
79
|
+
post_install_message:
|
|
80
|
+
rdoc_options: []
|
|
81
|
+
require_paths:
|
|
82
|
+
- lib
|
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - '>='
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - '>='
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
requirements: []
|
|
94
|
+
rubyforge_project:
|
|
95
|
+
rubygems_version: 2.0.3
|
|
96
|
+
signing_key:
|
|
97
|
+
specification_version: 4
|
|
98
|
+
summary: ciel's useful libraries of Ruby
|
|
99
|
+
test_files:
|
|
100
|
+
- spec/libciel_spec.rb
|
|
101
|
+
- spec/spec_helper.rb
|
|
102
|
+
- spec/test.sqlite
|