Module: Stuff::ApiBehaviour
- Included in:
- ShellFileContext, ShellIfContext
- Defined in:
- lib/cabeza-de-termo/cachivache-helpers/utilities/stuff-api-behaviour.rb
Instance Method Summary collapse
-
#configure(class_name, &block) ⇒ Object
Example:.
- #execute(task_name, *args) ⇒ Object
-
#in_file(filename, &block) ⇒ Object
Examples:.
- #invoke(task_name, *args) ⇒ Object
- #raise_validation_error(message) ⇒ Object
-
#remind_to(text) ⇒ Object
Examples:.
- #shell(command) ⇒ Object
- #shell!(command) ⇒ Object
- #shell_context ⇒ Object
-
#shell_unless(params, &block) ⇒ Object
Examples:.
Instance Method Details
#configure(class_name, &block) ⇒ Object
Example:
configure :Something do let(:bla) { ‘123’ } let(:ble) { ‘abc’ } end
108 109 110 111 |
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/stuff-api-behaviour.rb', line 108 def configure(class_name, &block) Stuff::Configuration.ensure_subclass_exists(class_name) Stuff::Configuration.class_named(class_name).instance_eval(&block) end |
#execute(task_name, *args) ⇒ Object
13 14 15 |
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/stuff-api-behaviour.rb', line 13 def execute(task_name, *args) shell_context.execute(task_name, *args) end |
#in_file(filename, &block) ⇒ Object
Examples:
in_file “/bla.conf” do shell replace pattern: “%user%”, with: “admin”
shell append “[cachivache]” shell append “path=‘/bla’” end
83 84 85 86 87 88 89 |
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/stuff-api-behaviour.rb', line 83 def in_file(filename, &block) script = during_shell_buffer do ShellFileContext.with(file: filename, &block) end shell script end |
#invoke(task_name, *args) ⇒ Object
9 10 11 |
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/stuff-api-behaviour.rb', line 9 def invoke(task_name, *args) shell_context.invoke(task_name, *args) end |
#raise_validation_error(message) ⇒ Object
98 99 100 |
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/stuff-api-behaviour.rb', line 98 def raise_validation_error() shell_context.raise_validation_error() end |
#remind_to(text) ⇒ Object
Examples:
remind_to ‘This is shown when the provision ends’
94 95 96 |
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/stuff-api-behaviour.rb', line 94 def remind_to(text) shell_context.remind_to(text) end |
#shell(command) ⇒ Object
17 18 19 |
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/stuff-api-behaviour.rb', line 17 def shell(command) shell_context.shell(command) end |
#shell!(command) ⇒ Object
21 22 23 |
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/stuff-api-behaviour.rb', line 21 def shell!(command) shell_context.shell!(command) end |
#shell_context ⇒ Object
5 6 7 |
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/stuff-api-behaviour.rb', line 5 def shell_context() ShellContext.current end |
#shell_unless(params, &block) ⇒ Object
Examples:
shell_unless file_exists: ‘/bla.conf’ do shell %Q{ ls -la rm -rf bla } end
shell_unless folder_exists: ‘/bla’ do shell %Q{ ls -la rm -rf bla } end
shell_unless file: ‘/bla’, contains: ‘some regex’ do shell %Q{ ls -la rm -rf bla } end
shell_unless command: ‘java -version’, contains: ‘java 1.8’ do shell %Q{ ls -la rm -rf bla } end
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cabeza-de-termo/cachivache-helpers/utilities/stuff-api-behaviour.rb', line 55 def shell_unless(params, &block) if params.key?(:file_exists) shell unless_file_exists(params[:file_exists], &block) return end if params.key?(:folder_exists) shell unless_folder_exists(params[:folder_exists], &block) return end if params.key?(:file) && params.key?(:contains) shell unless_regex_in_file(params[:contains], params[:file], &block) return end if params.key?(:command) && params.key?(:contains) shell unless_regex_in_command(params[:contains], params[:command], &block) return end raise 'Invalid unless option' end |