tramway-core 1.17.1.1 → 1.17.2

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: 4be07671b875ed3901b13904f9d54f3915ab5c4c42d637609a25bebee8b233a0
4
- data.tar.gz: 77d1050db409315611f0fda8586c20cd15aa9b85e49d23f86ebc995556e420da
3
+ metadata.gz: 0c40b8698ddbb5a6d4a3bcd28c91178aea7c2b69ecbd91a3aa0c1c52935acff9
4
+ data.tar.gz: fa1d9920ee66893ad98b227d48806ba71e932216f927e33124ebd0c98be4d4b3
5
5
  SHA512:
6
- metadata.gz: 875d00ccf2b6cdfa9bdb7fb64ab77b60b517be9f4ae24f856b5e79e2e90c068d97f074ea4df90b70f70457dbbbd955525d850f3f6a5939ba404eec020d144fc6
7
- data.tar.gz: 3c0ffdef1b9dba8d41353908a82d2841879b9490d191e10ca017ed16d6b14bbabceeb5da27318dbf1939203820eed1d3227980e59f0410864e74785e48d85f68
6
+ metadata.gz: 289701396c7578d7202d1bbf7bcfd794e360ef258c0396b82b98eacc76049a974a75e122a63e48893bb1cc8fd966e921c0fcc8a642c7dcfde2e45c8bb39b1eb7
7
+ data.tar.gz: f69609928571b316461d3ddf7d25fc59b5abadb0d0d788c53572d146be06f585400a8736f44d64adab5b7935eca4c3e6387086890f3e3ee2a47bb3f80c1896e6
data/README.md CHANGED
@@ -33,7 +33,53 @@ Tramway::Core.initialize_application model_class: ::Tramway::Conference::Unity #
33
33
  Rails.application.config.assets.precompile += %w( *.jpg *.png *.js )
34
34
  ```
35
35
  # Usage
36
+
36
37
  ## Decorators
38
+ ### Associations
39
+
40
+ Your can decorate association models. Supporting all types of association
41
+
42
+ *app/decorators/your_model_decorator.rb*
43
+ ```ruby
44
+ class YourModelDecorator < Tramway::Core::ApplicationDecorator
45
+ decorate_association :some_model
46
+ decorate_association :another_model, decorator: SpecificDecoratorForThisCase
47
+ decorate_association :another_one_model, as: :repeat_here_as_parameter_from_model
48
+ decorate_association :something_else_model, state_machines: [ :here_array_of_state_machines_you_want_to_see_in_YourModel_show_page ] # support from tramway-admin gem
49
+ end
50
+ ```
51
+
52
+ You can decorate a lot of models in one line
53
+
54
+ *app/decorators/your_model_decorator.rb*
55
+ ```ruby
56
+ class YourModelDecorator < Tramway::Core::ApplicationDecorator
57
+ decorate_associations :some_model, :another_model, :another_one_model, :something_else_model
58
+ end
59
+ ```
60
+
61
+ Also, you can configurate what associations you want to see in YourModel page in admin panel *support only for [tramway-admin](https://rubygems.org/gems/tramway-admin) gem*
62
+
63
+ *app/decorators/your_model_decorator.rb*
64
+ ```ruby
65
+ class YourModelDecorator < Tramway::Core::ApplicationDecorator
66
+ class << self
67
+ def show_associations
68
+ [ :some_model, :another_model, :another_one_model ]
69
+ end
70
+ end
71
+ end
72
+ ```
73
+
74
+ ### Delegating attributes
75
+
76
+ *app/decorators/your_model_decorator.rb*
77
+ ```ruby
78
+ class YourModelDecorator < Tramway::Core::ApplicationDecorator
79
+ delegate_attributes :title, :something_else, :another_atttribute
80
+ end
81
+ ```
82
+
37
83
  ### Helper methods
38
84
 
39
85
  #### date_view
@@ -22,8 +22,12 @@ class Tramway::Core::ApplicationDecorator
22
22
  raise error.message
23
23
  end
24
24
 
25
+ delegate :id, to: :object
26
+ delegate :human_state_name, to: :object
27
+
25
28
  class << self
26
29
  include ::Tramway::Core::Associations::ClassHelper
30
+ include ::Tramway::Core::Delegating::ClassHelper
27
31
 
28
32
  def collections
29
33
  [:all]
@@ -61,8 +65,6 @@ class Tramway::Core::ApplicationDecorator
61
65
  end
62
66
  end
63
67
 
64
- delegate :id, to: :object
65
- delegate :human_state_name, to: :object
66
68
 
67
69
  def link
68
70
  if object.try :file
@@ -18,6 +18,12 @@ module Tramway::Core::Associations::ClassHelper
18
18
  end
19
19
  end
20
20
 
21
+ def decorate_associations(*association_names)
22
+ association_names.each do |association_name|
23
+ decorate_association association_name
24
+ end
25
+ end
26
+
21
27
 
22
28
  def define_main_association_method(association_name, decorator)
23
29
  define_method association_name do
@@ -0,0 +1,7 @@
1
+ module Tramway::Core::Delegating::ClassHelper
2
+ def delegate_attributes(*attributes)
3
+ attributes.each do |attr|
4
+ delegate attr, to: :object
5
+ end
6
+ end
7
+ end
@@ -12,11 +12,13 @@ module Tramway::Core
12
12
  self.class.full_class_name_associations.each do |association, class_name|
13
13
  if class_name.is_a? Array
14
14
  self.class.send(:define_method, "#{association}=") do |value|
15
- association_class = send("#{association}_type")
15
+ association_class = value.split('_')[0..-2].join('_').camelize
16
+ association_class = association_class.constantize if association_class.is_a? String
16
17
  if association_class.nil?
17
18
  raise Tramway::Error.new(plugin: :core, method: :initialize, message: 'Polymorphic association class is nil. Maybe, you should write `assocation #{association_name}` after `properties #{association_name}_id, #{association_name}_type`')
