trk_datatables 0.1.18 → 0.1.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 206ca38dbabdc5c5efc6977db4c34ee6300336e7162479a7c7b8a94f3fb74b8c
4
- data.tar.gz: db45ebc154b0da6a653c785eee388128bfc3d982750fd3dd296e77c120932740
3
+ metadata.gz: 6b70dfeaa82979653c2cf84807fffe3bd41803c9d156f42886f374d8b89ffea9
4
+ data.tar.gz: 9e0f18c46d97d61db46ffeded483c3c3628b2a7ae4be8dbe3e4f04dcb74a1ac2
5
5
  SHA512:
6
- metadata.gz: 15ecc3cc4c9c0fb978bb76cdc9f136d7907956d6c4c7c464f5d4d5d6298147be91b00ed6e9314ef9b32318fd2772600067003da937c634585f687b0e27b3e3c4
7
- data.tar.gz: ccf49ae9953ca13b9c0f850b67eb38f03cd7429a780ed46c15b078eea1028116a1ee19a29115474e3954cafb021c685e2ccf214e169f1c7b447fce34770e43a0
6
+ metadata.gz: 0bfb35f05f38a4717324930d66551f24ca4f7848666b44cd275028368e03e7c1613ae2b3bae0ba3a296db53e58fe7a71732b2cd14bf29d78c4bdb74b1cf46975
7
+ data.tar.gz: 8a16bc9d2fd8cc2d59677f1106a53b1bca5479f1e4508a298cc7559188862936eedeab3241ab867c5f6c5c349c16f85f477f0dfbfc066c72a117ab6d8896f0fc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trk_datatables (0.1.18)
4
+ trk_datatables (0.1.19)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -47,6 +47,7 @@ You need to create a class that inherits from `TrkDatatables::ActiveRecord` (you
47
47
  can use Rails generator)
48
48
 
49
49
  ```
50
+ rails g trk_datatables user
50
51
  ```
51
52
 
52
53
  ## Usage example in Ruby on Rails
@@ -90,7 +90,8 @@ module TrkDatatables
90
90
  column_options[SEARCH_OPTION] = false
91
91
  column_options[ORDER_OPTION] = false
92
92
  else
93
- table_class = table_name.singularize.camelcase.constantize
93
+ table_class = _determine_table_class table_name
94
+
94
95
  column_type_in_db = _determine_db_type_for_column(table_class, column_name) unless column_options[SEARCH_OPTION] == false && column_options[ORDER_OPTION] == false
95
96
  end
96
97
  arr << {
@@ -106,10 +107,26 @@ module TrkDatatables
106
107
  end
107
108
  end
108
109
 
110
+ def _determine_table_class(table_name)
111
+ # post_users -> PostUser
112
+ # but also check if admin_posts -> Admin::Post
113
+ # https://github.com/duleorlovic/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb#L289
114
+ if [table_name.classify].inject(Object) { |c, n| c.const_defined? n }
115
+ table_name.classify.constantize
116
+ else
117
+ module_name, *class_name = table_name.split('_')
118
+ if module_name.present? && [module_name.classify].inject(Object) { |c, n| c.const_defined? n }
119
+ "#{module_name.classify}::#{class_name.join('_').classify}".constantize
120
+ else
121
+ table_name.classify.constantize
122
+ end
123
+ end
124
+ end
125
+
109
126
  def _set_global_search_cols(global_search_cols)
110
127
  @global_search_cols = global_search_cols.each_with_object([]) do |column_key, arr|
111
128
  table_name, column_name = column_key.to_s.split '.'
112
- table_class = table_name.singularize.camelcase.constantize
129
+ table_class = _determine_table_class table_name
113
130
  column_type_in_db = _determine_db_type_for_column(table_class, column_name)
114
131
  arr << {
115
132
  column_key: column_key.to_sym,
@@ -206,7 +223,6 @@ module TrkDatatables
206
223
  end
207
224
  res
208
225
  end
209
-
210
226
  end
211
227
  # rubocop:enable ClassLength
212
228
  end
@@ -1,3 +1,3 @@
1
1
  module TrkDatatables
2
- VERSION = '0.1.18'.freeze
2
+ VERSION = '0.1.19'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trk_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dusan Orlovic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-18 00:00:00.000000000 Z
11
+ date: 2019-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  - !ruby/object:Gem::Version
207
207
  version: '0'
208
208
  requirements: []
209
- rubygems_version: 3.0.4
209
+ rubygems_version: 3.0.3
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: Gem that simplify using datatables with Ruby on Rails and Sinatra.