Class: Wordmove::Deployer::Base
- Inherits:
-
Object
- Object
- Wordmove::Deployer::Base
- Defined in:
- lib/wordmove/deployer/base.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .current_dir ⇒ Object
- .deployer_for(cli_options) ⇒ Object
- .extract_available_envs(options) ⇒ Object
- .fetch_movefile(name = nil, start_dir = current_dir) ⇒ Object
- .last_dir?(directory) ⇒ Boolean
- .logger ⇒ Object
- .upper_dir(directory) ⇒ Object
Instance Method Summary collapse
- #exclude_dir_contents(path) ⇒ Object
-
#initialize(environment, options = {}) ⇒ Base
constructor
A new instance of Base.
- #pull_db ⇒ Object
- #pull_wordpress ⇒ Object
- #push_db ⇒ Object
- #push_wordpress ⇒ Object
- #remote_get_directory(directory) ⇒ Object
- #remote_put_directory(directory) ⇒ Object
Constructor Details
#initialize(environment, options = {}) ⇒ Base
Returns a new instance of Base.
78 79 80 81 82 |
# File 'lib/wordmove/deployer/base.rb', line 78 def initialize(environment, = {}) @environment = environment.to_sym @options = @logger = self.class.logger end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
16 17 18 |
# File 'lib/wordmove/deployer/base.rb', line 16 def environment @environment end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
15 16 17 |
# File 'lib/wordmove/deployer/base.rb', line 15 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/wordmove/deployer/base.rb', line 14 def @options end |
Class Method Details
.current_dir ⇒ Object
61 62 63 |
# File 'lib/wordmove/deployer/base.rb', line 61 def current_dir '.' end |
.deployer_for(cli_options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wordmove/deployer/base.rb', line 19 def deployer_for() = fetch_movefile([:config]) available_enviroments = extract_available_envs() .merge!().recursive_symbolize_keys! if available_enviroments.size > 1 && [:environment].nil? raise "You need to specify an environment with --environment parameter" end environment = ([:environment] || available_enviroments.first).to_sym if [environment][:ftp] require 'wordmove/deployer/ftp' FTP.new(environment, ) elsif [environment][:ssh] require 'wordmove/deployer/ssh' SSH.new(environment, ) else raise StandardError, "No valid adapter found." end end |
.extract_available_envs(options) ⇒ Object
40 41 42 |
# File 'lib/wordmove/deployer/base.rb', line 40 def extract_available_envs() .keys.map(&:to_sym) - [ :local ] end |
.fetch_movefile(name = nil, start_dir = current_dir) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/wordmove/deployer/base.rb', line 44 def fetch_movefile(name = nil, start_dir = current_dir) name ||= "Movefile" entries = Dir["#{File.join(start_dir, name)}*"] if entries.empty? if last_dir?(start_dir) raise StandardError, "Could not find a valid Movefile" else return fetch_movefile(name, upper_dir(start_dir)) end end found = entries.first logger.task("Using Movefile: #{found}") YAML::load(File.open(found)) end |
.last_dir?(directory) ⇒ Boolean
65 66 67 |
# File 'lib/wordmove/deployer/base.rb', line 65 def last_dir?(directory) directory == "/" || File.exists?(File.join(directory, 'wp-config.php')) end |
.logger ⇒ Object
73 74 75 |
# File 'lib/wordmove/deployer/base.rb', line 73 def logger Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG } end |
.upper_dir(directory) ⇒ Object
69 70 71 |
# File 'lib/wordmove/deployer/base.rb', line 69 def upper_dir(directory) File.(File.join(directory, '..')) end |
Instance Method Details
#exclude_dir_contents(path) ⇒ Object
111 112 113 |
# File 'lib/wordmove/deployer/base.rb', line 111 def exclude_dir_contents(path) "#{path}/*" end |
#pull_db ⇒ Object
88 89 90 |
# File 'lib/wordmove/deployer/base.rb', line 88 def pull_db logger.task "Pulling Database" end |
#pull_wordpress ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/wordmove/deployer/base.rb', line 126 def pull_wordpress logger.task "Pulling wordpress core" local_path = [:wordpress_path] remote_path = [:wordpress_path] exclude_wp_content = exclude_dir_contents(remote_wp_content_dir.relative_path) exclude_paths = paths_to_exclude.push(exclude_wp_content) remote_get_directory(remote_path, local_path, exclude_paths) end |
#push_db ⇒ Object
84 85 86 |
# File 'lib/wordmove/deployer/base.rb', line 84 def push_db; logger.task "Pushing Database" end |
#push_wordpress ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/wordmove/deployer/base.rb', line 115 def push_wordpress logger.task "Pushing wordpress core" local_path = [:wordpress_path] remote_path = [:wordpress_path] exclude_wp_content = exclude_dir_contents(local_wp_content_dir.relative_path) exclude_paths = paths_to_exclude.push(exclude_wp_content) remote_put_directory(local_path, remote_path, exclude_paths) end |
#remote_get_directory(directory) ⇒ Object
92 |
# File 'lib/wordmove/deployer/base.rb', line 92 def remote_get_directory(directory); end |
#remote_put_directory(directory) ⇒ Object
93 |
# File 'lib/wordmove/deployer/base.rb', line 93 def remote_put_directory(directory); end |