custom_fields 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/README.textile +4 -4
  3. data/config/locales/de.yml +11 -5
  4. data/config/locales/en.yml +4 -0
  5. data/config/locales/fr.yml +4 -0
  6. data/config/locales/ru.yml +15 -0
  7. data/lib/custom_fields.rb +37 -27
  8. data/lib/custom_fields/extensions/active_support.rb +1 -1
  9. data/lib/custom_fields/extensions/carrierwave.rb +2 -2
  10. data/lib/custom_fields/extensions/mongoid/factory.rb +3 -3
  11. data/lib/custom_fields/extensions/mongoid/fields.rb +4 -3
  12. data/lib/custom_fields/extensions/mongoid/fields/localized.rb +39 -0
  13. data/lib/custom_fields/extensions/mongoid/relations/referenced/in.rb +1 -1
  14. data/lib/custom_fields/extensions/mongoid/relations/referenced/many.rb +3 -3
  15. data/lib/custom_fields/field.rb +14 -8
  16. data/lib/custom_fields/source.rb +23 -14
  17. data/lib/custom_fields/target.rb +16 -8
  18. data/lib/custom_fields/target_helpers.rb +6 -6
  19. data/lib/custom_fields/types/belongs_to.rb +4 -4
  20. data/lib/custom_fields/types/boolean.rb +1 -1
  21. data/lib/custom_fields/types/date.rb +2 -2
  22. data/lib/custom_fields/types/default.rb +5 -6
  23. data/lib/custom_fields/types/email.rb +60 -0
  24. data/lib/custom_fields/types/file.rb +2 -2
  25. data/lib/custom_fields/types/float.rb +52 -0
  26. data/lib/custom_fields/types/has_many.rb +6 -8
  27. data/lib/custom_fields/types/integer.rb +54 -0
  28. data/lib/custom_fields/types/many_to_many.rb +3 -3
  29. data/lib/custom_fields/types/money.rb +146 -0
  30. data/lib/custom_fields/types/relationship_default.rb +2 -2
  31. data/lib/custom_fields/types/select.rb +16 -13
  32. data/lib/custom_fields/types/tags.rb +35 -0
  33. data/lib/custom_fields/types/text.rb +1 -1
  34. data/lib/custom_fields/version.rb +1 -1
  35. metadata +65 -76
  36. data/init.rb +0 -2
  37. data/lib/custom_fields/extensions/mongoid/fields/internal/localized.rb +0 -86
@@ -14,8 +14,8 @@ module CustomFields
14
14
  field :inverse_of
15
15
  field :order_by
16
16
 
17
- validates_presence_of :class_name, :if => :is_relationship?
18
- validate :ensure_class_name_security, :if => :is_relationship?
17
+ validates_presence_of :class_name, if: :is_relationship?
18
+ validate :ensure_class_name_security, if: :is_relationship?
19
19
 
20
20
  def is_relationship?
21
21
  method_name = :"#{self.type}_is_relationship?"
@@ -8,15 +8,15 @@ module CustomFields
8
8
 
9
9
  include Mongoid::Document
10
10
 
11
- field :name, :localize => true
12
- field :position, :type => Integer, :default => 0
11
+ field :name, localize: true
12
+ field :position, type: ::Integer, default: 0
13
13
 
14
- embedded_in :custom_field, :inverse_of => :select_options
14
+ embedded_in :custom_field, inverse_of: :select_options
15
15
 
16
16
  validates_presence_of :name
17
17
 
18
18
  def as_json(options = nil)
19
- super :methods => %w(_id name position)
19
+ super methods: %w(_id name position)
20
20
  end
21
21
 
22
22
  end
@@ -27,11 +27,11 @@ module CustomFields
27
27
 
28
28
  included do
29
29
 
30
- embeds_many :select_options, :class_name => 'CustomFields::Types::Select::Option'
30
+ embeds_many :select_options, class_name: 'CustomFields::Types::Select::Option'
31
31
 
32
32
  validates_associated :select_options
33
33
 
34
- accepts_nested_attributes_for :select_options, :allow_destroy => true
34
+ accepts_nested_attributes_for :select_options, allow_destroy: true
35
35
 
36
36
  end
37
37
 
@@ -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: Moped::BSON::ObjectId, localize: rule['localized'] || false
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'] }
@@ -129,22 +129,25 @@ module CustomFields
129
129
 
130
130
  # Returns a list of documents groupes by select values defined in the custom fields recipe
131
131
  #
