Class: UzuUzu::Environments
Constant Summary collapse
- DEFAULT_YAML =
'uzuuzu.yaml'
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#dm ⇒ Object
Returns the value of attribute dm.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#localize ⇒ Object
Returns the value of attribute localize.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#map ⇒ Object
Returns the value of attribute map.
-
#memcache ⇒ Object
Returns the value of attribute memcache.
-
#rack_session ⇒ Object
Returns the value of attribute rack_session.
-
#s3 ⇒ Object
Returns the value of attribute s3.
-
#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.
44 45 46 47 |
# File 'lib/uzuuzu-core/environments.rb', line 44 def initialize(yaml=nil) load_yaml(yaml||self.class.default_yaml) dm end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
26 27 28 |
# File 'lib/uzuuzu-core/environments.rb', line 26 def config @config end |
#dm ⇒ Object
Returns the value of attribute dm.
16 17 18 |
# File 'lib/uzuuzu-core/environments.rb', line 16 def dm @dm end |
#lang ⇒ Object
Returns the value of attribute lang.
28 29 30 |
# File 'lib/uzuuzu-core/environments.rb', line 28 def lang @lang end |
#localize ⇒ Object
Returns the value of attribute localize.
30 31 32 |
# File 'lib/uzuuzu-core/environments.rb', line 30 def localize @localize end |
#logger ⇒ Object
Returns the value of attribute logger.
20 21 22 |
# File 'lib/uzuuzu-core/environments.rb', line 20 def logger @logger end |
#map ⇒ Object
Returns the value of attribute map.
12 13 14 |
# File 'lib/uzuuzu-core/environments.rb', line 12 def map @map end |
#memcache ⇒ Object
Returns the value of attribute memcache.
22 23 24 |
# File 'lib/uzuuzu-core/environments.rb', line 22 def memcache @memcache end |
#rack_session ⇒ Object
Returns the value of attribute rack_session.
24 25 26 |
# File 'lib/uzuuzu-core/environments.rb', line 24 def rack_session @rack_session end |
#s3 ⇒ Object
Returns the value of attribute s3.
18 19 20 |
# File 'lib/uzuuzu-core/environments.rb', line 18 def s3 @s3 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
32 33 34 |
# File 'lib/uzuuzu-core/environments.rb', line 32 def self.current ::UzuUzu.current.environments end |
.default_yaml ⇒ Object
40 41 42 |
# File 'lib/uzuuzu-core/environments.rb', line 40 def self.default_yaml @@default_yaml ||= DEFAULT_YAML end |
.default_yaml=(yaml) ⇒ Object
36 37 38 |
# File 'lib/uzuuzu-core/environments.rb', line 36 def self.default_yaml=(yaml) @@default_yaml = yaml end |
Instance Method Details
#load_localize ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/uzuuzu-core/environments.rb', line 63 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
49 50 51 52 53 |
# File 'lib/uzuuzu-core/environments.rb', line 49 def load_yaml(yaml) return if yaml.blank? yaml = ::YAML.load_file(yaml) unless yaml.kind_of?(Hash) setup(yaml) end |
#setup(map) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/uzuuzu-core/environments.rb', line 55 def setup(map) return if map.blank? @config = map @lang = map['lang'] || 'ja' @service_name = map['service'] load_localize end |