custom_fields 2.8.0 → 2.9.0.rc1

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
- SHA1:
3
- metadata.gz: 88e261b104e415fe6b64700e80b1f69e8e2448b7
4
- data.tar.gz: 5dd052af6575958e56d77eac8ea79186833503fb
2
+ SHA256:
3
+ metadata.gz: 061b3bb511a4f4faf547c49285c6c67a319d8ad748c7c0a21d37bfa67cb3d841
4
+ data.tar.gz: a45eebe1d9e9db697ee417c7b07d24633477351078cf0a1efb2e174e4c576b6d
5
5
  SHA512:
6
- metadata.gz: 3f4d7290c9222c0ed84170942c6143a27a469aca8068bc556caeb5fb9c8f9967acb9b7cfcb04796c5785e9078ccad8ba92d7aab7cd9715319ae33912cca20fb1
7
- data.tar.gz: 3576971a4a8f027036499520b95002ca27c7520db9418a7862aba0013b69d8bd8e61d86b21151a7dad820d37252cde870e075ef18babaa70c0d076390371f716
6
+ metadata.gz: 407631ca5ba6a4963221a27d87b87323143fbed3009646959c7d0db38cb7ea3c920301c0e77b4460d9a6399232d999639d8dc8c2eeda19ce6e5949c47d529f14
7
+ data.tar.gz: 608ba250b8dbc986a0dc0562ac830b8cfa11de3b18ea53a0d798ed23382cc3f54ad5343eca1ce41d3f9210439ff4001578eb829ea73729ebfb78e6da8c3caad5
@@ -1,4 +1,6 @@
1
- Copyright (c) 2017, NoCoffee
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 NoCoffee
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -17,8 +17,8 @@ Requirements
17
17
  ------------
18
18
 
19
19
  * MongoDB 3.x
20
- * Mongoid 5.x
21
- * ActiveSupport 4.2.x
20
+ * Mongoid 6.x
21
+ * ActiveSupport 5.2.x
22
22
 
23
23
  Examples
24
24
  --------
@@ -93,7 +93,7 @@ Feel free to contact me at did at locomotivecms dot com.
93
93
  License
94
94
  -------
95
95
 
96
- Copyright (c) 2017 NoCoffee, released under the [MIT License (MIT)], see [LICENSE].
96
+ Copyright (c) 2018 NoCoffee, released under the [MIT License (MIT)], see [MIT-LICENSE].
97
97
 
98
98
  [CustomFields]: https://github.com/locomotivecms/custom_fields "Custom fields extension for Mongoid."
99
99
  [Gemnasium]: https://gemnasium.com/locomotivecms/custom_fields "CustomFields at Gemnasium"
data/lib/custom_fields.rb CHANGED
@@ -29,6 +29,8 @@ end
29
29
  extensions/carrierwave
30
30
  extensions/mongoid/document
31
31
  extensions/mongoid/factory
32
+ extensions/mongoid/criteria/queryable/smash
33
+ extensions/mongoid/relations/options
32
34
  extensions/mongoid/relations/referenced/many
33
35
  extensions/mongoid/relations/referenced/in
34
36
  extensions/mongoid/fields.rb
@@ -36,7 +38,6 @@ end
36
38
  extensions/mongoid/fields/localized.rb
37
39
  extensions/mongoid/validations/collection_size.rb
38
40
  extensions/mongoid/validations/macros.rb
39
- extensions/mongoid/attributes
40
41
  extensions/origin/smash.rb
41
42
  types/default
42
43
  types/string
@@ -24,5 +24,7 @@ class String
24
24
  end
25
25
  end
26
26
 
27
- alias_method_chain :constantize, :custom_fields
27
+ alias_method :constantize_without_custom_fields, :constantize
28
+ alias_method :constantize, :constantize_with_custom_fields
29
+
28
30
  end
@@ -19,7 +19,30 @@ module CarrierWave
19
19
  end
20
20
  end
21
21
 
22
- alias_method_chain :mount_uploader, :localization
22
+ alias_method :mount_uploader_without_localization, :mount_uploader
23
+ alias_method :mount_uploader, :mount_uploader_with_localization
24
+
25
+ end
26
+
27
+ class Mounter
28
+
29
+ def remove_previous_with_localization(before=nil, after=nil)
30
+ _after = after
31
+
32
+ if after && after.first.is_a?(Hash)
33
+ locale = ::Mongoid::Fields::I18n.locale.to_s
34
+ _after = [after.first[locale]]
35
+ end
36
+
37
+ remove_previous_without_localization(before, _after)
38
+ end
39
+
40
+ alias_method :remove_previous_without_localization, :remove_previous
41
+ alias_method :remove_previous, :remove_previous_with_localization
42
+
43
+
23
44
  end
