custom_fields 2.5.0 → 2.6.0

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: a2d0f1cab5f7e3c7153f38202b4a77b8f466e04d
4
- data.tar.gz: eb6e1f46553f3a565939c16ecd15ae5ab6613d87
3
+ metadata.gz: 1e33b47ab6170cca8bcce7196f00f81d1b7fbf6d
4
+ data.tar.gz: e604ee4eea1a252ebf53ea0155f6b146e5bc8427
5
5
  SHA512:
6
- metadata.gz: bef098cd02a0e26ef093432d3dd3233d361b8e4cec1d32c88f94928c7644e9653974e8789bbed6609f5e550c54225997de3130da7f16605fdb607cce56efd3a6
7
- data.tar.gz: dd15ddff7b81739385881fbd93e3897ca511db4a6fce1b8aa1eb1df3770848280077eb176e041e0e2c54006d04d724075d685db00c58ea1b7c7fb92752028896
6
+ metadata.gz: 61d40ce45b216bf05e9187571bbeec95d29cad9af0fb776d73358b8fd912b85ea23a5ededc74b2ecd9a6584d27771d6549252cc79745a4e0392146fed8d80974
7
+ data.tar.gz: ffa68d31f8e3167147e9a5a7ca8fb7acbe3d7943bdcd49254f0878199ef4fd0199f417370082761a2735218a639c75cd490ff476d69a802a57bbdbb0134f9f29
@@ -22,6 +22,7 @@ module CustomFields
22
22
  field :required, type: ::Boolean, default: false
23
23
  field :unique, type: ::Boolean, default: false
24
24
  field :localized, type: ::Boolean, default: false
25
+ field :default
25
26
 
26
27
  ## validations ##
27
28
  validates_presence_of :label, :type
@@ -67,7 +68,8 @@ module CustomFields
67
68
  'type' => self.type,
68
69
  'required' => self.required?,
69
70
  'unique' => self.unique?,
70
- 'localized' => self.localized? }.merge(custom_to_recipe)
71
+ 'localized' => self.localized?,
72
+ 'default' => self.default }.merge(custom_to_recipe)
71
73
  end
72
74
 
73
75
  def as_json(options = {})
@@ -18,7 +18,7 @@ module CustomFields
18
18
  # @param [ Hash ] rule It contains the name of the field.
19
19
  #
20
20
  def apply_boolean_custom_field(klass, rule)
21
- klass.field rule['name'], type: ::Boolean, localize: rule['localized'] || false, default: false
21
+ klass.field rule['name'], type: ::Boolean, localize: rule['localized'] || false, default: rule['default'].nil? ? false : rule['default']
22
22
  end
23
23
 
24
24
  # Build a hash storing the boolean value (true / false) for
@@ -52,4 +52,4 @@ module CustomFields
52
52
 
53
53
  end
54
54
 
55
- end
55
+ end
@@ -47,7 +47,7 @@ module CustomFields
47
47
  # @param [ Hash ] rule It contains the name of the field and if it is required or not
48
48
  #
49
49
  def apply_custom_field(klass, rule)
50
- klass.field rule['name'], localize: rule['localized'] || false
50
+ klass.field rule['name'], localize: rule['localized'] || false, default: rule['default']
51
51
 
52
52
  klass.validates_presence_of rule['name'] if rule['required']
53
53
  klass.validates_uniqueness_of rule['name'], scope: :_type if rule['unique']
@@ -100,4 +100,4 @@ module CustomFields
100
100
 
101
101
  end
102
102
 
103
- end
103
+ end
@@ -20,7 +20,7 @@ module CustomFields
20
20
  def apply_email_custom_field(klass, rule)
21
21
  name = rule['name']
22
22
 
23
- klass.field name, type: ::String, localize: rule['localized'] || false
23
+ klass.field name, type: ::String, localize: rule['localized'] || false, default: rule['default']
24
24
  klass.validates_presence_of name if rule['required']
25
25
  klass.validates_format_of name, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, allow_blank: !rule['required']
26
26
  klass.validates_uniqueness_of rule['name'], scope: :_type if rule['unique']
@@ -57,4 +57,4 @@ module CustomFields
57
57
 
58
58
  end
59
59
 
60
- end
60
+ end
@@ -15,7 +15,7 @@ module CustomFields
15
15
  # @param [ Hash ] rule It contains the name of the field and if it is required or not
16
16
  #
17
17
  def apply_float_custom_field(klass, rule)
18
- klass.field rule['name'], type: ::Float, localize: rule['localized'] || false
18
+ klass.field rule['name'], type: ::Float, localize: rule['localized'] || false, default: rule['default']
19
19
  klass.validates_presence_of rule['name'] if rule['required']
20
20
  klass.validates rule['name'], numericality: true, if: ->(x){ rule['required'] }
21
21
  end
@@ -17,7 +17,7 @@ module CustomFields
17
17
  def apply_integer_custom_field(klass, rule)
18
18
  name = rule['name']
19
19
 
20
- klass.field name, type: ::Integer, localize: rule['localized'] || false
20
+ klass.field name, type: ::Integer, localize: rule['localized'] || false, default: rule['default']
21
21
  klass.validates_presence_of name if rule['required']
22
22
  klass.validates name, numericality: { only_integer: true }, if: ->(x){ rule['required'] }
23
23
  end
@@ -67,7 +67,7 @@ module CustomFields
67
67
  def apply_select_custom_field(klass, rule)
68
68
  name, base_collection_name = rule['name'], "#{rule['name']}_options".to_sym
69
69
 
70
- klass.field :"#{name}_id", type: BSON::ObjectId, localize: rule['localized'] || false
70
+ klass.field :"#{name}_id", type: BSON::ObjectId, localize: rule['localized'] || false, default: ->{ _set_select_option(name, rule['default']) }
71
71
 
72
72
  klass.cattr_accessor "_raw_#{base_collection_name}"
73
73
  klass.send :"_raw_#{base_collection_name}=", rule['select_options'].sort { |a, b| a['position'] <=> b['position'] }
@@ -1,5 +1,5 @@
1
1
  module CustomFields #:nodoc
2
2
 
3
- VERSION = '2.5.0'
3
+ VERSION = '2.6.0'
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.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-12 00:00:00.000000000 Z
11
+ date: 2016-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3.1
61
+ version: 1.4.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.3.1
68
+ version: 1.4.0
69
69
  description: Manage custom fields to a Mongoid document or a collection. This module
70
70
  is one of the core features we implemented in our custom CMS, named LocomotiveCMS.
71
71
  email: didier@nocoffee.fr