Class: Gonzui::Config

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/gonzui/config.rb

Instance Method Summary collapse

Methods included from Util

assert, assert_equal, assert_equal_all, assert_non_nil, assert_not_reached, benchmark, command_exist?, commify, eprintf, format_bytes, program_name, protect_from_signals, require_command, set_verbosity, shell_escape, unix?, vprintf, windows?, wprintf

Constructor Details

#initializeConfig

Returns a new instance of Config.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gonzui/config.rb', line 16

def initialize
  #
  # All paths should be expanded to absolute paths
  # because the current directory would be changed when
  # a process becomes a daemon.
  #
  @temporary_directory = ENV['tmp'] || "/tmp"
  @db_directory = File.expand_path("gonzui.db")
  @cache_directory = File.join(@db_directory, "cache")
  @gonzui_log_file = File.expand_path("gonzui.log")

  @db_cache_size = 5 * 1024 ** 2

  @quiet = false
  @verbose = false

  @utf8 = true
  @encoding_preference = UTF8::Preference

  @noindex_formats = []
  # FIXME: should be more flexible
  @exclude_pattern = /~$|\.bak$|CVS|\.svn|\.git/

  #
  # For gonzui-server
  #
  @pid_file = File.expand_path("gonzui.pid")
  @daemon = false
  @access_log_file = File.expand_path("access.log")
  @catalog_directory = choose_directory("catalog")
  @doc_directory = choose_directory("doc")
  @http_port = Gonzui::HTTP_PORT
  @bind_address = '*'
  @user = nil
  @group = nil
  @site_title = "gonzui"
  @base_mount_point = "/"

  @default_results_per_page = 10
  @max_results_per_page = 50
  @max_pages = 20
  @max_words = 10
  @max_packages_per_page = 100
  @nresults_candidates = [10, 20, 30, 50]

  set_user_and_group if unix?
  instance_variables.each {|name|
	self.class.class_eval { 
      attr_accessor name.delete("@")
    }
  }
end

Instance Method Details

#dump(out = STDOUT) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/gonzui/config.rb', line 98

def dump(out = STDOUT)
  len = keys.map {|key| key.inspect.length }.max
  out.puts "{"
  keys.sort_by {|key| key.to_s }.each {|key|
    out.printf("  %-#{len}s => %s,\n", key.inspect, send(key).inspect)
  }
  out.puts "}"
end

#load(file_name) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/gonzui/config.rb', line 107

def load(file_name)
  f = File.open(file_name)
  hash = eval(f.read)
  f.close
  return if hash.nil?
  hash.each {|key, value|
    send(key.to_s + "=", value)
  }
end

#max_results_overallObject



94
95
96
# File 'lib/gonzui/config.rb', line 94

def max_results_overall
  @max_results_per_page * @max_pages
end