Class: Cuca::Config

Inherits:
Hash
  • Object
show all
Defined in:
lib/cuca/config.rb

Overview

Configure the application

App::Config is normally called from conf/environment.rb . The attributes below the framework will make use of, but you can always define own ones.

Example

Cuca::App.configure do |conf|
    conf.include_directories = %{_widgets _special_widgets}
    conf.database            = 'mydb'		# application specific
end

Attributes:

  • include_directories

An array of directories that will be automatically included if you call an action.
If one of the directories is found in the path where the action file is located it will require
all files found. (default: %w{_controllers _widgets _layouts} )
Optionally it's possible to autoload these support files. To do this you must pass an 
array of hashes to the method with the following keys:
  - :dir The name of the directory (e.g. _controllers)
  - :class_naming A proc that will take one parameter and returns the name of the class
    found within the file. It will get the filename as parameter.
    example :class_naming => Proc.new { |file_name| file_name.capitalize+'Controller' }
  • log_level - default 3 (future?)

  • magic_prefix - default: ‘_default’ (see Cuca::Controller)

  • display_errors - default: true , display errors in browser (swith off within production systems)

Instance Method Summary collapse

Constructor Details

#initializeConfig

some default stuff



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cuca/config.rb', line 50

def initialize
  self['include_directories'] = %w{_controllers _widgets _layouts}
  self['log_level']  = 3
  self['magic_prefix'] = '__default_'
  self['session_key'] = 'cuca_session'
  self['session_prefix'] = 'cuca.'
  self['session_valid'] = 3600*24
  self['view_directory'] = 'app/_views'	# where to find views for the view/erb generator
  self['http_404'] = '404.html'
  self['http_500'] = '500.html'
  self['default_mime_type'] = 'text/html'
  self['display_errors'] = true
  self['http_static_content_expires'] = 300	# expires http header for static content (only if served by the dispatcher)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *params) ⇒ Object

Raises:

  • (NoMethodError)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cuca/config.rb', line 29

def method_missing(m, *params)
    met = m.id2name

#    raise NoMethodError 
    if met[met.size-1].chr == '=' then
      self[met[0..met.size-2]] = params[0]
      return
    end

    if met[-2..-1] == '<<' then
      self[met[0..met.size-3]] ||= []
      self[met[0..met.size-3]] << params[0]
      return
    end

    return self[met] unless self[met].nil?
  
   raise NoMethodError
end