thor-validations 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +47 -0
- data/lib/thor/validations/version.rb +7 -0
- data/lib/thor/validations.rb +44 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ff22a39235a36fde79684aadb15fa502d5148c53b720c88997995af023293940
|
4
|
+
data.tar.gz: e9303579d55681beee89b7ff52a64b134c09dc8fa0db1543a15008785db28d85
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b74b03bf1ff3a208db87645811d808937f2d2045d7de52965143de16616e291d28bad8d0bf647a10ffc692dbae8ce166884e04319ccba14d5e849d48c50023c
|
7
|
+
data.tar.gz: bbdaf8f4564ba02ad3da82c837512356bb8fe463983b41b42378c6c877d53f133f9be3b500be2628f0cd990ea0731ff660007df1ad6ca2f29906968ca3f6cf96
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Thor::Validations
|
2
|
+
|
3
|
+
Thor::Validations adds a `validate_before` method to Thor, allowing you to perform validations before executing commands.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'thor-validations'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Inspiration
|
14
|
+
|
15
|
+
Thanks to https://github.com/kddnewton/thor-hollaback for the original idea.
|
16
|
+
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
class MyCommand < Thor
|
22
|
+
include Thor::Validations
|
23
|
+
|
24
|
+
validate_before, :deploy, :rollback do
|
25
|
+
check_permissions
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "deploy", "Deploy app"
|
29
|
+
def deploy
|
30
|
+
sleep(1)
|
31
|
+
puts "Deploying..."
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "rollback", "Rollback app"
|
35
|
+
def rollback
|
36
|
+
sleep(1)
|
37
|
+
puts "Rolling back..."
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def check_permissions
|
43
|
+
puts "Checking permissions..."
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
```
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require_relative 'validations/version
|
5
|
+
|
6
|
+
class Thor
|
7
|
+
module Validations
|
8
|
+
def self.included(base)
|
9
|
+
base.extend(ClassMethods)
|
10
|
+
base.prepend(InstanceMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def validations
|
15
|
+
@validations ||= {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate_before(*method_names, &validation)
|
19
|
+
method_names.each do |method_name|
|
20
|
+
validations[method_name.to_sym] ||= []
|
21
|
+
validations[method_name.to_sym] << validation
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module InstanceMethods
|
27
|
+
def invoke_command(command, *args)
|
28
|
+
run_validations(command)
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def run_validations(command)
|
35
|
+
return unless command && self.class.validations.key?(command.name.to_sym)
|
36
|
+
|
37
|
+
self.class.validations[command.name.to_sym].each do |validation|
|
38
|
+
result = instance_exec(&validation)
|
39
|
+
raise Thor::Error, "Validation failed for #{command.name}" unless result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thor-validations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benoit Tigeot
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.3.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.3.1
|
33
|
+
description: A simple gem that adds a validate_before method to Thor, allowing pre-command
|
34
|
+
validations
|
35
|
+
email:
|
36
|
+
- benoit.tigeot@gmail.com
|
37
|
+
executables: []
|
38
|
+
extensions: []
|
39
|
+
extra_rdoc_files: []
|
40
|
+
files:
|
41
|
+
- README.md
|
42
|
+
- lib/thor/validations.rb
|
43
|
+
- lib/thor/validations/version.rb
|
44
|
+
homepage: https://github.com/benoittgt/thor-validations
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata:
|
48
|
+
allowed_push_host: https://rubygems.org
|
49
|
+
homepage_uri: https://github.com/benoittgt/thor-validations
|
50
|
+
source_code_uri: https://github.com/benoittgt/thor-validations
|
51
|
+
changelog_uri: https://github.com/benoittgt/thor-validations/blob/main/CHANGELOG.md
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.6.0
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.5.11
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Adds validate_before functionality to Thor commands
|
71
|
+
test_files: []
|