Class: MiddleSquid::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/middle_squid/cli.rb

Instance Method Summary collapse

Instance Method Details

#index(*directories) ⇒ Object

Note:

Builder#database must be called in your configuration script in order to initialize the database.

Populates the database from one or more blacklists.

Flags:

-a, --append, --no-append

Whether to keep the entries already in the database.

--domains, --no-domains

Whether to index domain lists.

Enabled by default.

--full, --no-full

Whether to index all blacklist categories. By default MiddleSquid will only read the categories registered using Builder#blacklist in the configuration script.

Enable if you want to reuse the same database in multiple configurations set to use different blacklist categories and you need to index everything.

-q, --quiet, --no-quiet

Whether to disable status output.

--urls, --no-urls

Whether to index url lists.

Enabled by default.

Examples:

middle_squid index ShallaBlackList -C middle_squid_config.rb


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/middle_squid/cli.rb', line 75

def index(*directories)
  config_file = File.expand_path options[:'config-file']
  directories.map! {|rel| File.expand_path rel }

  builder = Builder.from_file config_file

  entries = []
  entries << :url if options[:urls]
  entries << :domain if options[:domains]

  indexer = MiddleSquid::Indexer.new
  indexer.blacklists = builder.blacklists

  indexer.append     = options[:append]
  indexer.entries    = entries
  indexer.full_index = options[:full]
  indexer.quiet      = options[:quiet]

  indexer.index directories
end

#startObject

Runs the given configuration file.

Examples:

middle_squid start -C middle_squid_config.rb


17
18
19
20
21
22
23
# File 'lib/middle_squid/cli.rb', line 17

def start
  config_file = File.expand_path options[:'config-file']

  builder = Builder.from_file config_file

  MiddleSquid::Runner.new builder
end

#versionObject

Shows MiddleSquid’s version and copyright notice.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/middle_squid/cli.rb', line 101

def version
  puts "MiddleSquid #{MiddleSquid::VERSION}"
  puts <<GPL
Copyright (C) 2014 by Christian Fillion

  This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
GPL
end