custom_fields 2.1.0.rc2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,10 +20,12 @@ module CustomFields
20
20
  end
21
21
 
22
22
  require 'custom_fields/version'
23
+ require 'custom_fields/extensions/active_support'
23
24
  require 'custom_fields/extensions/carrierwave'
24
25
  require 'custom_fields/extensions/mongoid/document'
25
26
  require 'custom_fields/extensions/mongoid/factory'
26
27
  require 'custom_fields/extensions/mongoid/relations/referenced/many'
28
+ require 'custom_fields/extensions/mongoid/relations/referenced/in'
27
29
  require 'custom_fields/extensions/mongoid/fields.rb'
28
30
  require 'custom_fields/extensions/mongoid/fields/i18n.rb'
29
31
  require 'custom_fields/extensions/mongoid/fields/internal/localized.rb'
@@ -1,12 +1,28 @@
1
- unless ActiveSupport::Callbacks::ClassMethods.method_defined?(:without_callback)
1
+ class String
2
2
 
3
- module ActiveSupport::Callbacks::ClassMethods
4
- def without_callback(*args, &block)
5
- skip_callback(*args)
6
- yield.tap do |result|
7
- set_callback(*args)
3
+ def constantize_with_custom_fields
4
+ begin
5
+ constantize_without_custom_fields
6
+ rescue NameError => exception
7
+ # DEBUG: puts "constantizing #{self.inspect}"
8
+ # alright, does it look like a custom_fields dynamic klass ?
9
+ if self =~ /(.*)([0-9a-fA-F]{24})$/
10
+ base = $1.constantize
11
+ # we can know it for sure
12
+ if base.with_custom_fields?
13
+ relation = base.relations.values.detect { |metadata| metadata[:custom_fields_parent_klass] == true }
14
+
15
+ # load the class which holds the recipe to build the dynamic klass
16
+ if relation && parent_instance = relation.klass.find($2)
17
+ # DEBUG: puts "re-building #{self}"
18
+ return parent_instance.klass_with_custom_fields(relation.inverse_of)
19
+ end
20
+ end
8
21
  end
22
+ # not a custom_fields dynamic klass or unable to re-build it
23
+ raise exception
9
24
  end
10
25
  end
11
26
 
27
+ alias_method_chain :constantize, :custom_fields
12
28
  end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ module Mongoid # :nodoc:
3
+ module Relations #:nodoc:
4
+ module Referenced #:nodoc:
5
+
6
+ class In < Relations::One
7
+
8
+ class << self
9
+
10
+ def valid_options
11
+ [:autosave, :foreign_key, :index, :polymorphic, :custom_fields_parent_klass]
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -63,7 +63,7 @@ module CustomFields
63
63
  #
64
64
  def custom_fields_recipe_for(name)
65
65
  {
66
- 'name' => "#{name.to_s.classify}#{self._id}",
66
+ 'name' => "#{self.relations[name.to_s].class_name.demodulize}#{self._id}",
67
67
  'rules' => self.ordered_custom_fields(name).map(&:to_recipe),
68
68
  'version' => self.custom_fields_version(name)
69
69
  }
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module CustomFields #:nodoc
3
3
 
4
- VERSION = '2.1.0.rc2'
4
+ VERSION = '2.1.0'
5
5
 
6
6
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_fields
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 2.1.0.rc2
4
+ 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-01-06 00:00:00.000000000 Z
12
+ date: 2013-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :runtime
@@ -223,6 +223,7 @@ files:
223
223
  - lib/custom_fields/extensions/mongoid/fields/i18n.rb
224
224
  - lib/custom_fields/extensions/mongoid/fields/internal/localized.rb
225
225
  - lib/custom_fields/extensions/mongoid/fields.rb
226
+ - lib/custom_fields/extensions/mongoid/relations/referenced/in.rb
226
227
  - lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
227
228
  - lib/custom_fields/field.rb
228
229
  - lib/custom_fields/source.rb
@@ -258,7 +259,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
258
259
  - !ruby/object:Gem::Version
259
260
  segments:
260
261
  - 0
261
- hash: -956939138895304007
262
+ hash: -3490434094111046422
262
263
  version: '0'
263
264
  required_rubygems_version: !ruby/object:Gem::Requirement
264
265
  none: false