soulless 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/soulless/inheritance.rb +15 -13
- data/lib/soulless/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5f1fdf92746ec9e608ea04972dc9bccca8e7dbb
|
4
|
+
data.tar.gz: 4f85870777d309a49b95e1183537cfde8fb5abca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76939041a34437f9cda7a52bde28c203f11964f29404ae1c6e5714e340594331f31449eadba64fc17320fe0bfd10258496d96f8277c02f8412045145e9279d6a
|
7
|
+
data.tar.gz: 3c03f011a6027fd83c33a26044f62fde6dbb81401cb2f0dbb9ce5b11edfaf93aa06d02b8ca1b2a2abd3d60fc34ecf3bfe6b90d6d1f3db599b56ee22836896f92
|
data/lib/soulless/inheritance.rb
CHANGED
@@ -4,7 +4,7 @@ module Soulless
|
|
4
4
|
base.instance_eval do
|
5
5
|
def inherit_from(klass, options = {})
|
6
6
|
attributes = get_attributes(klass, options)
|
7
|
-
|
7
|
+
|
8
8
|
attributes.each do |attribute|
|
9
9
|
self.attribute(attribute[:name], attribute[:primitive], attribute[:options])
|
10
10
|
if Object.const_defined?('ActiveModel'.to_sym) && klass.ancestors.include?(ActiveModel::Validations)
|
@@ -12,7 +12,7 @@ module Soulless
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
private
|
17
17
|
def get_attributes(klass, options)
|
18
18
|
if klass.ancestors.include?(Virtus::Model::Core)
|
@@ -21,7 +21,7 @@ module Soulless
|
|
21
21
|
get_active_record_attributes(klass, options)
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def get_virtus_attributes(klass, options)
|
26
26
|
attributes = []
|
27
27
|
attribute_set = klass.attribute_set
|
@@ -40,7 +40,7 @@ module Soulless
|
|
40
40
|
end
|
41
41
|
attributes
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def get_active_record_attributes(klass, options)
|
45
45
|
attributes = []
|
46
46
|
attribute_names = get_attribute_names(klass.attribute_names.dup, options)
|
@@ -53,7 +53,7 @@ module Soulless
|
|
53
53
|
options: {}
|
54
54
|
}
|
55
55
|
attribute[:primitive] = translate_primitive(column.type) if column
|
56
|
-
attribute[:options] = { default: column.default } if column &&
|
56
|
+
attribute[:options] = { default: column.default } if column &&
|
57
57
|
(options[:use_database_default] == true ||
|
58
58
|
options[:use_database_default] == attribute_name ||
|
59
59
|
(options[:use_database_default].kind_of?(Array) &&
|
@@ -63,7 +63,7 @@ module Soulless
|
|
63
63
|
end
|
64
64
|
attributes
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def setup_validators(attribute_name, klass, options)
|
68
68
|
return if skip_validators?(attribute_name, options) || !include_attribute?(attribute_name, options)
|
69
69
|
klass.validators.each do |validator|
|
@@ -82,13 +82,15 @@ module Soulless
|
|
82
82
|
# environment without a database. It's
|
83
83
|
# necessary to convert to an ActiveModel
|
84
84
|
# validation.
|
85
|
-
|
85
|
+
if validator_class.name =~ /\AActiveRecord/
|
86
|
+
validator_class = "ActiveModel::Validations::#{validator_class.name.split('::').last}".constantize
|
87
|
+
end
|
86
88
|
end
|
87
89
|
validates_with(validator_class, { attributes: attribute_name }.merge(validator_options))
|
88
90
|
end
|
89
91
|
end
|
90
92
|
end
|
91
|
-
|
93
|
+
|
92
94
|
def get_attribute_names(attributes, options)
|
93
95
|
attribute_names = attributes
|
94
96
|
attribute_names << options[:additional_attributes] if options[:additional_attributes]
|
@@ -96,7 +98,7 @@ module Soulless
|
|
96
98
|
attribute_names.map!{ |a| a.to_s }
|
97
99
|
attribute_names
|
98
100
|
end
|
99
|
-
|
101
|
+
|
100
102
|
def translate_primitive(primitive)
|
101
103
|
return nil unless primitive
|
102
104
|
translated_primitive = primitive.to_s.capitalize
|
@@ -105,7 +107,7 @@ module Soulless
|
|
105
107
|
translated_primitive = String if translated_primitive == 'Uuid'
|
106
108
|
translated_primitive
|
107
109
|
end
|
108
|
-
|
110
|
+
|
109
111
|
def include_attribute?(attribute_name, options)
|
110
112
|
# Attributes we don't want to inherit
|
111
113
|
exclude_attributes = ['id']
|
@@ -118,10 +120,10 @@ module Soulless
|
|
118
120
|
only_attributes << options[:only] if options[:only]
|
119
121
|
only_attributes.flatten!
|
120
122
|
only_attributes.collect!{ |v| v.to_s }
|
121
|
-
|
123
|
+
|
122
124
|
!exclude_attributes.include?(attribute_name) && (only_attributes.empty? || only_attributes.include?(attribute_name))
|
123
125
|
end
|
124
|
-
|
126
|
+
|
125
127
|
def skip_validators?(attribute_name, options)
|
126
128
|
return true if options[:skip_validators] == true
|
127
129
|
skip_validators = []
|
@@ -133,4 +135,4 @@ module Soulless
|
|
133
135
|
end
|
134
136
|
end
|
135
137
|
end
|
136
|
-
end
|
138
|
+
end
|
data/lib/soulless/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soulless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|