Class: Tml::Session
- Inherits:
-
Object
- Object
- Tml::Session
- Defined in:
- lib/tml/session.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Session Attributes - Move to Session.
-
#application ⇒ Object
Session Attributes - Move to Session.
-
#block_options ⇒ Object
Session Attributes - Move to Session.
-
#cookie_params ⇒ Object
Session Attributes - Move to Session.
-
#current_component ⇒ Object
Session Attributes - Move to Session.
-
#current_language ⇒ Object
Session Attributes - Move to Session.
-
#current_locale ⇒ Object
Session Attributes - Move to Session.
-
#current_source ⇒ Object
Session Attributes - Move to Session.
-
#current_translator ⇒ Object
Session Attributes - Move to Session.
-
#current_user ⇒ Object
Session Attributes - Move to Session.
-
#tools_enabled ⇒ Object
Session Attributes - Move to Session.
Class Method Summary collapse
Instance Method Summary collapse
- #block_options_queue ⇒ Object
- #cookie_name ⇒ Object
- #current_component_from_block_options ⇒ Object
- #current_source_from_block_options ⇒ Object
- #init(opts = {}) ⇒ Object
- #inline_mode? ⇒ Boolean
- #pop_block_options ⇒ Object
-
#push_block_options(opts) ⇒ Object
Block Options.
- #reset ⇒ Object
- #source_language ⇒ Object
- #target_language ⇒ Object
- #tools_enabled? ⇒ Boolean
- #with_block_options(opts) ⇒ Object
Instance Attribute Details
#access_token ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tml/session.rb', line 41 def access_token @access_token end |
#application ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tml/session.rb', line 41 def application @application end |
#block_options ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tml/session.rb', line 41 def @block_options end |
#cookie_params ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tml/session.rb', line 41 def @cookie_params end |
#current_component ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tml/session.rb', line 41 def current_component @current_component end |
#current_language ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tml/session.rb', line 41 def current_language @current_language end |
#current_locale ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tml/session.rb', line 41 def current_locale @current_locale end |
#current_source ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tml/session.rb', line 41 def current_source @current_source end |
#current_translator ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tml/session.rb', line 41 def current_translator @current_translator end |
#current_user ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tml/session.rb', line 41 def current_user @current_user end |
#tools_enabled ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tml/session.rb', line 41 def tools_enabled @tools_enabled end |
Class Method Details
.access_token ⇒ Object
44 45 46 |
# File 'lib/tml/session.rb', line 44 def self.access_token @access_token end |
.access_token=(token) ⇒ Object
48 49 50 |
# File 'lib/tml/session.rb', line 48 def self.access_token=(token) @access_token = token end |
Instance Method Details
#block_options_queue ⇒ Object
177 178 179 |
# File 'lib/tml/session.rb', line 177 def @block_options end |
#cookie_name ⇒ Object
52 53 54 |
# File 'lib/tml/session.rb', line 52 def "trex_#{self.application.key}" end |
#current_component_from_block_options ⇒ Object
198 199 200 201 202 203 204 |
# File 'lib/tml/session.rb', line 198 def arr = @block_options || [] arr.reverse.each do |opts| return application.component_by_key(opts[:component]) unless opts[:component].blank? end Tml.config.current_component end |
#current_source_from_block_options ⇒ Object
190 191 192 193 194 195 196 |
# File 'lib/tml/session.rb', line 190 def arr = @block_options || [] arr.reverse.each do |opts| return application.source_by_key(opts[:source]) unless opts[:source].blank? end nil end |
#init(opts = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/tml/session.rb', line 56 def init(opts = {}) return unless Tml.config.enabled? and Tml.config.application host = opts[:host] || Tml.config.application[:host] Tml::Session.access_token ||= begin self.access_token = opts[:token] || Tml.config.application[:token] self.access_token ||= opts[:access_token] || Tml.config.application[:access_token] end Tml.cache.reset_version self.application = Tml::Application.new(:host => host, :access_token => Tml::Session.access_token).fetch if Tml.cache.read_only? self.class.access_token = self.application.access_token end # Tml.logger.info(self.cookie_params.inspect) self. = begin if opts[:cookies] and opts[:cookies][] begin params = HashWithIndifferentAccess.new(Tml::Utils.decode(opts[:cookies][])) params[:locale] = opts[:locale] if opts[:change_locale] params rescue Exception => ex Tml.logger.error("Failed to parse tml cookie: #{ex.}") {} end else {} end end self.tools_enabled = opts[:tools_enabled] self.current_user = opts[:user] self.current_source = opts[:source] || 'index' self.current_component = opts[:component] self.current_locale = self.[:locale] || opts[:locale] || Tml.config.default_locale if self.['translator'] self.current_translator = Tml::Translator.new(self.['translator']) end # if inline mode don't use any app cache if inline_mode? self.application = self.application.dup self.application.reset_translation_cache end if self.current_translator self.current_translator.application = self.application end self.current_language = self.application.current_language(self.current_locale) self.current_locale = self.current_language.locale self end |
#inline_mode? ⇒ Boolean
156 157 158 |
# File 'lib/tml/session.rb', line 156 def inline_mode? current_translator and current_translator.inline? end |
#pop_block_options ⇒ Object
168 169 170 171 |
# File 'lib/tml/session.rb', line 168 def return unless @block_options @block_options.pop end |
#push_block_options(opts) ⇒ Object
Block Options
164 165 166 |
# File 'lib/tml/session.rb', line 164 def (opts) (@block_options ||= []).push(opts) end |
#reset ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/tml/session.rb', line 121 def reset self.application= nil self.current_user= nil self.current_language= nil self.current_translator= nil self.current_source= nil self.current_component= nil self.tools_enabled= nil self.= nil end |
#source_language ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/tml/session.rb', line 140 def source_language (@block_options || []).reverse.each do |opts| return application.language(opts[:locale]) unless opts[:locale].nil? end application.language end |
#target_language ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/tml/session.rb', line 148 def target_language (@block_options || []).reverse.each do |opts| return application.language(opts[:target_locale]) unless opts[:target_locale].nil? end current_language end |
#tools_enabled? ⇒ Boolean
117 118 119 |
# File 'lib/tml/session.rb', line 117 def tools_enabled? self.tools_enabled end |
#with_block_options(opts) ⇒ Object
181 182 183 184 185 186 187 188 |
# File 'lib/tml/session.rb', line 181 def (opts) (opts) if block_given? ret = yield end ret end |