Class: Tr8n::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/tr8n/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#applicationObject

Session Attributes - Move to Session



41
42
43
# File 'lib/tr8n/session.rb', line 41

def application
  @application
end

#block_optionsObject

Block Options



41
42
43
# File 'lib/tr8n/session.rb', line 41

def block_options
  @block_options
end

#current_componentObject

Session Attributes - Move to Session



41
42
43
# File 'lib/tr8n/session.rb', line 41

def current_component
  @current_component
end

#current_languageObject

Session Attributes - Move to Session



41
42
43
# File 'lib/tr8n/session.rb', line 41

def current_language
  @current_language
end

#current_sourceObject

Session Attributes - Move to Session



41
42
43
# File 'lib/tr8n/session.rb', line 41

def current_source
  @current_source
end

#current_translatorObject

Session Attributes - Move to Session



41
42
43
# File 'lib/tr8n/session.rb', line 41

def current_translator
  @current_translator
end

#current_userObject

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_optionsObject



116
117
118
119
120
121
122
# File 'lib/tr8n/session.rb', line 116

def current_component_from_block_options
  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_optionsObject



108
109
110
111
112
113
114
# File 'lib/tr8n/session.rb', line 108

def current_source_from_block_options
  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

#resetObject



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.block_options= nil
end

#source_languageObject



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_languageObject



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 with_block_options(opts)
  @block_options ||= []
  @block_options.push(opts)
  if block_given?
    ret = yield
  end
  @block_options.pop if @block_options
  ret
end