Class: CLI::Mastermind::Configuration::DSL

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(config, filename) ⇒ DSL

Returns a new instance of DSL.



126
127
128
129
130
# File 'lib/cli/mastermind/configuration.rb', line 126

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_rootObject

Syntactic sugar on top of ‘project_root` to specify that the current masterplan resides in the root of the project.



150
151
152
# File 'lib/cli/mastermind/configuration.rb', line 150

def at_project_root
  project_root File.dirname(@filename)
end

#configure(attribute, value = nil, &block) ⇒ Object Also known as: set

Add arbitrary configuration attributes to the configuration object. Use this to add plan specific configuration options.



182
183
184
185
186
187
# File 'lib/cli/mastermind/configuration.rb', line 182

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.



192
193
194
# File 'lib/cli/mastermind/configuration.rb', line 192

def define_alias(name, arguments)
  @config.define_alias(name, arguments)
end

#has_plan_filesObject

Syntactic sugar on top of ‘plan_files` to specify that plans exist in a plans/ directory in the current directory.



169
170
171
# File 'lib/cli/mastermind/configuration.rb', line 169

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.



174
175
176
177
178
# File 'lib/cli/mastermind/configuration.rb', line 174

def plan_file(*files)
  files = files.map { |file| File.expand_path file }

  @config.add_plans(files)
end

#plan_files(directory) ⇒ Object

Specify that plans exist in the given directory. Must be a valid directory



156
157
158
159
160
161
162
163
164
165
# File 'lib/cli/mastermind/configuration.rb', line 156

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.expand_path(file) }

  @config.add_plans(planfiles)
end

#project_root(root) ⇒ Object

Specifies the root of the project. root must be a directory.



140
141
142
143
144
145
146
# File 'lib/cli/mastermind/configuration.rb', line 140

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.



134
135
136
# File 'lib/cli/mastermind/configuration.rb', line 134

def see_also(filename)
  @config.load_masterplan(File.expand_path(filename))
end

#skip_confirmationObject

SKip confirmation before plan execution. Identical to -A.



198
199
200
# File 'lib/cli/mastermind/configuration.rb', line 198

def skip_confirmation
  @config.skip_confirmation!
end