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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88f57e54e293b5c5a85a88563762fd8c26df2ccbcb6eedebcb8ad1636d19ab08
4
- data.tar.gz: 721461846180ea4eb78ebdbc314029be09ff3c391c995900ef0d2a498236af62
3
+ metadata.gz: ff863d7c75ba76a10d1f9c751b9710474a16b0cd126a6974224d8cbcb26d9dd4
4
+ data.tar.gz: b890fdbb1e3a33e6dc9cac04ca8cc3d91a5c240a9337c4313b576faf44f47c7b
5
5
  SHA512:
6
- metadata.gz: b641dc9b842fb20fef05c90a73ed0007ddb9804b45cef8e6b74b2c6eea99e6610580d79450a7ef121a53a373685369addb83078e0db5e658c2129306c542c62c
7
- data.tar.gz: 7f19244857938c969c03e52d49c063d34b52e25e4aad17d9bdee41bc7d12b2e650f241ec51a2f6a90ce71ab2cc2fd5409ac5d26857c59b464d44a095632d69c8
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) == :belongs_to
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".constantize
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
@@ -12,7 +12,7 @@ class Tramway::Core::ApplicationRecord < ActiveRecord::Base
12
12
  state :removed
13
13
 
14
14
  event :remove do
15
- transition active: :remove
15
+ transition active: :removed
16
16
  end
17
17
  end
18
18
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Core
5
- VERSION = '1.18.1'
5
+ VERSION = '1.18.1.1'
6
6
  end
7
7
  end
@@ -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
@@ -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-26 00:00:00.000000000 Z
12
+ date: 2020-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: audited