Class: Cinch::BotTemplate::Classes::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/cinch/bot_template/classes/gen_init.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options:, shell:, all:) ⇒ Init

Returns a new instance of Init.



9
10
11
12
13
14
15
# File 'lib/cinch/bot_template/classes/gen_init.rb', line 9

def initialize(options:, shell:, all:)
  @hl      = HighLine.new($stdin, $stderr, 80)
  @opts    = Hash.new { |hash, key| hash[key] = {} }
  @options = options
  @all     = all
  @shell   = shell
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



7
8
9
# File 'lib/cinch/bot_template/classes/gen_init.rb', line 7

def directory
  @directory
end

Instance Method Details

#check_pathArray<Boolean,String>, Array<String>

Note:

There’s more a format on return of [parsed,input]

Success => [parsed,input] Error => [parsed,input,error] Error+ => [parsed,input,error,varstring,varstring,varstring]

Parameters:

  • path (String)

    Check path for existence.

Returns:

  • (Array<Boolean,String>)

    if there was an error

  • (Array<String>)

    path if successful



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cinch/bot_template/classes/gen_init.rb', line 25

def check_path(path)
  current_dir   = Pathname('.').expand_path.realdirpath
  home_dir      = Pathname('~').expand_path.realdirpath
  path_string   = path
  path_instance = Pathname(path)
  path_full     = Pathname(path).expand_path.realdirpath

  if current_dir == home_dir and path_full == home_dir or path_string == '~'
    abort Paint['Error', 'red', :bold] + ': Will not create files in user home, use a subdirectory'
  else
    [path_full, path]

  end

end

#generateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cinch/bot_template/classes/gen_init.rb', line 41

def generate
  @shell.say "What path should be used to house the bot?"
  @shell.say "If directories don't exist, they will be created."
  @shell.say "'~' and '.' are available for compactness"
  @shell.say "However '~' is disallowed when using it by itself"
  @shell.say "This is so you don't put a bot directly in your home directory."
  @shell.say "ex: '~/bots/cinchfolder', '.' or './cinchfolder'"
  path = @shell.ask("What directory?")

  path_response = self.check_path(path)
  if path_response.length == 2 # Success
    parsed = path_response.first
    if parsed.exist?
      @directory = parsed
    else
      @directory = parsed
      FileUtils.mkpath(@directory.to_s)

    end

  elsif path_response.length == 3 # Error

  elsif path_response.length > 3 # Error+
  end
end