enforce 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62c84e4dfbce7b5a0e150a3b25dfc5e7c91b99aebed8eb75dc18ed22dad114a4
4
- data.tar.gz: a4677ac19839c3fcd6265f912d448a65b8c58f72d91f84c999dffb8f74f6b54c
3
+ metadata.gz: a4f0f43d49e308c9c65fb2b0dd8dda636f357158140dcce83c003ba6c19d30f1
4
+ data.tar.gz: fa414dce653faafb66fb4701250c8de8914dfd4992901aa51156b99c144d68d1
5
5
  SHA512:
6
- metadata.gz: 53e3ce2334e0ea0572f32e63c4d9f726cd018ea12033277c6a91e29824ba1f0a6e4a8c121f958d4bb424b67af8e62c305634573ffa61bca6656bf4753fbc3c0c
7
- data.tar.gz: 53cc87b17ce8110ae060999107c548ad1a23cbdb47d5d11588740745bbbbce97f272c014afe7131fe487dbbb07e2e6db679f1eff15eb640e7399abf3425ad44e
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
  [![Gem](https://img.shields.io/gem/v/enforce.svg?style=flat-square)](https://rubygems.org/gems/enforce)
5
5
  [![Build](https://img.shields.io/travis/DannyBen/enforce/master.svg?style=flat-square)](https://travis-ci.org/DannyBen/enforce)
6
- [![Dependencies](https://img.shields.io/gemnasium/DannyBen/enforce.svg?style=flat-square)](https://gemnasium.com/DannyBen/enforce)
7
6
  [![Maintainability](https://img.shields.io/codeclimate/maintainability/DannyBen/enforce.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/enforce)
8
7
  [![Issues](https://img.shields.io/codeclimate/issues/github/DannyBen/enforce.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/enforce)
9
8
 
@@ -30,11 +29,69 @@ gem 'enforce'
30
29
  Example
31
30
  --------------------------------------------------
32
31
 
33
- Soon
32
+ [![asciicast](https://asciinema.org/a/YqUrRMXdUXVGh7KqJpvy5DVBm.png)](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
- Soon
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
+ ```
@@ -10,7 +10,6 @@ module Enforce
10
10
  file = find_file argv[0]
11
11
  return show_file_not_found unless file
12
12
 
13
-
14
13
  handler.execute file
15
14
  handler.failed? ? 1 : 0
16
15
  end
@@ -51,5 +50,3 @@ module Enforce
51
50
 
52
51
  end
53
52
  end
54
-
55
-
@@ -6,21 +6,20 @@ module Enforce
6
6
  pass = File.exist?(name)
7
7
  @last_file = name
8
8
 
9
- add_result message: "File `#{name}` should exist", pass: pass
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
- add_result message: "File `#{name}` should not exist",
18
- pass: !File.exist?(name)
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: "Folder `#{name}` should exist", pass: pass
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: "File `#{last_file}` should contain `#{content_as_string}`",
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: "File `#{last_file}` should not contain `#{content_as_string}`",
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
@@ -20,7 +20,7 @@ module Enforce
20
20
 
21
21
  def handle(message:, pass:)
22
22
  status = pass ? "%{green}PASS%{reset}" : "%{red}FAIL%{reset}"
23
- say "#{status} #{message}"
23
+ say "#{status} #{message}"
24
24
  end
25
25
  end
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module Enforce
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
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.1
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.0.0
125
+ version: 2.4.0
127
126
  required_rubygems_version: !ruby/object:Gem::Requirement
128
127
  requirements:
129
128
  - - ">="
@@ -1,4 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'bin/enforce' do
4
- end