enforce 0.0.1 → 0.1.0
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/README.md +60 -3
- data/lib/enforce/command_line.rb +0 -3
- data/lib/enforce/dsl.rb +16 -7
- data/lib/enforce/handler.rb +1 -1
- data/lib/enforce/version.rb +1 -1
- metadata +2 -3
- data/lib/enforce/bin_spec.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4f0f43d49e308c9c65fb2b0dd8dda636f357158140dcce83c003ba6c19d30f1
|
4
|
+
data.tar.gz: fa414dce653faafb66fb4701250c8de8914dfd4992901aa51156b99c144d68d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae03e8d2b4c8d0b60be8522b720c0f64f7bea0766759fb951cf763e192ff000b2fea036f9bb0b739a305ff964ca3e64c9b01908e029c30793425e6a7c73eca0c
|
7
|
+
data.tar.gz: f3ddde5fb021c84b1df97fca4cf0443a3982a3be63f053c2533370eff1bd666450ae265e6745f643a6f372d574cdc25e40a110e44426fd73b5a31e8e39368ff2
|
data/README.md
CHANGED
@@ -3,7 +3,6 @@ Enforce - A DSL for verifying file/folder content
|
|
3
3
|
|
4
4
|
[](https://rubygems.org/gems/enforce)
|
5
5
|
[](https://travis-ci.org/DannyBen/enforce)
|
6
|
-
[](https://gemnasium.com/DannyBen/enforce)
|
7
6
|
[](https://codeclimate.com/github/DannyBen/enforce)
|
8
7
|
[](https://codeclimate.com/github/DannyBen/enforce)
|
9
8
|
|
@@ -30,11 +29,69 @@ gem 'enforce'
|
|
30
29
|
Example
|
31
30
|
--------------------------------------------------
|
32
31
|
|
33
|
-
|
32
|
+
[](https://asciinema.org/a/YqUrRMXdUXVGh7KqJpvy5DVBm)
|
33
|
+
|
34
|
+
Also see the [example folder](/example).
|
34
35
|
|
35
36
|
|
36
37
|
Usage
|
37
38
|
--------------------------------------------------
|
38
39
|
|
39
|
-
|
40
|
+
1. Create a rules file containing any of the DSL commands below.
|
41
|
+
2. Run `$ enforce <fules file name>` in the directory you want to test
|
42
|
+
(without the `.rb` extension)
|
43
|
+
|
44
|
+
Rules files are ruby scripts that are located either in the current directory
|
45
|
+
or in your home directory, under `enforce` subdirectory (~/enforce/*.rb).
|
46
|
+
|
47
|
+
If you wish to place your rules files elsewhere, set the `ENFORCE_HOME`
|
48
|
+
environment variable.
|
49
|
+
|
50
|
+
DSL
|
51
|
+
--------------------------------------------------
|
52
|
+
|
53
|
+
### File Commands
|
54
|
+
|
55
|
+
Verify that a file exists:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
file 'filename'
|
59
|
+
```
|
60
|
+
|
61
|
+
Verify that a file exists, and has (or doesn't have) some content:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
file 'filename' do
|
65
|
+
with 'any content'
|
66
|
+
with /any.regex/
|
67
|
+
without 'other content or regex'
|
68
|
+
with_line 'line to match, leading and trailing spaces are ignored'
|
69
|
+
without_line 'line to make sure is not in the file'
|
70
|
+
end
|
71
|
+
```
|
40
72
|
|
73
|
+
Verify that a file does not exist:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
no_file 'filename'
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
### Folder Commands
|
81
|
+
|
82
|
+
Verify that a folder exists:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
folder 'dirname'
|
86
|
+
```
|
87
|
+
|
88
|
+
Verify that a folder exists, and run additional validations inside it:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
folder 'dirname' do
|
92
|
+
file 'file-inside-dirname'
|
93
|
+
file 'another-file' do
|
94
|
+
with 'some content'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
```
|
data/lib/enforce/command_line.rb
CHANGED
data/lib/enforce/dsl.rb
CHANGED
@@ -6,21 +6,20 @@ module Enforce
|
|
6
6
|
pass = File.exist?(name)
|
7
7
|
@last_file = name
|
8
8
|
|
9
|
-
add_result message: "
|
9
|
+
add_result message: "file `#{name}`", pass: pass
|
10
10
|
|
11
11
|
return unless pass
|
12
|
-
|
13
12
|
yield if block_given?
|
14
13
|
end
|
15
14
|
|
16
15
|
def no_file(name)
|
17
|
-
|
18
|
-
|
16
|
+
pass = !File.exist?(name)
|
17
|
+
add_result message: "no file `#{name}`", pass: pass
|
19
18
|
end
|
20
19
|
|
21
20
|
def folder(name)
|
22
21
|
pass = Dir.exist?(name)
|
23
|
-
add_result message: "
|
22
|
+
add_result message: "folder `#{name}`", pass: pass
|
24
23
|
|
25
24
|
return unless pass && block_given?
|
26
25
|
|
@@ -31,16 +30,26 @@ module Enforce
|
|
31
30
|
|
32
31
|
def with(content)
|
33
32
|
content_as_string = content.is_a?(String) ? content : content.inspect
|
34
|
-
add_result message: "
|
33
|
+
add_result message: "with `#{content_as_string}`",
|
35
34
|
pass: File.read(last_file).match?(content)
|
36
35
|
end
|
37
36
|
|
38
37
|
def without(content)
|
39
38
|
content_as_string = content.is_a?(String) ? content : content.inspect
|
40
|
-
add_result message: "
|
39
|
+
add_result message: "without `#{content_as_string}`",
|
41
40
|
pass: !File.read(last_file).match?(content)
|
42
41
|
end
|
43
42
|
|
43
|
+
def with_line(content)
|
44
|
+
add_result message: "with line `#{content}`",
|
45
|
+
pass: File.readlines(last_file).map(&:strip).include?(content)
|
46
|
+
end
|
47
|
+
|
48
|
+
def without_line(content)
|
49
|
+
add_result message: "without line `#{content}`",
|
50
|
+
pass: !File.readlines(last_file).map(&:strip).include?(content)
|
51
|
+
end
|
52
|
+
|
44
53
|
def results
|
45
54
|
@results ||= []
|
46
55
|
end
|
data/lib/enforce/handler.rb
CHANGED
data/lib/enforce/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enforce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
@@ -105,7 +105,6 @@ files:
|
|
105
105
|
- README.md
|
106
106
|
- bin/enforce
|
107
107
|
- lib/enforce.rb
|
108
|
-
- lib/enforce/bin_spec.rb
|
109
108
|
- lib/enforce/colors.rb
|
110
109
|
- lib/enforce/command_line.rb
|
111
110
|
- lib/enforce/dsl.rb
|
@@ -123,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
122
|
requirements:
|
124
123
|
- - ">="
|
125
124
|
- !ruby/object:Gem::Version
|
126
|
-
version: 2.
|
125
|
+
version: 2.4.0
|
127
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
127
|
requirements:
|
129
128
|
- - ">="
|
data/lib/enforce/bin_spec.rb
DELETED