mongoid-dsl 1.1.0 → 1.2.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: 07cba5496b2f12f68d75578a881013f36b133288
4
- data.tar.gz: 478b9e6aea688f647d828e4c165f79c6d2fba26b
3
+ metadata.gz: 928b2c13156001ffe932ffa4201615a28104110b
4
+ data.tar.gz: e6600e3388d6de69f86435e48b4cdc4c9574da34
5
5
  SHA512:
6
- metadata.gz: 61812e613671a67fd4c76bfb4e8d00194782f230b374828859bc53f8357d034f695b71c13dc03b60710e9a7ca8de2d6cfb8823a6ce0227a093a05010b3c028b5
7
- data.tar.gz: f791fc0ff404285a5b5a1e372119f6b3bbba55666170ff4d47c8dfd1de99485b4eea0da53e6c22d7de633f111197e45daf4814d017ecdf2ea425a2ee1ea4f399
6
+ metadata.gz: 19438b72f6df2eb261fc584c57f73bb0e1fa7b259d14335f124a0e7882aa5028fbc9f528e921c84c9a081499ac403fa91b1abf18d27db7eefaead3946fefa293
7
+ data.tar.gz: 94b87661afaefde981345e4c43ae887c5308736b39d80649f33e17df56772dfa54677e6ec6ea692e8d748551d165fae80fbb2f587617cdc3d482d00ef8989dba
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -187,23 +187,73 @@ end
187
187
 
188
188
  field.instance_variable_get('@options')[:hidden]= field.instance_variable_get('@options').delete(name_to_use)
189
189
 
190
- model.instance_eval do
190
+ if value
191
+ model.instance_eval do
192
+
193
+ begin
194
+ self.class_variable_get(:@@mongoid_dsl_hidden_fields)
195
+ rescue NameError
191
196
 
192
- begin
193
- self.class_variable_get(:@@mongoid_dsl_hidden_fields)
194
- rescue NameError
197
+ self.class_variable_set :@@mongoid_dsl_hidden_fields, []
198
+ [:hidden,:hide].each { |sym| scope sym, -> { without(*self.class_variable_get(:@@mongoid_dsl_hidden_fields)) } }
195
199
 
196
- self.class_variable_set :@@mongoid_dsl_hidden_fields, []
197
- [:hidden,:hide].each { |sym| scope sym, -> { without(*self.class_variable_get(:@@mongoid_dsl_hidden_fields)) } }
200
+ unless default_scoping?
201
+ default_scope -> { hidden }
202
+ end
198
203
 
199
- unless default_scoping?
200
- default_scope -> { hidden }
201
204
  end
202
205
 
206
+ self.class_variable_get(:@@mongoid_dsl_hidden_fields).push(field.instance_variable_get(:@name)) if !!value
207
+
203
208
  end
209
+ end
210
+
211
+ end
212
+ end
213
+
214
+ [:index].each do |name_to_use|
215
+ Mongoid::Fields.option name_to_use do |model, field, value|
216
+
217
+ field.instance_variable_get('@options')[:index]= field.instance_variable_get('@options').delete(name_to_use)
218
+
219
+ if value
220
+ model.instance_eval do
221
+
222
+ begin
223
+ self.class_variable_get(:@@mongoid_dsl_index_fields)
224
+ rescue NameError
225
+ self.class_variable_set :@@mongoid_dsl_index_fields, [{},{}]
226
+ end
227
+
228
+ case
229
+
230
+ when value.class <= Hash
231
+ self.class_variable_get(:@@mongoid_dsl_index_fields)[0].merge!(value)
232
+
233
+ when value.class <= Array
234
+ 2.times do |index_number|
235
+ if value[index_number].class <= Hash
236
+ self.class_variable_get(:@@mongoid_dsl_index_fields)[index_number].merge!(value[index_number])
237
+ end
238
+ end
204
239
 
205
- self.class_variable_get(:@@mongoid_dsl_hidden_fields).push(field.instance_variable_get(:@name)) if !!value
240
+ when value.class <= TrueClass
241
+ self.class_variable_get(:@@mongoid_dsl_index_fields)[0].merge!(
242
+ {field.instance_variable_get(:@name) => 1}
243
+ )
206
244
 
245
+ when value.class <= Numeric && (-1..1).include?(value)
246
+ self.class_variable_get(:@@mongoid_dsl_index_fields)[0].merge!(
247
+ {field.instance_variable_get(:@name) => value}
248
+ )
249
+
250
+ end
251
+
252
+ if self.class_variable_get(:@@mongoid_dsl_index_fields)[0].respond_to?(:empty?) && !self.class_variable_get(:@@mongoid_dsl_index_fields)[0].empty?
253
+ index(*(self.class_variable_get(:@@mongoid_dsl_index_fields).select{|e| e.respond_to?(:empty?) && !e.empty? }))
254
+ end
255
+
256
+ end
207
257
  end
208
258
 
209
259
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi