flash_speaker 0.0.1.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 +7 -0
- data/lib/flash_speaker.rb +39 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1eb281a565e1533807575679451f5c5b1e8711cd
|
4
|
+
data.tar.gz: 6e2b9af3c8b907297dcfe581706da1b82f46b486
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75d03889df68f4b769f8db8562d360119593da4fc87be96bcc0e81dc7300f7b138377479d53c6bc2ed923e63751dac22feb6c22fd65bc12dd4e6ef12e3ceac5d
|
7
|
+
data.tar.gz: 73d06339843cd38520fa529c6098d651156384580b7a0dcf114811f927e802c8da6f707a6f0263432da361f58fa9ac96bbab7593deee7f3260b0018ad4164dab
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module FlashSpeaker
|
2
|
+
def attach_message(success_flag, entity_errors = nil)
|
3
|
+
flash_type = success_flag ? :success : :failed
|
4
|
+
flash[:errors] = entity_errors if entity_errors.present?
|
5
|
+
flash[flash_type] = message(flash_type)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def message(flash_type)
|
11
|
+
case
|
12
|
+
when message_exists?(message_path(flash_type))
|
13
|
+
t message_path(flash_type)
|
14
|
+
when message_exists?(default_message_path(flash_type))
|
15
|
+
msg = t default_message_path(flash_type)
|
16
|
+
msg.sub('<entity>', entity_name)
|
17
|
+
else
|
18
|
+
raise "translation missing: #{message_path}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def message_path(flash_type)
|
23
|
+
"#{controller_name}.actions.#{action_name}.#{flash_type}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_message_path(flash_type)
|
27
|
+
"default.actions.#{action_name}.#{flash_type}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def entity_name
|
31
|
+
t "#{controller_name}.entity"
|
32
|
+
end
|
33
|
+
|
34
|
+
def message_exists?(path)
|
35
|
+
I18n.t path, raise: true
|
36
|
+
rescue
|
37
|
+
false
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flash_speaker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kris Aberfort
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails-i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
description: |2
|
28
|
+
Help to organize and minimize boring flash messages code in controllers.
|
29
|
+
Also it requires using internationalization i18n gem.
|
30
|
+
email:
|
31
|
+
- elhowm@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- lib/flash_speaker.rb
|
37
|
+
homepage: http://rubygems.org/gems/flash_speaker
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.2.2
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Simplify organizing your flash messages
|
61
|
+
test_files: []
|