24
45
 
25
46
  end
47
+
48
+
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ module Mongoid
3
+ class Criteria
4
+ module Queryable
5
+
6
+ # This is a smart hash for use with options and selectors.
7
+ class Smash < Hash
8
+
9
+ private
10
+
11
+ # Get the localized value for the key if needed. If the field uses
12
+ # localization the current locale will be appended to the key in
13
+ # MongoDB dot notation.
14
+ #
15
+ # @api private
16
+ #
17
+ # @example Get the normalized key name.
18
+ # smash.localized_key("field", serializer)
19
+ #
20
+ # @param [ String ] name The name of the field.
21
+ # @param [ Object ] serializer The optional field serializer.
22
+ #
23
+ # @return [ String ] The normalized key.
24
+ #
25
+ # @since 1.0.0
26
+ def localized_key(name, serializer)
27
+ serializer && serializer.localized? ? "#{name}.#{::Mongoid::Fields::I18n.locale}" : name
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ module Mongoid
3
+ module Relations
4
+
5
+ module Options
6
+
7
+ def validate_with_custom_fields!(options)
8
+ _options = options.dup
9
+ _options.delete(:custom_fields_parent_klass)
10
+ validate_without_custom_fields!(_options)
11
+ end
12
+
13
+ alias_method :validate_without_custom_fields!, :validate!
14
+ alias_method :validate!, :validate_with_custom_fields!
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -7,7 +7,10 @@ module Mongoid # :nodoc:
7
7
  def valid_options_with_parent_class
8
8
  valid_options_without_parent_class.push :custom_fields_parent_klass
9
9
  end
10
- alias_method_chain :valid_options, :parent_class
10
+
11
+ alias_method :valid_options_without_parent_class, :valid_options
12
+ alias_method :valid_options, :valid_options_with_parent_class
13
+
11
14
  end
12
15
  end
13
16
  end
@@ -17,7 +17,9 @@ module Mongoid #:nodoc:
17
17
  end
18
18
  build_without_custom_fields(attributes, type)
19
19
  end
20
- alias_method_chain :build, :custom_fields
20
+
21
+ alias_method :build_without_custom_fields, :build
22
+ alias_method :build, :build_with_custom_fields
21
23
 
22
24
  # new should point to the new build method
23
25
  alias :new :build_with_custom_fields
@@ -20,7 +20,8 @@ module Mongoid
20
20
  self.validate_each_without_collection(record, attribute, value)
21
21
  end
22
22
 
23
- alias_method_chain :validate_each, :collection
23
+ alias_method :validate_each_without_collection, :validate_each
24
+ alias_method :validate_each, :validate_each_with_collection
24
25
 
25
26
  private
26
27
 
@@ -95,7 +95,7 @@ module CustomFields
95
95
  return if self.label.blank? && self.name.blank?
96
96
 
97
97
  if self.name.blank?
98
- self.name = self.label.parameterize('_').gsub('-', '_').downcase
98
+ self.name = self.label.parameterize(separator: '_').gsub('-', '_').downcase
99
99
  end
100
100
  end
101
101
 
@@ -42,7 +42,7 @@ module CustomFields
42
42
 
43
43
  klass.field position_name, type: ::Integer, default: 0
44
44
 
45
- options = { class_name: rule['class_name'] }
45
+ options = { class_name: rule['class_name'], optional: true }
46
46
  options[:inverse_of] = rule['inverse_of'] unless rule['inverse_of'].blank? # an empty String can cause weird behaviours
47
47
 
48
48
  klass.belongs_to rule['name'].to_sym, options
@@ -19,14 +19,16 @@ module CustomFields
19
19
  # @param [ Hash ] rule It contains the name of the field and if it is required or not
20
20
  #
21
21
  def apply_password_custom_field(klass, rule)
22
- name = rule['name']
22
+ label, name = rule['label'], rule['name']
23
23
 
24
24
  klass.field :"#{name}_hash"
25
25
 
26
26
  klass.send(:define_method, name.to_sym) { '' }
27
27
  klass.send(:define_method, :"#{name}=") { |value| _encrypt_password(name, value) }
28
+ klass.send(:define_method, :"#{name}_confirmation") { '' }
29
+ klass.send(:define_method, :"#{name}_confirmation=") { |value| _set_confirmation_password(name, value) }
28
30
 
29
- klass.validate { _check_password(name) }
31
+ klass.validate { _check_password(label, name) }
30
32
  end
31
33
 
