tramway-core 1.17.1.1 → 1.17.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -0
- data/app/decorators/tramway/core/application_decorator.rb +4 -2
- data/app/decorators/tramway/core/associations/class_helper.rb +6 -0
- data/app/decorators/tramway/core/delegating/class_helper.rb +7 -0
- data/app/forms/tramway/core/application_form.rb +5 -30
- data/app/forms/tramway/core/extendable_form.rb +1 -1
- data/lib/tramway/core/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c40b8698ddbb5a6d4a3bcd28c91178aea7c2b69ecbd91a3aa0c1c52935acff9
|
4
|
+
data.tar.gz: fa1d9920ee66893ad98b227d48806ba71e932216f927e33124ebd0c98be4d4b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -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 =
|
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.
|
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
|
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
|
data/lib/tramway/core/version.rb
CHANGED
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.
|
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-
|
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
|