Class: Tml::Session
- Inherits:
-
Object
- Object
- Tml::Session
- Defined in:
- lib/tml/session.rb
Instance Attribute Summary collapse
-
#application ⇒ Object
Returns the value of attribute application.
-
#block_options ⇒ Object
Returns the value of attribute block_options.
-
#current_language ⇒ Object
Returns the value of attribute current_language.
-
#current_locale ⇒ Object
Returns the value of attribute current_locale.
-
#current_source ⇒ Object
Returns the value of attribute current_source.
-
#current_translator ⇒ Object
Returns the value of attribute current_translator.
-
#current_user ⇒ Object
Returns the value of attribute current_user.
Instance Method Summary collapse
-
#block_option(key, lookup = true) ⇒ Object
Block Options.
- #block_options_queue ⇒ Object
- #init(opts = {}) ⇒ Object
- #init_application(opts = {}) ⇒ Object
- #inline_mode? ⇒ Boolean
- #pop_block_options ⇒ Object
- #preferred_locale(locales) ⇒ Object
- #push_block_options(opts) ⇒ Object
- #reset ⇒ Object
- #source_language ⇒ Object
- #target_language ⇒ Object
- #with_block_options(opts) ⇒ Object
Instance Attribute Details
#application ⇒ Object
Returns the value of attribute application.
40 41 42 |
# File 'lib/tml/session.rb', line 40 def application @application end |
#block_options ⇒ Object
Returns the value of attribute block_options.
40 41 42 |
# File 'lib/tml/session.rb', line 40 def end |
#current_language ⇒ Object
Returns the value of attribute current_language.
41 42 43 |
# File 'lib/tml/session.rb', line 41 def current_language @current_language end |
#current_locale ⇒ Object
Returns the value of attribute current_locale.
41 42 43 |
# File 'lib/tml/session.rb', line 41 def current_locale @current_locale end |
#current_source ⇒ Object
Returns the value of attribute current_source.
41 42 43 |
# File 'lib/tml/session.rb', line 41 def current_source @current_source end |
#current_translator ⇒ Object
Returns the value of attribute current_translator.
41 42 43 |
# File 'lib/tml/session.rb', line 41 def current_translator @current_translator end |
#current_user ⇒ Object
Returns the value of attribute current_user.
41 42 43 |
# File 'lib/tml/session.rb', line 41 def current_user @current_user end |
Instance Method Details
#block_option(key, lookup = true) ⇒ Object
Block Options
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/tml/session.rb', line 123 def block_option(key, lookup = true) if lookup .reverse.each do || value = [key.to_s] || [key.to_sym] return value if value end return nil end [key] end |
#block_options_queue ⇒ Object
143 144 145 |
# File 'lib/tml/session.rb', line 143 def ||= [] end |
#init(opts = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/tml/session.rb', line 43 def init(opts = {}) return if Tml.config.disabled? # Tml.logger.debug(opts.inspect) Tml.cache.reset_version Tml.cache.namespace = opts[:namespace] init_application(opts) self end |
#init_application(opts = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/tml/session.rb', line 56 def init_application(opts = {}) self.current_user = opts[:user] self.current_source = opts[:source] || 'index' self.current_locale = opts[:locale] self.current_translator = opts[:translator] app_config = Tml.config.application || {} self.application = Tml::Application.new( :key => opts[:key] || app_config[:key], :access_token => opts[:access_token] || opts[:token] || app_config[:token], :host => opts[:host] || app_config[:host], :cdn_host => opts[:cdn_host] || app_config[:cdn_host] ).fetch if self.current_translator self.current_translator.application = self.application end self.current_locale = preferred_locale(opts[:locale]) self.current_language = self.application.current_language(self.current_locale) end |
#inline_mode? ⇒ Boolean
115 116 117 |
# File 'lib/tml/session.rb', line 115 def inline_mode? current_translator and current_translator.inline? end |
#pop_block_options ⇒ Object
138 139 140 141 |
# File 'lib/tml/session.rb', line 138 def return unless .pop end |
#preferred_locale(locales) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/tml/session.rb', line 78 def preferred_locale(locales) return application.default_locale unless locales locales = locales.is_a?(String) ? locales.split(',') : locales locales.each do |locale| return locale if application.locales.include?(locale) end application.default_locale end |
#push_block_options(opts) ⇒ Object
134 135 136 |
# File 'lib/tml/session.rb', line 134 def (opts) .push(opts) end |
#reset ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/tml/session.rb', line 87 def reset self.application= nil self.current_user= nil self.current_language= nil self.current_translator= nil self.current_source= nil self.= nil end |
#source_language ⇒ Object
104 105 106 107 |
# File 'lib/tml/session.rb', line 104 def source_language locale = block_option(:locale) locale ? application.language(locale) : application.language end |
#target_language ⇒ Object
109 110 111 112 113 |
# File 'lib/tml/session.rb', line 109 def target_language target_locale = block_option(:target_locale) language = (target_locale ? application.language(target_locale) : current_language) language || Tml.config.default_language end |
#with_block_options(opts) ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/tml/session.rb', line 151 def (opts) (opts) if block_given? ret = yield end ret end |