Class: ConfigmonkeyCli::Application::ManifestAction::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/configmonkey_cli/application/manifest_actions/base.rb

Direct Known Subclasses

Chmod, Copy, Custom, Inplace, Invoke, Link, Mkdir, Remove, Rsync, Rtfm, SyncLinks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, manifest, *args, &block) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
15
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 7

def initialize app, manifest, *args, &block
  @app = app
  @thor = manifest.thor
  @args = []
  @opts = {}
  @manifest = manifest

  init(*args, &block)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



5
6
7
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 5

def app
  @app
end

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 5

def args
  @args
end

#manifestObject (readonly)

Returns the value of attribute manifest.



5
6
7
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 5

def manifest
  @manifest
end

#optsObject (readonly)

Returns the value of attribute opts.



5
6
7
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 5

def opts
  @opts
end

#thorObject (readonly)

Returns the value of attribute thor.



5
6
7
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 5

def thor
  @thor
end

Instance Method Details

#args_and_opts(hargs_and_opts = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 22

def args_and_opts hargs_and_opts = {}
  args, opts = [], {}
  hargs_and_opts.each do |k, v|
    if k.is_a?(String)
      args << k << v
    elsif k.is_a?(Symbol)
      opts[k] = v
    else
      raise "what the heck did you pass as a key?"
    end
  end
  [args, opts]
end

#destructive(&b) ⇒ Object



72
73
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 72

def destructive &b
end

#exists?(*args) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 48

def exists? *args
  if args[0].is_a?(Hash)
    File.exists?(send(:"expand_#{args[0].keys[0]}", args[0].values[0]))
  else
    File.exists?(args[0])
  end
end

#expand_dst(dst = "") ⇒ Object



44
45
46
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 44

def expand_dst dst = ""
  File.join(thor.destination_root, dst)
end

#expand_src(src = "") ⇒ Object



40
41
42
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 40

def expand_src src = ""
  File.join(manifest.directory, src)
end

#init(*a, &b) ⇒ Object



62
63
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 62

def init *a, &b
end

#prepareObject



65
66
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 65

def prepare
end

#rel(path) ⇒ Object



36
37
38
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 36

def rel path
  thor.relative_to_original_destination_root(path)
end

#simulate(&b) ⇒ Object



68
69
70
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 68

def simulate &b
  app.warn self.inspect
end

#to_sObject Also known as: inspect



17
18
19
# File 'lib/configmonkey_cli/application/manifest_actions/base.rb', line 17

def to_s
  "#<…::#{self.class.name.split("::").last(2).join("::")} @args=#{@args} @opts=#{@opts}>"
end