railstar 0.0.11 → 0.0.12
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/lib/railstar/search_base.rb +97 -45
- data/lib/railstar/version.rb +1 -1
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/tmp/cache/assets/BD2/850/sprockets%2F212d40170837515304b9063333be003f +0 -0
- data/test/dummy/tmp/cache/assets/BDB/F80/sprockets%2Fd092351b54cb720432480172c4550671 +0 -0
- data/test/dummy/tmp/cache/assets/C0E/6F0/sprockets%2F26725ce722134754103cc60f4113f741 +0 -0
- data/test/dummy/tmp/cache/assets/C16/850/sprockets%2Ff4c43aa1311657553d81a21368338645 +0 -0
- data/test/dummy/tmp/cache/assets/C41/B70/sprockets%2F711502a8b1581b81fae03815e6943350 +0 -0
- data/test/dummy/tmp/cache/assets/C4C/070/sprockets%2F340993b012bf8035917e042533856bfe +0 -0
- data/test/dummy/tmp/cache/assets/C53/DB0/sprockets%2F40d0821d8f791b174067645637bf4e24 +0 -0
- data/test/dummy/tmp/cache/assets/C6E/730/sprockets%2F91874fafd1045394dd491568659e7926 +0 -0
- data/test/dummy/tmp/cache/assets/C76/160/sprockets%2F49c594d143212b346d11f1ecf9358103 +0 -0
- data/test/dummy/tmp/cache/assets/C7A/550/sprockets%2F8130e207e861a29e1b3411c0fd728858 +0 -0
- data/test/dummy/tmp/cache/assets/C8C/B80/sprockets%2F371bf96e99717688ed7313a0c53f4212 +0 -0
- data/test/dummy/tmp/cache/assets/CA7/800/sprockets%2Fe69178b5678ba83ba797559476fd6771 +0 -0
- data/test/dummy/tmp/cache/assets/CC1/390/sprockets%2F6c2a3ad7293b20d74f629fd692953985 +0 -0
- data/test/dummy/tmp/cache/assets/CD0/A50/sprockets%2Faf1a52f4402e0d40b20f84cb17536598 +0 -0
- data/test/dummy/tmp/cache/assets/CD1/190/sprockets%2F2dfba8128914fcc04e4621b03b614656 +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CE0/760/sprockets%2F337cad824c44b29db86894b1d12b2990 +0 -0
- data/test/dummy/tmp/cache/assets/CE9/4A0/sprockets%2F2677fb28f82f2351e55fd8a87c16503a +0 -0
- data/test/dummy/tmp/cache/assets/CEB/770/sprockets%2Fd47389dcf7a3411b695e5a7f88032e42 +0 -0
- data/test/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/test/dummy/tmp/cache/assets/CF7/8E0/sprockets%2Fc7246096aa7393cf2d9b295ef766f619 +0 -0
- data/test/dummy/tmp/cache/assets/CFB/BC0/sprockets%2F06712eb9b4546c3ace17f21e2de20701 +0 -0
- data/test/dummy/tmp/cache/assets/CFF/920/sprockets%2F978f196f9aebd8f2427385ad60455e87 +0 -0
- data/test/dummy/tmp/cache/assets/D02/180/sprockets%2Fa2b299d2e064d59021a229159fcb3be1 +0 -0
- data/test/dummy/tmp/cache/assets/D02/840/sprockets%2F5c24c1571e8550c21caf59bfa2048b63 +0 -0
- data/test/dummy/tmp/cache/assets/D06/910/sprockets%2Fcd3a511c04c4949626d23b83de17c37b +0 -0
- data/test/dummy/tmp/cache/assets/D10/0E0/sprockets%2Fc99ee79715dc1e42acc661251f720b44 +0 -0
- data/test/dummy/tmp/cache/assets/D1A/340/sprockets%2Fc91959db477af6672fae11158d0e574a +0 -0
- data/test/dummy/tmp/cache/assets/D1D/F20/sprockets%2Fd6bb8c79b5667def69f4301e7013628b +0 -0
- data/test/dummy/tmp/cache/assets/D2C/E30/sprockets%2F1142f2a14b9b84e21b28f864d223bdbb +0 -0
- data/test/dummy/tmp/cache/assets/D31/ED0/sprockets%2F9913807526d036cb3fa19b0bbca3e54b +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D38/A90/sprockets%2F60870f38f70884cdfb1caa382311d2ce +0 -0
- data/test/dummy/tmp/cache/assets/D43/620/sprockets%2F179c3d423f233e8ad85e1e59bf14c4a8 +0 -0
- data/test/dummy/tmp/cache/assets/D45/650/sprockets%2F751853950dfa5eaa0329d25cf68ad4e9 +0 -0
- data/test/dummy/tmp/cache/assets/D46/0F0/sprockets%2F268fc8d914b620b386f2abcdf846085c +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D5E/4E0/sprockets%2F27425a534e3a0132fc0b54ceced18f5f +0 -0
- data/test/dummy/tmp/cache/assets/D6F/530/sprockets%2F4b2f4da153cfe1bf54f95b25f1b94646 +0 -0
- data/test/dummy/tmp/cache/assets/D70/CD0/sprockets%2F4c8b0d0ed73cf706749e0f44ca4b49e3 +0 -0
- data/test/dummy/tmp/cache/assets/D72/F00/sprockets%2Fab9c6d46e48d2f4e92085bd1a921da66 +0 -0
- data/test/dummy/tmp/cache/assets/D78/2A0/sprockets%2F24afdb9e785b7c66cb5c0ee16347a297 +0 -0
- data/test/dummy/tmp/cache/assets/D7D/E40/sprockets%2F5bae168d39d154d44c68a848fbbf09c9 +0 -0
- data/test/dummy/tmp/cache/assets/D89/460/sprockets%2Fd3da7452aa3ad6cf1528dcf542af0043 +0 -0
- data/test/dummy/tmp/cache/assets/D9A/290/sprockets%2F6190a38e1e28b2d90e3fb276af7bbbd5 +0 -0
- data/test/dummy/tmp/cache/assets/DA5/4B0/sprockets%2Fae01bf1936611de0fe2aa0a4e3a0aa43 +0 -0
- data/test/dummy/tmp/cache/assets/DA8/900/sprockets%2Fde7a2b3987b89b9d9afb268ce4204a4a +0 -0
- data/test/dummy/tmp/cache/assets/DC0/120/sprockets%2Fe5ce1f8a1f71614cd25b45dbbc4a36c3 +0 -0
- data/test/dummy/tmp/cache/assets/DC3/C70/sprockets%2F4d00f6d834e5d6a4fbde56341baa84ab +0 -0
- data/test/dummy/tmp/cache/assets/DD2/B10/sprockets%2F3fbe0f1ad09409fb8f1c66767bdd35bf +0 -0
- data/test/dummy/tmp/cache/assets/DD5/E00/sprockets%2F23ad9be17726d9cfeeb23450b29dfd8e +0 -0
- data/test/dummy/tmp/cache/assets/DD6/E70/sprockets%2Fb37f1888c20e8a6bfe17e753fce3b4bd +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/DE5/170/sprockets%2Fef6f9b493262394abdb85beafc88e9e3 +0 -0
- data/test/dummy/tmp/cache/assets/DF0/4D0/sprockets%2F6af61cc3fe9e7d3f7e758e38ff649ed2 +0 -0
- data/test/dummy/tmp/cache/assets/DFC/960/sprockets%2Fc9e6a7da83b5ea8666fa4422cabfa80b +0 -0
- data/test/dummy/tmp/cache/assets/E04/5A0/sprockets%2Fc8052f0d827a69d3feef3e3efef0e4b2 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E09/CF0/sprockets%2Fe42ceae7f6bf3e688024e463baefcf39 +0 -0
- data/test/dummy/tmp/cache/assets/E21/980/sprockets%2F1888a60aeec9e026ccc1b4e8a2a2acdf +0 -0
- data/test/dummy/tmp/cache/assets/E28/6A0/sprockets%2F7d5af50b0e7b5ca1eaaf9f7a87c51e1d +0 -0
- data/test/dummy/tmp/cache/assets/E3C/400/sprockets%2Fa5d07c411dccbbba1db3fe5cae5001f6 +0 -0
- data/test/dummy/tmp/cache/assets/E50/390/sprockets%2Ff2d2b0db1ed0f3a7daedf49c2d9d0d80 +0 -0
- metadata +19 -9
data/lib/railstar/search_base.rb
CHANGED
|
@@ -1,68 +1,116 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+
#検索ベースモデル
|
|
3
|
+
# V2.0
|
|
4
|
+
|
|
5
|
+
=begin
|
|
6
|
+
使用例
|
|
7
|
+
|
|
8
|
+
class Search::Profile
|
|
9
|
+
include Railstar::SearchBase
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
=end
|
|
13
|
+
|
|
14
|
+
|
|
2
15
|
module Railstar
|
|
3
|
-
|
|
4
|
-
attr_accessor :where, :values
|
|
16
|
+
module SearchBase
|
|
5
17
|
|
|
6
|
-
def
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
def self.included base
|
|
19
|
+
base.class_eval do
|
|
20
|
+
attr_accessor :where, :values
|
|
21
|
+
extend ClassMethods
|
|
22
|
+
include ActiveModel::Naming
|
|
23
|
+
include ActiveModel::Validations
|
|
24
|
+
include ActiveModel::Conversion
|
|
13
25
|
end
|
|
14
26
|
end
|
|
15
27
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
module ClassMethods
|
|
29
|
+
#meta data setter
|
|
30
|
+
def column name, options={}
|
|
31
|
+
ActiveRecord::ConnectionAdapters::Column.new(name, options[:default], options[:type] || "string").tap do |col|
|
|
32
|
+
define_method("#{name}=") do |value|
|
|
33
|
+
instance_variable_set("@#{name}", col.type_cast(value))
|
|
34
|
+
end
|
|
35
|
+
define_method(name) do
|
|
36
|
+
unless instance_variable_defined?("@#{name}")
|
|
37
|
+
instance_variable_set("@#{name}", col.default)
|
|
38
|
+
end
|
|
39
|
+
instance_variable_get("@#{name}")
|
|
40
|
+
end
|
|
21
41
|
end
|
|
22
42
|
end
|
|
23
|
-
return ret
|
|
24
|
-
end
|
|
25
43
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
def set_model klass
|
|
45
|
+
#TODO: klassが存在する(ActiveRecord::Baseの子供として)かどうかをチェックしたい。
|
|
46
|
+
# ActiveRecord::Base.connection.tablesをみて、テーブル名からクラスを探すチェックをいれる
|
|
47
|
+
raise ArgumentError.new('please set ActiveRecord classs') unless defined?(klass)
|
|
48
|
+
define_method(:target_model) do
|
|
49
|
+
klass
|
|
31
50
|
end
|
|
32
51
|
end
|
|
33
|
-
ret.join("&")
|
|
34
52
|
end
|
|
35
53
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
54
|
+
#params(検索条件を渡す)
|
|
55
|
+
def initialize conditions={}
|
|
56
|
+
conditions.each_pair do | key, val |
|
|
57
|
+
writer_method = "#{key}="
|
|
58
|
+
self.send(writer_method, val) if self.respond_to?(writer_method)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def find(options={})
|
|
63
|
+
reset_conditions
|
|
64
|
+
create_conditions
|
|
65
|
+
if where.blank?
|
|
66
|
+
target_model.scoped
|
|
67
|
+
else
|
|
68
|
+
target_model.where([where.join(" and "), values])
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def count(options={})
|
|
73
|
+
reset_conditions
|
|
74
|
+
create_conditions
|
|
75
|
+
target_model.count("#{target_model.table_name}.id", options.merge(
|
|
76
|
+
:conditions => where.blank? ? nil : [where.join(" and "), values]
|
|
77
|
+
))
|
|
39
78
|
end
|
|
40
79
|
|
|
41
80
|
private
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
81
|
+
|
|
82
|
+
def abstract!
|
|
83
|
+
raise "this is abstract class"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def create_conditions
|
|
87
|
+
abstract!
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def like _method, table_name, options={}
|
|
92
|
+
value = eval _method.to_s
|
|
93
|
+
if value.present?
|
|
94
|
+
self.where << "#{with_table_name(table_name, _method)} like :#{_method}"
|
|
95
|
+
self.values[_method] = "%#{value}%"
|
|
48
96
|
end
|
|
49
97
|
end
|
|
50
|
-
|
|
51
|
-
def eq
|
|
52
|
-
compare
|
|
98
|
+
|
|
99
|
+
def eq _method, table_name, options={}
|
|
100
|
+
compare _method, "=", table_name, options
|
|
53
101
|
end
|
|
54
|
-
|
|
55
|
-
def inc
|
|
56
|
-
value = eval
|
|
57
|
-
value = value.
|
|
58
|
-
|
|
59
|
-
column = options[:column] ||
|
|
60
|
-
self.where << "#{with_table_name(options[:table_name],column)} in (:#{
|
|
61
|
-
self.values[
|
|
102
|
+
|
|
103
|
+
def inc _method, table_name, options={}
|
|
104
|
+
value = eval _method.to_s
|
|
105
|
+
value = value.splot(",") if value.is_a(String) && value.include?(",")
|
|
106
|
+
if value.present?
|
|
107
|
+
column = options[:column] || _method
|
|
108
|
+
self.where << "#{with_table_name(options[:table_name],column)} in (:#{_method})"
|
|
109
|
+
self.values[_method] = value
|
|
62
110
|
end
|
|
63
111
|
end
|
|
64
112
|
|
|
65
|
-
def compare
|
|
113
|
+
def compare method, sign, table_name, options={}
|
|
66
114
|
return unless sign =~ /^[<>=]{1,2}$/
|
|
67
115
|
value = eval(method.to_s)
|
|
68
116
|
unless value.blank?
|
|
@@ -72,7 +120,7 @@ module Railstar
|
|
|
72
120
|
end
|
|
73
121
|
end
|
|
74
122
|
|
|
75
|
-
def bit
|
|
123
|
+
def bit method, table_name, options={}
|
|
76
124
|
value = eval(method.to_s)
|
|
77
125
|
unless value.blank?
|
|
78
126
|
column = options[:column] || method
|
|
@@ -81,12 +129,16 @@ module Railstar
|
|
|
81
129
|
end
|
|
82
130
|
end
|
|
83
131
|
|
|
84
|
-
|
|
85
132
|
def with_table_name table_name, method
|
|
86
133
|
ret = ""
|
|
87
134
|
ret << "#{table_name || target_model.table_name}." if table_name
|
|
88
135
|
ret << method.to_s
|
|
89
136
|
ret
|
|
90
137
|
end
|
|
138
|
+
|
|
139
|
+
def reset_conditions
|
|
140
|
+
self.where = []
|
|
141
|
+
self.values = {}
|
|
142
|
+
end
|
|
91
143
|
end
|
|
92
144
|
end
|
data/lib/railstar/version.rb
CHANGED
|
File without changes
|
data/test/dummy/db/test.sqlite3
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: railstar
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.12
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,11 +9,11 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rails
|
|
16
|
-
requirement:
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ~>
|
|
@@ -21,10 +21,15 @@ dependencies:
|
|
|
21
21
|
version: 3.2.2
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements:
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 3.2.2
|
|
25
30
|
- !ruby/object:Gem::Dependency
|
|
26
31
|
name: sqlite3
|
|
27
|
-
requirement:
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
28
33
|
none: false
|
|
29
34
|
requirements:
|
|
30
35
|
- - ! '>='
|
|
@@ -32,7 +37,12 @@ dependencies:
|
|
|
32
37
|
version: '0'
|
|
33
38
|
type: :development
|
|
34
39
|
prerelease: false
|
|
35
|
-
version_requirements:
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
36
46
|
description: railstar
|
|
37
47
|
email:
|
|
38
48
|
- info@raw-hide.co.jp
|
|
@@ -254,7 +264,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
254
264
|
version: '0'
|
|
255
265
|
segments:
|
|
256
266
|
- 0
|
|
257
|
-
hash:
|
|
267
|
+
hash: 1332917519886964449
|
|
258
268
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
269
|
none: false
|
|
260
270
|
requirements:
|
|
@@ -263,10 +273,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
263
273
|
version: '0'
|
|
264
274
|
segments:
|
|
265
275
|
- 0
|
|
266
|
-
hash:
|
|
276
|
+
hash: 1332917519886964449
|
|
267
277
|
requirements: []
|
|
268
278
|
rubyforge_project:
|
|
269
|
-
rubygems_version: 1.8.
|
|
279
|
+
rubygems_version: 1.8.24
|
|
270
280
|
signing_key:
|
|
271
281
|
specification_version: 3
|
|
272
282
|
summary: RAWHIDE. Core Rails Lib
|