Class: LaunchBase::Plugin

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/launch_base/plugin.rb

Direct Known Subclasses

LaunchBase::Plugins::Sidekiq

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.class_nameObject



56
57
58
59
60
# File 'lib/launch_base/plugin.rb', line 56

def self.class_name
  name
    .split('::')
    .last
end

.command_line_flagObject



48
49
50
# File 'lib/launch_base/plugin.rb', line 48

def self.command_line_flag
  "with-#{plugin_name.tr('_', '-')}"
end

.descriptionObject



26
27
28
# File 'lib/launch_base/plugin.rb', line 26

def self.description
  to_s
end

.each_plugin(&block) ⇒ Object



40
41
42
# File 'lib/launch_base/plugin.rb', line 40

def self.each_plugin(&block)
  @plugins.each(&block)
end

.inherited(child_class) ⇒ Object



30
31
32
33
# File 'lib/launch_base/plugin.rb', line 30

def self.inherited(child_class)
  plugin_name = child_class.plugin_name
  register(plugin_name, child_class)
end

.install(destination_root:) ⇒ Object



22
23
24
# File 'lib/launch_base/plugin.rb', line 22

def self.install(destination_root:)
  new([], {}, destination_root: destination_root).run_install
end

.method_added(method_sym) ⇒ Object



7
8
9
# File 'lib/launch_base/plugin.rb', line 7

def self.method_added(method_sym)
  super unless method_sym == :install
end

.plugin_nameObject



44
45
46
# File 'lib/launch_base/plugin.rb', line 44

def self.plugin_name
  to_snake_case(class_name)
end

.register(name, plugin) ⇒ Object



35
36
37
38
# File 'lib/launch_base/plugin.rb', line 35

def self.register(name, plugin)
  @plugins ||= {}
  @plugins[name] = plugin
end

.to_snake_case(str) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/launch_base/plugin.rb', line 62

def self.to_snake_case(str)
  str
    .gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .tr('-', '_')
    .downcase
end

Instance Method Details

#class_nameObject



52
53
54
# File 'lib/launch_base/plugin.rb', line 52

def class_name
  self.class.class_name
end

#run_installObject



16
17
18
19
20
# File 'lib/launch_base/plugin.rb', line 16

def run_install
  say "Install #{class_name} module"
  install
  say "Successfully installed #{class_name} module"
end

#touch(file_path) ⇒ Object



11
12
13
14
# File 'lib/launch_base/plugin.rb', line 11

def touch(file_path)
  full_path = File.join(destination_root, file_path)
  FileUtils.touch(full_path)
end