Class: CloudDoor::Config

Inherits:
CloudYaml show all
Defined in:
lib/cloud_door/config.rb

Constant Summary collapse

CONFIG_FILE =
'./cloud_door_config.yml'
GLOBAL_CONFIG_ITEMS =
[
  'data_path',
  'sessoin_flg',
]
CONFIG_ITEMS =
[
  'client_id',
  'client_secret',
  'redirect_url'
]
SESSION_FLG_ON =
'1'
SESSION_FLG_OFF =
'0'

Instance Attribute Summary collapse

Attributes inherited from CloudYaml

#file, #items, #storage

Instance Method Summary collapse

Methods inherited from CloudYaml

#load_yaml, #update_yaml

Constructor Details

#initialize(storage) ⇒ Config

Returns a new instance of Config.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cloud_door/config.rb', line 25

def initialize(storage)
  @storage       = storage
  @data_path     = './data/'
  @session_flg   = SESSION_FLG_OFF
  @file          = CONFIG_FILE
  @items         = CONFIG_ITEMS
  @client_id     = ''
  @client_secret = ''
  @redirect_url  = ''
  load_global_config
  load_yaml
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



6
7
8
# File 'lib/cloud_door/config.rb', line 6

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



6
7
8
# File 'lib/cloud_door/config.rb', line 6

def client_secret
  @client_secret
end

#data_pathObject (readonly)

Returns the value of attribute data_path.



7
8
9
# File 'lib/cloud_door/config.rb', line 7

def data_path
  @data_path
end

#redirect_urlObject

Returns the value of attribute redirect_url.



6
7
8
# File 'lib/cloud_door/config.rb', line 6

def redirect_url
  @redirect_url
end

Instance Method Details

#init?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
# File 'lib/cloud_door/config.rb', line 50

def init?
  CONFIG_ITEMS.each do |item|
    val = instance_variable_get("@#{item}")
    return false if val.nil? || val.empty?
  end
  true
end

#load_global_configObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cloud_door/config.rb', line 38

def load_global_config
  return false unless File.exist?(@file)
  all_config = YAML.load_file(@file)
  return false unless all_config.is_a?(Hash)
  return false unless all_config.key?('global')
  config = all_config['global']
  GLOBAL_CONFIG_ITEMS.each do |item|
    instance_variable_set("@#{item}", config[item]) if config.key?(item)
  end
  true
end

#session_use?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/cloud_door/config.rb', line 58

def session_use?
  (@session_flg.to_s == SESSION_FLG_ON.to_s)
end