rails-add_ons 1.2.0 → 1.3.0

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
  SHA1:
3
- metadata.gz: 18e80cea0b380e67e927007dcd7b2949f87630bf
4
- data.tar.gz: ff99fe37e0bfecbf4c587856172bd50e6bb75304
3
+ metadata.gz: cd79a1f105339160f14c6a412ef75b42e9f7d50f
4
+ data.tar.gz: 015abda897b21e519b302b3506735e56283fa6f5
5
5
  SHA512:
6
- metadata.gz: 36ae97c17d7ffa5603d4e2d481ce51208922b58d33e80991333679bc25d006d91df6adb557f7ab081b078c4ff57ade2b19afea96f8b063cea04f023edb9d709e
7
- data.tar.gz: 98f3dd66e289a04dcbc7f03996b1a476edf462d18b2f5793d8bc2c1f3002b2699a4b4218abc76ae43f7f120afd44e6d9e5acb862140248e63e44464eed8240fb
6
+ metadata.gz: 60657e6fd37fc69c29ef99c5c16a33a42d2126a32d7d0f2998f7fd75814340ea9dfcafe059284eb69733e9a623480cbed8b06b0de9971ec4cd75e0a18fc2d9e3
7
+ data.tar.gz: a85a0636872dc7e3d958dd7a2685d74c61346c3df4b236ac1ef2a7353dc33d2f856d9e52687c623e03a47c546a7dd91e5d6215d5f35d729792d13d6691aeded9
@@ -1,4 +1,3 @@
1
1
  @import "application/bootstrap_overrides";
2
2
  @import "application/table_monospaced";
3
- @import "application/widgets";
4
- @import "bootstrap";
3
+ @import "application/widgets";
@@ -72,7 +72,7 @@ module Rails
72
72
  private
73
73
 
74
74
  def initialize_result
75
- @result = result_class.new
75
+ @result = result_class.new(self)
76
76
  end
77
77
 
78
78
  def perform_result
@@ -102,12 +102,44 @@ module Rails
102
102
  @errors.add(key_prefix, message)
103
103
  end
104
104
  end
105
+
106
+ def add_error_and_say(attribute, message)
107
+ @errors.add(attribute, message)
108
+ say(message)
109
+ end
110
+ end
111
+
112
+ module Autosave
113
+ extend ActiveSupport::Concern
114
+
115
+ class_methods do
116
+ def call!(*args)
117
+ new(*args).autosave!.perform
118
+ end
119
+ end
120
+
121
+ def autosave?
122
+ !!@options[:autosave]
123
+ end
124
+
125
+ def autosave!
126
+ @options[:autosave] = true
127
+ self
128
+ end
129
+ end
130
+
131
+ module Internationalization
132
+ def t(key, options)
133
+ I18n.t("activemodel.#{self.class.name.underscore}#{key}", options)
134
+ end
105
135
  end
106
136
 
107
137
  include Errors
108
138
  include Resultable
109
139
  include Callbacks
110
140
  include Rails::AddOns::Service::Messages
141
+ include Autosave
142
+ include Internationalization
111
143
  end
112
144
  end
113
145
  end
@@ -0,0 +1,20 @@
1
+ module Rails
2
+ module AddOns
3
+ module Service::Message
4
+ class Base
5
+ def initialize(content, options = {})
6
+ @indent_level = options.fetch(:indent_level) { 1 }
7
+ @content = content
8
+ end
9
+
10
+ def level
11
+ @indent_level
12
+ end
13
+
14
+ def to_s
15
+ @content
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -12,13 +12,13 @@ module Rails
12
12
  @indent ||= 0
13
13
  if block_given?
14
14
  @indent += 1
15
- output "#{output_prefix}#{(" " * @indent)}#{what}..."
15
+ output(_message("#{output_prefix}#{(" " * @indent)}#{what}...", level: @indent))
16
16
  block_result = yield
17
17
  say_done
18
18
  @indent -= 1
19
19
  block_result
20
20
  else
21
- output "#{output_prefix}#{(" " * @indent)}#{what}"
21
+ output(_message("#{output_prefix}#{(" " * @indent)}#{what}", level: @indent))
22
22
  end
23
23
  end
24
24
 
@@ -42,6 +42,10 @@ module Rails
42
42
  def copy_messages_to_result
43
43
  @result.instance_variable_set(:@messages, @messages)
44
44
  end
45
+
46
+ def _message(content, options = {})
47
+ Rails::AddOns::Service::Message::Base.new(content, level: options[:level])
48
+ end
45
49
  end
46
50
  end
47
51
  end
@@ -2,7 +2,17 @@ module Rails
2
2
  module AddOns
3
3
  module Service::Result
4
4
  class Base
5
- attr_reader :messages, :errors
5
+ extend ActiveModel::Translation
6
+
7
+ attr_reader :messages, :errors, :service
8
+
9
+ def initialize(service)
10
+ @service = service
11
+ end
12
+
13
+ def model_name
14
+ @service.model_name
15
+ end
6
16
 
7
17
  module Succeedable
8
18
  def success?
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module AddOns
3
- VERSION = '1.2.0'
3
+ VERSION = '1.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-add_ons
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Vasquez Angel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2017-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -208,6 +208,7 @@ files:
208
208
  - app/helpers/rails/add_ons/widget_helper.rb
209
209
  - app/parsers/api/resources_controller/condition_parser.rb
210
210
  - app/services/rails/add_ons/service/base.rb
211
+ - app/services/rails/add_ons/service/message/base.rb
211
212
  - app/services/rails/add_ons/service/messages.rb
212
213
  - app/services/rails/add_ons/service/result/base.rb
213
214
  - app/views/component/_collection_table.haml