32
34
  # Build a hash storing the raw value for
@@ -54,6 +56,10 @@ module CustomFields
54
56
 
55
57
  end # ClassMethods
56
58
 
59
+ def _set_confirmation_password(name, confirmation)
60
+ self.instance_variable_set(:"@#{name}_confirmation", confirmation)
61
+ end
62
+
57
63
  def _encrypt_password(name, new_password)
58
64
  return if new_password.blank?
59
65
 
@@ -62,13 +68,18 @@ module CustomFields
62
68
  self.send(:"#{name}_hash=", BCrypt::Password.create(new_password))
63
69
  end
64
70
 
65
- def _check_password(name)
71
+ def _check_password(label, name)
66
72
  new_password = self.instance_variable_get(:"@#{name}")
73
+ confirmation = self.instance_variable_get(:"@#{name}_confirmation")
67
74
 
68
75
  return if new_password.blank?
69
76
 
70
77
  if new_password.size < CustomFields::Types::Password::Field::MIN_PASSWORD_LENGTH
71
- self.errors.add(name, :too_short, count: 6)
78
+ self.errors.add(name, :too_short, count: CustomFields::Types::Password::Field::MIN_PASSWORD_LENGTH)
79
+ end
80
+
81
+ if confirmation && confirmation != new_password
82
+ self.errors.add("#{name}_confirmation", :confirmation, attribute: label || name)
72
83
  end
73
84
  end
74
85
 
@@ -1,5 +1,5 @@
1
1
  module CustomFields #:nodoc
2
2
 
3
- VERSION = '2.8.0'
3
+ VERSION = '2.9.0.rc1'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.9.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 2018-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.0
19
+ version: 6.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.0
26
+ version: 6.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: carrierwave-mongoid
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.10.0
33
+ version: 1.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.10.0
40
+ version: 1.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 4.2.7
47
+ version: 5.1.5
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 4.2.7
54
+ version: 5.1.5
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: monetize
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.6.0
61
+ version: 1.7.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.6.0
68
+ version: 1.7.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bcrypt
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,10 +86,10 @@ email: didier@nocoffee.fr
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files:
89
- - LICENSE
89
+ - MIT-LICENSE
90
90
  - README.md
91
91
  files:
92
- - LICENSE
92
+ - MIT-LICENSE
93
93
  - README.md
94
94
  - config/locales/de.yml
95
95
  - config/locales/en.yml
@@ -99,12 +99,13 @@ files:
99
99
  - lib/custom_fields.rb
100
100
  - lib/custom_fields/extensions/active_support.rb
101
101
  - lib/custom_fields/extensions/carrierwave.rb
102
- - lib/custom_fields/extensions/mongoid/attributes.rb
102
+ - lib/custom_fields/extensions/mongoid/criteria/queryable/smash.rb
103
103
  - lib/custom_fields/extensions/mongoid/document.rb
104
104
  - lib/custom_fields/extensions/mongoid/factory.rb
105
105
  - lib/custom_fields/extensions/mongoid/fields.rb
106
106
  - lib/custom_fields/extensions/mongoid/fields/i18n.rb
107
107
  - lib/custom_fields/extensions/mongoid/fields/localized.rb
108
+ - lib/custom_fields/extensions/mongoid/relations/options.rb
108
109
  - lib/custom_fields/extensions/mongoid/relations/referenced/in.rb
109
110
  - lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
110
111
  - lib/custom_fields/extensions/mongoid/validations/collection_size.rb
@@ -147,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
148
  requirements:
148
149
  - - "~>"
149
150
  - !ruby/object:Gem::Version
150
- version: '2.1'
151
+ version: '2.3'
151
152
  required_rubygems_version: !ruby/object:Gem::Requirement
152
153
  requirements:
153
154
  - - "~>"
@@ -155,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
156
  version: '2.4'
156
157
  requirements: []
157
158
  rubyforge_project:
158
- rubygems_version: 2.5.2
159
+ rubygems_version: 2.7.3
159
160
  signing_key:
160
161
  specification_version: 4
161
162
  summary: Custom fields extension for Mongoid.
@@ -1,14 +0,0 @@
1
- module Mongoid
2
- module Attributes
3
-
4
- # FIXME: ::Mongoid::Fields::I18n.locale is also a valid locale
5
- def selection_included?(name, selection, field)
6
- if field && field.localized?
7
- selection.has_key?("#{name}.#{::I18n.locale}") || selection.has_key?("#{name}.#{::Mongoid::Fields::I18n.locale}")
8
- else
9
- selection.has_key?(name)
10
- end
11
- end
12
-
13
- end
14
- end