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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58bfab446a9def4e9ef52b7069a1aa20ab1622e4
4
- data.tar.gz: 73318d9ab3aa9c504167f6183ce4d6c0dbe6f17f
3
+ metadata.gz: b0e8f6cd5c894c89bc43c1a35a95ecbcaeb746dd
4
+ data.tar.gz: 8bb85811fcf937a02c13c202df424e9851daa8e2
5
5
  SHA512:
6
- metadata.gz: 2e82e40de780dac51b0e50874a9c3ff26056a8218e0b7d8f6044b62170e05e587f030f88849a1c040db7a3a8bd1ed61e6d76d50b566e52c82d2ea80159c4b3f6
7
- data.tar.gz: 9ce48b1235bdaae25647dc345713b0e3e1d8440bdceef9daf51f9259669175577cd6432ba80277caf808e65e621b140153ec185f7a6efe434c47bb0d04659ab8
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.
@@ -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.each do |attribute|
29
- attribute_name = attribute.options[:name].to_s
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
- columns = klass.columns
46
- columns.each do |column|
47
- if include_attribute?(column.name, options)
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: column.name,
50
- primitive: translate_primitive(column.type),
51
+ name: attribute_name,
52
+ primitive: String,
51
53
  options: {}
52
54
  }
53
- attribute[:options] = { default: column.default } if options[:use_database_default] == true ||
54
- options[:use_database_default] == column.name ||
55
- (options[:use_database_default].kind_of?(Array) &&
56
- options[:use_database_default].collect { |v| v.to_s }.include?(column.name))
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.name if translated_primitive == 'Boolean'
89
- translated_primitive = DateTime.name if translated_primitive == 'Datetime'
90
- translated_primitive.constantize
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
@@ -1,3 +1,3 @@
1
1
  module Soulless
2
- VERSION = "0.5.0.rc2"
2
+ VERSION = "0.5.0.rc3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soulless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.rc2
4
+ version: 0.5.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Smith