tramway-core 4.1.3.1 → 4.1.3.3

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: 3996e22dd536b17253eb34170ab6338f7065488e7f421b4fb94af68fab0d3a11
4
- data.tar.gz: 849987597f7fb8651749e992610e073337f71ba21a0ced634f53e7f6291fb172
3
+ metadata.gz: a529593e57a18a84cd219057822b88d6fb0ed029b4495ffd1fc293802aace1fe
4
+ data.tar.gz: aff562047af45837b8fc31a3e13cae5f83e30537fbb6239abc0479811b1f788f
5
5
  SHA512:
6
- metadata.gz: 275c115262843a94b71703317a02a6e07dedae325d9d5c0b39e682b98c72cf69aa720926aa0428c6fafdab7a97df77dca475bcb247ce7e5891cab327734b4754
7
- data.tar.gz: e422d1be9ecefe65c38b6dfb398e3e7757930a7b145a05e1aa3b5fe0dca44a19593b9e653c0f88b03b0264669b8a604d2274072226100ec9e3b09b86b5516691
6
+ metadata.gz: 799f9693fc7ff532aa0f2db5846c72867565ed0e0fa0968d6ec0a1b21026295a58596f03e414cdca973a3adaba05373f61ab6ca03fa6affa53a82df09e986b13
7
+ data.tar.gz: 73aa841c04f0f8a76011675296ccb32064466874ab92f8f0023986b30fa94a86ab8120ba0126d5bc3e7706cfd7e222e90edd23b0f0e5ec624e2f165bf88b56b7
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
@@ -28,6 +28,10 @@ class Tramway::Core::ApplicationDecorator
28
28
  )
29
29
  end
30
30
 
31
+ def present?
32
+ object.present?
33
+ end
34
+
31
35
  def render(view, **locals)
32
36
  view_name = view.split('/').map.with_index do |dir, index|
33
37
  if index == view.split('/').length - 1
@@ -36,7 +40,7 @@ class Tramway::Core::ApplicationDecorator
36
40
  dir
37
41
  end
38
42
  end.join('/')
39
- Haml::Engine.new(File.read"#{Rails.root}/app/views/#{view_name}.html.haml").render(self, locals)
43
+ Haml::Engine.new(File.read("#{Rails.root}/app/views/#{view_name}.html.haml")).render(self, locals)
40
44
  end
41
45
 
42
46
  def listed_state_machines
@@ -44,30 +48,16 @@ class Tramway::Core::ApplicationDecorator
44
48
  end
45
49
 
46
50
  delegate :id, to: :object
47
- delegate :human_state_name, to: :object
48
51
 
49
52
  class << self
50
53
  include ::Tramway::Core::Associations::ClassHelper
51
54
  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
55
+ include ::Tramway::Core::Default::ValuesHelper
68
56
 
69
57
  def decorate(object_or_array)
70
- if object_or_array.class.superclass == ActiveRecord::Relation || object_or_array.class.to_s.include?('ActiveRecord_AssociationRelation')
58
+ is_activerecord_relation = object_or_array.class.superclass == ActiveRecord::Relation
59
+ is_activerecord_association_relation = object_or_array.class.to_s.include?('ActiveRecord_AssociationRelation')
60
+ if is_activerecord_relation || is_activerecord_association_relation
71
61
  decorated_array = object_or_array.map do |obj|
72
62
  new obj
73
63
  end
@@ -84,10 +74,6 @@ class Tramway::Core::ApplicationDecorator
84
74
  def model_name
85
75
  model_class.try(:model_name)
86
76
  end
87
-
88
- def list_filters
89
- {}
90
- end
91
77
  end
92
78
 
93
79
  def link
@@ -99,10 +85,7 @@ class Tramway::Core::ApplicationDecorator
99
85
  end
100
86
 
101
87
  def additional_buttons
102
- {
103
- show: [],
104
- index: []
105
- }
88
+ { show: [], index: [] }
106
89
  end
107
90
 
108
91
  def public_path; end
@@ -133,10 +116,6 @@ class Tramway::Core::ApplicationDecorator
133
116
  end
134
117
  end
135
118
 
136
- def yes_no(boolean_attr)
137
- boolean_attr.to_s == 'true' ? I18n.t('helpers.yes') : I18n.t('helpers.no')
138
- end
139
-
140
119
  protected
141
120
 
142
121
  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
@@ -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.1'
5
+ VERSION = '4.1.3.3'
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.1
4
+ version: 4.1.3.3
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-09-17 00:00:00.000000000 Z
12
+ date: 2022-11-07 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