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
Constructor Details
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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/wordmove/movefile.rb', line 41 def environment( = {}) = fetch(false) available_enviroments = extract_available_envs() .merge!().deep_symbolize_keys! if available_enviroments.size > 1 && [:environment].nil? raise( UndefinedEnvironment, "You need to specify an environment with --environment parameter" ) 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 |
# 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? raise MovefileNotFound, "Could not find a valid Movefile" if last_dir?(start_dir) @start_dir = upper_dir(start_dir) return fetch 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
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wordmove/movefile.rb', line 29 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 |