Class: CLI::Mastermind::Configuration::DSL
- Inherits:
-
Object
- Object
- CLI::Mastermind::Configuration::DSL
- Defined in:
- lib/cli/mastermind/configuration.rb
Overview
Describes the DSL used in masterplan files.
See the .masterplan file in the root of this repo for a full example of the available options.
Instance Method Summary collapse
-
#at_project_root ⇒ Object
Syntactic sugar on top of ‘project_root` to specify that the current masterplan resides in the root of the project.
-
#configure(attribute, value = nil, &block) ⇒ Object
(also: #set)
Add arbitrary configuration attributes to the configuration object.
-
#define_alias(name, arguments) ⇒ Object
Define a user alias.
-
#has_plan_files ⇒ Object
Syntactic sugar on top of ‘plan_files` to specify that plans exist in a
plans/
directory in the current directory. -
#initialize(config, filename) ⇒ DSL
constructor
A new instance of DSL.
-
#plan_file(*files) ⇒ Object
Specifies that a specific plan file exists at the given
filename
. -
#plan_files(directory) ⇒ Object
Specify that plans exist in the given
directory
. -
#project_root(root) ⇒ Object
Specifies the root of the project.
-
#see_also(filename) ⇒ Object
Specifies that another masterplan should also be loaded when loading this masterplan.
-
#skip_confirmation ⇒ Object
SKip confirmation before plan execution.
Constructor Details
#initialize(config, filename) ⇒ DSL
Returns a new instance of DSL.
171 172 173 174 175 |
# File 'lib/cli/mastermind/configuration.rb', line 171 def initialize(config, filename) @config = config @filename = filename instance_eval(File.read(filename), filename, 0) if File.exists? filename end |
Instance Method Details
#at_project_root ⇒ Object
Syntactic sugar on top of ‘project_root` to specify that the current masterplan resides in the root of the project.
202 203 204 |
# File 'lib/cli/mastermind/configuration.rb', line 202 def at_project_root project_root File.dirname(@filename) end |
#configure(attribute, value = nil, &block) ⇒ Object #configure(attribute) ⇒ Object Also known as: set
Add arbitrary configuration attributes to the configuration object. Use this to add plan specific configuration options.
254 255 256 257 258 259 |
# File 'lib/cli/mastermind/configuration.rb', line 254 def configure(attribute, value=nil, &block) attribute, value = attribute.first if attribute.is_a? Hash Configuration.add_attribute(attribute) @config.public_send "#{attribute}=", value, &block end |
#define_alias(name, arguments) ⇒ Object
Define a user alias. User aliases are expanded as part of plan selection.
267 268 269 |
# File 'lib/cli/mastermind/configuration.rb', line 267 def define_alias(name, arguments) @config.define_alias(name, arguments) end |
#has_plan_files ⇒ Object
Syntactic sugar on top of ‘plan_files` to specify that plans exist in a plans/
directory in the current directory.
226 227 228 |
# File 'lib/cli/mastermind/configuration.rb', line 226 def has_plan_files plan_files File.join(File.dirname(@filename), 'plans') end |
#plan_file(*files) ⇒ Object
Specifies that a specific plan file exists at the given filename
.
233 234 235 236 237 |
# File 'lib/cli/mastermind/configuration.rb', line 233 def plan_file(*files) files = files.map { |file| File. file } @config.add_plans(files) end |
#plan_files(directory) ⇒ Object
Specify that plans exist in the given directory
. Must be a valid directory.
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/cli/mastermind/configuration.rb', line 211 def plan_files(directory) unless Dir.exist? directory raise InvalidDirectoryError.new('Invalid plan file directory', directory) end planfiles = Dir.glob(File.join(directory, '**', "*{#{supported_extensions}}")) planfiles.map! { |file| File.(file) } @config.add_plans(planfiles) end |
#project_root(root) ⇒ Object
Specifies the root of the project. root
must be a directory.
190 191 192 193 194 195 196 |
# File 'lib/cli/mastermind/configuration.rb', line 190 def project_root(root) unless Dir.exist? root raise InvalidDirectoryError.new('Invalid project root', root) end @config.project_root = root end |
#see_also(filename) ⇒ Object
Specifies that another masterplan should also be loaded when loading this masterplan. NOTE: This immediately loads the other masterplan.
181 182 183 |
# File 'lib/cli/mastermind/configuration.rb', line 181 def see_also(filename) @config.load_masterplan(File.(filename)) end |
#skip_confirmation ⇒ Object
SKip confirmation before plan execution. Identical to -A.
273 274 275 |
# File 'lib/cli/mastermind/configuration.rb', line 273 def skip_confirmation @config.skip_confirmation! end |