Class: UzuUzu::Environments
Constant Summary collapse
- DEFAULT_YAML =
'uzuuzu.yaml'
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#flyweight ⇒ Object
Returns the value of attribute flyweight.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#localize ⇒ Object
Returns the value of attribute localize.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#memcache ⇒ Object
Returns the value of attribute memcache.
-
#rack_session ⇒ Object
Returns the value of attribute rack_session.
-
#service_name ⇒ Object
Returns the value of attribute service_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(yaml = nil) ⇒ Environments
constructor
A new instance of Environments.
- #load_localize ⇒ Object
- #load_yaml(yaml) ⇒ Object
- #setup(map) ⇒ Object
Constructor Details
#initialize(yaml = nil) ⇒ Environments
Returns a new instance of Environments.
40 41 42 |
# File 'lib/uzuuzu-core/environments.rb', line 40 def initialize(yaml=nil) load_yaml(yaml||self.class.default_yaml) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
22 23 24 |
# File 'lib/uzuuzu-core/environments.rb', line 22 def config @config end |
#flyweight ⇒ Object
Returns the value of attribute flyweight.
12 13 14 |
# File 'lib/uzuuzu-core/environments.rb', line 12 def flyweight @flyweight end |
#lang ⇒ Object
Returns the value of attribute lang.
24 25 26 |
# File 'lib/uzuuzu-core/environments.rb', line 24 def lang @lang end |
#localize ⇒ Object
Returns the value of attribute localize.
26 27 28 |
# File 'lib/uzuuzu-core/environments.rb', line 26 def localize @localize end |
#logger ⇒ Object
Returns the value of attribute logger.
16 17 18 |
# File 'lib/uzuuzu-core/environments.rb', line 16 def logger @logger end |
#memcache ⇒ Object
Returns the value of attribute memcache.
18 19 20 |
# File 'lib/uzuuzu-core/environments.rb', line 18 def memcache @memcache end |
#rack_session ⇒ Object
Returns the value of attribute rack_session.
20 21 22 |
# File 'lib/uzuuzu-core/environments.rb', line 20 def rack_session @rack_session end |
#service_name ⇒ Object
Returns the value of attribute service_name.
14 15 16 |
# File 'lib/uzuuzu-core/environments.rb', line 14 def service_name @service_name end |
Class Method Details
.current ⇒ Object
28 29 30 |
# File 'lib/uzuuzu-core/environments.rb', line 28 def self.current ::UzuUzu.current.environments end |
.default_yaml ⇒ Object
36 37 38 |
# File 'lib/uzuuzu-core/environments.rb', line 36 def self.default_yaml @@default_yaml ||= DEFAULT_YAML end |
.default_yaml=(yaml) ⇒ Object
32 33 34 |
# File 'lib/uzuuzu-core/environments.rb', line 32 def self.default_yaml=(yaml) @@default_yaml = yaml end |
Instance Method Details
#load_localize ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/uzuuzu-core/environments.rb', line 58 def load_localize @localize = {} if ::File.file?("./lang/#{@lang}.yaml") ::File.open("./lang/#{@lang}.yaml", :encoding => "UTF-8") do |f| @localize.merge!(::YAML.load(f)) end end if ::File.file?(__DIR__("lang/#{@lang}.yaml")) ::File.open(__DIR__("lang/#{@lang}.yaml"), :encoding => "UTF-8") do |f| @localize.merge!(::YAML.load(f)) end end end |
#load_yaml(yaml) ⇒ Object
44 45 46 47 48 |
# File 'lib/uzuuzu-core/environments.rb', line 44 def load_yaml(yaml) return if yaml.blank? yaml = ::YAML.load_file(yaml) unless yaml.kind_of?(Hash) setup(yaml) end |
#setup(map) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/uzuuzu-core/environments.rb', line 50 def setup(map) return if map.blank? @config = map @lang = map['lang'] || 'ja' @service_name = map['service'] load_localize end |