json-spec 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/cachivache/Gemfile +2 -1
- data/cachivache/README.md +8 -3
- data/cachivache/Rakefile +37 -3
- data/cachivache/Vagrantfile +14 -12
- data/cachivache/cachivache.rb +1 -1
- data/cachivache/{lib → utilities}/stuff-configuration.rb +2 -0
- data/json-spec.gemspec +1 -1
- data/lib/cabeza-de-termo/json-spec/expectations-library/default-expectations/default-expectations-mapping.rb +1 -1
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb +2 -2
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-library-definition-builder.rb +1 -1
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/modifiers-definition-builder.rb +1 -1
- data/lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb +1 -1
- data/lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb +1 -1
- data/lib/cabeza-de-termo/json-spec/expressions/json-each-field.rb +1 -1
- data/lib/cabeza-de-termo/json-spec/expressions/json-each.rb +1 -1
- data/lib/cabeza-de-termo/json-spec/expressions/json-expression.rb +2 -2
- data/lib/cabeza-de-termo/json-spec/expressions/json-field.rb +1 -1
- data/lib/cabeza-de-termo/json-spec/expressions/json-list.rb +1 -1
- data/lib/cabeza-de-termo/json-spec/expressions/json-object.rb +1 -1
- data/lib/cabeza-de-termo/json-spec/expressions/json-spec.rb +3 -3
- data/lib/cabeza-de-termo/json-spec/version.rb +1 -1
- metadata +5 -14
- data/cachivache/lib/rake-helper.rb +0 -53
- data/cachivache/lib/shell-contexts/shell-context.rb +0 -63
- data/cachivache/lib/shell-contexts/shell-exec.rb +0 -19
- data/cachivache/lib/shell-contexts/shell_buffer.rb +0 -25
- data/cachivache/lib/shell-contexts/shell_debugger.rb +0 -11
- data/cachivache/lib/shell-file-context.rb +0 -36
- data/cachivache/lib/shell-if-context.rb +0 -21
- data/cachivache/lib/stuff-api-behaviour.rb +0 -145
- data/cachivache/lib/stuff-reminders-behaviour.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88fa5f44774aebd47659b16c57b1cf9fb3ef2ccd
|
4
|
+
data.tar.gz: 5d3e524a2f0339defdfeece219eea8fa3d78c014
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be1e7578c169920b687b50eb9918e24ee2cf1f0f98c265b485d1155df56e28ac87580ee29a846bb817e2af4286571e3ca340fd2a1c67592329336fc80b4bf41e
|
7
|
+
data.tar.gz: d647c78b14358b6977f7c33c6ee7be46f9f68ca81bb3957d178a6f22fd62eae035d06214082e24baa8cc2e0170b0c6c88d39a189be3520d0dbbf8aaf32203334
|
data/cachivache/Gemfile
CHANGED
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
|
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
|
-
|
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
|
-
|
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
|
|
data/cachivache/Vagrantfile
CHANGED
@@ -39,23 +39,25 @@ Vagrant.configure(2) do |config|
|
|
39
39
|
type: "shell",
|
40
40
|
privileged: false,
|
41
41
|
inline: %Q{
|
42
|
-
|
43
|
-
|
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
|
-
|
45
|
+
sudo apt-get update
|
46
46
|
|
47
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
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
|
-
|
58
|
-
|
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",
|
data/cachivache/cachivache.rb
CHANGED
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.
|
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.
|
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.
|
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.
|
60
|
+
CdT.bind_block_evaluation_to self, &block
|
61
61
|
|
62
62
|
define_expectation_in_library
|
63
63
|
define_expectation_message_in_library
|
@@ -58,7 +58,7 @@ module CabezaDeTermo
|
|
58
58
|
# Defining
|
59
59
|
|
60
60
|
def define(&block)
|
61
|
-
CdT.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
37
|
+
CdT.bind_block_evaluation_to expression, &block unless block.nil?
|
38
38
|
expression
|
39
39
|
end
|
40
40
|
|
@@ -61,7 +61,7 @@ module CabezaDeTermo
|
|
61
61
|
def each_field(&block)
|
62
62
|
@each_field_expression = new_each_field
|
63
63
|
|
64
|
-
CdT.
|
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.
|
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.
|
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.
|
75
|
+
CdT.bind_block_evaluation_to @root_expression, &block unless block.nil?
|
76
76
|
|
77
77
|
@root_expression
|
78
78
|
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.
|
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-
|
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.
|
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.
|
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,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
|