Class: Tml::Session
- Inherits:
-
Object
- Object
- Tml::Session
- Defined in:
- lib/tml/session.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#application ⇒ Object
Returns the value of attribute application.
-
#block_options ⇒ Object
Returns the value of attribute block_options.
-
#cookie_params ⇒ Object
Returns the value of attribute cookie_params.
-
#current_component ⇒ Object
Returns the value of attribute current_component.
-
#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.
-
#tools_enabled ⇒ Object
Returns the value of attribute tools_enabled.
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
Returns the value of attribute access_token.
40 41 42 |
# File 'lib/tml/session.rb', line 40 def access_token @access_token end |
#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 |
#cookie_params ⇒ Object
Returns the value of attribute cookie_params.
40 41 42 |
# File 'lib/tml/session.rb', line 40 def end |
#current_component ⇒ Object
Returns the value of attribute current_component.
40 41 42 |
# File 'lib/tml/session.rb', line 40 def current_component @current_component end |
#current_language ⇒ Object
Returns the value of attribute current_language.
40 41 42 |
# File 'lib/tml/session.rb', line 40 def current_language @current_language end |
#current_locale ⇒ Object
Returns the value of attribute current_locale.
40 41 42 |
# File 'lib/tml/session.rb', line 40 def current_locale @current_locale end |
#current_source ⇒ Object
Returns the value of attribute current_source.
40 41 42 |
# File 'lib/tml/session.rb', line 40 def current_source @current_source end |
#current_translator ⇒ Object
Returns the value of attribute current_translator.
40 41 42 |
# File 'lib/tml/session.rb', line 40 def current_translator @current_translator end |
#current_user ⇒ Object
Returns the value of attribute current_user.
40 41 42 |
# File 'lib/tml/session.rb', line 40 def current_user @current_user end |
#tools_enabled ⇒ Object
Returns the value of attribute tools_enabled.
40 41 42 |
# File 'lib/tml/session.rb', line 40 def tools_enabled @tools_enabled end |
Instance Method Details
#block_options_queue ⇒ Object
159 160 161 |
# File 'lib/tml/session.rb', line 159 def end |
#cookie_name ⇒ Object
43 44 45 |
# File 'lib/tml/session.rb', line 43 def "trex_#{self.application.key}" end |
#current_component_from_block_options ⇒ Object
180 181 182 183 184 185 186 |
# File 'lib/tml/session.rb', line 180 def arr = || [] 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
172 173 174 175 176 177 178 |
# File 'lib/tml/session.rb', line 172 def arr = || [] arr.reverse.each do |opts| return application.source_by_key(opts[:source]) unless opts[:source].blank? end nil end |
#init(opts = {}) ⇒ Object
47 48 49 50 51 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 |
# File 'lib/tml/session.rb', line 47 def init(opts = {}) return unless Tml.config.enabled? and Tml.config.application host = opts[:host] || Tml.config.application[:host] Tml.cache.reset_version self.application = Tml::Application.new(:host => host).fetch # 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.message}") {} 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
138 139 140 |
# File 'lib/tml/session.rb', line 138 def inline_mode? current_translator and current_translator.inline? end |
#pop_block_options ⇒ Object
150 151 152 153 |
# File 'lib/tml/session.rb', line 150 def return unless .pop end |
#push_block_options(opts) ⇒ Object
Block Options
146 147 148 |
# File 'lib/tml/session.rb', line 146 def (opts) ( ||= []).push(opts) end |
#reset ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/tml/session.rb', line 103 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
122 123 124 125 126 127 128 |
# File 'lib/tml/session.rb', line 122 def source_language ( || []).reverse.each do |opts| return application.language(opts[:locale]) unless opts[:locale].nil? end application.language end |
#target_language ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/tml/session.rb', line 130 def target_language ( || []).reverse.each do |opts| return application.language(opts[:target_locale]) unless opts[:target_locale].nil? end current_language end |
#tools_enabled? ⇒ Boolean
99 100 101 |
# File 'lib/tml/session.rb', line 99 def tools_enabled? self.tools_enabled end |
#with_block_options(opts) ⇒ Object
163 164 165 166 167 168 169 170 |
# File 'lib/tml/session.rb', line 163 def (opts) (opts) if block_given? ret = yield end ret end |