simple_form_extension 1.4.0 → 1.4.1
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9ed7a20a6896f059604491974a53e303a86c76a
|
4
|
+
data.tar.gz: 348fd0e432cca498201bbaa8e7173bc72915c337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58eb6c567ed00b012d833d116100fddd57547bfb94a6232d2c73353f39b752280b1676fa1d1ba77e8b29ea6f956351db6e76f47831c1d885a8cb95be645bd023
|
7
|
+
data.tar.gz: ea95c4b677f723bb8144adfd7473639cdf8131e3bf7302eaada2406134df95afc36f2c9958a960455191ebbacc425aa964b62ff766a394bc7bdf794bf306922f
|
@@ -14,7 +14,6 @@ module SimpleFormExtension
|
|
14
14
|
#
|
15
15
|
def input(wrapper_options = {})
|
16
16
|
@attribute_name = foreign_key if relation?
|
17
|
-
set_sort_field!
|
18
17
|
|
19
18
|
input_html_options[:data] ||= {}
|
20
19
|
|
@@ -60,18 +59,16 @@ module SimpleFormExtension
|
|
60
59
|
options[:max_items]
|
61
60
|
end
|
62
61
|
|
63
|
-
def
|
64
|
-
options[:sort_field]
|
62
|
+
def sort_field
|
63
|
+
if (sort_field = options[:sort_field]).present?
|
64
|
+
sort_field
|
65
|
+
elsif enum?
|
65
66
|
'position'
|
66
67
|
else
|
67
68
|
'text'
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
71
|
-
def sort_field
|
72
|
-
options[:sort_field] ||= 'text'
|
73
|
-
end
|
74
|
-
|
75
72
|
def collection
|
76
73
|
return if search_url
|
77
74
|
|
@@ -146,8 +143,11 @@ module SimpleFormExtension
|
|
146
143
|
block ? block.call : nil
|
147
144
|
end
|
148
145
|
|
149
|
-
|
150
|
-
|
146
|
+
# Check if the given target object is enumerable. Used internally to
|
147
|
+
# check wether :collection or :value arguments are collections.
|
148
|
+
#
|
149
|
+
def enumerable?(target)
|
150
|
+
target.class.include?(Enumerable) || ActiveRecord::Relation === target
|
151
151
|
end
|
152
152
|
|
153
153
|
def name_for(option)
|
@@ -163,17 +163,17 @@ module SimpleFormExtension
|
|
163
163
|
end
|
164
164
|
|
165
165
|
def reflection
|
166
|
-
@reflection ||= if
|
167
|
-
|
166
|
+
@reflection ||= if object_class.respond_to?(:reflect_on_association)
|
167
|
+
object_class.reflect_on_association(attribute_name)
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
171
|
def enum?
|
172
|
-
|
172
|
+
object_class.defined_enums.key?(attribute_name.to_s)
|
173
173
|
end
|
174
174
|
|
175
175
|
def enum_options
|
176
|
-
|
176
|
+
object_class.defined_enums[attribute_name.to_s].map do |key, value|
|
177
177
|
path = [object.model_name.i18n_key, attribute_name, key].join('.')
|
178
178
|
translation = ::I18n.t("activerecord.enums.#{ path }", default: '')
|
179
179
|
|
@@ -192,6 +192,19 @@ module SimpleFormExtension
|
|
192
192
|
def text_from(resource)
|
193
193
|
resource.try(:title) || resource.try(:name)
|
194
194
|
end
|
195
|
+
|
196
|
+
# Retrieve actual model class even when the form object is a proxy like
|
197
|
+
# for Ransack::Search or ActiveRecord::Relation classes
|
198
|
+
#
|
199
|
+
def object_class
|
200
|
+
@object_class ||= if ((object_class = object.class) < ActiveRecord::Base)
|
201
|
+
object_class
|
202
|
+
elsif (klass = object.try(:klass))
|
203
|
+
klass
|
204
|
+
else
|
205
|
+
object_class
|
206
|
+
end
|
207
|
+
end
|
195
208
|
end
|
196
209
|
end
|
197
210
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form_extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glyph-fr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|