flash_messenger 0.0.1

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.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +46 -0
  5. data/Gemfile +14 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.rdoc +3 -0
  8. data/Rakefile +26 -0
  9. data/app/assets/images/flash_messenger/.keep +0 -0
  10. data/app/assets/stylesheets/flash_messenger/.keep +0 -0
  11. data/app/controllers/application_controller.rb +39 -0
  12. data/app/helpers/.keep +0 -0
  13. data/app/mailers/.keep +0 -0
  14. data/app/models/.keep +0 -0
  15. data/app/views/.keep +0 -0
  16. data/bin/rails +12 -0
  17. data/config/locales/en-US.yml +28 -0
  18. data/config/routes.rb +3 -0
  19. data/flash_messenger.gemspec +32 -0
  20. data/lib/flash_messenger.rb +9 -0
  21. data/lib/flash_messenger/controller_injection.rb +45 -0
  22. data/lib/flash_messenger/engine.rb +14 -0
  23. data/lib/flash_messenger/messages/base.rb +174 -0
  24. data/lib/flash_messenger/messages/nonpersistent.rb +9 -0
  25. data/lib/flash_messenger/messages/persistent.rb +9 -0
  26. data/lib/flash_messenger/messenger.rb +25 -0
  27. data/lib/flash_messenger/storage.rb +141 -0
  28. data/lib/flash_messenger/version.rb +3 -0
  29. data/lib/tasks/flash_messenger_tasks.rake +4 -0
  30. data/spec/dummy/README.rdoc +28 -0
  31. data/spec/dummy/Rakefile +6 -0
  32. data/spec/dummy/app/assets/images/.keep +0 -0
  33. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  34. data/spec/dummy/app/assets/javascripts/index.js +2 -0
  35. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  36. data/spec/dummy/app/assets/stylesheets/index.css +4 -0
  37. data/spec/dummy/app/controllers/application_controller.rb +7 -0
  38. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  39. data/spec/dummy/app/controllers/index_controller.rb +6 -0
  40. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  41. data/spec/dummy/app/helpers/index_helper.rb +2 -0
  42. data/spec/dummy/app/mailers/.keep +0 -0
  43. data/spec/dummy/app/models/.keep +0 -0
  44. data/spec/dummy/app/models/concerns/.keep +0 -0
  45. data/spec/dummy/app/views/index/index.html.erb +5 -0
  46. data/spec/dummy/app/views/layouts/application.html.erb +13 -0
  47. data/spec/dummy/bin/bundle +3 -0
  48. data/spec/dummy/bin/rails +4 -0
  49. data/spec/dummy/bin/rake +4 -0
  50. data/spec/dummy/config.ru +4 -0
  51. data/spec/dummy/config/application.rb +22 -0
  52. data/spec/dummy/config/boot.rb +5 -0
  53. data/spec/dummy/config/database.yml +25 -0
  54. data/spec/dummy/config/environment.rb +5 -0
  55. data/spec/dummy/config/environments/development.rb +37 -0
  56. data/spec/dummy/config/environments/production.rb +78 -0
  57. data/spec/dummy/config/environments/test.rb +39 -0
  58. data/spec/dummy/config/initializers/assets.rb +8 -0
  59. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  61. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  62. data/spec/dummy/config/initializers/inflections.rb +16 -0
  63. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  64. data/spec/dummy/config/initializers/session_store.rb +3 -0
  65. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/spec/dummy/config/locales/en.yml +23 -0
  67. data/spec/dummy/config/routes.rb +56 -0
  68. data/spec/dummy/config/secrets.yml +22 -0
  69. data/spec/dummy/lib/assets/.keep +0 -0
  70. data/spec/dummy/public/404.html +67 -0
  71. data/spec/dummy/public/422.html +67 -0
  72. data/spec/dummy/public/500.html +66 -0
  73. data/spec/dummy/public/favicon.ico +0 -0
  74. data/spec/dummy/spec/controllers/index_controller_spec.rb +5 -0
  75. data/spec/dummy/spec/helpers/index_helper_spec.rb +15 -0
  76. data/spec/examples/shared_examples.rb +27 -0
  77. data/spec/features/messages/base_spec.rb +102 -0
  78. data/spec/features/messages/nonpersistent_spec.rb +46 -0
  79. data/spec/features/messages/persistent_spec.rb +46 -0
  80. data/spec/features/messenger_spec.rb +96 -0
  81. data/spec/features/storage_spec.rb +152 -0
  82. data/spec/rails_helper.rb +50 -0
  83. data/spec/spec_helper.rb +92 -0
  84. data/spec/support/shared_examples.rb +26 -0
  85. metadata +309 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dbaa8f9d09975651d700f3f83efc33f48b70c0ba
