https://github.com/dannyben/enforce
DSL for verifying file/folder content
https://github.com/dannyben/enforce
dsl gem ruby rules-engine
Last synced: 7 months ago
JSON representation
DSL for verifying file/folder content
- Host: GitHub
- URL: https://github.com/dannyben/enforce
- Owner: DannyBen
- License: mit
- Created: 2018-02-03T10:51:29.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-28T15:38:42.000Z (almost 3 years ago)
- Last Synced: 2025-06-14T11:03:10.172Z (7 months ago)
- Topics: dsl, gem, ruby, rules-engine
- Language: Ruby
- Size: 51.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Enforce - A DSL for verifying file/folder content
[](https://badge.fury.io/rb/enforce)
[](https://github.com/DannyBen/enforce/actions?query=workflow%3ATest)
[](https://codeclimate.com/github/DannyBen/enforce/maintainability)
---
Create globally available DSL scripts to verify the existence of files in
a folder, and the contents of these files.
---
## Install
```
$ gem install enforce
```
## Example
[](https://asciinema.org/a/bGvwdnrAzrUeHeGvY4UYfIdFZ)
Also see the [example folder](/example).
## Usage
1. Create a rules file containing any of the DSL commands below.
2. Run `$ enforce ` in the directory you want to test
(without the `.rb` extension)
Rules files are ruby scripts that are located either in the current directory
or in your home directory, under `enforce` subdirectory (`~/enforce/*.rb`).
If you wish to place your rules files elsewhere, set the `ENFORCE_HOME`
environment variable.
## DSL
### File Commands
Verify that a file exists:
```ruby
file 'filename'
```
Verify that a file exists, and has (or doesn't have) some content:
```ruby
file 'filename' do
text 'any content'
no_text 'other content or regex'
regex /any.regex/
no_regex /any.regex/
line 'line to match, leading and trailing spaces are ignored'
no_line 'line to make sure is not in the file'
end
```
Verify that a file does not exist:
```ruby
no_file 'filename'
```
### Folder Commands
Verify that a folder exists:
```ruby
folder 'dirname'
```
Verify that a folder does not exist:
```ruby
no_folder 'dirname'
```
Verify that a folder exists, and run additional validations inside it:
```ruby
folder 'dirname' do
file 'file-inside-dirname'
file 'another-file' do
text 'some content'
end
end
```