enforce 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +40 -0
- data/bin/enforce +6 -0
- data/lib/enforce.rb +5 -0
- data/lib/enforce/bin_spec.rb +4 -0
- data/lib/enforce/colors.rb +16 -0
- data/lib/enforce/command_line.rb +55 -0
- data/lib/enforce/dsl.rb +67 -0
- data/lib/enforce/handler.rb +26 -0
- data/lib/enforce/version.rb +3 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 62c84e4dfbce7b5a0e150a3b25dfc5e7c91b99aebed8eb75dc18ed22dad114a4
|
4
|
+
data.tar.gz: a4677ac19839c3fcd6265f912d448a65b8c58f72d91f84c999dffb8f74f6b54c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 53e3ce2334e0ea0572f32e63c4d9f726cd018ea12033277c6a91e29824ba1f0a6e4a8c121f958d4bb424b67af8e62c305634573ffa61bca6656bf4753fbc3c0c
|
7
|
+
data.tar.gz: 53cc87b17ce8110ae060999107c548ad1a23cbdb47d5d11588740745bbbbce97f272c014afe7131fe487dbbb07e2e6db679f1eff15eb640e7399abf3425ad44e
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Enforce - A DSL for verifying file/folder content
|
2
|
+
==================================================
|
3
|
+
|
4
|
+
[![Gem](https://img.shields.io/gem/v/enforce.svg?style=flat-square)](https://rubygems.org/gems/enforce)
|
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
|
+
[![Maintainability](https://img.shields.io/codeclimate/maintainability/DannyBen/enforce.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/enforce)
|
8
|
+
[![Issues](https://img.shields.io/codeclimate/issues/github/DannyBen/enforce.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/enforce)
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
Create globally available DSL scripts to verify the existence of files in
|
13
|
+
a folder, and the contents of these files.
|
14
|
+
|
15
|
+
---
|
16
|
+
|
17
|
+
Install
|
18
|
+
--------------------------------------------------
|
19
|
+
|
20
|
+
```
|
21
|
+
$ gem install enforce
|
22
|
+
```
|
23
|
+
|
24
|
+
Or with bundler:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'enforce'
|
28
|
+
```
|
29
|
+
|
30
|
+
Example
|
31
|
+
--------------------------------------------------
|
32
|
+
|
33
|
+
Soon
|
34
|
+
|
35
|
+
|
36
|
+
Usage
|
37
|
+
--------------------------------------------------
|
38
|
+
|
39
|
+
Soon
|
40
|
+
|
data/bin/enforce
ADDED
data/lib/enforce.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Enforce
|
2
|
+
module Colors
|
3
|
+
def colors
|
4
|
+
{
|
5
|
+
reset: "\e[0m", black: "\e[30m", red: "\e[31m",
|
6
|
+
green: "\e[32m", yellow: "\e[33m", blue: "\e[34m",
|
7
|
+
magenta:"\e[35m", cyan: "\e[36m", white: "\e[37m",
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def say(message)
|
12
|
+
message.gsub!(/`([^`]+)`/, "%{blue}\\1%{reset}")
|
13
|
+
puts "#{message}%{reset}" % colors
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Enforce
|
4
|
+
class CommandLine
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
def execute(argv=[])
|
8
|
+
return show_usage if argv.empty?
|
9
|
+
|
10
|
+
file = find_file argv[0]
|
11
|
+
return show_file_not_found unless file
|
12
|
+
|
13
|
+
|
14
|
+
handler.execute file
|
15
|
+
handler.failed? ? 1 : 0
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def find_file(basename)
|
21
|
+
candidates = [
|
22
|
+
"#{basename}.rb",
|
23
|
+
"#{home_dir}/#{basename}.rb"
|
24
|
+
]
|
25
|
+
|
26
|
+
candidates.each do |candidate|
|
27
|
+
return candidate if File.exist? candidate
|
28
|
+
end
|
29
|
+
|
30
|
+
false
|
31
|
+
end
|
32
|
+
|
33
|
+
def handler
|
34
|
+
@handler ||= Enforce::Handler.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def show_usage
|
38
|
+
puts "Enforce #{Enforce::VERSION}"
|
39
|
+
puts " Usage: enforce RULES_FILE"
|
40
|
+
0
|
41
|
+
end
|
42
|
+
|
43
|
+
def show_file_not_found
|
44
|
+
puts "Error: Could not find rules file"
|
45
|
+
1
|
46
|
+
end
|
47
|
+
|
48
|
+
def home_dir
|
49
|
+
ENV['ENFORCE_HOME'] ||= "#{Dir.home}/enforce"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
data/lib/enforce/dsl.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Enforce
|
2
|
+
class DSL
|
3
|
+
attr_reader :last_file
|
4
|
+
|
5
|
+
def file(name)
|
6
|
+
pass = File.exist?(name)
|
7
|
+
@last_file = name
|
8
|
+
|
9
|
+
add_result message: "File `#{name}` should exist", pass: pass
|
10
|
+
|
11
|
+
return unless pass
|
12
|
+
|
13
|
+
yield if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def no_file(name)
|
17
|
+
add_result message: "File `#{name}` should not exist",
|
18
|
+
pass: !File.exist?(name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def folder(name)
|
22
|
+
pass = Dir.exist?(name)
|
23
|
+
add_result message: "Folder `#{name}` should exist", pass: pass
|
24
|
+
|
25
|
+
return unless pass && block_given?
|
26
|
+
|
27
|
+
Dir.chdir name do
|
28
|
+
yield
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def with(content)
|
33
|
+
content_as_string = content.is_a?(String) ? content : content.inspect
|
34
|
+
add_result message: "File `#{last_file}` should contain `#{content_as_string}`",
|
35
|
+
pass: File.read(last_file).match?(content)
|
36
|
+
end
|
37
|
+
|
38
|
+
def without(content)
|
39
|
+
content_as_string = content.is_a?(String) ? content : content.inspect
|
40
|
+
add_result message: "File `#{last_file}` should not contain `#{content_as_string}`",
|
41
|
+
pass: !File.read(last_file).match?(content)
|
42
|
+
end
|
43
|
+
|
44
|
+
def results
|
45
|
+
@results ||= []
|
46
|
+
end
|
47
|
+
|
48
|
+
def passed_results
|
49
|
+
results.select { |result| result[:pass] }
|
50
|
+
end
|
51
|
+
|
52
|
+
def failed_results
|
53
|
+
results.reject { |result| result[:pass] }
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
|
58
|
+
def add_result(result)
|
59
|
+
results.push result unless results.include? result
|
60
|
+
handle result
|
61
|
+
end
|
62
|
+
|
63
|
+
def handle(result)
|
64
|
+
# Do nothing, should be overridden
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Enforce
|
4
|
+
class Handler < DSL
|
5
|
+
include Colors
|
6
|
+
|
7
|
+
def execute(file)
|
8
|
+
eval File.read file
|
9
|
+
color = failed? ? "%{red}" : "%{green}"
|
10
|
+
say "#{color}#{results.count} rules, #{failed} failures"
|
11
|
+
end
|
12
|
+
|
13
|
+
def failed
|
14
|
+
failed_results.count
|
15
|
+
end
|
16
|
+
|
17
|
+
def failed?
|
18
|
+
failed_results.count > 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle(message:, pass:)
|
22
|
+
status = pass ? "%{green}PASS%{reset}" : "%{red}FAIL%{reset}"
|
23
|
+
say "#{status} #{message}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enforce
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danny Ben Shitrit
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: runfile
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: runfile-tasks
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec_fixtures
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.15'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.15'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '9.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '9.0'
|
97
|
+
description: Define rules for folder and file contents and enforce them from the command
|
98
|
+
line
|
99
|
+
email: db@dannyben.com
|
100
|
+
executables:
|
101
|
+
- enforce
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- README.md
|
106
|
+
- bin/enforce
|
107
|
+
- lib/enforce.rb
|
108
|
+
- lib/enforce/bin_spec.rb
|
109
|
+
- lib/enforce/colors.rb
|
110
|
+
- lib/enforce/command_line.rb
|
111
|
+
- lib/enforce/dsl.rb
|
112
|
+
- lib/enforce/handler.rb
|
113
|
+
- lib/enforce/version.rb
|
114
|
+
homepage: https://github.com/DannyBen/enforce
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 2.0.0
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.7.3
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: DSL for enforcing folder and file contents
|
138
|
+
test_files: []
|