4
+ data.tar.gz: bb74fbea64de6a21487f86604d1e7c0a8aa39e4e
5
+ SHA512:
6
+ metadata.gz: fb881726eac15c98e10a09dc909b683b0661505fccc5dbd5b78dc7d792306f97efe5611ef53f7380043b1546fd2b8665f6ed2867ef81de3572f8e822aa8975f7
7
+ data.tar.gz: 959b2b22389bcb8681c1779e29fa1b375035c1586b938380a4b8966c7712ac87797c4742d52bf0b2edc7d221a11310a86b071691e755077a42c7744f461c7cd4
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.a
2
+ *.bundle
3
+ *.o
4
+ *.so
5
+ .DS_Store
6
+ .bundle/
7
+ /.bundle/
8
+ /.yardoc
9
+ /Gemfile.lock
10
+ /_yardoc/
11
+ /coverage/
12
+ /doc/
13
+ /pkg/
14
+ /spec/reports/
15
+ /tmp/
16
+ log/*.log
17
+ mkmf.log
18
+ pkg/
19
+ spec/dummy/.sass-cache
20
+ spec/dummy/db/*.sqlite3
21
+ spec/dummy/db/*.sqlite3-journal
22
+ spec/dummy/log/
23
+ spec/dummy/tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format Fivemat
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,46 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Style/CollectionMethods:
5
+ Enabled: false
6
+
7
+ Style/EachWithObject:
8
+ Enabled: false
9
+
10
+ Style/StringLiterals:
11
+ Enabled: false
12
+
13
+ Style/SignalException:
14
+ Enabled: false
15
+
16
+ Style/TrailingComma:
17
+ EnforcedStyleForMultiline: no_comma
18
+
19
+ Style/AlignHash:
20
+ EnforcedLastArgumentHashStyle: ignore_implicit
21
+
22
+ Style/AlignParameters:
23
+ EnforcedStyle: with_fixed_indentation
24
+
25
+ Style/CaseIndentation:
26
+ IndentOneStep: true
27
+
28
+ Style/SingleLineBlockParams:
29
+ Enabled: false
30
+
31
+ Metrics/BlockNesting:
32
+ Max: 2
33
+
34
+ Metrics/MethodLength:
35
+ Max: 7
36
+
37
+ Metrics/ParameterLists:
38
+ Max: 4
39
+
40
+ Metrics/LineLength:
41
+ Exclude:
42
+ - flash_messenger.gemspec
43
+
44
+ Style/RegexpLiteral:
45
+ Exclude:
46
+ - flash_messenger.gemspec
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in flash_messenger.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use debugger
14
+ # gem 'debugger'
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = FlashMessenger
2
+
3
+ This project rocks.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'FlashMessenger'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ # APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ # load 'rails/tasks/engine.rake'
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rspec/core'
23
+ require 'rspec/core/rake_task'
24
+ RSpec::Core::RakeTask.new(:spec)
25
+
26
+ task default: :spec
File without changes
File without changes
@@ -0,0 +1,39 @@
1
+ class ApplicationController < ActionController::Base
2
+ # around_filter :synchronize_flash_messenger_session
3
+ #
4
+ # def flash_messenger
5
+ # serialize_flash_messenger
6
+ # deserialize_flash_messenger
7
+ # end
8
+ #
9
+ # protected
10
+ #
11
+ # def clear_flash_messenger_session
12
+ # @flash_messenger = nil
13
+ # session.delete(:flash_messenger)
14
+ # initialize_flash_messenger
15
+ # end
16
+ #
17
+ # private
18
+ #
19
+ # def synchronize_flash_messenger_session(&block)
20
+ # deserialize_flash_messenger
21
+ # block.call
22
+ # serialize_flash_messenger
23
+ # end
24
+ #
25
+ # def initialize_flash_messenger
26
+ # @flash_messenger ||= FlashMessenger.new
27
+ # session[:flash_messenger] ||= @flash_messenger.to_session
28
+ # end
29
+ #
30
+ # def serialize_flash_messenger
31
+ # initialize_flash_messenger
32
+ # session[:flash_messenger] = @flash_messenger.to_session
33
+ # end
34
+ #
35
+ # def deserialize_flash_messenger
36
+ # initialize_flash_messenger
37
+ # @flash_messenger = FlashMessenger.from_session(session[:flash_messenger])
38
+ # end
39
+ end
data/app/helpers/.keep ADDED
File without changes
data/app/mailers/.keep ADDED
File without changes
data/app/models/.keep ADDED
File without changes
data/app/views/.keep ADDED
File without changes
data/bin/rails ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/flash_messenger/engine', __FILE__)
6
+
7
+ # Set up gems listed in the Gemfile.
8
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
10
+
11
+ require 'rails/all'
12
+ require 'rails/engine/commands'
@@ -0,0 +1,28 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en-US:
23
+ development:
24
+ lorem_ipsum_1: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce id lobortis tortor. Nam cursus pharetra purus non elementum. Sed eu libero leo. Aliquam eget justo vel odio consectetur facilisis id a sapien. Duis pulvinar tincidunt suscipit. Quisque volutpat justo vitae fringilla lacinia. Aenean semper, nulla at mattis sagittis, purus felis aliquet lorem, sit amet suscipit dolor elit nec tellus. Pellentesque interdum nulla maximus massa elementum, at posuere augue scelerisque.
25
+ lorem_ipsum_2: Nulla sagittis quam at est tincidunt, at consectetur leo vehicula. Vestibulum et faucibus odio. Vivamus interdum consectetur metus vitae aliquam. Integer vitae felis diam. Vestibulum consectetur dictum magna eget finibus. Integer sit amet interdum augue. Nullam ultricies malesuada odio, at tincidunt nisi semper nec. Pellentesque vitae convallis ligula. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Ut vitae risus blandit, sodales nulla at, placerat dui.
26
+ lorem_ipsum_3: Curabitur at orci sodales, luctus enim ac, lobortis mi. Curabitur ut sapien purus. Duis volutpat nulla feugiat iaculis porta. Ut ultricies nunc maximus placerat lobortis. Morbi ac lacinia nulla, sit amet aliquet tellus. Morbi viverra volutpat turpis ac sodales. Cras lacinia, felis quis tincidunt gravida, lectus dolor lobortis ex, eu imperdiet lectus urna vel risus. In et malesuada diam. Praesent finibus a ligula id laoreet. Nunc at dolor in nibh fermentum auctor.
27
+ lorem_ipsum_4: Morbi eu leo ipsum. Praesent vehicula risus ut tortor mattis, sit amet varius nisl sagittis. Ut sed ante finibus, eleifend ligula nec, faucibus ligula. Cras eget ipsum eleifend, aliquam diam sit amet, placerat dui. Curabitur nec diam consequat, tristique velit ut, porta tortor. Vestibulum ullamcorper vel mi ut elementum. Donec vel neque urna.
28
+ lorem_ipsum_5: Sed tempus hendrerit justo id tristique. Fusce pharetra dictum metus et vulputate. Donec at sem vitae mi elementum dictum. Ut fermentum, lorem in porttitor interdum, diam mi fringilla nisl, at maximus tortor dolor nec turpis. Proin sollicitudin nec ligula vel tempor. Phasellus dapibus hendrerit blandit. Quisque mauris quam, cursus mollis nulla quis, eleifend sagittis turpis. Mauris dictum ligula et ultricies fermentum. Donec imperdiet nisl cursus, commodo odio ac, commodo neque. Vestibulum vitae pulvinar turpis. Quisque nec condimentum velit. Suspendisse elementum tincidunt felis id lacinia. Cras tempus sollicitudin tortor, non mollis massa aliquet non. Quisque molestie arcu a justo tincidunt venenatis.
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ root to: 'index#index'
3
+ end
@@ -0,0 +1,32 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require "flash_messenger/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'flash_messenger'
7
+ spec.version = FlashMessenger::VERSION
8
+ spec.authors = ['Adam Eberlin']
9
+ spec.email = ['ae@adameberlin.com']
10
+ spec.homepage = 'https://github.com/arkbot/flash_messenger'
11
+ spec.summary = 'Persistent flash messenger.'
12
+ spec.description = 'Persistent flash messenger.'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.required_ruby_version = '>= 2.0.0'
21
+
22
+ spec.add_dependency 'rails', '>= 4.0'
23
+ spec.add_dependency 'activesupport', '>= 4.0'
24
+
25
+ spec.add_development_dependency 'factory_girl'
26
+ spec.add_development_dependency 'fivemat'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'rspec-rails'
29
+ spec.add_development_dependency 'rubocop'
30
+ spec.add_development_dependency 'sqlite3'
31
+ spec.add_development_dependency 'pry'
32
+ end
@@ -0,0 +1,9 @@
1
+ require 'flash_messenger/engine'
2
+ require 'flash_messenger/controller_injection'
3
+
4
+ module FlashMessenger
5
+ DEFAULT_LOCALE = :'en-US'
6
+ # Rails.configuration.tap do |c|
7
+ # DEFAULT_LOCALE = c.flash_messenger.default_locale || c.i18n.default_locale
8
+ # end
9
+ end
@@ -0,0 +1,45 @@
1
+ module FlashMessenger
2
+ module ControllerInjection
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ around_filter :synchronize_flash_messenger_session
7
+
8
+ def flash_messenger
9
+ serialize_flash_messenger
10
+ deserialize_flash_messenger
11
+ end
12
+
13
+ protected
14
+
15
+ def clear_flash_messenger_session
16
+ @flash_messenger = nil
17
+ session.delete(:flash_messenger)
18
+ initialize_flash_messenger
19
+ end
20
+
21
+ private
22
+
23
+ def synchronize_flash_messenger_session(&block)
24
+ deserialize_flash_messenger
25
+ block.call
26
+ serialize_flash_messenger
27
+ end
28
+
29
+ def initialize_flash_messenger
30
+ @flash_messenger ||= FlashMessenger.new
31
+ session[:flash_messenger] ||= @flash_messenger.to_session
32
+ end
33
+
34
+ def serialize_flash_messenger
35
+ initialize_flash_messenger
36
+ session[:flash_messenger] = @flash_messenger.to_session
37
+ end
38
+
39
+ def deserialize_flash_messenger
40
+ initialize_flash_messenger
41
+ @flash_messenger = FlashMessenger.from_session(session[:flash_messenger])
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,14 @@
1
+ require 'flash_messenger/messenger'
2
+
3
+ module FlashMessenger
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace ::FlashMessenger
6
+
7
+ config.generators do |g|
8
+ g.test_framework :rspec, :fixture => false
9
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
10
+ g.assets false
11
+ g.helper false
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,174 @@
1
+ module FlashMessenger
2
+ module Messages
3
+ class Base
4
+ include ActiveModel::Model
5
+ include ActiveModel::Serializers::JSON
6
+ include ActiveModel::AttributeMethods
7
+ extend ActiveModel::Naming
8
+
9
+ attr_accessor :i18n_params, :level, :translation
10
+
11
+ def initialize(level, translation, **i18n_params)
12
+ @i18n_params, @level, @translation = i18n_params, level, translation
13
+ end
14
+
15
+ # Normalize hash and force :raise so we can catch exceptions
16
+ def i18n_params
17
+ @i18n_params[:raise] = true
18
+ @i18n_params.sort.to_h
19
+ end
20
+
21
+ def i18n_params=(params)
22
+ @i18n_params = Hash[params.map{ |k, v| [k.to_sym, v] }]
23
+ end
24
+
25
+ def level
26
+ @level.to_sym
27
+ end
28
+
29
+ def message
30
+ I18n.translate(self.translation, **self.i18n_params)
31
+ rescue I18n::MissingTranslationData
32
+ return self.translation.join('.') if self.translation.is_a?(Array)
33
+ self.translation
34
+ # rescue I18n::MissingInterpolationArgument
35
+ # TODO
36
+ end
37
+
38
+ def to_s
39
+ self.message.strip
40
+ end
41
+
42
+ #
43
+ # Overridden Comparison Operators
44
+ #
45
+
46
+ def <=>(other)
47
+ return (self.message <=> other) if other.is_a?(String)
48
+ return nil unless other.is_a?(self.class)
49
+ my_values = [self.message, self.level, self.class_name]
50
+ other_values = [other.message, other.level, self.class_name]
51
+ (my_values <=> other_values)
52
+ rescue NoMethodError
53
+ nil
54
+ end
55
+
56
+ def eql?(other)
57
+ (self.<=> other) == 0
58
+ end
59
+
60
+ def match?(other)
61
+ if other.is_a?(Base)
62
+ us = "#{self.class_name}, #{self.level}, #{self.message}"
63
+ them = "#{self.class_name}, #{self.level}, #{self.message}"
64
+ us =~ them
65
+ elsif other.is_a?(String)
66
+ self.to_s =~ other
67
+ end
68
+ nil
69
+ end
70
+
71
+ alias_method :==, :eql?
72
+
73
+ #
74
+ # Message Interface Definitions
75
+ #
76
+
77
+ def persistent?
78
+ raise NotImplementedError
79
+ end
80
+
81
+ #
82
+ # Message Helpers (by level)
83
+ #
84
+
85
+ def alert?
86
+ @level == :alert
87
+ end
88
+
89
+ def error?
90
+ @level == :error
91
+ end
92
+
93
+ def info?
94
+ @level == :info
95
+ end
96
+
97
+ def notice?
98
+ @level == :notice
99
+ end
100
+
101
+ def self.alert(message, **i18n_params)
102
+ new(:alert, message, **i18n_params)
103
+ end
104
+
105
+ def self.error(message, **i18n_params)
106
+ new(:error, message, **i18n_params)
107
+ end
108
+
109
+ def self.info(message, **i18n_params)
110
+ new(:info, message, **i18n_params)
111
+ end
112
+
113
+ def self.notice(message, **i18n_params)
114
+ new(:notice, message, **i18n_params)
115
+ end
116
+
117
+ def class_name
118
+ self.class.model_name.element
119
+ end
120
+
121
+ def self.class_name
122
+ model_name.element
123
+ end
124
+
125
+ #
126
+ # Serialization Helpers
127
+ #
128
+
129
+ def from_json(json, include_root=include_root_in_json)
130
+ super(JSON.parse(json).tap { |this| this.delete('class') }.to_json)
131
+ end
132
+
133
+ def serializable_hash(options = {})
134
+ super.merge({ 'class' => self.class_name })
135
+ end
136
+
137
+ def to_session
138
+ serializable_hash.to_json
139
+ end
140
+
141
+ def self.from_session(json)
142
+ new(:stub, nil).from_json(json, false)
143
+ end
144
+
145
+ #
146
+ # Required Serialization Interface Methods
147
+ #
148
+
149
+ attribute_method_suffix '_contrived?'
150
+ attribute_method_prefix 'clear_'
151
+ define_attribute_methods :i18n_params, :level, :translation
152
+
153
+ def attributes=(hash)
154
+ hash.each do |key, value|
155
+ send("#{key}=", value)
156
+ end
157
+ end
158
+
159
+ def attributes
160
+ instance_values
161
+ end
162
+
163
+ private
164
+
165
+ def attribute_contrived?(attr)
166
+ true
167
+ end
168
+
169
+ def clear_attribute(attr)
170
+ send("#{attr}=", nil)
171
+ end
172
+ end
173
+ end
174
+ end