custom_fields 1.1.0.rc1 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +1 -1
- data/README.textile +14 -6
- data/config/locales/fr.yml +5 -1
- data/lib/custom_fields.rb +11 -37
- data/lib/custom_fields/extensions/carrierwave.rb +25 -0
- data/lib/custom_fields/extensions/mongoid/document.rb +12 -50
- data/lib/custom_fields/extensions/mongoid/factory.rb +20 -0
- data/lib/custom_fields/extensions/mongoid/fields.rb +29 -0
- data/lib/custom_fields/extensions/mongoid/fields/i18n.rb +53 -0
- data/lib/custom_fields/extensions/mongoid/fields/internal/localized.rb +84 -0
- data/lib/custom_fields/extensions/mongoid/relations/referenced/many.rb +29 -0
- data/lib/custom_fields/field.rb +44 -175
- data/lib/custom_fields/source.rb +333 -0
- data/lib/custom_fields/target.rb +90 -0
- data/lib/custom_fields/types/boolean.rb +26 -3
- data/lib/custom_fields/types/date.rb +36 -24
- data/lib/custom_fields/types/default.rb +44 -24
- data/lib/custom_fields/types/file.rb +35 -17
- data/lib/custom_fields/types/select.rb +184 -0
- data/lib/custom_fields/types/string.rb +25 -6
- data/lib/custom_fields/types/text.rb +35 -8
- data/lib/custom_fields/types_old/boolean.rb +13 -0
- data/lib/custom_fields/{types → types_old}/category.rb +0 -0
- data/lib/custom_fields/types_old/date.rb +49 -0
- data/lib/custom_fields/types_old/default.rb +44 -0
- data/lib/custom_fields/types_old/file.rb +27 -0
- data/lib/custom_fields/{types → types_old}/has_many.rb +0 -0
- data/lib/custom_fields/{types → types_old}/has_many/proxy_collection.rb +0 -0
- data/lib/custom_fields/{types → types_old}/has_many/reverse_lookup_proxy_collection.rb +0 -0
- data/lib/custom_fields/{types → types_old}/has_one.rb +0 -0
- data/lib/custom_fields/types_old/string.rb +13 -0
- data/lib/custom_fields/types_old/text.rb +15 -0
- data/lib/custom_fields/version.rb +1 -1
- metadata +115 -91
- data/lib/custom_fields/custom_fields_for.rb +0 -350
- data/lib/custom_fields/extensions/mongoid/relations/accessors.rb +0 -31
- data/lib/custom_fields/extensions/mongoid/relations/builders.rb +0 -30
- data/lib/custom_fields/proxy_class/base.rb +0 -112
- data/lib/custom_fields/proxy_class/builder.rb +0 -60
- data/lib/custom_fields/proxy_class/helper.rb +0 -57
- data/lib/custom_fields/self_metadata.rb +0 -30
@@ -1,60 +0,0 @@
|
|
1
|
-
module CustomFields
|
2
|
-
module ProxyClass
|
3
|
-
|
4
|
-
module Builder
|
5
|
-
|
6
|
-
# Returns the proxy class based on the current class and enhanced by the custom fields.
|
7
|
-
# If the custom fields have been modified, then a new version
|
8
|
-
# of the proxy class is built
|
9
|
-
#
|
10
|
-
# @param [ String, Symbol ] name The name of the relation in the parent object
|
11
|
-
# @param [ Document ] parent The parent document describing the custom fields
|
12
|
-
# @param [ List ] fields The list of custom fields
|
13
|
-
#
|
14
|
-
# @return [ Class ] The proxy class.
|
15
|
-
#
|
16
|
-
def to_klass_with_custom_fields(name, parent, fields)
|
17
|
-
klass = self.klass_with_custom_fields(name, parent)
|
18
|
-
|
19
|
-
if klass && klass.version != self.klass_version_with_custom_fields(name, parent) # new version ?
|
20
|
-
self.invalidate_klass_with_custom_fields(name, parent)
|
21
|
-
klass = nil
|
22
|
-
end
|
23
|
-
|
24
|
-
if klass.nil?
|
25
|
-
klass = self.build_klass_with_custom_fields(name, parent, fields)
|
26
|
-
klass_name = self.klass_name_with_custom_fields(name, parent)
|
27
|
-
|
28
|
-
Object.const_set(klass_name, klass)
|
29
|
-
end
|
30
|
-
|
31
|
-
klass
|
32
|
-
end
|
33
|
-
|
34
|
-
# Builds the proxy class based on the current class and enhanced by the custom fields.
|
35
|
-
#
|
36
|
-
# @param [ String, Symbol ] name The name of the relation in the parent object
|
37
|
-
# @param [ Document ] parent The parent document describing the custom fields
|
38
|
-
# @param [ List ] fields The list of custom fields
|
39
|
-
#
|
40
|
-
# @return [ Class ] The proxy class.
|
41
|
-
#
|
42
|
-
def build_klass_with_custom_fields(name, parent, fields)
|
43
|
-
# puts "CREATING new '#{name}' klass (#{self.klass_version_with_custom_fields(name, parent)})"
|
44
|
-
Class.new(self).tap do |klass|
|
45
|
-
klass.send :include, CustomFields::ProxyClass::Base
|
46
|
-
|
47
|
-
# copy scopes from the parent class (scopes does not inherit automatically from the parents in mongoid)
|
48
|
-
klass.write_inheritable_attribute(:scopes, self.scopes)
|
49
|
-
|
50
|
-
klass.association_name = name.to_sym
|
51
|
-
klass._parent = parent
|
52
|
-
klass.version = self.klass_version_with_custom_fields(name, parent)
|
53
|
-
|
54
|
-
[*fields].each { |field| klass.apply_custom_field(field) }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module CustomFields
|
2
|
-
module ProxyClass
|
3
|
-
|
4
|
-
module Helper
|
5
|
-
|
6
|
-
# Gets the name of the proxy class built with the custom fields.
|
7
|
-
#
|
8
|
-
# @param [ String, Symbol ] name The name of the relation in the parent object
|
9
|
-
# @param [ Document ] parent The parent document describing the custom fields
|
10
|
-
#
|
11
|
-
# @return [ String ] The class name
|
12
|
-
#
|
13
|
-
def klass_name_with_custom_fields(name, parent)
|
14
|
-
"#{name.to_s.gsub(/^_/, '').singularize.camelize}#{parent.class.name.camelize}#{parent._id}"
|
15
|
-
end
|
16
|
-
|
17
|
-
# Returns the current proxy class built with the custom fields.
|
18
|
-
#
|
19
|
-
# @param [ String, Symbol ] name The name of the relation in the parent object
|
20
|
-
# @param [ Document ] parent The parent document describing the custom fields
|
21
|
-
#
|
22
|
-
# @return [ Class ] The proxy class
|
23
|
-
#
|
24
|
-
def klass_with_custom_fields(name, parent)
|
25
|
-
klass_name = self.klass_name_with_custom_fields(name, parent)
|
26
|
-
Object.const_defined?(klass_name) ? Object.const_get(klass_name): nil
|
27
|
-
end
|
28
|
-
|
29
|
-
# Returns the version of the proxy class built with the custom fields.
|
30
|
-
#
|
31
|
-
# @param [ String, Symbol ] name The name of the relation in the parent object
|
32
|
-
# @param [ Document ] parent The parent document describing the custom fields
|
33
|
-
#
|
34
|
-
# @return [ String ] The class name
|
35
|
-
#
|
36
|
-
def klass_version_with_custom_fields(name, parent)
|
37
|
-
parent.send(:"#{name}_custom_fields_version")
|
38
|
-
end
|
39
|
-
|
40
|
-
# Destroy the class enhanced by the custom fields so that next time we need it,
|
41
|
-
# we have a fresh new one.
|
42
|
-
#
|
43
|
-
# @param [ String, Symbol ] name The name of the relation in the parent object
|
44
|
-
# @param [ Document ] parent The parent document describing the custom fields
|
45
|
-
#
|
46
|
-
def invalidate_klass_with_custom_fields(name, parent)
|
47
|
-
klass_name = self.klass_name_with_custom_fields(name, parent)
|
48
|
-
|
49
|
-
if Object.const_defined?(klass_name)
|
50
|
-
Object.send(:remove_const, klass_name)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module CustomFields
|
2
|
-
|
3
|
-
class SelfMetadata
|
4
|
-
|
5
|
-
include ::Mongoid::Document
|
6
|
-
extend CustomFields::ProxyClass::Helper
|
7
|
-
extend CustomFields::ProxyClass::Builder
|
8
|
-
|
9
|
-
## other accessors ##
|
10
|
-
attr_accessor :association_name # missing in 2.0.0 rc
|
11
|
-
|
12
|
-
protected
|
13
|
-
|
14
|
-
def parentize_with_custom_fields(object)
|
15
|
-
object_name = object.class.to_s.underscore
|
16
|
-
|
17
|
-
self.association_name = self.metadata ? self.metadata.name : self.relations[object_name].inverse_of
|
18
|
-
|
19
|
-
if !self.relations.key?(object_name)
|
20
|
-
self.singleton_class.embedded_in object_name.to_sym, :inverse_of => self.association_name
|
21
|
-
end
|
22
|
-
|
23
|
-
parentize_without_custom_fields(object)
|
24
|
-
end
|
25
|
-
|
26
|
-
alias_method_chain :parentize, :custom_fields
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|