tramway-core 4.1.3 → 4.1.3.2

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
  SHA256:
3
- metadata.gz: 6c84e09b4acb7d9593eea58e775c5df69cd5ab2c441bf65f3a1e42667bad071d
4
- data.tar.gz: e80ee805784db8ab7b545025060a41650e0b30d8e3d02e32953346d6da1ad955
3
+ metadata.gz: 153521a03d19b366091c152c6ae00ae8aed672b056a33ab45e4ab2ee2c50f401
4
+ data.tar.gz: d90e8463f246895e6b0304b5d6be32e7985c6e13a4957f4c54ef90aa6e18531c
5
5
  SHA512:
6
- metadata.gz: 8ca4dfb010df866f974e45165428505763c9840194e70bd2f4e0a49e9bb015f5e56aa592d3444109c78994423a6562064481e4c26fa755b9b39d842e73745643
7
- data.tar.gz: 85f72f24a12cf2a62860dc5636e91a67e230962da4c08828d644a8e509a7f20ea54293fd30de10e2fb3cf4d6d4298887636cb5c8028bcd6cff47c441adcb45d7
6
+ metadata.gz: cedafd11ac58eb5b35de79fb235c5ebf5b2deb0257c3cd30c6b843fe7f38e353671d28bf72a7eb2f41f6fb5f33f65dbf9d8524da56a57dc41ee4565b7cf90487
7
+ data.tar.gz: 7b4398329d6ab326176434bed3bc30b5a274261331efd586380b0b7c1984c4c054fd057b0038511456bb8d22eeec8b6e6d1306c60f0e12a0c0b76649fcf65fae
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ![tramway-ico](https://raw.githubusercontent.com/kalashnikovisme/kalashnikovisme/master/%D1%82%D1%80%D1%8D%D0%BC%D0%B2%D1%8D%D0%B9%D0%B1%D0%B5%D0%B7%D1%84%D0%BE%D0%BD%D0%B0-min.png) Tramway::Core ![Ruby](https://github.com/Purple-Magic/tramway-core/workflows/Tests/badge.svg) ![Ruby](https://github.com/Purple-Magic/tramway-core/workflows/Rubocop/badge.svg) [![Gem Version](https://badge.fury.io/rb/tramway-core.svg)](https://badge.fury.io/rb/tramway-core)
1
+ # ![tramway-ico](https://raw.githubusercontent.com/kalashnikovisme/kalashnikovisme/master/%D1%82%D1%80%D1%8D%D0%BC%D0%B2%D1%8D%D0%B9%D0%B1%D0%B5%D0%B7%D1%84%D0%BE%D0%BD%D0%B0-min.png) Tramway::Core [![Tests](https://github.com/Purple-Magic/tramway-core/actions/workflows/tests.yml/badge.svg)](https://github.com/Purple-Magic/tramway-core/actions/workflows/tests.yml) [![Rubocop](https://github.com/Purple-Magic/tramway-core/actions/workflows/rubocop.yml/badge.svg)](https://github.com/Purple-Magic/tramway-core/actions/workflows/rubocop.yml) [![Gem Version](https://badge.fury.io/rb/tramway-core.svg)](https://badge.fury.io/rb/tramway-core)
2
2
 
3
3
  *If you need translation of this Readme, please message us kalashnikov@ulmic.ru. We'll translate for you and post to this page*
4
4
 
@@ -5,9 +5,9 @@ class Tramway::Core::ApplicationController < ActionController::Base
5
5
  before_action :load_extensions
6
6
 
7
7
  def application
8
- if ::Tramway::Core.application
9
- @application ||= Tramway::Core.application&.model_class&.first || Tramway::Core.application
10
- end
8
+ return unless ::Tramway::Core.application
9
+
10
+ @application ||= Tramway::Core.application&.model_class&.first || Tramway::Core.application
11
11
  end
12
12
 
13
13
  def load_extensions
@@ -36,7 +36,7 @@ class Tramway::Core::ApplicationDecorator
36
36
  dir
37
37
  end
38
38
  end.join('/')
39
- Haml::Engine.new(File.read"#{Rails.root}/app/views/#{view_name}.html.haml").render(self, locals)
39
+ Haml::Engine.new(File.read("#{Rails.root}/app/views/#{view_name}.html.haml")).render(self, locals)
40
40
  end
41
41
 
42
42
  def listed_state_machines
@@ -44,30 +44,16 @@ class Tramway::Core::ApplicationDecorator
44
44
  end
45
45
 
46
46
  delegate :id, to: :object
47
- delegate :human_state_name, to: :object
48
47
 
49
48
  class << self
50
49
  include ::Tramway::Core::Associations::ClassHelper
51
50
  include ::Tramway::Core::Delegating::ClassHelper
52
-
53
- def collections
54
- [:all]
55
- end
56
-
57
- def list_attributes
58
- []
59
- end
60
-
61
- def show_attributes
62
- []
63
- end
64
-
65
- def show_associations
66
- []
67
- end
51
+ include ::Tramway::Core::Default::ValuesHelper
68
52
 
69
53
  def decorate(object_or_array)
70
- if object_or_array.class.superclass == ActiveRecord::Relation || object_or_array.class.to_s.include?('ActiveRecord_AssociationRelation')
54
+ is_activerecord_relation = object_or_array.class.superclass == ActiveRecord::Relation
55
+ is_activerecord_association_relation = object_or_array.class.to_s.include?('ActiveRecord_AssociationRelation')
56
+ if is_activerecord_relation || is_activerecord_association_relation
71
57
  decorated_array = object_or_array.map do |obj|
72
58
  new obj
73
59
  end
@@ -84,10 +70,6 @@ class Tramway::Core::ApplicationDecorator
84
70
  def model_name
85
71
  model_class.try(:model_name)
86
72
  end
87
-
88
- def list_filters
89
- {}
90
- end
91
73
  end
92
74
 
93
75
  def link
@@ -99,10 +81,7 @@ class Tramway::Core::ApplicationDecorator
99
81
  end
100
82
 
101
83
  def additional_buttons
102
- {
103
- show: [],
104
- index: []
105
- }
84
+ { show: [], index: [] }
106
85
  end
107
86
 
108
87
  def public_path; end
@@ -133,10 +112,6 @@ class Tramway::Core::ApplicationDecorator
133
112
  end
134
113
  end
135
114
 
136
- def yes_no(boolean_attr)
137
- boolean_attr.to_s == 'true' ? I18n.t('helpers.yes') : I18n.t('helpers.no')
138
- end
139
-
140
115
  protected
141
116
 
142
117
  attr_reader :object
@@ -10,8 +10,9 @@ module Tramway::Core::Concerns::AttributesDecoratorHelper
10
10
  end
11
11
 
12
12
  def state_machine_view(object, attribute_name)
13
- I18n.t("state_machines.#{object.class.model_name.to_s.underscore}.#{attribute_name}.states.#{object.send(attribute_name)}")
14
- rescue
13
+ state = object.send(attribute_name)
14
+ I18n.t("state_machines.#{object.class.model_name.to_s.underscore}.#{attribute_name}.states.#{state}")
15
+ rescue StandardError
15
16
  object.aasm.human_state
16
17
  end
17
18
 
@@ -88,4 +89,8 @@ module Tramway::Core::Concerns::AttributesDecoratorHelper
88
89
  def download_button(filename:, original:)
89
90
  link_to(fa_icon(:download), src_original(original), class: 'btn btn-success', download: filename)
90
91
  end
92
+
93
+ def yes_no(boolean_attr)
94
+ boolean_attr.to_s == 'true' ? I18n.t('helpers.yes') : I18n.t('helpers.no')
95
+ end
91
96
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tramway::Core::Default::ValuesHelper
4
+ def collections
5
+ [:all]
6
+ end
7
+
8
+ def list_attributes
9
+ []
10
+ end
11
+
12
+ def show_attributes
13
+ []
14
+ end
15
+
16
+ def show_associations
17
+ []
18
+ end
19
+
20
+ def list_filters
21
+ {}
22
+ end
23
+ end
@@ -3,7 +3,7 @@
3
3
  module Tramway::Core::ApplicationForms::AssociationObjectHelpers
4
4
  def define_association_method(association, class_name)
5
5
  if class_name.is_a? Array
6
- define_polymorphic_association association, class_name
6
+ define_polymorphic_association association
7
7
  else
8
8
  self.class.send(:define_method, "#{association}=") do |value|
9
9
  model.send "#{association}_id=", value
@@ -12,19 +12,25 @@ module Tramway::Core::ApplicationForms::AssociationObjectHelpers
12
12
  end
13
13
  end
14
14
 
15
- def define_polymorphic_association(association, _class_name)
15
+ def define_polymorphic_association(association)
16
16
  self.class.send(:define_method, "#{association}=") do |value|
17
17
  if value.present?
18
- association_class = value.split('_')[0..-2].join('_').camelize
19
- association_class = association_class.constantize if association_class.is_a? String
20
- if association_class.nil?
18
+ if association_class(value).nil?
21
19
  Tramway::Error.raise_error :tramway, :core, :application_form, :initialize, :polymorphic_class_is_nil,
22
20
  association_name: association
23
21
  else
24
- model.send "#{association}=", association_class.find(value.split('_')[-1])
25
- send "#{association}_type=", association_class.to_s
22
+ model.send "#{association}=", association_class(value).find(value.split('_')[-1])
23
+ send "#{association}_type=", association_class(value).to_s
26
24
  end
27
25
  end
28
26
  end
29
27
  end
28
+
29
+ private
30
+
31
+ def association_class(value)
32
+ association_class_object = value.split('_')[0..-2].join('_').camelize
33
+ association_class_object = association_class_object.constantize if association_class_object.is_a? String
34
+ association_class_object
35
+ end
30
36
  end
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tramway::Core::ApplicationForms::Frontend
2
4
  def react_component(on = false)
3
5
  @react_component = on
4
6
  end
5
7
 
6
- def is_react_component?
8
+ def react_component?
7
9
  @react_component ||= false
10
+ @react_component
8
11
  end
9
12
  end
@@ -18,11 +18,9 @@ module Tramway::Core::ApplicationForms::SubmitHelper
18
18
  rescue ArgumentError => e
19
19
  Tramway::Error.raise_error :tramway, :core, :application_form, :save, :argument_error, message: e.message
20
20
  rescue StandardError => e
21
- if e.try :name
22
- Tramway::Error.raise_error :tramway, :core, :application_form, :save, :looks_like_you_have_method,
23
- method_name: e.name.to_s.gsub('=', ''), model_class: model.class, class_name: self.class
24
- else
25
- raise e
26
- end
21
+ raise e unless e.try :name
22
+
23
+ Tramway::Error.raise_error :tramway, :core, :application_form, :save, :looks_like_you_have_method,
24
+ method_name: e.name.to_s.gsub('=', ''), model_class: model.class, class_name: self.class
27
25
  end
28
26
  end
@@ -7,7 +7,9 @@ module Tramway::Core::Inputs::AssociationsHelper
7
7
  check_valid_association full_class_name_association
8
8
  full_class_name_association.send("#{user.role}_scope", user.id).map do |obj|
9
9
  decorator_class(full_class_name_association).decorate obj
10
- end.sort_by(&:name)
10
+ end.sort_by do |association|
11
+ association.name || "#{association.class.name} ##{association.id}"
12
+ end
11
13
  end
12
14
 
13
15
  def build_value_for_association(form_object, property, value)
@@ -14,10 +14,8 @@ module Tramway::Core::Inputs::PolymorphicAssociationsHelper
14
14
  def build_value_for_polymorphic_association(form_object, property, value)
15
15
  if form_object.send(property).present?
16
16
  "#{form_object.send(property).class.to_s.underscore}_#{form_object.send(property).id}"
17
- else
18
- if value[:type].present? && value[:id].present?
19
- "#{value[:type]&.underscore}_#{value[:id]}"
20
- end
17
+ elsif value[:type].present? && value[:id].present?
18
+ "#{value[:type]&.underscore}_#{value[:id]}"
21
19
  end
22
20
  end
23
21
 
@@ -11,9 +11,9 @@ class Tramway::Core::ApplicationRecord < ActiveRecord::Base
11
11
  scope :created_by_user, lambda { |user_id|
12
12
  joins(:audits).where('audits.action = \'create\' AND audits.user_id = ?', user_id)
13
13
  }
14
- scope :admin_scope, -> (_arg) { all }
14
+ scope :admin_scope, ->(_arg) { all }
15
15
 
16
- # FIXME remove this after testing soft-deletion
16
+ # FIXME: remove this after testing soft-deletion
17
17
  aasm column: :state do
18
18
  state :active, initial: true
19
19
  state :removed
@@ -42,7 +42,10 @@ class Tramway::Core::ApplicationRecord < ActiveRecord::Base
42
42
  end
43
43
 
44
44
  def search_by(*attributes, **associations)
45
- pg_search_scope :full_text_search, against: attributes, associated_against: associations, using: [:tsearch, :trigram]
45
+ pg_search_scope :full_text_search,
46
+ against: attributes,
47
+ associated_against: associations,
48
+ using: %i[tsearch trigram]
46
49
  end
47
50
 
48
51
  def uploader(attribute_name, uploader_name, **options)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Core
5
- VERSION = '4.1.3'
5
+ VERSION = '4.1.3.2'
6
6
  end
7
7
  end
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: 4.1.3
4
+ version: 4.1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-06-22 00:00:00.000000000 Z
12
+ date: 2022-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aasm
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: audited
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -321,6 +335,7 @@ files:
321
335
  - app/decorators/tramway/core/attributes/view_helper.rb
322
336
  - app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
323
337
  - app/decorators/tramway/core/concerns/table_builder.rb
338
+ - app/decorators/tramway/core/default/values_helper.rb
324
339
  - app/decorators/tramway/core/delegating/class_helper.rb
325
340
  - app/forms/tramway/core/application_form.rb
326
341
  - app/forms/tramway/core/application_forms/association_class_helpers.rb