json-spec 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/cachivache/Gemfile +2 -1
  3. data/cachivache/README.md +8 -3
  4. data/cachivache/Rakefile +37 -3
  5. data/cachivache/Vagrantfile +14 -12
  6. data/cachivache/cachivache.rb +1 -1
  7. data/cachivache/{lib → utilities}/stuff-configuration.rb +2 -0
  8. data/json-spec.gemspec +1 -1
  9. data/lib/cabeza-de-termo/json-spec/expectations-library/default-expectations/default-expectations-mapping.rb +1 -1
  10. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb +2 -2
  11. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-library-definition-builder.rb +1 -1
  12. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/modifiers-definition-builder.rb +1 -1
  13. data/lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb +1 -1
  14. data/lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb +1 -1
  15. data/lib/cabeza-de-termo/json-spec/expressions/json-each-field.rb +1 -1
  16. data/lib/cabeza-de-termo/json-spec/expressions/json-each.rb +1 -1
  17. data/lib/cabeza-de-termo/json-spec/expressions/json-expression.rb +2 -2
  18. data/lib/cabeza-de-termo/json-spec/expressions/json-field.rb +1 -1
  19. data/lib/cabeza-de-termo/json-spec/expressions/json-list.rb +1 -1
  20. data/lib/cabeza-de-termo/json-spec/expressions/json-object.rb +1 -1
  21. data/lib/cabeza-de-termo/json-spec/expressions/json-spec.rb +3 -3
  22. data/lib/cabeza-de-termo/json-spec/version.rb +1 -1
  23. metadata +5 -14
  24. data/cachivache/lib/rake-helper.rb +0 -53
  25. data/cachivache/lib/shell-contexts/shell-context.rb +0 -63
  26. data/cachivache/lib/shell-contexts/shell-exec.rb +0 -19
  27. data/cachivache/lib/shell-contexts/shell_buffer.rb +0 -25
  28. data/cachivache/lib/shell-contexts/shell_debugger.rb +0 -11
  29. data/cachivache/lib/shell-file-context.rb +0 -36
  30. data/cachivache/lib/shell-if-context.rb +0 -21
  31. data/cachivache/lib/stuff-api-behaviour.rb +0 -145
  32. data/cachivache/lib/stuff-reminders-behaviour.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2136aa485a249788e83e6b962ae039d5cf3ceac9
4
- data.tar.gz: 4786b07cf34a2c1045fcd64a8901e20709cc136a
3
+ metadata.gz: 88fa5f44774aebd47659b16c57b1cf9fb3ef2ccd
4
+ data.tar.gz: 5d3e524a2f0339defdfeece219eea8fa3d78c014
5
5
  SHA512:
6
- metadata.gz: 74cc87284c78691d63eeca202be7b6216e1591bf047efa885fb99366956686db57c0ce31014fa1418ee11bd90bb22a25a1eb2864c606868047ec8a19f7179243
7
- data.tar.gz: f77c2df721f9c977958774551650a6fe16098fbefd0bab75f826a2d92a6aacaf166bb3915e4d1c4ffd2e1dd8c884776b01100edc4980398cb523fac572dc2ff3
6
+ metadata.gz: be1e7578c169920b687b50eb9918e24ee2cf1f0f98c265b485d1155df56e28ac87580ee29a846bb817e2af4286571e3ca340fd2a1c67592329336fc80b4bf41e
7
+ data.tar.gz: d647c78b14358b6977f7c33c6ee7be46f9f68ca81bb3957d178a6f22fd62eae035d06214082e24baa8cc2e0170b0c6c88d39a189be3520d0dbbf8aaf32203334
data/cachivache/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rake'
4
- gem 'colorize'
4
+ gem 'colorize'
5
+ gem 'cachivache-helpers'
data/cachivache/README.md CHANGED
@@ -37,7 +37,7 @@ Once you installed the `cachivache` gem, setup cachivache for your project:
37
37
 
38
38
  write some stuffs in your `stuff` folder and set what stuff to install and your git email and user:
39
39
 
40
- - `cachivache config`
40
+ - `cachivache configure`
41
41
 
