Module: Capnotify::Plugin
- Defined in:
- lib/capnotify/plugin.rb,
lib/capnotify/plugin/details.rb,
lib/capnotify/plugin/message.rb,
lib/capnotify/plugin/overview.rb
Defined Under Namespace
Modules: Details, Message, Overview
Instance Method Summary collapse
-
#appname ⇒ Object
convenience method for getting the friendly app name If the stage is specified (the deployment is using multistage), include that.
-
#build_components! ⇒ Object
build all components.
-
#build_template(template_path) ⇒ Object
given a path to an ERB template, process it with the current binding and return the output.
-
#built_in_template_for(template_name) ⇒ Object
return the path to the built-in template with the given name.
-
#component(name) ⇒ Object
fetch a component given the name this is most useful for getting a component directly if you want to make modificatins to it.
-
#components ⇒ Object
returns the capnotify_component_list this is the underlying mechanism for working with components append or prepend or insert from here.
-
#delete_component(name) ⇒ Object
delete the component with the given name return the remaining list of components (to enable chaining).
-
#deployed_by ⇒ Object
get the name of the deploying user currently this only supports git.
-
#insert_component_after(name, component) ⇒ Object
insert the given component after the component with ‘name` if no component is found with that name, the component will be inserted at the end.
-
#insert_component_before(name, component) ⇒ Object
insert the given component before the component with ‘name` if no component is found with that name, the component will be inserted at the end.
-
#load_default_plugins ⇒ Object
load the default built-in plugins this is called automatically when capistrano is done loading you can disable this (and not laod any plugins by default) by setting capnotify_disable_default_components set :capnotify_disable_default_components, true.
-
#load_plugin(mod) ⇒ Object
given a module name, load it as a plugin capnotify plugins must conform to the spec.
-
#print_splash ⇒ Object
output a pretty splash screen of the Capnotify logo this can be enabled by setting capnotify_show_splash to a truthy value: set :capnotify_show_splash, true.
-
#unload_plugin(name) ⇒ Object
given a plugin name as a symbol, unload the capnotify plugin this will also unload any kind of capistrano plugin if the plugin supports the unload method, it will be called.
Instance Method Details
#appname ⇒ Object
convenience method for getting the friendly app name If the stage is specified (the deployment is using multistage), include that. given that the application is “MyApp” and the stage is “production”, this will return “MyApp production” if capnotify_appname is not set, it’ll return an empty string
26 27 28 |
# File 'lib/capnotify/plugin.rb', line 26 def appname fetch(:capnotify_appname, "") end |
#build_components! ⇒ Object
build all components
154 155 156 |
# File 'lib/capnotify/plugin.rb', line 154 def build_components! set :capnotify_component_list, self.components.map { |c| c.build!(self) } end |
#build_template(template_path) ⇒ Object
given a path to an ERB template, process it with the current binding and return the output.
93 94 95 96 97 98 99 |
# File 'lib/capnotify/plugin.rb', line 93 def build_template(template_path) # FIXME: this is called every time build_template is called. # although this is idepodent, it's got room for optimization self.build_components! ERB.new( File.open( template_path ).read, nil, '<>' ).result(self.binding) end |
#built_in_template_for(template_name) ⇒ Object
return the path to the built-in template with the given name
88 89 90 |
# File 'lib/capnotify/plugin.rb', line 88 def built_in_template_for(template_name) File.join( File.dirname(__FILE__), 'templates', template_name ) end |
#component(name) ⇒ Object
fetch a component given the name this is most useful for getting a component directly if you want to make modificatins to it
112 113 114 115 |
# File 'lib/capnotify/plugin.rb', line 112 def component(name) components.each { |c| return c if c.name == name.to_sym } return nil end |
#components ⇒ Object
returns the capnotify_component_list this is the underlying mechanism for working with components append or prepend or insert from here.
106 107 108 |
# File 'lib/capnotify/plugin.rb', line 106 def components fetch(:capnotify_component_list) end |
#delete_component(name) ⇒ Object
delete the component with the given name return the remaining list of components (to enable chaining)
149 150 151 |
# File 'lib/capnotify/plugin.rb', line 149 def delete_component(name) components.delete_if { |c| c.name == name.to_sym } end |
#deployed_by ⇒ Object
get the name of the deploying user currently this only supports git. if reading the git user.name, fall back on ‘whoami`
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/capnotify/plugin.rb', line 33 def deployed_by username = nil scm = fetch(:scm, nil) if scm if scm.to_sym == :git username = `git config user.name`.chomp username = nil if $? != 0 || username.strip == '' end end username || `whoami`.chomp end |
#insert_component_after(name, component) ⇒ Object
insert the given component after the component with ‘name` if no component is found with that name, the component will be inserted at the end
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/capnotify/plugin.rb', line 134 def insert_component_after(name, component) # iterate over all components, find the component with the given name # once found, insert the given component at the following location and return components.each_with_index do |c, i| if c.name == name components.insert(i + 1, component) return end end components << component end |
#insert_component_before(name, component) ⇒ Object
insert the given component before the component with ‘name` if no component is found with that name, the component will be inserted at the end
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/capnotify/plugin.rb', line 119 def insert_component_before(name, component) # iterate over all components, find the component with the given name # once found, insert the given component at that location and return components.each_with_index do |c, i| if c.name == name components.insert(i, component) return end end components << component end |
#load_default_plugins ⇒ Object
load the default built-in plugins this is called automatically when capistrano is done loading you can disable this (and not laod any plugins by default) by setting capnotify_disable_default_components
set :capnotify_disable_default_components, true
52 53 54 55 56 |
# File 'lib/capnotify/plugin.rb', line 52 def load_default_plugins capnotify.load_plugin Capnotify::Plugin::Message capnotify.load_plugin Capnotify::Plugin::Overview capnotify.load_plugin Capnotify::Plugin::Details end |
#load_plugin(mod) ⇒ Object
62 63 64 65 66 |
# File 'lib/capnotify/plugin.rb', line 62 def load_plugin(mod) Capistrano.plugin mod::PLUGIN_NAME, mod get_plugin(mod::PLUGIN_NAME).init end |
#print_splash ⇒ Object
output a pretty splash screen of the Capnotify logo this can be enabled by setting capnotify_show_splash to a truthy value:
set :capnotify_show_splash, true
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/capnotify/plugin.rb', line 10 def print_splash puts <<-SPLASH __________________ - --|\\ Deployment /| _____ __ _ ___ - ---| \\ Complete / | / ___/__ ____ ___ ___ / /_(_) _/_ __ - ----| /\\____________/\\ | / /__/ _ `/ _ \\/ _ \\/ _ \\/ __/ / _/ // / - -----|/ - Capistrano - \\| \\___/\\_,_/ .__/_//_/\\___/\\__/_/_/ \\_, / - ------|__________________| /_/ /___/ SPLASH end |
#unload_plugin(name) ⇒ Object
given a plugin name as a symbol, unload the capnotify plugin this will also unload any kind of capistrano plugin if the plugin supports the unload method, it will be called.
71 72 73 74 75 76 |
# File 'lib/capnotify/plugin.rb', line 71 def unload_plugin(name) p = get_plugin(name) p.unload if p.respond_to?(:unload) Capistrano.remove_plugin(name) end |