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.
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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wordmove/movefile.rb', line 29 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 |