simple_form_extension 1.4.4 → 1.4.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
  SHA1:
3
- metadata.gz: 40fbec443efaab587eaab9a367d11c9f84f48731
4
- data.tar.gz: 1172dbd58841a6e555484d3b6e46a5f5b95faaaa
3
+ metadata.gz: 1bc4702ff35a135cc1c1edee65f105adfa8d2280
4
+ data.tar.gz: 9dad68f004f12782e3a75ed7fa16e54a33b29b71
5
5
  SHA512:
6
- metadata.gz: 6500c1baa1234eaa0c3c802c2c4145b2353fed3e330de5c1c1b99ef9e1aedbddc9621f80130d4442c3baa11537ae0efb88452e07f71f50686b3f352e0f6f94fa
7
- data.tar.gz: c021c7c719ea62860ef1b99cc547b5c9dd9042cea39575b25525a0c2abf09336831bb82523fd07ffaa40eecdca6785268d278bbfc70c69569449b81c7553bdd2
6
+ metadata.gz: eee90d167eab2a47212a42e7cdf9bf7f6e912612f09a57263c15590661727cb349f290e57608c18319160f67cb1bc22745697b7500ca383705cd3721107dd479
7
+ data.tar.gz: 3e74a498ec1fd53dbee724ead15764cff4d8b736cf64acbf256e52171a7393d70bf55271fadad329b53ad5a1bc55a8c0744268261c7fa72ec2b30b4e8b0db819
@@ -8,9 +8,16 @@ module SimpleFormExtension
8
8
 
9
9
  eager_autoload do
10
10
  autoload :Translations
11
+ autoload :ResourceNameHelper
11
12
  autoload :Components
12
13
  autoload :Inputs
13
14
  end
15
+
16
+ # Allows overriding which methods are used by the fields that try to fetch
17
+ # the name of a resource to display it instead of calling #to_s
18
+ #
19
+ mattr_accessor :resource_name_methods
20
+ @@resource_name_methods = [:name, :title]
14
21
  end
15
22
 
16
23
  SimpleForm::Inputs::Base.send(:include, SimpleFormExtension::Components::Icons)
@@ -2,6 +2,7 @@ module SimpleFormExtension
2
2
  module Inputs
3
3
  class SelectizeInput < SimpleForm::Inputs::Base
4
4
  include SimpleFormExtension::Translations
5
+ include SimpleFormExtension::ResourceNameHelper
5
6
 
6
7
  # This field only allows local select options (serialized into JSON)
7
8
  # Searching for remote ones will be implemented later.
@@ -151,7 +152,7 @@ module SimpleFormExtension
151
152
  end
152
153
 
153
154
  def name_for(option)
154
- option.try(:name) || option.try(:title) || option.to_s
155
+ resource_name_for(option) || option.to_s
155
156
  end
156
157
 
157
158
  def relation
@@ -190,7 +191,7 @@ module SimpleFormExtension
190
191
  end
191
192
 
192
193
  def text_from(resource)
193
- resource.try(:title) || resource.try(:name)
194
+ resource_name_for(resource)
194
195
  end
195
196
 
196
197
  # Retrieve actual model class even when the form object is a proxy like
@@ -0,0 +1,9 @@
1
+ module SimpleFormExtension
2
+ module ResourceNameHelper
3
+ def resource_name_for(resource)
4
+ SimpleFormExtension.resource_name_methods.each do |method_name|
5
+ if (value = resource.try(method_name)) then return value end
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleFormExtension
2
- VERSION = "1.4.4"
2
+ VERSION = "1.4.5"
3
3
  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
4
+ version: 1.4.5
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-11-08 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -132,6 +132,7 @@ files:
132
132
  - lib/simple_form_extension/inputs/selectize_input.rb
133
133
  - lib/simple_form_extension/inputs/slider_input.rb
134
134
  - lib/simple_form_extension/railtie.rb
135
+ - lib/simple_form_extension/resource_name_helper.rb
135
136
  - lib/simple_form_extension/translations.rb
136
137
  - lib/simple_form_extension/version.rb
137
138
  - simple_form_extension.gemspec