soulless 0.5.0.rc2 → 0.5.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/soulless/inheritance.rb +28 -14
- data/lib/soulless/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0e8f6cd5c894c89bc43c1a35a95ecbcaeb746dd
|
4
|
+
data.tar.gz: 8bb85811fcf937a02c13c202df424e9851daa8e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f99bb3322957ba131391e8f94e7b1a25a94eddf2f4ccec9cd2270b80c9dd21d46ddd7dba532215863e8efae9f5233027692e49e0bb51df363e13952d6c1d0b5
|
7
|
+
data.tar.gz: 4c766068bb9e1f78fc9560d6fb30fba5ac77685c5b6e214df43c4aba5de494bf3cc853b11205e8c70baa1ba2eb65ca70790b0205f34a4ff41c26b630a27a770b
|
data/README.md
CHANGED
@@ -329,6 +329,8 @@ form.errors.messages # => { name: ["can't be blank"] }
|
|
329
329
|
|
330
330
|
```use_database_default``` - Use the value of the ```default``` migration option as the default value for an attribute. Accepts either a boolean (for all attributes), a string or symbol for a single attribute or an array of strings and symbols for multiple attributes.
|
331
331
|
|
332
|
+
```additional_attributes``` - Used to specify attributes that cannot automatically be added to the form model. These are generally attributes that have been specified using ```attr_accessor```. Accepts a string, symbolr or an array of strings and symbols for multiple attributes.
|
333
|
+
|
332
334
|
### I18n
|
333
335
|
|
334
336
|
Define locales similar to how you would define them in Rails.
|
data/lib/soulless/inheritance.rb
CHANGED
@@ -25,8 +25,9 @@ module Soulless
|
|
25
25
|
def get_virtus_attributes(klass, options)
|
26
26
|
attributes = []
|
27
27
|
attribute_set = klass.attribute_set
|
28
|
-
attribute_set.
|
29
|
-
|
28
|
+
attribute_names = get_attribute_names(attribute_set.map{ |a| a.options[:name] }, options)
|
29
|
+
attribute_names.each do |attribute_name|
|
30
|
+
attribute = attribute_set[attribute_name]
|
30
31
|
if include_attribute?(attribute_name, options)
|
31
32
|
attributes << {
|
32
33
|
name: attribute_name,
|
@@ -42,18 +43,21 @@ module Soulless
|
|
42
43
|
|
43
44
|
def get_active_record_attributes(klass, options)
|
44
45
|
attributes = []
|
45
|
-
|
46
|
-
|
47
|
-
if include_attribute?(
|
46
|
+
attribute_names = get_attribute_names(klass.attribute_names.dup, options)
|
47
|
+
attribute_names.each do |attribute_name|
|
48
|
+
if include_attribute?(attribute_name, options)
|
49
|
+
column = klass.columns_hash[attribute_name.to_s]
|
48
50
|
attribute = {
|
49
|
-
name:
|
50
|
-
primitive:
|
51
|
+
name: attribute_name,
|
52
|
+
primitive: String,
|
51
53
|
options: {}
|
52
54
|
}
|
53
|
-
attribute[:
|
54
|
-
|
55
|
-
(options[:use_database_default]
|
56
|
-
|
55
|
+
attribute[:primitive] = translate_primitive(column.type) if column
|
56
|
+
attribute[:options] = { default: column.default } if column &&
|
57
|
+
(options[:use_database_default] == true ||
|
58
|
+
options[:use_database_default] == attribute_name ||
|
59
|
+
(options[:use_database_default].kind_of?(Array) &&
|
60
|
+
options[:use_database_default].collect { |v| v.to_s }.include?(attribute_name)))
|
57
61
|
attributes << attribute
|
58
62
|
end
|
59
63
|
end
|
@@ -84,10 +88,12 @@ module Soulless
|
|
84
88
|
end
|
85
89
|
|
86
90
|
def translate_primitive(primitive)
|
91
|
+
return nil unless primitive
|
87
92
|
translated_primitive = primitive.to_s.capitalize
|
88
|
-
translated_primitive = Virtus::Attribute::Boolean
|
89
|
-
translated_primitive = DateTime
|
90
|
-
translated_primitive
|
93
|
+
translated_primitive = Virtus::Attribute::Boolean if translated_primitive == 'Boolean'
|
94
|
+
translated_primitive = DateTime if translated_primitive == 'Datetime'
|
95
|
+
translated_primitive = String if translated_primitive == 'Uuid'
|
96
|
+
translated_primitive
|
91
97
|
end
|
92
98
|
|
93
99
|
def include_attribute?(attribute_name, options)
|
@@ -105,6 +111,14 @@ module Soulless
|
|
105
111
|
|
106
112
|
!exclude_attributes.include?(attribute_name) && (only_attributes.empty? || only_attributes.include?(attribute_name))
|
107
113
|
end
|
114
|
+
|
115
|
+
def get_attribute_names(attributes, options)
|
116
|
+
attribute_names = attributes
|
117
|
+
attribute_names << options[:additional_attributes] if options[:additional_attributes]
|
118
|
+
attribute_names.flatten!
|
119
|
+
attribute_names.map!{ |a| a.to_s }
|
120
|
+
attribute_names
|
121
|
+
end
|
108
122
|
end
|
109
123
|
end
|
110
124
|
end
|
data/lib/soulless/version.rb
CHANGED