Class: Tr8n::Session
- Inherits:
-
Object
- Object
- Tr8n::Session
- Defined in:
- lib/tr8n/session.rb
Instance Attribute Summary collapse
-
#application ⇒ Object
Session Attributes - Move to Session.
-
#block_options ⇒ Object
Block Options.
-
#current_component ⇒ Object
Session Attributes - Move to Session.
-
#current_language ⇒ 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.
Instance Method Summary collapse
- #current_component_from_block_options ⇒ Object
- #current_source_from_block_options ⇒ Object
- #init(key = nil, secret = nil, host = nil) ⇒ Object
- #reset ⇒ Object
- #source_language ⇒ Object
- #target_language ⇒ Object
- #with_block_options(opts) ⇒ Object
Instance Attribute Details
#application ⇒ Object
Session Attributes - Move to Session
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def application @application end |
#block_options ⇒ Object
Block Options
41 42 43 |
# File 'lib/tr8n/session.rb', line 41 def @block_options 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_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 |
Instance Method Details
#current_component_from_block_options ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/tr8n/session.rb', line 116 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
108 109 110 111 112 113 114 |
# File 'lib/tr8n/session.rb', line 108 def arr = @block_options || [] arr.reverse.each do |opts| return application.source_by_key(opts[:source]) unless opts[:source].blank? end nil end |
#init(key = nil, secret = nil, host = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/tr8n/session.rb', line 44 def init(key = nil, secret = nil, host = nil) return unless Tr8n.config.enabled? and Tr8n.config.application key ||= Tr8n.config.application[:key] secret ||= Tr8n.config.application[:secret] host ||= Tr8n.config.application[:host] Tr8n.cache.reset_version self.current_source = '/tr8n/core' # default source self.application = Tr8n::Application.new(:host => host, :key => key, :secret => secret).fetch end |
#reset ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/tr8n/session.rb', line 56 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
74 75 76 77 78 79 80 |
# File 'lib/tr8n/session.rb', line 74 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
82 83 84 85 86 87 88 |
# File 'lib/tr8n/session.rb', line 82 def target_language arr = @block_options || [] arr.reverse.each do |opts| return application.language(opts[:target_locale]) unless opts[:target_locale].blank? end current_language end |
#with_block_options(opts) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/tr8n/session.rb', line 98 def (opts) @block_options ||= [] @block_options.push(opts) if block_given? ret = yield end @block_options.pop if @block_options ret end |