flame-flash 2.3.3 → 3.0.1.rc2

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
- SHA1:
3
- metadata.gz: 9f5d38ded2a6652b2a52e66b1106dc7ca1a9ef4a
4
- data.tar.gz: bf2f0f90d3197dc220be3ea4c79f0368398e6a1e
2
+ SHA256:
3
+ metadata.gz: fc9f9a14d66bfe9bf9253bf85d6ead97c66ffedbadff7b3ea5e72bdeadb46aa7
4
+ data.tar.gz: 3970ce4c11b6fb738b78a2a0f2e15f6df75949015c71fe4c0ba3eea583d35080
5
5
  SHA512:
6
- metadata.gz: 962a3d06b24372dff6c6e7e25c727048f67e3ddfbc1c8a90c74ca3dcea69e276f286d630052e0fc2b1046b3fa0bf7e47e12ca9146be963c78a1b4e0598ec5df6
7
- data.tar.gz: ecd21f4f4f8e9db3be37db04ebca8719b82a49c3a20b3afdb5872de8a42a31fc5bacf8ba60825e8044ad338bf4387179348cae940a0b78471950975adee6cbf1
6
+ metadata.gz: 4a6c08438d21676c7220b9e74a82ea552e246d8f8440b9f1201428fbce1c9877d228fc6b304962730b1bf19758c1085dceb86d1db1fab563db582fb2280cd7e3
7
+ data.tar.gz: e95ebb0e5e8b04126b88fec66c57cc444d7107f48500ec4cedea4a55dcb45e5c18f1fac7a71242003587448fa267c2fcc6a98e10fd95da67e61dad535ffc13f3
data/CHANGELOG.md ADDED
@@ -0,0 +1,87 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ## 3.0.1.rc2 (2022-09-24)
6
+
7
+ * Drop Ruby 2.5 support.
8
+ * Add Ruby 3.1 support.
9
+ * Update dependencies, like Flame, Gorilla Patch, development ones.
10
+ * Update metadata in gemspec.
11
+ * Add `bundle-audit` CI task.
12
+
13
+ ## 3.0.1.rc1 (2021-04-16)
14
+
15
+ * Support Flame 5
16
+ * Forward flashes on redirect
17
+ * Replace `Array` check with `Enumerable`
18
+ * Take flashes only from reserved keys (error, warning, notice) or `flash` key
19
+ Don't extract parameters for controller's path as flashes.
20
+ Reference: <http://guides.rubyonrails.org/action_controller_overview.html#the-flash>
21
+ * Change `FlashArray` to `FlashObject` with `now` and `next` as `FlashArray`
22
+ * Add `FlashArray#delete` method
23
+ * Fix calls of redefined `view` without parameters
24
+ * Make `execute` and methods below `protected`
25
+ * Make `FlashObject` private, test `Flame::Flash` better.
26
+ * Remove `flash.scope` method.
27
+ It was taken not from Rails, but from (abandoned) `sinatra-flash`.
28
+ But we can add it later in more correct way if somebody's needing!
29
+ * Fix requiring by `path` in `Gemfile`
30
+ * Drop Ruby 2.3 and 2.4 support (after Flame)
31
+ * Support Ruby 3.
32
+ * Add MIT license file
33
+ * Add tests, 100% coverage
34
+ * Fix RuboCop warnings, and RuboCop configuration file
35
+ With `rubocop-performance` and `rubocop-rspec`.
36
+ * Improve documentation of methods
37
+ * Add Cirrus CI
38
+ * Add `remark` CI task.
39
+ * Replace `rake` with `toys`.
40
+ * Update development dependencies.
41
+ * Add more meta-information to gem specs.
42
+ * Add "Development", "Contributing" and "License" sections to README.
43
+ * Add CHANGELOG file.
44
+ * Move gem version to a separate file (and constant).
45
+
46
+ ## 2.3.3 (2016-11-16)
47
+
48
+ * Flashes extracting fixed for `params` key
49
+ * Migrate from GitLab to GitHub
50
+
51
+ ## 2.3.2 (2016-08-09)
52
+
53
+ * Fixed `fix_messages_as_array` method
54
+
55
+ ## 2.3.1 (2016-03-11)
56
+
57
+ * Trying to fix messages as `Array`
58
+
59
+ ## 2.3.0 (2016-03-11)
60
+
61
+ * Capture `halt` method and take out flash-recording to private method
62
+ * Adding ability to add `Array` as many flashes
63
+
64
+ ## 2.2.0 (2016-02-11)
65
+
66
+ * Allowing assign array to `FlashArray`
67
+
68
+ ## 2.1.1 (2016-02-04)
69
+
70
+ * Support `String` redirects
71
+
72
+ ## 2.1.0 (2016-02-02)
73
+
74
+ * Add flash-options for redirect method of controller
75
+
76
+ ## 2.0.0 (2016-01-29)
77
+
78
+ * Support Flame 4.0
79
+
80
+ ## 1.0.1 (2015-12-10)
81
+
82
+ * Add `flame` as runtime dependency
83
+ * Update after-hook for Flame 3.3.4
84
+
85
+ ## 1.0.0 (2015-12-07)
86
+
87
+ * Initial release.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2015 Alexander Popov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # Flame Flash
2
+
3
+ [![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/AlexWayfer/flame-flash?style=flat-square)](https://cirrus-ci.com/github/AlexWayfer/flame-flash)
4
+ [![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/flame-flash/main.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/flame-flash)
5
+ [![Code Climate](https://img.shields.io/codeclimate/maintainability/AlexWayfer/flame-flash.svg?style=flat-square)](https://codeclimate.com/github/AlexWayfer/flame-flash)
6
+ ![Depfu](https://img.shields.io/depfu/AlexWayfer/flame-flash?style=flat-square)
7
+ [![Inline docs](https://inch-ci.org/github/AlexWayfer/flame-flash.svg?branch=main)](https://inch-ci.org/github/AlexWayfer/flame-flash)
8
+ [![Gem](https://img.shields.io/gem/v/flame-flash.svg?style=flat-square)](https://rubygems.org/gems/flame-flash)
9
+ [![License](https://img.shields.io/github/license/AlexWayfer/flame-flash.svg?style=flat-square)](LICENSE.txt)
10
+
11
+ [Flashes](http://guides.rubyonrails.org/action_controller_overview.html#the-flash)
12
+ for [Flame](https://github.com/AlexWayfer/flame).
13
+
14
+ ## Usage
15
+
16
+ ```ruby
17
+ # Gemfile
18
+ gem 'flame-flash'
19
+
20
+ # config.ru
21
+ require 'flame-flash' # or `Bundler.require`
22
+
23
+ # _controller.rb
24
+ include Flame::Flash
25
+ ```
26
+
27
+ ```erb
28
+ <!-- layout.html.erb -->
29
+
30
+ <%
31
+ %i[error warning notice].each do |type|
32
+ flash[type].each do |text|
33
+ %>
34
+ <p class="flash <%= type %>">
35
+ <%= text %>
36
+ </p>
37
+ <%
38
+ end
39
+ end
40
+ %>
41
+ ```
42
+
43
+ ## Examples
44
+
45
+ ```ruby
46
+ class PostsController < Flame::Controller
47
+ def update
48
+ flash[:error] = "You don't have permissions"
49
+ redirect :show
50
+ end
51
+
52
+ def delete
53
+ redirect :show, notice: 'Deleted'
54
+ end
55
+
56
+ def move
57
+ redirect :index, flash: { success: 'Moved' }
58
+ end
59
+
60
+ def create
61
+ flash.now[:error] = 'Not enought permissions'
62
+ view :new
63
+ end
64
+ end
65
+ ```
66
+
67
+ ### Reserved keys
68
+
69
+ * `error`
70
+ * `warning`
71
+ * `notice`
72
+
73
+ ## Development
74
+
75
+ After checking out the repo, run `bundle install` to install dependencies.
76
+
77
+ Then, run `toys rspec` to run the tests.
78
+
79
+ To install this gem onto your local machine, run `toys gem install`.
80
+
81
+ To release a new version, run `toys gem release %version%`.
82
+ See how it works [here](https://github.com/AlexWayfer/gem_toys#release).
83
+
84
+ ## Contributing
85
+
86
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/flame-flash).
87
+
88
+ ## License
89
+
90
+ The gem is available as open source under the terms of the
91
+ [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flame
4
+ ## https://github.com/bbatsov/rubocop/issues/5831
5
+ module Flash
6
+ ## Just contains flashes
7
+ class FlashArray
8
+ ## Initialize Flash Array from regular Array
9
+ ## @param array [Array<Hash>] initial Array with raw data
10
+ def initialize(array = [])
11
+ @array = []
12
+ concat(array)
13
+ end
14
+
15
+ ## Go through internal Array
16
+ def each(&block)
17
+ @array.each(&block)
18
+ end
19
+
20
+ ## Write text by type
21
+ def push(type, text)
22
+ if text.is_a?(Enumerable)
23
+ text.each { |el| push(type, el) }
24
+ return
25
+ end
26
+ hash = { type: type, text: text }
27
+ @array.push(hash)
28
+ end
29
+
30
+ alias []= push
31
+
32
+ ## Delete text in type
33
+ def delete(type, text)
34
+ @array.delete(type: type, text: text)
35
+ end
36
+
37
+ ## Select values by text or type
38
+ def select(**options)
39
+ @array.select do |hash|
40
+ options.reject { |key, val| hash[key] == val || val.nil? }.empty?
41
+ end
42
+ end
43
+
44
+ ## Concat with other Array-like
45
+ def concat(array)
46
+ array.each do |hash|
47
+ push(hash[:type], hash[:text])
48
+ end
49
+ end
50
+
51
+ ## Merge with other Hash-like
52
+ def merge(hash)
53
+ hash.each { |type, text| self[type] = text }
54
+ end
55
+
56
+ ## Return internal Array
57
+ def to_a
58
+ @array
59
+ end
60
+ end
61
+
62
+ private_constant :FlashArray
63
+ end
64
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'flash_array'
4
+
5
+ module Flame
6
+ ## https://github.com/bbatsov/rubocop/issues/5831
7
+ module Flash
8
+ ## Contains info about current and next flashes
9
+ class FlashObject
10
+ attr_reader :now, :next
11
+
12
+ ## Initialize Flash Object with specific session
13
+ ## @param session [Rack::Session::Abstract::Persisted] Rack's session convertible to an Array
14
+ def initialize(session)
15
+ @now = FlashArray.new(session.to_a)
16
+ @next = FlashArray.new
17
+ end
18
+
19
+ ## Add entry with type and text
20
+ def []=(type, text)
21
+ self.next.push type, text
22
+ end
23
+
24
+ ## Get entries by type
25
+ def [](type = nil)
26
+ now.select(type: type).map { |hash| hash[:text] }
27
+ end
28
+
29
+ ## Mass adding to next
30
+ def merge(hash)
31
+ hash.each { |type, text| self[type] = text }
32
+ end
33
+ end
34
+
35
+ private_constant :FlashObject
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flame
4
+ module Flash
5
+ VERSION = '3.0.1.rc2'
6
+ end
7
+ end
data/lib/flame/flash.rb CHANGED
@@ -1,8 +1,17 @@
1
- require_relative 'flash_array'
1
+ # frozen_string_literal: true
2
+
3
+ require 'gorilla_patch/deep_dup'
4
+ require 'gorilla_patch/slice'
5
+
6
+ require_relative 'flash/version'
7
+
8
+ require_relative 'flash/flash_object'
2
9
 
3
10
  module Flame
4
11
  # Module for Flame::Flash extension with helper methods and base class
5
12
  module Flash
13
+ protected
14
+
6
15
  ## After hook
7
16
  def execute(method)
8
17
  super
@@ -13,18 +22,26 @@ module Flame
13
22
  ## @example Redirect to show method of Articles controller with error
14
23
  ## redirect ArticlesController, :show, id: 2, error: 'Access required'
15
24
  def redirect(*args)
16
- if args.last.is_a? Hash
17
- if args[0].is_a? String
18
- flashes = args.pop
19
- else
20
- args[-1], flashes = extract_flashes(args)
21
- end
22
- flash.merge(flashes)
23
- end
24
- super
25
+ args, flashes = extract_flashes_for_redirect(args)
26
+ flash.merge flashes
27
+ flash.next.concat(flash.now) ## for multiple redirects
28
+ super(*args)
29
+ end
30
+
31
+ ## Upgrade view method
32
+ ## @example Render view with error
33
+ ## view :show, error: 'Access required'
34
+ def view(path = nil, options = {}, &block)
35
+ options, flashes = extract_flashes(options)
36
+ flash.now.merge flashes
37
+ super(
38
+ path || caller_locations(1, 1)[0].label.to_sym,
39
+ options,
40
+ &block
41
+ )
25
42
  end
26
43
 
27
- ## Capture halt method
44
+ ## Record flashes before halting
28
45
  def halt(*args)
29
46
  record_flashes
30
47
  super
@@ -33,21 +50,36 @@ module Flame
33
50
  private
34
51
 
35
52
  ## Main helper method
36
- def flash(key = nil)
37
- (
38
- @flash ||= FlashArray.new(
39
- (session ? session[:flash] : [])
40
- )
41
- ).scope(key)
53
+ def flash
54
+ @flash ||= FlashObject.new(
55
+ (session ? session[:flash] : [])
56
+ )
42
57
  end
43
58
 
59
+ RESERVED_FLASH_KEYS = %i[error warning notice].freeze
60
+
61
+ using GorillaPatch::DeepDup
62
+ using GorillaPatch::Slice
63
+
44
64
  ## Split Hash-argument to parameters and flashes
45
- def extract_flashes(args)
65
+ def extract_flashes(options)
66
+ options = options.deep_dup
67
+ flashes = options.delete(:flash) { {} }
68
+ ## Yeah, `RESERVED_FLASH_KEYS` will be deleted from `options`
69
+ ## and will not be passed into parent's `redirect` or `view`.
70
+ ## But I don't see a problem cause of it for now.
71
+ ## If you see - please, send a PR, or create an issue.
72
+ flashes.merge! options.slice_reverse!(*RESERVED_FLASH_KEYS)
73
+ [options, flashes]
74
+ end
75
+
76
+ def extract_flashes_for_redirect(args)
77
+ return [args, {}] unless args.last.is_a? Hash
78
+ return [args, args.pop] if args.first.is_a?(String)
79
+
46
80
  add_controller_class(args)
47
- parameters = args[0].instance_method(args[1]).parameters.map(&:last)
48
- args.last.partition do |key, _value|
49
- parameters.include?(key) || key == :params
50
- end.map(&:to_h)
81
+ options, flashes = extract_flashes(args.last)
82
+ [args[0..-2].push(options), flashes]
51
83
  end
52
84
 
53
85
  ## Move flash.next to session
metadata CHANGED
@@ -1,50 +1,251 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flame-flash
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.3
4
+ version: 3.0.1.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-16 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flame
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0.rc8
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
18
28
  - !ruby/object:Gem::Version
19
- version: '4.6'
29
+ version: 5.0.0.rc8
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
33
+ - !ruby/object:Gem::Dependency
34
+ name: gorilla_patch
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
20
37
  - - ">="
21
38
  - !ruby/object:Gem::Version
22
- version: 4.6.0
39
+ version: '1'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6'
23
43
  type: :runtime
24
44
  prerelease: false
25
45
  version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '1'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6'
53
+ - !ruby/object:Gem::Dependency
54
+ name: pry-byebug
55
+ requirement: !ruby/object:Gem::Requirement
26
56
  requirements:
27
57
  - - "~>"
28
58
  - !ruby/object:Gem::Version
29
- version: '4.6'
30
- - - ">="
59
+ version: '3.9'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '3.9'
67
+ - !ruby/object:Gem::Dependency
68
+ name: bundler
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '2.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
31
79
  - !ruby/object:Gem::Version
32
- version: 4.6.0
33
- description: Show messages (notifies, errors, warnings) in current or next routes
80
+ version: '2.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: bundler-audit
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: 0.9.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: 0.9.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: gem_toys
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: 0.12.1
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: 0.12.1
109
+ - !ruby/object:Gem::Dependency
110
+ name: toys
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: 0.13.1
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: 0.13.1
123
+ - !ruby/object:Gem::Dependency
124
+ name: rack-test
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '2.0'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '2.0'
137
+ - !ruby/object:Gem::Dependency
138
+ name: rspec
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '3.9'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: '3.9'
151
+ - !ruby/object:Gem::Dependency
152
+ name: simplecov
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: 0.21.2
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: 0.21.2
165
+ - !ruby/object:Gem::Dependency
166
+ name: simplecov-cobertura
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: '2.1'
172
+ type: :development
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - "~>"
177
+ - !ruby/object:Gem::Version
178
+ version: '2.1'
179
+ - !ruby/object:Gem::Dependency
180
+ name: rubocop
181
+ requirement: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - "~>"
184
+ - !ruby/object:Gem::Version
185
+ version: 1.36.0
186
+ type: :development
187
+ prerelease: false
188
+ version_requirements: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - "~>"
191
+ - !ruby/object:Gem::Version
192
+ version: 1.36.0
193
+ - !ruby/object:Gem::Dependency
194
+ name: rubocop-performance
195
+ requirement: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - "~>"
198
+ - !ruby/object:Gem::Version
199
+ version: '1.0'
200
+ type: :development
201
+ prerelease: false
202
+ version_requirements: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - "~>"
205
+ - !ruby/object:Gem::Version
206
+ version: '1.0'
207
+ - !ruby/object:Gem::Dependency
208
+ name: rubocop-rspec
209
+ requirement: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - "~>"
212
+ - !ruby/object:Gem::Version
213
+ version: '2.0'
214
+ type: :development
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - "~>"
219
+ - !ruby/object:Gem::Version
220
+ version: '2.0'
221
+ description: 'Show messages (notifies, errors, warnings) in current or next routes
34
222
  after redirect.
223
+
224
+ '
35
225
  email:
36
226
  - alex.wayfer@gmail.com
37
227
  executables: []
38
228
  extensions: []
39
229
  extra_rdoc_files: []
40
230
  files:
231
+ - CHANGELOG.md
232
+ - LICENSE.txt
233
+ - README.md
41
234
  - lib/flame/flash.rb
42
- - lib/flame/flash_array.rb
235
+ - lib/flame/flash/flash_array.rb
236
+ - lib/flame/flash/flash_object.rb
237
+ - lib/flame/flash/version.rb
43
238
  homepage: https://github.com/AlexWayfer/flame-flash
44
239
  licenses:
45
240
  - MIT
46
- metadata: {}
47
- post_install_message:
241
+ metadata:
242
+ bug_tracker_uri: https://github.com/AlexWayfer/flame-flash/issues
243
+ changelog_uri: https://github.com/AlexWayfer/flame-flash/blob/v3.0.1.rc2/CHANGELOG.md
244
+ documentation_uri: http://www.rubydoc.info/gems/flame-flash/3.0.1.rc2
245
+ homepage_uri: https://github.com/AlexWayfer/flame-flash
246
+ rubygems_mfa_required: 'true'
247
+ source_code_uri: https://github.com/AlexWayfer/flame-flash
248
+ post_install_message:
48
249
  rdoc_options: []
49
250
  require_paths:
50
251
  - lib
@@ -52,16 +253,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
253
  requirements:
53
254
  - - ">="
54
255
  - !ruby/object:Gem::Version
55
- version: '0'
256
+ version: '2.6'
257
+ - - "<"
258
+ - !ruby/object:Gem::Version
259
+ version: '4'
56
260
  required_rubygems_version: !ruby/object:Gem::Requirement
57
261
  requirements:
58
- - - ">="
262
+ - - ">"
59
263
  - !ruby/object:Gem::Version
60
- version: '0'
264
+ version: 1.3.1
61
265
  requirements: []
62
- rubyforge_project:
63
- rubygems_version: 2.5.1
64
- signing_key:
266
+ rubygems_version: 3.3.7
267
+ signing_key:
65
268
  specification_version: 4
66
269
  summary: Flash plugin for Flame-framework
67
270
  test_files: []
@@ -1,73 +0,0 @@
1
- module Flame
2
- module Flash
3
- # A subclass of Array that "remembers forward" by exactly one action.
4
- # Tastes just like the API of Rails's ActionController::Flash::FlashHash,
5
- # but with fewer calories.
6
- class FlashArray
7
- attr_reader :now, :next
8
-
9
- # Builds a new FlashHash. It takes the hash for this action's values
10
- # as an initialization variable.
11
- def initialize(session, parent = nil, scope = nil)
12
- @now = session || []
13
- fix_messages_as_array
14
- @next = []
15
- @parent = parent || self
16
- @scope = scope
17
- end
18
-
19
- def scope(scope = nil)
20
- # p 'scope', scope
21
- return self unless scope
22
- self.class.new(
23
- @now.select { |hash| condition(hash, scope: scope) },
24
- self,
25
- scope
26
- )
27
- end
28
-
29
- # We assign to the _next_ hash, but retrieve values
30
- # from the _now_ hash. Freaky, huh?
31
- def []=(type, text)
32
- return text.each { |el| self[type] = el } if text.is_a?(Array)
33
- hash = { type: type, text: text }
34
- # p @parent == self, @scope
35
- hash[:scope] = @scope if @parent != self
36
- # p hash
37
- @parent.next.push(hash)
38
- # p @parent.next
39
- end
40
-
41
- def [](type = nil)
42
- selected = @parent.now.select do |hash|
43
- condition(hash, type: type, scope: @scope)
44
- end
45
- # p 'flash[]', type, @scope, selected
46
- selected.map { |hash| hash[:text] }
47
- end
48
-
49
- def each(&block)
50
- @now.each(&block)
51
- end
52
-
53
- ## Mass adding to next
54
- def merge(hash)
55
- hash.each { |type, text| self[type] = text }
56
- end
57
-
58
- private
59
-
60
- def condition(hash, options = {}) # kind, section)
61
- options.reject { |key, val| hash[key] == val || val.nil? }.empty?
62
- end
63
-
64
- def fix_messages_as_array
65
- @now.each_with_index do |hash, ind|
66
- next unless hash[:text].is_a?(Array)
67
- hash = @now.delete(hash)
68
- @now.insert(ind, hash[:text].map { |text| hash.merge(text: text) })
69
- end
70
- end
71
- end
72
- end
73
- end