tramway-core 1.6.3 → 1.6.4
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7a31d83fb7b26555a3b8576ca1b95e411be1b37cdf17a06fd799e2a07623201
|
4
|
+
data.tar.gz: 0f6f62ec9a9e36575747947c55932dedbab9292c77e05012d5dd66020f29aa8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d5166de9d1a332ccc120d027d6563c93fcbdbb499236bf01e8019add7cdb3900e72c3551a5c0761fcd0b0f1169b1511a24e5d1c13fa9149cc078bc4f0283b55
|
7
|
+
data.tar.gz: ffa7418423d002e5efb9809db865bdcd6132d92485968f79876ba729bcfc1f05d5c0ad41f1f2236e0c6e9c127b41e29b9f02ea7093a933e42249cc09b05d48d5
|
@@ -27,14 +27,20 @@ class Tramway::Core::ApplicationDecorator
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def decorate_association(association_name)
|
30
|
+
def decorate_association(association_name, decorator: nil)
|
31
31
|
@@decorated_associations ||= []
|
32
32
|
@@decorated_associations << association_name
|
33
33
|
|
34
34
|
define_method association_name do
|
35
35
|
class_name = object.class.reflect_on_association(association_name).options[:class_name]
|
36
|
-
|
37
|
-
|
36
|
+
#FIXME use error abstraction
|
37
|
+
unless class_name
|
38
|
+
raise "Please, specify `#{association_name}` association class_name in #{object.class} model. For example: `has_many :#{association_name}, class_name: 'ModelName'`"
|
39
|
+
end
|
40
|
+
|
41
|
+
object.send(association_name).active.map do |association_object|
|
42
|
+
decorator_class_name = decorator || "#{class_name.singularize}Decorator".constantize
|
43
|
+
decorator_class_name.decorate association_object
|
38
44
|
end
|
39
45
|
end
|
40
46
|
end
|
@@ -5,13 +5,7 @@ module Tramway::Core
|
|
5
5
|
@@model_class = object.class
|
6
6
|
@@enumerized_attributes = object.class.enumerized_attributes
|
7
7
|
|
8
|
-
|
9
|
-
options = object.class.reflect_on_all_associations(:belongs_to).select do |a|
|
10
|
-
a.name == association.to_sym
|
11
|
-
end.first&.options
|
12
|
-
next unless options
|
13
|
-
|
14
|
-
class_name = options[:class_name].constantize
|
8
|
+
self.class.full_class_name_associations.each do |association, class_name|
|
15
9
|
self.class.send(:define_method, "#{association}=") do |value|
|
16
10
|
super class_name.find value
|
17
11
|
end
|
@@ -40,6 +34,26 @@ module Tramway::Core
|
|
40
34
|
@@associations ||= []
|
41
35
|
@@associations << property
|
42
36
|
end
|
37
|
+
|
38
|
+
def associations(*properties)
|
39
|
+
properties.each do |property|
|
40
|
+
association property
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def full_class_name_associations
|
45
|
+
@@associations&.reduce({}) do |hash, association|
|
46
|
+
options = @@model_class.reflect_on_all_associations(:belongs_to).select do |a|
|
47
|
+
a.name == association.to_sym
|
48
|
+
end.first&.options
|
49
|
+
|
50
|
+
options ? hash.merge!(association => options[:class_name].constantize) : hash
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def full_class_name_association(association_name)
|
55
|
+
full_class_name_associations[association_name]
|
56
|
+
end
|
43
57
|
|
44
58
|
def enumerized_attributes
|
45
59
|
@@enumerized_attributes
|
data/lib/tramway/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tramway-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reform-rails
|