132
- # @param [ Class ] klass The class to modify
132
+ # @param [ Class ] klass The class to modify
133
133
  # @return [ Array ] An array of hashes (keys: select option and related documents)
134
134
  #
135
135
  def group_by_select_option(name, order_by = nil)
136
- groups = self.only(:"#{name}_id").group
136
+ name_id = "#{name}_id"
137
+ groups = self.each.group_by{|x| x.send(name_id)}.map do |(k, v)|
138
+ {name_id => k, "group" => v}
139
+ end
137
140
 
138
141
  _select_options(name).map do |option|
139
- group = groups.detect { |g| g["#{name}_id"].to_s == option['_id'].to_s }
142
+ group = groups.detect { |g| g[name_id].to_s == option['_id'].to_s }
140
143
  list = group ? group['group'] : []
141
144
 
142
145
  groups.delete(group) if group
143
146
 
144
- { :name => option['name'], :entries => self._order_select_entries(list, order_by) }.with_indifferent_access
147
+ { name: option['name'], entries: self._order_select_entries(list, order_by) }.with_indifferent_access
145
148
  end.tap do |array|
146
149
  if not groups.empty? # orphan entries ?
147
- empty = { :name => nil, :entries => [] }.with_indifferent_access
150
+ empty = { name: nil, entries: [] }.with_indifferent_access
148
151
  groups.each do |group|
149
152
  empty[:entries] += group['group']
150
153
  end
@@ -211,4 +214,4 @@ module CustomFields
211
214
 
212
215
  end
213
216
 
214
- end
217
+ end
@@ -0,0 +1,35 @@
1
+ module CustomFields
2
+ module Types
3
+ module Tags
4
+ module Field; end
5
+
6
+ module Target
7
+ extend ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+
11
+ def apply_tags_custom_field(klass, rule)
12
+ klass.field rule['name'], localize: rule['localized'] || false, type: Array
13
+
14
+ klass.class_eval do
15
+ define_method("#{rule['name']}=") do |val|
16
+ #FIXME I would use is_a?(), but it doesn't work in my machine!
17
+ val = val.split(/ *, */) if val.class.to_s == "String"
18
+ super(val)
19
+ end
20
+ end
21
+ end
22
+
23
+ def tags_attribute_get(instance, name)
24
+ self.default_attribute_get(instance, name)
25
+ end
26
+
27
+ def tags_attribute_set(instance, name, attributes)
28
+ self.default_attribute_set(instance, name, attributes)
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -10,7 +10,7 @@ module CustomFields
10
10
 
11
11
  included do
12
12
 
13
- field :text_formatting, :default => 'html'
13
+ field :text_formatting, default: 'html'
14
14
 
15
15
  end
16
16
 
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module CustomFields #:nodoc
3
3
 
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
5
5
 
6
6
  end
metadata CHANGED
@@ -1,203 +1,187 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_fields
3
3
  version: !ruby/object:Gem::Version
4
+ version: 2.2.0
4
5
  prerelease:
5
- version: 2.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Didier Lafforgue
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-26 00:00:00.000000000 Z
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- type: :runtime
16
- version_requirements: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 2.4.12
22
15
  name: mongoid
23
- prerelease: false
24
16
  requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
18
  requirements:
27
19
  - - ~>
28
20
  - !ruby/object:Gem::Version
29
- version: 2.4.12
30
- - !ruby/object:Gem::Dependency
21
+ version: 3.1.3
31
22
  type: :runtime
23
+ prerelease: false
32
24
  version_requirements: !ruby/object:Gem::Requirement
33
25
  none: false
34
26
  requirements:
35
27
  - - ~>
36
28
  - !ruby/object:Gem::Version
37
- version: 3.2.9
29
+ version: 3.1.3
30
+ - !ruby/object:Gem::Dependency
38
31
  name: activesupport
39
- prerelease: false
40
32
  requirement: !ruby/object:Gem::Requirement
41
33
  none: false
42
34
  requirements:
43
35
  - - ~>
44
36
  - !ruby/object:Gem::Version
45
- version: 3.2.9
46
- - !ruby/object:Gem::Dependency
37
+ version: 3.2.13
47
38
  type: :runtime
39
+ prerelease: false
48
40
  version_requirements: !ruby/object:Gem::Requirement
49
41
  none: false
50
42
  requirements:
51
43
  - - ~>
52
44
  - !ruby/object:Gem::Version
