tramway-core 1.18.1 → 1.18.1.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/app/decorators/tramway/core/associations/class_helper.rb +3 -1
- data/app/decorators/tramway/core/associations/object_helper.rb +10 -1
- data/app/models/tramway/core/application_record.rb +1 -1
- data/lib/tramway/core/version.rb +1 -1
- data/lib/tramway/error.rb +1 -0
- data/lib/yaml/errors.yml +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff863d7c75ba76a10d1f9c751b9710474a16b0cd126a6974224d8cbcb26d9dd4
|
4
|
+
data.tar.gz: b890fdbb1e3a33e6dc9cac04ca8cc3d91a5c240a9337c4313b576faf44f47c7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ae3500906ffdc568ce881fad3c6581958bfcb32d5f145242f93eac7d6710a05a0d549e734ae3542040366cc75e584846f5100bdcada8e29e9529975f6e194af
|
7
|
+
data.tar.gz: f6be135129633829f2585831fc2576a566618f023f1bc4ab15f7b96e35437c9fddc668c6fa14a02d273d3c46e8c5ee5be4149946f6df8a679fe5628c8a26d398
|
@@ -29,12 +29,14 @@ module Tramway::Core::Associations::ClassHelper
|
|
29
29
|
def define_main_association_method(association_name, decorator)
|
30
30
|
define_method association_name do
|
31
31
|
association = object.class.reflect_on_association(association_name)
|
32
|
+
return if association_type(association) == :has_one && object.send(association_name) == nil
|
33
|
+
|
32
34
|
check_association object, association_name, association
|
33
35
|
decorator_class_name = decorator || decorator_class_name(class_name(association))
|
34
36
|
if association_type(association).in? %i[has_many has_and_belongs_to_many]
|
35
37
|
return associations_collection(object, association_name, decorator_class_name)
|
36
38
|
end
|
37
|
-
return decorator_class_name.decorate object.send association_name if association_type(association)
|
39
|
+
return decorator_class_name.decorate object.send association_name if association_type(association).in? [ :belongs_to, :has_one ]
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
@@ -36,6 +36,15 @@ module Tramway::Core::Associations::ObjectHelper
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def add_association_form_class_name(object, association_name)
|
39
|
-
"Admin::#{object.class.to_s.pluralize}::Add#{association_name.to_s.camelize.singularize}Form"
|
39
|
+
form_class = "Admin::#{object.class.to_s.pluralize}::Add#{association_name.to_s.camelize.singularize}Form"
|
40
|
+
|
41
|
+
begin
|
42
|
+
form_class.constantize
|
43
|
+
rescue
|
44
|
+
Tramway::Error.raise_error(
|
45
|
+
:tramway, :core, :associations, :object_helper, :habtm_add_class_not_defined,
|
46
|
+
class: form_class, association_name: association_name
|
47
|
+
)
|
48
|
+
end
|
40
49
|
end
|
41
50
|
end
|
data/lib/tramway/core/version.rb
CHANGED
data/lib/tramway/error.rb
CHANGED
@@ -21,6 +21,7 @@ class Tramway::Error < RuntimeError
|
|
21
21
|
def raise_error(*coordinates, **options)
|
22
22
|
@errors ||= YAML.load_file("#{Tramway::Core.root}/yaml/errors.yml").with_indifferent_access
|
23
23
|
error = @errors.dig(*coordinates)
|
24
|
+
raise 'Error is not defined in YAML' unless error
|
24
25
|
options.each do |pair|
|
25
26
|
error.gsub!("%{#{pair[0]}}", pair[1].to_s)
|
26
27
|
end
|
data/lib/yaml/errors.yml
CHANGED
@@ -29,6 +29,7 @@ tramway:
|
|
29
29
|
associations:
|
30
30
|
object_helper:
|
31
31
|
please_specify_association_name: "Please, specify `%{association_name}` association class_name in %{object_class} model. For example: `has_many :%{association_name}, class_name: '%{association_class_name}'`"
|
32
|
+
habtm_add_class_not_defined: "You should define class `%{class}` to be able add and remove `%{association_name}`"
|
32
33
|
class_helper:
|
33
34
|
model_does_not_have_association: "Model %{object_class} does not have association named `%{association_name}`"
|
34
35
|
application_decorator:
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tramway-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.18.1
|
4
|
+
version: 1.18.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-04-
|
12
|
+
date: 2020-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: audited
|