18
19
  else
19
- super association_class.constantize.find value
20
+ super association_class.find value.split('_')[-1]
21
+ send "#{association}_type=", association_class.to_s
20
22
  end
21
23
  end
22
24
  else
@@ -34,28 +36,19 @@ module Tramway::Core
34
36
  if params
35
37
  if validate params
36
38
  begin
37
- save.tap do
38
- # self.class.remove_validations_from_model!
39
- end
39
+ save
40
40
  rescue StandardError => e
41
- # self.class.remove_validations_from_model!
42
41
  error = Tramway::Error.new(plugin: :core, method: :submit, message: "Looks like you have method `#{e.name.to_s.gsub('=', '')}` in #{@@model_class}. You should rename it or rename property in #{self.class}")
43
42
  raise error.message
44
43
  end
45
44
  else
46
- association_error = false
47
45
  @@associations.each do |association|
48
46
  if errors.details[association] == [{ error: :blank }]
49
47
  model.send("#{association}=", send(association))
50
- association_error = true
51
48
  end
52
49
  end
53
- (association_error && save).tap do
54
- # self.class.remove_validations_from_model!
55
- end
56
50
  end
57
51
  else
58
- # self.class.remove_validations_from_model!
59
52
  error = Tramway::Error.new(plugin: :core, method: :submit, message: 'ApplicationForm::Params should not be nil')
60
53
  raise error.message
61
54
  end
@@ -180,25 +173,7 @@ module Tramway::Core
180
173
  raise error.message
181
174
  end
182
175
  @@model_class.validates attribute, **options
183
- # @@validations ||= {}
184
- # @@validations.deep_merge! attribute => options
185
176
  end
186
-
187
- # FIXME: Removes all validations in a field. We must implement own validations
188
-
189
- # def remove_validations_from_model!
190
- # return unless defined? @@validations
191
- # @@validations&.each do |validation|
192
- # @@model_class.class_eval do
193
- # _validators.except validation[0]
194
- #
195
- # binding.pry
196
- # _validate_callbacks.each do |callback|
197
- # callback.raw_filter.attributes.delete validation[0]
198
- # end
199
- # end
200
- # end
201
- # end
202
177
  end
203
178
  end
204
179
  end
@@ -19,7 +19,7 @@ class Tramway::Core::ExtendableForm
19
19
  model.values = extended_params.permit!.to_h.reduce(model.values) do |hash, pair|
20
20
  hash.merge! pair[0] => pair[1]
21
21
  end
22
- super params
22
+ super(params) && model.errors.empty?
23
23
  end
24
24
 
25
25
  define_method 'properties' do
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Core
5
- VERSION = '1.17.1.1'
5
+ VERSION = '1.17.2'
6
6
  end
7
7
  end
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.17.1.1
4
+ version: 1.17.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-12 00:00:00.000000000 Z
11
+ date: 2020-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: audited
@@ -358,6 +358,7 @@ files:
358
358
  - app/decorators/tramway/core/associations/class_helper.rb
359
359
  - app/decorators/tramway/core/associations/object_helper.rb
360
360
  - app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
361
+ - app/decorators/tramway/core/delegating/class_helper.rb
361
362
  - app/forms/tramway/core/application_form.rb
362
363
  - app/forms/tramway/core/extendable_form.rb
363
364
  - app/forms/tramway/core/extended_application_form.rb