Class: Wordmove::Movefile
- Inherits:
-
Object
- Object
- Wordmove::Movefile
- Defined in:
- lib/wordmove/movefile.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#start_dir ⇒ Object
readonly
Returns the value of attribute start_dir.
Instance Method Summary collapse
- #environment(cli_options = {}) ⇒ Object
- #fetch(verbose = true) ⇒ Object
-
#initialize(name = nil, start_dir = current_dir) ⇒ Movefile
constructor
A new instance of Movefile.
- #load_dotenv(cli_options = {}) ⇒ Object
- #secrets ⇒ Object
Constructor Details
#initialize(name = nil, start_dir = current_dir) ⇒ Movefile
Returns a new instance of Movefile.
5 6 7 8 9 |
# File 'lib/wordmove/movefile.rb', line 5 def initialize(name = nil, start_dir = current_dir) @logger = Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG } @name = name @start_dir = start_dir end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'lib/wordmove/movefile.rb', line 3 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/wordmove/movefile.rb', line 3 def name @name end |
#start_dir ⇒ Object (readonly)
Returns the value of attribute start_dir.
3 4 5 |
# File 'lib/wordmove/movefile.rb', line 3 def start_dir @start_dir end |
Instance Method Details
#environment(cli_options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/wordmove/movefile.rb', line 45 def environment( = {}) = fetch(false) available_enviroments = extract_available_envs() .merge!().deep_symbolize_keys! if [:environment] != 'local' if available_enviroments.size > 1 && [:environment].nil? raise( UndefinedEnvironment, "You need to specify an environment with --environment parameter" ) end if [:environment].present? unless available_enviroments.include?([:environment].to_sym) raise UndefinedEnvironment, "No environment found for \"#{[:environment]}\". "\ "Available Environments: #{available_enviroments.join(' ')}" end end end ([:environment] || available_enviroments.first).to_sym end |
#fetch(verbose = true) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wordmove/movefile.rb', line 11 def fetch(verbose = true) entries = if name.nil? Dir["#{File.join(start_dir, '{M,m}ovefile')}{,.yml,.yaml}"] else Dir["#{File.join(start_dir, name)}{,.yml,.yaml}"] end if entries.empty? if last_dir?(start_dir) raise MovefileNotFound, "Could not find a valid Movefile. Searched"\ " for filename \"#{name}\" in folder \"#{start_dir}\"" end @start_dir = upper_dir(start_dir) return fetch(verbose) end found = entries.first logger.task("Using Movefile: #{found}") if verbose == true YAML.safe_load(ERB.new(File.read(found)).result, [], [], true).deep_symbolize_keys! end |
#load_dotenv(cli_options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wordmove/movefile.rb', line 33 def load_dotenv( = {}) env = environment() env_files = Dir[File.join(start_dir, ".env{.#{env},}")] found_env = env_files.first return false unless found_env.present? logger.info("Using .env file: #{found_env}") Dotenv.load(found_env) end |
#secrets ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/wordmove/movefile.rb', line 69 def secrets = fetch(false) secrets = [] .each_key do |env| secrets << .dig(env, :database, :password) secrets << .dig(env, :database, :host) secrets << .dig(env, :vhost) secrets << .dig(env, :ssh, :password) secrets << .dig(env, :ssh, :host) secrets << .dig(env, :ftp, :password) secrets << .dig(env, :ftp, :host) secrets << .dig(env, :wordpress_path) end secrets.compact.delete_if(&:empty?) end |