Class: Sanctum::Command::Config

Inherits:
Object
  • Object
show all
Includes:
Sanctum::Colorizer
Defined in:
lib/sanctum/command/config.rb

Overview

Intentionally not extending Base This command creates an example config

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sanctum::Colorizer

#blue, #colorize, colorize=, colorize?, #green, #light_blue, #pink, #red, #yellow

Constructor Details

#initialize(options = {}, _args = []) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
# File 'lib/sanctum/command/config.rb', line 11

def initialize(options={}, _args=[])
  options = {working_dir: Dir.pwd}.merge(options)

  relative_path = File.expand_path File.dirname(__FILE__)
  @config_path = "#{options[:working_dir]}/sanctum.yaml"
  @example_file = "#{relative_path}/sanctum.example.yaml"
end

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



9
10
11
# File 'lib/sanctum/command/config.rb', line 9

def config_path
  @config_path
end

#example_fileObject (readonly)

Returns the value of attribute example_file.



9
10
11
# File 'lib/sanctum/command/config.rb', line 9

def example_file
  @example_file
end

Instance Method Details

#config_exist?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/sanctum/command/config.rb', line 24

def config_exist?
  File.file?(config_path)
end

#create_config_fileObject



28
29
30
# File 'lib/sanctum/command/config.rb', line 28

def create_config_file
  FileUtils.cp(example_file, config_path)
end

#runObject



19
20
21
22
# File 'lib/sanctum/command/config.rb', line 19

def run
  raise yellow("config file already exists") if config_exist?
  create_config_file
end