Class: Tr8n::Session
- Inherits:
-
Object
- Object
- Tr8n::Session
- Defined in:
- lib/tr8n/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.
Class Method Summary collapse
Instance Method Summary collapse
- #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
- #with_block_options(opts) ⇒ Object
Instance Attribute Details
#access_token ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def access_token @access_token end |
#application ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def application @application end |
#block_options ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def @block_options end |
#cookie_params ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def @cookie_params end |
#current_component ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def current_component @current_component end |
#current_language ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def current_language @current_language end |
#current_locale ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def current_locale @current_locale end |
#current_source ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def current_source @current_source end |
#current_translator ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def current_translator @current_translator end |
#current_user ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def current_user @current_user end |
Class Method Details
.access_token ⇒ Object
44 45 46 |
# File 'lib/tr8n/session.rb', line 44 def self.access_token @access_token end |
.access_token=(token) ⇒ Object
48 49 50 |
# File 'lib/tr8n/session.rb', line 48 def self.access_token=(token) @access_token = token end |
Instance Method Details
#current_component_from_block_options ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/tr8n/session.rb', line 174 def arr = @block_options || [] arr.reverse.each do |opts| return application.component_by_key(opts[:component]) unless opts[:component].blank? end Tr8n.config.current_component end |
#current_source_from_block_options ⇒ Object
166 167 168 169 170 171 172 |
# File 'lib/tr8n/session.rb', line 166 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
52 53 54 55 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 |
# File 'lib/tr8n/session.rb', line 52 def init(opts = {}) return unless Tr8n.config.enabled? and Tr8n.config.application key = opts[:key] || Tr8n.config.application[:key] secret = opts[:secret] || Tr8n.config.application[:secret] host = opts[:host] || Tr8n.config.application[:host] self. = begin = "tr8n_#{key}" if opts[:cookies] and opts[:cookies][] begin HashWithIndifferentAccess.new(Tr8n::Utils.decode_and_verify_params(opts[:cookies][], secret)) rescue Exception => ex Tr8n.logger.error("Failed to parse tr8n cookie: #{ex.}") {} end else {} end end # Tr8n.logger.info(self.cookie_params.inspect) self.access_token = opts[:access_token] self.current_user = opts[:user] self.current_source = opts[:source] || '/tr8n/core' self.current_component = opts[:component] self.current_locale = self.[:locale] || opts[:locale] || Tr8n.config.default_locale if self.['translator'] self.current_translator = Tr8n::Translator.new(self.['translator']) end Tr8n.cache.reset_version self.application = Tr8n.memory.fetch(Tr8n::Application.cache_key) do Tr8n::Application.new(:host => host, :key => key, :secret => secret, :access_token => self.class.access_token).fetch end if Tr8n.cache.read_only? self.class.access_token = self.application.access_token end if self.current_translator self.current_translator.application = self.application end self.current_language = self.application.language(self.current_locale) end |
#inline_mode? ⇒ Boolean
136 137 138 |
# File 'lib/tr8n/session.rb', line 136 def inline_mode? current_translator and current_translator.inline? end |
#pop_block_options ⇒ Object
148 149 150 151 |
# File 'lib/tr8n/session.rb', line 148 def return unless @block_options @block_options.pop end |
#push_block_options(opts) ⇒ Object
Block Options
144 145 146 |
# File 'lib/tr8n/session.rb', line 144 def (opts) (@block_options ||= []).push(opts) end |
#reset ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/tr8n/session.rb', line 102 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.= nil end |
#source_language ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/tr8n/session.rb', line 120 def source_language arr = @block_options || [] arr.reverse.each do |opts| return application.language(opts[:locale]) unless opts[:locale].blank? end application.language end |
#target_language ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/tr8n/session.rb', line 128 def target_language arr = @block_options || [] arr.reverse.each do |opts| return application.language(opts[:target_locale]) unless opts[:target_locale].nil? end current_language end |
#with_block_options(opts) ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'lib/tr8n/session.rb', line 157 def (opts) (opts) if block_given? ret = yield end ret end |