Class: Qwandry::Configuration
- Inherits:
-
Object
- Object
- Qwandry::Configuration
- Defined in:
- lib/qwandry/configuration.rb
Class Method Summary collapse
-
.configurations ⇒ Object
Returns the registered configurations.
-
.default(*configurations) ⇒ Object
Sets the default configuration to launch, if no ‘configurations` are passed in, it returns their names.
-
.load_configuration(path) ⇒ Object
Loads a configuration file, and executes it in the context of the Qwandry::Configuration class.
-
.load_configuration_files ⇒ Object
Loads the Qwandry default configuration and then the user’s custom configuration file if it is present.
-
.present?(name) ⇒ Boolean
Returns true if executable ‘name` is present.
-
.register(name, &block) ⇒ Object
Regsisters a new Qwandry configuration.
-
.register_if_present(name, binary = nil, &block) ⇒ Object
Registers a configuration is a specific binary is available.
-
.repositories(*names) ⇒ Object
Loads the repositories for ‘names` if no names are given, it loads the defaults.
Instance Method Summary collapse
- #<<(block) ⇒ Object
-
#add(paths, options = {}) ⇒ Object
Adds a new Repository to the current configuration.
-
#initialize(name) ⇒ Configuration
constructor
Creates a new Configuration for building a set of Repositories, this should probably only be invoked by Configuration.build, it only exists to make the customization DSL relatively easy to work with.
- #repositories ⇒ Object
Constructor Details
#initialize(name) ⇒ Configuration
Creates a new Configuration for building a set of Repositories, this should probably only be invoked by Configuration.build, it only exists to make the customization DSL relatively easy to work with.
107 108 109 110 111 |
# File 'lib/qwandry/configuration.rb', line 107 def initialize(name) @name = name @blocks = [] @repositories = [] end |
Class Method Details
.configurations ⇒ Object
Returns the registered configurations
42 43 44 |
# File 'lib/qwandry/configuration.rb', line 42 def configurations builders.keys end |
.default(*configurations) ⇒ Object
Sets the default configuration to launch, if no ‘configurations` are passed in, it returns their names.
33 34 35 36 37 38 39 |
# File 'lib/qwandry/configuration.rb', line 33 def default(*configurations) if configurations.empty? @default ||= [] else @default = configurations end end |
.load_configuration(path) ⇒ Object
Loads a configuration file, and executes it in the context of the Qwandry::Configuration class. See ‘configuration/default.rb` for an example, or run:
qw --customize
For a sample customization file.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/qwandry/configuration.rb', line 52 def load_configuration(path) if File.exist?(path) begin eval IO.read(path), nil, path, 1 rescue Exception=>ex STDERR.puts "Warning: error in configuration file: #{path.inspect}" STDERR.puts "Exception: #{ex.}" STDERR.puts ex.backtrace end end end |
.load_configuration_files ⇒ Object
Loads the Qwandry default configuration and then the user’s custom configuration file if it is present.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/qwandry/configuration.rb', line 66 def load_configuration_files # load default configuration files system_config_dir = File.join(File.dirname(__FILE__), 'configuration') Dir[system_config_dir+"/*.rb"].each do |path| load_configuration path end # load user custom init files if config_dir = Qwandry.config_dir custom_path = File.join(config_dir, 'init.rb') load_configuration(custom_path) end end |
.present?(name) ⇒ Boolean
Returns true if executable ‘name` is present.
25 26 27 28 29 |
# File 'lib/qwandry/configuration.rb', line 25 def present? name ENV['PATH'].split(File::PATH_SEPARATOR).any? do |pathDir| File.executable?(File.join pathDir, name.to_s) end end |
.register(name, &block) ⇒ Object
Regsisters a new Qwandry configuration. Use in conjunction with Configuration#add like so:
register 'projects' do
add '~/Projects/personal'
add '~/Projects/work'
add '~/Experiments'
end
12 13 14 15 |
# File 'lib/qwandry/configuration.rb', line 12 def register name, &block name = name.to_sym builders[name] << block end |
.register_if_present(name, binary = nil, &block) ⇒ Object
Registers a configuration is a specific binary is available. If ‘binary` is not specified, it is assumed to be the same as the configuration name.
19 20 21 22 |
# File 'lib/qwandry/configuration.rb', line 19 def register_if_present name, binary=nil, &block binary ||= name register(name, &block) if present? binary end |
.repositories(*names) ⇒ Object
Loads the repositories for ‘names` if no names are given, it loads the defaults
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/qwandry/configuration.rb', line 81 def repositories(*names) names = default if names.empty? repositories = [] names.each do |name| name = name.to_sym raise ArgumentError, "Unknown Repository type '#{name}'" unless builders.has_key? name builder = builders[name] repositories += builder.repositories end repositories end |
Instance Method Details
#<<(block) ⇒ Object
113 114 115 |
# File 'lib/qwandry/configuration.rb', line 113 def << (block) @blocks << block end |
#add(paths, options = {}) ⇒ Object
Adds a new Repository to the current configuration.
The ‘options` can be used to customize the repository.
- :class
-
Repository class, defaults to Qwandry::FlatRepository
- :accept
-
Filters paths, only keeping ones matching the accept option
- :reject
-
Filters paths, rejecting any paths matching the reject option
‘:accept` and `:reject` take patterns such as ’*.py’, procs, and regular expressions.
Examples:
# Add all my little ruby scripts in the scratch directory
add '~/scratch', :accept => '*.rb'
# Add log files in common locations for easy access, but ignore the zipped ones
add ['/var/log/', '/usr/local/var/log/'], :reject => '*.bz2'
140 141 142 143 144 145 146 |
# File 'lib/qwandry/configuration.rb', line 140 def add(paths, ={}) paths = [paths] if paths.is_a?(String) paths.each do |path| repository_class = [:class] || Qwandry::FlatRepository @repositories << repository_class.new(@name, File.(path), ) end end |
#repositories ⇒ Object
117 118 119 120 121 122 |
# File 'lib/qwandry/configuration.rb', line 117 def repositories @blocks.each{|block| instance_eval(&block) } @blocks.clear @repositories end |