53
- version: 0.2.1
45
+ version: 3.2.13
46
+ - !ruby/object:Gem::Dependency
54
47
  name: carrierwave-mongoid
55
- prerelease: false
56
48
  requirement: !ruby/object:Gem::Requirement
57
49
  none: false
58
50
  requirements:
59
51
  - - ~>
60
52
  - !ruby/object:Gem::Version
61
- version: 0.2.1
62
- - !ruby/object:Gem::Dependency
63
- type: :development
64
- version_requirements: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: 0.7.3
70
- name: yard
53
+ version: 0.6.0
54
+ type: :runtime
71
55
  prerelease: false
72
- requirement: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: 0.7.3
78
- - !ruby/object:Gem::Dependency
79
- type: :development
80
56
  version_requirements: !ruby/object:Gem::Requirement
81
57
  none: false
82
58
  requirements:
83
59
  - - ~>
84
60
  - !ruby/object:Gem::Version
85
- version: 1.3.1
86
- name: bson
87
- prerelease: false
61
+ version: 0.6.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: money
88
64
  requirement: !ruby/object:Gem::Requirement
89
65
  none: false
90
66
  requirements:
91
67
  - - ~>
92
68
  - !ruby/object:Gem::Version
93
- version: 1.3.1
94
- - !ruby/object:Gem::Dependency
95
- type: :development
69
+ version: '5.0'
70
+ type: :runtime
71
+ prerelease: false
96
72
  version_requirements: !ruby/object:Gem::Requirement
97
73
  none: false
98
74
  requirements:
99
75
  - - ~>
100
76
  - !ruby/object:Gem::Version
101
- version: 1.3.1
102
- name: mongo
103
- prerelease: false
77
+ version: '5.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: yard
104
80
  requirement: !ruby/object:Gem::Requirement
105
81
  none: false
106
82
  requirements:
107
83
  - - ~>
108
84
  - !ruby/object:Gem::Version
109
- version: 1.3.1
110
- - !ruby/object:Gem::Dependency
85
+ version: 0.7.3
111
86
  type: :development
87
+ prerelease: false
112
88
  version_requirements: !ruby/object:Gem::Requirement
113
89
  none: false
114
90
  requirements:
115
91
  - - ~>
116
92
  - !ruby/object:Gem::Version
117
- version: 1.3.1
118
- name: bson_ext
119
- prerelease: false
93
+ version: 0.7.3
94
+ - !ruby/object:Gem::Dependency
95
+ name: mocha
120
96
  requirement: !ruby/object:Gem::Requirement
121
97
  none: false
122
98
  requirements:
123
99
  - - ~>
124
100
  - !ruby/object:Gem::Version
125
- version: 1.3.1
126
- - !ruby/object:Gem::Dependency
101
+ version: 0.9.12
127
102
  type: :development
103
+ prerelease: false
128
104
  version_requirements: !ruby/object:Gem::Requirement
129
105
  none: false
130
106
  requirements:
131
107
  - - ~>
132
108
  - !ruby/object:Gem::Version
133
109
  version: 0.9.12
134
- name: mocha
135
- prerelease: false
110
+ - !ruby/object:Gem::Dependency
111
+ name: rspec
136
112
  requirement: !ruby/object:Gem::Requirement
137
113
  none: false
138
114
  requirements:
139
115
  - - ~>
140
116
  - !ruby/object:Gem::Version
141
- version: 0.9.12
142
- - !ruby/object:Gem::Dependency
117
+ version: '2.6'
143
118
  type: :development
119
+ prerelease: false
144
120
  version_requirements: !ruby/object:Gem::Requirement
145
121
  none: false
146
122
  requirements:
147
123
  - - ~>
148
124
  - !ruby/object:Gem::Version
149
125
  version: '2.6'
150
- name: rspec
151
- prerelease: false
126
+ - !ruby/object:Gem::Dependency
127
+ name: simplecov
152
128
  requirement: !ruby/object:Gem::Requirement
153
129
  none: false
154
130
  requirements:
155
131
  - - ~>
156
132
  - !ruby/object:Gem::Version
157
- version: '2.6'
158
- - !ruby/object:Gem::Dependency
133
+ version: 0.6.1
159
134
  type: :development
135
+ prerelease: false
160
136
  version_requirements: !ruby/object:Gem::Requirement
161
137
  none: false
162
138
  requirements:
163
139
  - - ~>
164
140
  - !ruby/object:Gem::Version
165
141
  version: 0.6.1
