chsh-complex_conditions 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/History.txt +6 -0
- data/Manifest.txt +7 -0
- data/README.txt +49 -0
- data/Rakefile +10 -0
- data/lib/complex_conditions.rb +66 -0
- data/test/test_complex_conditions.rb +8 -0
- metadata +73 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= complex_conditions
|
2
|
+
|
3
|
+
* http://github.com/chsh/complex_conditions
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
ComplexConditions is a simple class for building conditions of ActiveRecord.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Only support for building conditions.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* None.
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* sudo gem -s http://gems.github.com/
|
24
|
+
* sudo gem i chsh-complex_conditions
|
25
|
+
|
26
|
+
== LICENSE:
|
27
|
+
|
28
|
+
(The MIT License)
|
29
|
+
|
30
|
+
Copyright (c) 2009 CHIKURA Shinsaku <scene.sc@gmail.com>
|
31
|
+
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
33
|
+
a copy of this software and associated documentation files (the
|
34
|
+
'Software'), to deal in the Software without restriction, including
|
35
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
36
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
37
|
+
permit persons to whom the Software is furnished to do so, subject to
|
38
|
+
the following conditions:
|
39
|
+
|
40
|
+
The above copyright notice and this permission notice shall be
|
41
|
+
included in all copies or substantial portions of the Software.
|
42
|
+
|
43
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
44
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
45
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
46
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
47
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
48
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
49
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
class ComplexConditions
|
2
|
+
VERSION = '0.0.0'
|
3
|
+
def initialize
|
4
|
+
@sqlconds = []
|
5
|
+
@params = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def push(sqlcond, *params)
|
9
|
+
@sqlconds << sqlcond
|
10
|
+
if params.size > 0
|
11
|
+
@params.push *params
|
12
|
+
end
|
13
|
+
end
|
14
|
+
def <<(sqlcond, *params)
|
15
|
+
self.push(sqlcond, *params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def conditions
|
19
|
+
sqls = @sqlconds.clone
|
20
|
+
sqls.map! do |item|
|
21
|
+
'(' + item + ')'
|
22
|
+
end
|
23
|
+
array = []
|
24
|
+
if 0 < sqls.size
|
25
|
+
array << sqls.join(' and ')
|
26
|
+
array.concat @params
|
27
|
+
end
|
28
|
+
if 0 < array.size
|
29
|
+
array
|
30
|
+
else
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def as_text
|
36
|
+
conds = conditions
|
37
|
+
return '' unless conds
|
38
|
+
blocks = conds.shift.split('?')
|
39
|
+
sqlarray = []
|
40
|
+
index = 0
|
41
|
+
blocks.each do |block|
|
42
|
+
value = sanitized_value(conds[index])
|
43
|
+
sqlarray << block
|
44
|
+
sqlarray << value if value
|
45
|
+
index += 1
|
46
|
+
end
|
47
|
+
sqlarray.join('')
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def sanitized_value(value)
|
52
|
+
return nil if value.nil?
|
53
|
+
if value.kind_of? Array
|
54
|
+
value.map do |v|
|
55
|
+
sanitized_value(v)
|
56
|
+
end.join(',')
|
57
|
+
elsif value.kind_of? ActiveRecord::Base
|
58
|
+
sanitized_value(value.id)
|
59
|
+
elsif value =~ /^\d+$/
|
60
|
+
value.to_s
|
61
|
+
else
|
62
|
+
qv = value.to_s.gsub("'", "''")
|
63
|
+
"'#{qv}'"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chsh-complex_conditions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CHIKURA Shinsaku
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-15 00:00:00 -07:00
|
13
|
+
default_executable: complex_conditions
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.3
|
24
|
+
version:
|
25
|
+
description: ComplexConditions is a simple class for building conditions of ActiveRecord.
|
26
|
+
email:
|
27
|
+
- scene.sc@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
files:
|
37
|
+
- .autotest
|
38
|
+
- History.txt
|
39
|
+
- Manifest.txt
|
40
|
+
- README.txt
|
41
|
+
- Rakefile
|
42
|
+
- lib/complex_conditions.rb
|
43
|
+
- test/test_complex_conditions.rb
|
44
|
+
has_rdoc: false
|
45
|
+
homepage: http://github.com/chsh/complex_conditions
|
46
|
+
licenses:
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --main
|
50
|
+
- README.txt
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: complex_conditions
|
68
|
+
rubygems_version: 1.3.5
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: ComplexConditions is a simple class for building conditions of ActiveRecord.
|
72
|
+
test_files:
|
73
|
+
- test/test_complex_conditions.rb
|