Class: Pawnee::Base
- Inherits:
-
Thor
- Object
- Thor
- Pawnee::Base
- Includes:
- Actions, Roles, Invocation, Modified, SshConnection, Thor::Actions, ThorSsh::Actions
- Defined in:
- lib/pawnee/pawnee/base.rb,
lib/pawnee/pawnee/roles.rb,
lib/pawnee/pawnee/setup.rb
Overview
The pawnee gem provides the Pawnee::Base class, which includes actions from the thor gem, thor-ssh gem, and the pawnee gem its self. Any class that inherits from Pawnee::Base will automatically be registered as a recipe.
Direct Known Subclasses
Defined Under Namespace
Modules: Roles Classes: Railtie
Instance Attribute Summary collapse
-
#server ⇒ Object
Returns the value of attribute server.
-
#server_options ⇒ Object
Returns the value of attribute server_options.
-
#setup_with_connection ⇒ Object
Returns the value of attribute setup_with_connection.
Class Method Summary collapse
-
.gem_name ⇒ Object
Guess the gem name based on the class name.
- .setup(gem_name) ⇒ Object
Instance Method Summary collapse
-
#initialize(args = [], options = {}, config = {}) ⇒ Base
constructor
Creates an instance of the pawnee recipe.
-
#setup ⇒ Object
All recipies should subclass Pawnee::Base and implement setup to install everything needed for the gem.
-
#teardown ⇒ Object
All recipies should also implement teardown to uninstall anything that gets installed.
Methods included from Roles
Methods included from SshConnection
Methods included from Modified
included, #modified?, #modify_block, #track_modification!
Methods included from Invocation
Methods included from Actions
#add_user_to_group, #compile, #create_user, #delete_user, #insert_into_file, #install_package, #install_packages, #installed_package_version, #package_installed?, #pawnee_setup_actions, #remove_package, #remove_packages, #update_package_list, #user
Constructor Details
#initialize(args = [], options = {}, config = {}) ⇒ Base
Creates an instance of the pawnee recipe
Parameters
- args<Array>
-
An array of objects. The objects are applied to their respective accessors declared with
argument
. - options<Hash>
-
An options hash that will be available as self.options. The hash given is converted to a hash with indifferent access, magic predicates (options.skip?) and then frozen.
- config<Hash>
-
Configuration for this Thor class.
def initialize(*args)
Options
:server - This can be:
1) a connected ssh connection (created by Net::SSH.start)
2) an Array of options to pass to Net::SSH.start
3) a domain name for the first argument to Net::SSH.start
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/pawnee/pawnee/base.rb', line 48 def initialize(args=[], ={}, config={}) pawnee_setup_invocations(args, , config) pawnee_setup_actions(args, , config) do # We need to change Thor::Options to use Pawnee::Options on # invoke so we can include the defaults from the config file, # so here we copy in the initialize from thor/base.rb#initialize = self.class. # The start method splits inbound arguments at the first argument # that looks like an option (starts with - or --). It then calls # new, passing in the two halves of the arguments Array as the # first two parameters. if .is_a?(Array) = config.delete(:task_options) # hook for start = .merge() if , = , {} else # Handle the case where the class was explicitly instantiated # with pre-parsed options. , = [], end # Let Thor::Options parse the options first, so it can remove # declared options from the array. This will leave us with # a list of arguments that weren't declared. # --- We change Thor::Options to Pawnee::Options to pull in # the config default's opts = Pawnee::Options.new(, ) self. = opts.parse() # If unknown options are disallowed, make sure that none of the # remaining arguments looks like an option. opts.check_unknown! if self.class.(config) # Add the remaining arguments from the options parser to the # arguments passed in to initialize. Then remove any positional # arguments declared using #argument (this is primarily used # by Thor::Group). Tis will leave us with the remaining # positional arguments. thor_args = Thor::Arguments.new(self.class.arguments) thor_args.parse(args + opts.remaining).each { |k,v| send("#{k}=", v) } args = thor_args.remaining @args = args #-- end copy from thor/base.rb#initialize end end |
Instance Attribute Details
#server ⇒ Object
Returns the value of attribute server.
28 29 30 |
# File 'lib/pawnee/pawnee/base.rb', line 28 def server @server end |
#server_options ⇒ Object
Returns the value of attribute server_options.
28 29 30 |
# File 'lib/pawnee/pawnee/base.rb', line 28 def @server_options end |
#setup_with_connection ⇒ Object
Returns the value of attribute setup_with_connection.
28 29 30 |
# File 'lib/pawnee/pawnee/base.rb', line 28 def setup_with_connection @setup_with_connection end |
Class Method Details
.gem_name ⇒ Object
Guess the gem name based on the class name
117 118 119 |
# File 'lib/pawnee/pawnee/base.rb', line 117 def self.gem_name self.name.gsub(/[:][:]Base$/, '').gsub(/^[^:]+[:][:]/, '').gsub(/([A-Z]+)([A-Z][a-z])/,'\1-\2').gsub(/([a-z\d])([A-Z])/,'\1-\2').downcase end |
.setup(gem_name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pawnee/pawnee/setup.rb', line 11 def self.setup(gem_name) # Setup the railtie require "pawnee/#{gem_name.gsub(/^pawnee[-]/, '')}/base" if defined?(Rails) && defined?(Rails::Railtie) Railtie.initializer "#{gem_name}.configure_rails_initialization" do gem_recipie_name = gem_name.gsub(/^pawnee[-]/, '') require "#{gem_recipie_name}/base" end end end |
Instance Method Details
#setup ⇒ Object
All recipies should subclass Pawnee::Base and implement setup to install everything needed for the gem. Setup should be able to be called multiple times
105 106 107 |
# File 'lib/pawnee/pawnee/base.rb', line 105 def setup raise 'this gem does not implement the setup method' end |
#teardown ⇒ Object
All recipies should also implement teardown to uninstall anything that gets installed
112 113 114 |
# File 'lib/pawnee/pawnee/base.rb', line 112 def teardown raise 'this gem does not implement the teardown method' end |