166
- name: simplecov
167
- prerelease: false
142
+ - !ruby/object:Gem::Dependency
143
+ name: database_cleaner
168
144
  requirement: !ruby/object:Gem::Requirement
169
145
  none: false
170
146
  requirements:
171
147
  - - ~>
172
148
  - !ruby/object:Gem::Version
173
- version: 0.6.1
174
- - !ruby/object:Gem::Dependency
149
+ version: 0.9.1
175
150
  type: :development
151
+ prerelease: false
176
152
  version_requirements: !ruby/object:Gem::Requirement
177
153
  none: false
178
154
  requirements:
179
155
  - - ~>
180
156
  - !ruby/object:Gem::Version
181
- version: 0.6.7
182
- name: database_cleaner
183
- prerelease: false
157
+ version: 0.9.1
158
+ - !ruby/object:Gem::Dependency
159
+ name: pry
184
160
  requirement: !ruby/object:Gem::Requirement
185
161
  none: false
186
162
  requirements:
187
- - - ~>
163
+ - - ! '>='
188
164
  - !ruby/object:Gem::Version
189
- version: 0.6.7
190
- - !ruby/object:Gem::Dependency
165
+ version: '0'
191
166
  type: :development
167
+ prerelease: false
192
168
  version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: RedCloth
176
+ requirement: !ruby/object:Gem::Requirement
193
177
  none: false
194
178
  requirements:
195
179
  - - ~>
196
180
  - !ruby/object:Gem::Version
197
181
  version: 4.2.8
198
- name: RedCloth
182
+ type: :development
199
183
  prerelease: false
200
- requirement: !ruby/object:Gem::Requirement
184
+ version_requirements: !ruby/object:Gem::Requirement
201
185
  none: false
202
186
  requirements:
203
187
  - - ~>
@@ -213,7 +197,6 @@ extra_rdoc_files:
213
197
  - MIT-LICENSE
214
198
  - README.textile
215
199
  files:
216
- - init.rb
217
200
  - MIT-LICENSE
218
201
  - README.textile
219
202
  - lib/custom_fields/extensions/active_support.rb
@@ -221,7 +204,7 @@ files:
221
204
  - lib/custom_fields/extensions/mongoid/document.rb
222
205
  - lib/custom_fields/extensions/mongoid/factory.rb
223
206
  - lib/custom_fields/extensions/mongoid/fields/i18n.rb
224
- - lib/custom_fields/extensions/mongoid/fields/internal/localized.rb
207
+ - lib/custom_fields/extensions/mongoid/fields/localized.rb
225
208
  - lib/custom_fields/extensions/mongoid/fields.rb
226
209
  - lib/custom_fields/extensions/mongoid/relations/referenced/in.rb
227
210
  - lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
@@ -233,12 +216,17 @@ files:
233
216
  - lib/custom_fields/types/boolean.rb
234
217
  - lib/custom_fields/types/date.rb
235
218
  - lib/custom_fields/types/default.rb
219
+ - lib/custom_fields/types/email.rb
236
220
  - lib/custom_fields/types/file.rb
221
+ - lib/custom_fields/types/float.rb
237
222
  - lib/custom_fields/types/has_many.rb
223
+ - lib/custom_fields/types/integer.rb
238
224
  - lib/custom_fields/types/many_to_many.rb
225
+ - lib/custom_fields/types/money.rb
239
226
  - lib/custom_fields/types/relationship_default.rb
240
227
  - lib/custom_fields/types/select.rb
241
228
  - lib/custom_fields/types/string.rb
229
+ - lib/custom_fields/types/tags.rb
242
230
  - lib/custom_fields/types/text.rb
243
231
  - lib/custom_fields/version.rb
244
232
  - lib/custom_fields.rb
@@ -246,6 +234,7 @@ files:
246
234
  - config/locales/en.yml
247
235
  - config/locales/fr.yml
248
236
  - config/locales/pt-BR.yml
237
+ - config/locales/ru.yml
249
238
  homepage: http://github.com/locomotivecms/custom_fields
250
239
  licenses: []
251
240
  post_install_message:
@@ -257,10 +246,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
257
246
  requirements:
258
247
  - - ! '>='
259
248
  - !ruby/object:Gem::Version
249
+ version: '0'
260
250
  segments:
261
251
  - 0
262
- hash: -3490434094111046422
263
- version: '0'
252
+ hash: 633775837337620959
264
253
  required_rubygems_version: !ruby/object:Gem::Requirement
265
254
  none: false
266
255
  requirements: