Class: UzuUzu::Environments

Inherits:
Object show all
Defined in:
lib/uzuuzu-core/environments.rb

Constant Summary collapse

DEFAULT_YAML =
'uzuuzu.yaml'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#configObject

Returns the value of attribute config.



26
27
28
# File 'lib/uzuuzu-core/environments.rb', line 26

def config
  @config
end

#dmObject

Returns the value of attribute dm.



16
17
18
# File 'lib/uzuuzu-core/environments.rb', line 16

def dm
  @dm
end

#langObject

Returns the value of attribute lang.



28
29
30
# File 'lib/uzuuzu-core/environments.rb', line 28

def lang
  @lang
end

#localizeObject

Returns the value of attribute localize.



30
31
32
# File 'lib/uzuuzu-core/environments.rb', line 30

def localize
  @localize
end

#loggerObject

Returns the value of attribute logger.



20
21
22
# File 'lib/uzuuzu-core/environments.rb', line 20

def logger
  @logger
end

#mapObject

Returns the value of attribute map.



12
13
14
# File 'lib/uzuuzu-core/environments.rb', line 12

def map
  @map
end

#memcacheObject

Returns the value of attribute memcache.



22
23
24
# File 'lib/uzuuzu-core/environments.rb', line 22

def memcache
  @memcache
end

#rack_sessionObject

Returns the value of attribute rack_session.



24
25
26
# File 'lib/uzuuzu-core/environments.rb', line 24

def rack_session
  @rack_session
end

#s3Object

Returns the value of attribute s3.



18
19
20
# File 'lib/uzuuzu-core/environments.rb', line 18

def s3
  @s3
end

#service_nameObject

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

.currentObject



32
33
34
# File 'lib/uzuuzu-core/environments.rb', line 32

def self.current
  ::UzuUzu.current.environments
end

.default_yamlObject



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_localizeObject



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