custom_fields 1.0.0.beta.20 → 1.0.0.beta.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,15 +5,15 @@ module CustomFields
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- cattr_accessor :custom_fields
8
+ cattr_accessor :_custom_fields_for
9
9
 
10
- self.custom_fields = []
10
+ self._custom_fields_for = []
11
11
  end
12
12
 
13
13
  module InstanceMethods
14
14
 
15
- def custom_fields?(collection_name)
16
- self.class.custom_fields?(collection_name)
15
+ def custom_fields_for?(collection_name)
16
+ self.class.custom_fields_for?(collection_name)
17
17
  end
18
18
 
19
19
  def clone_metadata_for_custom_fields(metadata)
@@ -57,8 +57,8 @@ module CustomFields
57
57
  #
58
58
  module ClassMethods
59
59
 
60
- def custom_fields?(collection_name)
61
- self.custom_fields.include?(collection_name.to_s)
60
+ def custom_fields_for?(collection_name)
61
+ self._custom_fields_for.include?(collection_name.to_s)
62
62
  end
63
63
 
64
64
  def custom_fields_for(collection_name)
@@ -81,7 +81,7 @@ module CustomFields
81
81
  end
82
82
 
83
83
  # record the collection_name
84
- self.custom_fields << collection_name.to_s
84
+ self._custom_fields_for << collection_name.to_s
85
85
 
86
86
  # common part
87
87
  class_eval <<-EOV
@@ -143,15 +143,17 @@ module CustomFields
143
143
  EOV
144
144
 
145
145
  # mongoid tiny patch: for performance optimization (ie: we do want to invalidate klass with custom fields every time we save a field)
146
- unless instance_methods.include?('write_attributes_with_custom_fields')
146
+ unless instance_methods.collect(&:to_s).include?('write_attributes_with_custom_fields')
147
+
147
148
  class_eval do
148
- def write_attributes_with_custom_fields(attrs = nil)
149
+ def write_attributes_with_custom_fields(attrs = nil, guard_protected_attributes = true)
149
150
  self.instance_variable_set(:@_writing_attributes_with_custom_fields, true)
150
- self.write_attributes_without_custom_fields(attrs)
151
+ self.write_attributes_without_custom_fields(attrs, guard_protected_attributes)
151
152
  end
152
153
 
153
154
  alias_method_chain :write_attributes, :custom_fields
154
155
  end
156
+
155
157
  end
156
158
 
157
159
  if itself
@@ -16,7 +16,7 @@ module Mongoid # :nodoc:
16
16
  #
17
17
  # @since 2.0.0.rc.1
18
18
  def create_relation_with_custom_fields(object, metadata)
19
- if self.respond_to?(:custom_fields?) && self.custom_fields?(metadata.name)
19
+ if self.respond_to?(:custom_fields_for?) && self.custom_fields_for?(metadata.name)
20
20
  metadata = self.clone_metadata_for_custom_fields(metadata)
21
21
  end
22
22
 
@@ -9,7 +9,7 @@ module Mongoid # :nodoc:
9
9
  def builder_with_custom_fields(name, metadata)
10
10
  tap do
11
11
  define_method("build_#{name}") do |*args|
12
- if self.custom_fields?(metadata.name)
12
+ if self.custom_fields_for?(metadata.name)
13
13
  metadata = self.clone_metadata_for_custom_fields(metadata)
14
14
  end
15
15
 
@@ -71,9 +71,12 @@ module CustomFields
71
71
  return unless field.valid?
72
72
  end
73
73
 
74
- (self.custom_fields ||= []) << field
74
+ self.custom_fields ||= []
75
75
 
76
- field.apply(self)
76
+ if self.lookup_custom_field(field._name).nil?
77
+ self.custom_fields << field
78
+ field.apply(self)
79
+ end
77
80
  end
78
81
 
79
82
  def self.lookup_custom_field(name)
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module CustomFields
3
- VERSION = "1.0.0.beta.20"
3
+ VERSION = "1.0.0.beta.21"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_fields
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196395
5
4
  prerelease: 6
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- - beta
11
- - 20
12
- version: 1.0.0.beta.20
5
+ version: 1.0.0.beta.21
13
6
  platform: ruby
14
7
  authors:
15
8
  - Didier Lafforgue
@@ -17,40 +10,31 @@ autorequire:
17
10
  bindir: bin
18
11
  cert_chain: []
19
12
 
20
- date: 2011-07-01 00:00:00 Z
13
+ date: 2011-07-03 00:00:00 +02:00
14
+ default_executable:
21
15
  dependencies:
22
16
  - !ruby/object:Gem::Dependency
23
17
  name: mongoid
24
- prerelease: false
25
- type: :runtime
26
- version_requirements: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &id001 !ruby/object:Gem::Requirement
27
19
  none: false
28
20
  requirements:
29
21
  - - "="
30
22
  - !ruby/object:Gem::Version
31
- hash: 11
32
- segments:
33
- - 2
34
- - 0
35
- - 2
36
23
  version: 2.0.2
37
- requirement: *id001
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
38
27
  - !ruby/object:Gem::Dependency
39
28
  name: activesupport
40
- prerelease: false
41
- type: :runtime
42
- version_requirements: &id002 !ruby/object:Gem::Requirement
29
+ requirement: &id002 !ruby/object:Gem::Requirement
43
30
  none: false
44
31
  requirements:
45
- - - ">="
32
+ - - ~>
46
33
  - !ruby/object:Gem::Version
47
- hash: 9
48
- segments:
49
- - 3
50
- - 0
51
- - 7
52
- version: 3.0.7
53
- requirement: *id002
34
+ version: 3.0.9
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
54
38
  description: Manage custom fields to a mongoid document or a collection. This module is one of the core features we implemented in our custom cms named Locomotive.
55
39
  email:
56
40
  - didier@nocoffee.fr
@@ -87,6 +71,7 @@ files:
87
71
  - config/locales/en.yml
88
72
  - config/locales/fr.yml
89
73
  - config/locales/pt-BR.yml
74
+ has_rdoc: true
90
75
  homepage: http://github.com/locomotivecms/custom_fields
91
76
  licenses: []
92
77
 
@@ -100,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
85
  requirements:
101
86
  - - ">="
102
87
  - !ruby/object:Gem::Version
103
- hash: 3
88
+ hash: -3396321950106991976
104
89
  segments:
105
90
  - 0
106
91
  version: "0"
@@ -109,16 +94,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
94
  requirements:
110
95
  - - ">="
111
96
  - !ruby/object:Gem::Version
112
- hash: 23
113
- segments:
114
- - 1
115
- - 3
116
- - 6
117
97
  version: 1.3.6
118
98
  requirements: []
119
99
 
120
100
  rubyforge_project: nowarning
121
- rubygems_version: 1.8.5
101
+ rubygems_version: 1.6.2
122
102
  signing_key:
123
103
  specification_version: 3
124
104
  summary: Custom fields extension for Mongoid