Class: Ki::KiConfig

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ki/ki_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/ki/ki_config.rb', line 7

def config
  @config
end

#environmentObject (readonly)

Returns the value of attribute environment.



7
8
9
# File 'lib/ki/ki_config.rb', line 7

def environment
  @environment
end

Instance Method Details

#config_file_pathObject



15
16
17
# File 'lib/ki/ki_config.rb', line 15

def config_file_path
  'config.yml'
end

#cors?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ki/ki_config.rb', line 19

def cors?
  @config['cors']
end

#databaseObject



37
38
39
# File 'lib/ki/ki_config.rb', line 37

def database
  @config['database']
end

#middlewareObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ki/ki_config.rb', line 23

def middleware
  used_middleware = %w(ApiHandler CoffeeCompiler SassCompiler HamlCompiler
                       PublicFileServer)
  used_middleware = @config['middleware'] if @config['middleware']

  used_middleware = add_rm_middleware used_middleware, 'add_middleware', 'push'
  used_middleware = add_rm_middleware used_middleware, 'rm_middleware', 'delete'

  # convert middleware to ruby object
  used_middleware.uniq.map do |middleware|
    Object.const_get('Ki').const_get('Middleware').const_get(middleware)
  end
end

#read(environment) ⇒ Object



9
10
11
12
13
# File 'lib/ki/ki_config.rb', line 9

def read(environment)
  @environment = environment
  @config = YAML.load_file(config_file_path)[environment]
  @config['cors'] ||= true
end