Class: ShellFileContext

Inherits:
Object
  • Object
show all
Includes:
Stuff::ApiBehaviour
Defined in:
lib/cabeza-de-termo/cachivache-helpers/utilities/shell-file-context.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Stuff::ApiBehaviour

#configure, #execute, #in_file, #invoke, #raise_validation_error, #remind_to, #shell, #shell!, #shell_context, #shell_unless

Constructor Details

#initialize(args) ⇒ ShellFileContext

Returns a new instance of ShellFileContext.



10
11
12
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/shell-file-context.rb', line 10

def initialize(args)
	@filename = args[:file]
end

Class Method Details

.with(args, &block) ⇒ Object



6
7
8
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/shell-file-context.rb', line 6

def self.with(args, &block)
	new(args).evaluate_with block
end

Instance Method Details

#append(text) ⇒ Object

append ‘[mongo]’ append :new_line



29
30
31
32
33
34
35
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/shell-file-context.rb', line 29

def append(text)
	text = "\n" if text == :new_line

	%Q{
		echo "#{text}" | sudo tee -a #{@filename}
	}
end

#evaluate_with(block) ⇒ Object



14
15
16
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/shell-file-context.rb', line 14

def evaluate_with(block)
	instance_eval(&block)
end

#replace(params) ⇒ Object

replace pattern: “user: ””, with: “user: ‘admin’”



19
20
21
22
23
24
25
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/shell-file-context.rb', line 19

def replace(params)
	pattern = params[:pattern]
	replacement = params[:with]
	%Q{
		sudo sed -i 's|#{pattern}|#{replacement}|g' #{@filename}
	}
end