Class: LocaleFlash::Flash
- Inherits:
-
Object
- Object
- LocaleFlash::Flash
- Defined in:
- lib/locale_flash/flash.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #controllers ⇒ Object
- #fallbacks ⇒ Object
-
#initialize(args = {}) ⇒ Flash
constructor
A new instance of Flash.
- #key ⇒ Object
- #legacy? ⇒ Boolean
- #to_html ⇒ Object
- #to_params ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Flash
Returns a new instance of Flash.
5 6 7 8 9 10 11 |
# File 'lib/locale_flash/flash.rb', line 5 def initialize(args={}) @type = args[:type] @controller = args[:controller] @action = args[:action] @options = args[:options] || {} @message = args[:message] end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
3 4 5 |
# File 'lib/locale_flash/flash.rb', line 3 def action @action end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
3 4 5 |
# File 'lib/locale_flash/flash.rb', line 3 def controller @controller end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
3 4 5 |
# File 'lib/locale_flash/flash.rb', line 3 def @message end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/locale_flash/flash.rb', line 3 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/locale_flash/flash.rb', line 3 def type @type end |
Class Method Details
.from_params(type, params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/locale_flash/flash.rb', line 13 def self.from_params(type, params={}) if params_hash_stringkeys? params build_from_hash_stringkeys type, params elsif params.is_a?(Hash) && params[:controller] && params[:action] new(params.merge(:type => type)) else new(:type => type, :message => params.to_s) end end |
Instance Method Details
#controllers ⇒ Object
49 50 51 |
# File 'lib/locale_flash/flash.rb', line 49 def controllers controller.split('/') end |
#fallbacks ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/locale_flash/flash.rb', line 57 def fallbacks if controllers.size > 1 defaults = [] controllers.each_with_index do |current, i| current = controllers[0, (controllers.size - i)].join('.') parent = controllers[0, (controllers.size - i - 1)].join('.') defaults << ['controllers', current, 'flash', type] defaults << ['controllers', parent, 'flash', action, type] unless parent.empty? end else defaults = [['controllers', controller, 'flash', type]] end defaults << ['controllers', 'flash', action, type] defaults << ['controllers', 'flash', type] defaults.map { |i| i.join('.').to_sym } end |
#key ⇒ Object
53 54 55 |
# File 'lib/locale_flash/flash.rb', line 53 def key ['controllers', controllers.join('.'), action, 'flash', type].join('.').to_sym end |
#legacy? ⇒ Boolean
45 46 47 |
# File 'lib/locale_flash/flash.rb', line 45 def legacy? !.nil? end |
#to_html ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/locale_flash/flash.rb', line 75 def to_html str = if legacy? else I18n.t(key, .merge(:default => fallbacks)) end LocaleFlash::Config.template.call(type, str) end |
#to_params ⇒ Object
39 40 41 42 43 |
# File 'lib/locale_flash/flash.rb', line 39 def to_params { :controller => controller, :action => action, :options => } end |