42
42
  and that's it, you can now start Vagrant with:
43
43
 
@@ -78,7 +78,7 @@ dependencies = [
78
78
  ]
79
79
 
80
80
  stuff :'php-json-spec' => dependencies do
81
- shell %{
81
+ shell %Q{
82
82
  cd #{PhpJsonSpec.project_folder}
83
83
 
84
84
  composer install
@@ -95,6 +95,11 @@ configure :PhpJsonSpec do
95
95
  let(:project_folder) { Cachivache.src_folder }
96
96
  end
97
97
  ```
98
+
99
+ ## How about a more complex stuff, like setting up an app for apache?
100
+
101
+ Here is an example of that: [php-site-sample](bin/template/stuff/php-site-sample)
102
+
98
103
  ## How do I tell Cachivache what to install?
99
104
 
100
105
  Edit the file `cachivache.rb` and define the stuffs to install in the section
@@ -144,7 +149,7 @@ end
144
149
  # or
145
150
 
146
151
  stuff :'do-stuff' do
147
- shell %(
152
+ shell %Q(
148
153
  echo "stuff"
149
154
  )
150
155
  end
data/cachivache/Rakefile CHANGED
@@ -1,13 +1,47 @@
1
- require_relative 'lib/rake-helper'
1
+ require 'rake'
2
+
3
+ require_relative 'cachivache'
4
+ require 'cabeza-de-termo/cachivache-helpers/helpers'
5
+
6
+ ######################################
7
+ # Include all stuffs behaviours
8
+ ######################################
9
+
10
+ include Stuff::ApiBehaviour
11
+ include Stuff::RemindersBehaviour
12
+ include RakeAdaptor
13
+ ShellContext.set_current( ShellExec.new(self) )
14
+
15
+ ######################################
16
+ # Validate the provision configuration
17
+ ######################################
2
18
 
3
19
  raise_validation_error "Please define the parameter Cachivache.git_user_email in './cachivache.rb' run 'vagrant provision' again" unless Cachivache.is_defined?(:git_user_email)
4
20
  raise_validation_error "Please define the parameter Cachivache.git_user_name in './cachivache.rb' run 'vagrant provision' again" unless Cachivache.is_defined?(:git_user_name)
5
21
  raise_validation_error "Please define some Cachivache.stuff_to_install in './cachivache.rb' run 'vagrant provision' again" if Cachivache.stuff_to_install.empty?
6
22
 
23
+ ######################################
24
+ # Load all the .rb files in this folder
25
+ ######################################
26
+
27
+ all_rb_files_in Cachivache.cachivache_folder do |file|
28
+ require file
29
+ end
30
+
31
+ ######################################
32
+ # Define the tasks that run the provision
33
+ ######################################
34
+
35
+ def stuff_to_install(&block)
36
+ Cachivache.stuff_to_install.each do |stuff_name|
37
+ block.call stuff_name
38
+ end
39
+ end
40
+
7
41
  def provision_stuff_to_install()
8
42
  stuff_to_install do |stuff_name|
9
43
  show_info "Provisioning #{stuff_name}"
10
- invoke stuff_name
44
+ invoke_stuff stuff_name
11
45
  end
12
46
  show_info "All done!!!"
13
47
  end
@@ -17,7 +51,7 @@ stuff :provision do
17
51
  end
18
52
 
19
53
  stuff :explain do
20
- ShellContext.set_current ShellDebugger.new
54
+ ShellContext.set_current ShellDebugger.new(self)
21
55
  provision_stuff_to_install
22
56
  end
23
57
 
@@ -39,23 +39,25 @@ Vagrant.configure(2) do |config|
39
39
  type: "shell",
40
40
  privileged: false,
41
41
  inline: %Q{
42
- # From https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-14-04
43
- if [ ! -d $HOME/.rbenv/ ]; then
42
+ # From https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-14-04
43
+ if [ ! -d $HOME/.rbenv/ ]; then
44
44
 
45
- sudo apt-get install git-core -y
45
+ sudo apt-get update
46
46
 
47
- git clone git://github.com/sstephenson/rbenv.git .rbenv
48
- echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
49
- echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
47
+ sudo apt-get install git-core -y
50
48
 
51
- git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
52
- echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
53
- source ~/.bash_profile
49
+ git clone git://github.com/sstephenson/rbenv.git .rbenv
50
+ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
51
+ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
54
52
 
55
- git clone git://github.com/carsomyr/rbenv-bundler.git ~/.rbenv/plugins/bundler
53
+ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
54
+ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
55
+ source ~/.bash_profile
56
56
 
57
- sudo gem install bundler
58
- fi
57
+ git clone git://github.com/carsomyr/rbenv-bundler.git ~/.rbenv/plugins/bundler
58
+
59
+ sudo gem install bundler
60
+ fi
59
61
  }
60
62
 
61
63
  config.vm.provision "rake-provision",
@@ -1,4 +1,4 @@
1
- require_relative 'lib/stuff-configuration'
1
+ require_relative 'utilities/stuff-configuration'
2
2
 
3
3
  class Cachivache < Stuff::Configuration
4
4
  # Vagrant params
@@ -1,3 +1,5 @@
1
+ # Duplicating this class here and in cachivache-helpers sucks, but I haven't
2
+ # come up with a decent workaround yet, so ...
1
3
  module Stuff
2
4
  class Configuration
3
5
  # Class methods
data/json-spec.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.required_ruby_version = '>= 2.0'
23
23
 
24
- spec.add_dependency "cdt-utilities", '~> 0.2'
24
+ spec.add_dependency "cdt-utilities", '~> 0.3'
25
25
  spec.add_dependency "validates_email_format_of", "~> 1.6"
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.10"
@@ -47,7 +47,7 @@ module CabezaDeTermo
47
47
  end
48
48
 
49
49
  def for_every_expression_of(json_expression_type, &block)
50
- CdT.bind_evaluation_of block, to: DefaultExpectationBuilder.new(self, json_expression_type)
50
+ CdT.bind_block_evaluation_to DefaultExpectationBuilder.new(self, json_expression_type), &block
51
51
  end
52
52
  end
53
53
  end
@@ -19,7 +19,7 @@ module CabezaDeTermo
19
19
  @expectations_library = expectations_library
20
20
  reset_current_definition
21
21
 
22
- CdT.bind_evaluation_of block, to: self
22
+ CdT.bind_block_evaluation_to self, &block
23
23
  end
24
24
 
25
25
  # Accessing
@@ -57,7 +57,7 @@ module CabezaDeTermo
57
57
  def define(method_name, &block)
58
58
  @method_name = method_name.to_sym
59
59
 
60
- CdT.bind_evaluation_of block, to: self
60
+ CdT.bind_block_evaluation_to self, &block
61
61
 
62
62
  define_expectation_in_library
63
63
  define_expectation_message_in_library
@@ -27,7 +27,7 @@ module CabezaDeTermo
27
27
  end
28
28
 
29
29
  def default_expectations(&block)
30
- CdT.bind_evaluation_of block, to: expectations_library.default_expectations
30
+ CdT.bind_block_evaluation_to expectations_library.default_expectations, &block
31
31
  self
32
32
  end
33
33
  end
@@ -11,7 +11,7 @@ module CabezaDeTermo
11
11
  def initialize(expectations_library, &block)
12
12
  @expectations_library = expectations_library
13
13
 
14
- CdT.bind_evaluation_of block, to: self
14
+ CdT.bind_block_evaluation_to self, &block
15
15
  end
16
16
 
17
17
  # Accessing
@@ -58,7 +58,7 @@ module CabezaDeTermo
58
58
  # Defining
59
59
 
60
60
  def define(&block)
61
- CdT.bind_evaluation_of block, to: ExpectationLibraryDefinitionBuilder.new(self)
61
+ CdT.bind_block_evaluation_to ExpectationLibraryDefinitionBuilder.new(self), &block
62
62
  end
63
63
 
64
64
  # Expectation messages
@@ -34,7 +34,7 @@ module CabezaDeTermo
34
34
  def expect_a(type, &block)
35
35
  expression = add_posibble_expression( new_expression_for(type) )
36
36
 
37
- CdT.bind_evaluation_of block, to: self unless block.nil?
37
+ CdT.bind_block_evaluation_to self, &block unless block.nil?
38
38
 
39
39
  expression
40
40
  end
@@ -43,7 +43,7 @@ module CabezaDeTermo
43
43
  def expect_a(type, &block)
44
44
  @value_expression = new_expression_for(type)
45
45
 
46
- CdT.bind_evaluation_of block, to: @value_expression unless block.nil?
46
+ CdT.bind_block_evaluation_to @value_expression, &block unless block.nil?
47
47
 
48
48
  @value_expression
49
49
  end
@@ -43,7 +43,7 @@ module CabezaDeTermo
43
43
  def expect_a(type, &block)
44
44
  @each_item_expression = new_expression_for(type)
45
45
 
46
- CdT.bind_evaluation_of block, to: @each_item_expression unless block.nil?
46
+ CdT.bind_block_evaluation_to @each_item_expression, &block unless block.nil?
47
47
 
48
48
  @each_item_expression
49
49
  end
@@ -158,7 +158,7 @@ module CabezaDeTermo
158
158
 
159
159
  add_expectation(expectation)
160
160
 
161
- CdT.bind_evaluation_of message.block, to: self unless message.block.nil?
161
+ CdT.bind_block_evaluation_to self, &message.block unless message.block.nil?
162
162
 
163
163
  self
164
164
  end
@@ -178,7 +178,7 @@ module CabezaDeTermo
178
178
 
179
179
  run_modifier(modifier)
180
180
 
181
- CdT.bind_evaluation_of message.block, to: self unless message.block.nil?
181
+ CdT.bind_block_evaluation_to self, &message.block unless message.block.nil?
182
182
 
183
183
  self
184
184
  end
@@ -34,7 +34,7 @@ module CabezaDeTermo
34
34
 
35
35
  def to_be_a(type, &block)
36
36
  expression = set_value_expression( new_expression_for(type) )
37
- CdT.bind_evaluation_of block, to: expression unless block.nil?
37
+ CdT.bind_block_evaluation_to expression, &block unless block.nil?
38
38
  expression
39
39
  end
40
40
 
@@ -25,7 +25,7 @@ module CabezaDeTermo
25
25
  # Defining Expectations
26
26
 
27
27
  def each(&block)
28
- CdT.bind_evaluation_of block, to: each_expression unless block.nil?
28
+ CdT.bind_block_evaluation_to each_expression, &block unless block.nil?
29
29
 
30
30
  each_expression
31
31
  end
@@ -61,7 +61,7 @@ module CabezaDeTermo
61
61
  def each_field(&block)
62
62
  @each_field_expression = new_each_field
63
63
 
64
- CdT.bind_evaluation_of block, to: @each_field_expression unless block.nil?
64
+ CdT.bind_block_evaluation_to @each_field_expression, &block unless block.nil?
65
65
 
66
66
  @each_field_expression
67
67
  end
@@ -28,7 +28,7 @@ module CabezaDeTermo
28
28
 
29
29
  use_expectations_library(global_expectations_library)
30
30
 
31
- CdT.bind_evaluation_of block, to: self unless block.nil?
31
+ CdT.bind_block_evaluation_to self, &block unless block.nil?
32
32
  end
33
33
 
34
34
  # Accessing
@@ -56,7 +56,7 @@ module CabezaDeTermo
56
56
  # Default expectations
57
57
 
58
58
  def define(&block)
59
- CdT.bind_evaluation_of block, to: ExpectationLibraryDefinitionBuilder.new(self)
59
+ CdT.bind_block_evaluation_to ExpectationLibraryDefinitionBuilder.new(self), &block
60
60
  end
61
61
 
62
62
  # Expectations
@@ -72,7 +72,7 @@ module CabezaDeTermo
72
72
  def expect_a(type, &block)
73
73
  @root_expression = new_expression_for(type)
74
74
 
75
- CdT.bind_evaluation_of block, to: @root_expression unless block.nil?
75
+ CdT.bind_block_evaluation_to @root_expression, &block unless block.nil?
76
76
 
77
77
  @root_expression
78
78
  end
@@ -1,5 +1,5 @@
1
1
  module CabezaDeTermo
2
2
  module JsonSpec
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Rubi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-18 00:00:00.000000000 Z
11
+ date: 2015-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cdt-utilities
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.2'
19
+ version: '0.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.2'
26
+ version: '0.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: validates_email_format_of
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -118,18 +118,9 @@ files:
118
118
  - cachivache/Rakefile
119
119
  - cachivache/Vagrantfile
120
120
  - cachivache/cachivache.rb
121
- - cachivache/lib/rake-helper.rb
122
- - cachivache/lib/shell-contexts/shell-context.rb
123
- - cachivache/lib/shell-contexts/shell-exec.rb
124
- - cachivache/lib/shell-contexts/shell_buffer.rb
125
- - cachivache/lib/shell-contexts/shell_debugger.rb
126
- - cachivache/lib/shell-file-context.rb
127
- - cachivache/lib/shell-if-context.rb
128
- - cachivache/lib/stuff-api-behaviour.rb
129
- - cachivache/lib/stuff-configuration.rb
130
- - cachivache/lib/stuff-reminders-behaviour.rb
131
121
  - cachivache/stuff/.gitkeep
132
122
  - cachivache/stuff/ruby-json-spec.rb
123
+ - cachivache/utilities/stuff-configuration.rb
133
124
  - examples/example-1-simple.rb
134
125
  - examples/example-2-default-expectations.rb
135
126
  - examples/example-3-each-field.rb
@@ -1,53 +0,0 @@
1
- require 'rake'
2
- require 'colorize'
3
- require 'pathname'
4
-
5
- require_relative '../cachivache'
6
-
7
- # Helper - Iterate all .rb files in a folder
8
- def all_rb_files_in(folder, &block)
9
- Dir[Pathname.new(folder) + '**/*.rb'].each do |file|
10
- block.call(file)
11
- end
12
- end
13
-
14
- def stuff_to_install(&block)
15
- Cachivache.stuff_to_install.each do |stuff_name|
16
- block.call stuff_name
17
- end
18
- end
19
-
20
- public
21
-
22
- ######################################
23
- # require all the files in /lib first
24
- ######################################
25
-
26
- all_rb_files_in Cachivache.cachivache_folder + '/lib' do |file|
27
- require file
28
- end
29
-
30
- ######################################
31
- # Stuff Api behaviour
32
- ######################################
33
-
34
- def stuff(task_definition, *args, &block)
35
- task(task_definition, *args, &block)
36
- end
37
-
38
- def execute_shell_command(command)
39
- sh command
40
- end
41
-
42
- include Stuff::ApiBehaviour
43
- include Stuff::RemindersBehaviour
44
-
45
- ShellContext.set_current( ShellExec.new(self) )
46
-
47
- ######################################
48
- # Load the rest of the files
49
- ######################################
50
-
51
- all_rb_files_in Cachivache.cachivache_folder do |file|
52
- require file
53
- end
@@ -1,63 +0,0 @@
1
- class ShellContext
2
- @current = nil
3
- @reminders = []
4
-
5
- def self.current()
6
- @current
7
- end
8
-
9
- def self.set_current(shell_context)
10
- @current = shell_context
11
- end
12
-
13
- def self.during_shell_context(new_shell_context, &block)
14
- current_shell_context = @current
15
-
16
- @current = new_shell_context
17
-
18
- block.call
19
-
20
- @current = current_shell_context
21
- end
22
-
23
- def self.reminders()
24
- @reminders
25
- end
26
-
27
- def self.show_info(text)
28
- puts '-----------------------------------------------'.red
29
- puts text.green
30
- puts '-----------------------------------------------'.red
31
- end
32
-
33
- # Instance methods
34
-
35
- def shell(command)
36
- raise 'Subclass responsibility'
37
- end
38
-
39
- def shell!(command)
40
- raise 'Subclass responsibility'
41
- end
42
-
43
- def invoke(task_name, *args)
44
- Rake::Task[task_name].invoke(*args)
45
- end
46
-
47
- def execute(task_name, *args)
48
- Rake::Task[task_name].execute(*args)
49
- end
50
-
51
- def remind_to(text)
52
- ShellContext.reminders << text
53
- end
54
-
55
- def raise_validation_error(message)
56
- show_info(message)
57
- exit
58
- end
59
-
60
- def show_info(text)
61
- ShellContext.show_info(text)
62
- end
63
- end
@@ -1,19 +0,0 @@
1
- require_relative 'shell-context'
2
-
3
- class ShellExec < ShellContext
4
- def initialize(scope)
5
- @scope = scope
6
- end
7
-
8
- def scope()
9
- @scope
10
- end
11
-
12
- def shell(command)
13
- shell! command
14
- end
15
-
16
- def shell!(command)
17
- scope.execute_shell_command(command)
18
- end
19
- end
@@ -1,25 +0,0 @@
1
- require_relative 'shell-context'
2
-
3
- class ShellBuffer < ShellContext
4
- def initialize(underlaying_shell_context)
5
- @underlaying_shell_context = underlaying_shell_context
6
- @contents = ''
7
- end
8
-
9
- def underlaying_shell_context()
10
- @underlaying_shell_context
11
- end
12
-
13
- def contents
14
- @contents
15
- end
16
-
17
- def shell(command)
18
- contents << "\n" unless contents.empty?
19
- contents << command
20
- end
21
-
22
- def shell!(command)
23
- underlaying_shell_context.shell! command
24
- end
25
- end
@@ -1,11 +0,0 @@
1
- require_relative 'shell-context'
2
-
3
- class ShellDebugger < ShellContext
4
- def shell(command)
5
- puts command.cyan
6
- end
7
-
8
- def shell!(command)
9
- puts command.red
10
- end
11
- end
@@ -1,36 +0,0 @@
1
- require_relative 'stuff-api-behaviour'
2
-
3
- class ShellFileContext
4
- include Stuff::ApiBehaviour
5
-
6
- def self.with(args, &block)
7
- new(args).evaluate_with block
8
- end
9
-
10
- def initialize(args)
11
- @filename = args[:file]
12
- end
13
-
14
- def evaluate_with(block)
15
- instance_eval(&block)
16
- end
17
-
18
- # replace pattern: "user: ''", with: "user: 'admin'"
19
- def replace(params)
20
- pattern = params[:pattern]
21
- replacement = params[:with]
22
- %Q{
23
- sudo sed -i 's|#{pattern}|#{replacement}|g' #{@filename}
24
- }
25
- end
26
-
27
- # append '[mongo]'
28
- # append :new_line
29
- def append(text)
30
- text = "\n" if text == :new_line
31
-
32
- %Q{
33
- echo "#{text}" | sudo tee -a #{@filename}
34
- }
35
- end
36
- end
@@ -1,21 +0,0 @@
1
- require_relative 'stuff-api-behaviour'
2
-
3
- class ShellIfContext
4
- include Stuff::ApiBehaviour
5
-
6
- def self.with(args, &block)
7
- new(args).evaluate_with block
8
- end
9
-
10
- def initialize(args)
11
- @guard = args[:guard]
12
- end
13
-
14
- def evaluate_with(block)
15
- shell "if #{@guard}; then"
16
-
17
- instance_eval(&block)
18
-
19
- shell "fi"
20
- end
21
- end
@@ -1,145 +0,0 @@
1
- module Stuff
2
- module ApiBehaviour
3
- def shell_context()
4
- ShellContext.current
5
- end
6
-
7
- def invoke(task_name, *args)
8
- shell_context.invoke(task_name, *args)
9
- end
10
-
11
- def execute(task_name, *args)
12
- shell_context.execute(task_name, *args)
13
- end
14
-
15
- def shell(command)
16
- shell_context.shell(command)
17
- end
18
-
19
- def shell!(command)
20
- shell_context.shell!(command)
21
- end
22
-
23
- # Examples:
24
- #
25
- # shell_unless file_exists: '/bla.conf' do
26
- # shell %Q{
27
- # ls -la
28
- # rm -rf bla
29
- # }
30
- # end
31
- #
32
- # shell_unless folder_exists: '/bla' do
33
- # shell %Q{
34
- # ls -la
35
- # rm -rf bla
36
- # }
37
- # end
38
- #
39
- # shell_unless file: '/bla', contains: 'some regex' do
40
- # shell %Q{
41
- # ls -la
42
- # rm -rf bla
43
- # }
44
- # end
45
- #
46
- # shell_unless command: 'java -version', contains: 'java 1.8' do
47
- # shell %Q{
48
- # ls -la
49
- # rm -rf bla
50
- # }
51
- # end
52
- #
53
- def shell_unless(params, &block)
54
- if params.key?(:file_exists)
55
- shell unless_file_exists(params[:file_exists], &block)
56
- return
57
- end
58
- if params.key?(:folder_exists)
59
- shell unless_folder_exists(params[:folder_exists], &block)
60
- return
61
- end
62
- if params.key?(:file) && params.key?(:contains)
63
- shell unless_regex_in_file(params[:contains], params[:file], &block)
64
- return
65
- end
66
- if params.key?(:command) && params.key?(:contains)
67
- shell unless_regex_in_command(params[:contains], params[:command], &block)
68
- return
69
- end
70
- raise 'Invalid unless option'
71
- end
72
-
73
- # Examples:
74
- #
75
- # in_file "/bla.conf" do
76
- # shell replace pattern: "%user%", with: "admin"
77
- #
78
- # shell append "[cachivache]"
79
- # shell append "path='/bla'"
80
- # end
81
- def in_file(filename, &block)
82
- script = during_shell_buffer do
83
- ShellFileContext.with(file: filename, &block)
84
- end
85
-
86
- shell script
87
- end
88
-
89
- # Examples:
90
- #
91
- # remind_to 'This is shown when the provision ends'
92
- def remind_to(text)
93
- shell_context.remind_to(text)
94
- end
95
-
96
- def raise_validation_error(message)
97
- shell_context.raise_validation_error(message)
98
- end
99
-
100
- # Example:
101
- #
102
- # configure :Something do
103
- # let(:bla) { '123' }
104
- # let(:ble) { 'abc' }
105
- # end
106
- def configure(class_name, &block)
107
- Stuff::Configuration.ensure_subclass_exists(class_name)
108
- Stuff::Configuration.class_named(class_name).instance_eval(&block)
109
- end
110
-
111
- protected
112
-
113
- def during_shell_buffer(&block)
114
- temporary_shell_buffer = ShellBuffer.new(shell_context)
115
-
116
- ShellContext.during_shell_context(temporary_shell_buffer, &block)
117
-
118
- temporary_shell_buffer.contents
119
- end
120
-
121
- def unless_file_exists(filename, &block)
122
- during_shell_buffer do
123
- ShellIfContext.with(guard: "[ ! -e #{filename} ]", &block)
124
- end
125
- end
126
-
127
- def unless_folder_exists(folder, &block)
128
- during_shell_buffer do
129
- ShellIfContext.with(guard: "[ ! -d #{folder} ]", &block)
130
- end
131
- end
132
-
133
- def unless_regex_in_file(regex, filename, &block)
134
- during_shell_buffer do
135
- ShellIfContext.with(guard: "! grep -q \"#{regex}\" \"#{filename}\"", &block)
136
- end
137
- end
138
-
139
- def unless_regex_in_command(regex, command, &block)
140
- during_shell_buffer do
141
- ShellIfContext.with(guard: "! #{command} | grep -q \"#{regex}\"", &block)
142
- end
143
- end
144
- end
145
- end
@@ -1,11 +0,0 @@
1
- module Stuff
2
- module RemindersBehaviour
3
- def show_reminders()
4
- ShellContext.reminders.each { |alert| show_info(alert) }
5
- end
6
-
7
- def show_info(text)
8
- ShellContext.show_info(text)
9
- end
10
- end
11
- end