auto_define_scope 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a42e8a3b1c3c38245055e738d04f307e116eee4d42aadd0684c90ebfd9c8be46
4
- data.tar.gz: 35f1fd2627d06df0bba793f5e79a9720478384107c2128691fba8ec44b96dd5f
3
+ metadata.gz: 6b411e8fbe13d8df01d64c0eed8ac40eab0e88d8bd079a6fb95478a169ee260a
4
+ data.tar.gz: 9c24148854615f854cd18f5f3fb6f485e2b729341ec25e7bd7a4c08768cee1e3
5
5
  SHA512:
6
- metadata.gz: 815358fcdb359d595eb7c0b39c501dd7fbe9243b21b7dc735568b76d9c55638ec439ed43eb652ae1de3eb3179dcbd04f61d59d7e38a53704fafded3de42497c7
7
- data.tar.gz: f7c9b4e7e8e3a89a8827e85de649b7b5c7b9267ac75ee6405f23dc6e6679bd8771e64bf3585df86e15392ffb915b8f80620e37e0441bfb0d353c6b350a4432b6
6
+ metadata.gz: 18d5a5df81ad4188fb132a47abd51e5940632742676b46e071d890a259231430e7966e5fbe2a2968c9a9a8f36da2be5c6d1dba06886a6094cbe47dd4dfc02f25
7
+ data.tar.gz: 2de98abcb378d8245acf94c1495897402454c4f36e56de7d0e2d74c7d758c739139bfbf7f90d2971c1765f220a6766b3a6a011f911e8dca626bbfbc46440374b
@@ -5,11 +5,11 @@ module AutoDefineScope
5
5
 
6
6
  # For example, CustomerAgentHistory include this
7
7
  # columns is a array like ["status", "p_way", {customer_agent: ["code", "name", agent: :province_id]}]
8
- def search_columns *columns
8
+ def search_columns(*columns)
9
9
  generate_cope columns, :search
10
10
  end
11
11
 
12
- def with_columns *columns
12
+ def with_columns(*columns)
13
13
  generate_cope columns, :with
14
14
  end
15
15
 
@@ -26,7 +26,7 @@ module AutoDefineScope
26
26
  end
27
27
 
28
28
  protected
29
- def generate_cope columns, type, klass = self, joins_params_array = []
29
+ def generate_cope(columns, type, klass = self, joins_params_array = [])
30
30
  columns.each do |c|
31
31
  if c.is_a?(Hash)
32
32
  c.keys.each do |k|
@@ -45,17 +45,29 @@ module AutoDefineScope
45
45
  end
46
46
  next
47
47
  end
48
+ column_type = columns_hash[c.to_s]&.type
49
+ raise "scopes defined error, not found column('#{c}') for table #{klass.table_name}" if column.nil?
48
50
  joins_params = joins_params_array.reverse.inject() { |a, n| { n => a } }
49
51
  table_name = klass.table_name
50
52
  @auto_define_scopes ||= []
51
53
  scope_name = "#{type}_#{joins_params_array.last&.to_s&.+ '_'}#{c}"
52
54
  @auto_define_scopes << scope_name
53
55
  scope scope_name, ->(v) do
54
- value = type == :with ? v : "%#{v}%"
56
+ value = case column_type
57
+ when :integer
58
+ value.to_i
59
+ when :string
60
+ value.to_s
61
+ end
62
+ value = type == :with ? value : "%#{value}%"
55
63
  joins(joins_params).where("#{table_name}.#{c} #{OPERATE_SQL[type]}", value)
56
64
  end
57
65
  end
58
66
  nil
59
67
  end
68
+
69
+ def convert_type(obj, type)
70
+
71
+ end
60
72
  end
61
73
  end
@@ -1,3 +1,3 @@
1
1
  module AutoDefineScope
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_define_scope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - tinyfeng.hou
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-04 00:00:00.000000000 Z
11
+ date: 2019-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler