easy_gen 1.4.0 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '039f3a56535913793c5650392d33a758ed535b5408d3378d0333931d8d4ad7c2'
4
- data.tar.gz: 88b749acf53e01644f352b29c70f3313c46461d964121c2b4c61fa59deaf4de5
3
+ metadata.gz: 9c04ab1432a5a0b018928023b51ad5e6b2c106bf459365872754b28888328023
4
+ data.tar.gz: ebb5079ef9cdc195f1c1260955ce428ebe94a47a19bb3d4c4d594a520025c229
5
5
  SHA512:
6
- metadata.gz: 3e5bc98279170412cc346fb9c0e3cdd0b2b73bd53411bbb767ddc0bafcd613db800ad73735b0dc3ba4848f9601603f4ff04ecbecf1d98821a58d1290a99af3d3
7
- data.tar.gz: 94ed33ad98ae628b1d7b8b471fe0ce75c9603f676861003f83722f8c2a6ba740ee300ba379b5513dedda24fe2a2dc608447d3e46c50dd7de50ad492fbf1b6637
6
+ metadata.gz: ea06ed2048dd9e0a15225009b82fa1f128dd939533c1918a62a2b6397a9f58e38ec80908a6498af7366b603eff956ca24e4c57cf68cd803e4d6b3403fee4dc77
7
+ data.tar.gz: eaccb356574eb88f88d7cb8b4eb93ed216f3c86de6eb66297ac0974d22dd1826acacb3230afd755a0b630fd98ab8ed1ab51037ee3c7bad86a6e7971cee9ad18b
data/README.md CHANGED
@@ -22,7 +22,7 @@ In the usual way.
22
22
 
23
23
  ## Using generators
24
24
 
25
- ### Service Object Classes
25
+ ### Service Classes
26
26
  (See this link for example usage: https://www.honeybadger.io/blog/refactor-ruby-rails-service-object/):
27
27
 
28
28
  ```sh
@@ -49,6 +49,23 @@ bundle exec rails g service serviceclassname --module cool
49
49
  - Creates '/test/services/cool' directory if it doesnt exist.
50
50
  - Installs new test class in '/test/services/cool' with the name 'ServiceClassNameTest' in the file '/test/services/cool/service_class_name_test.rb'.
51
51
 
52
+ ### Validator Classes
53
+ (See this link for example usage: https://womanonrails.com/custom-rails-validators ):
54
+
55
+ ```sh
56
+ bundle exec rails g validator target
57
+ ```
58
+
59
+ The command above:
60
+
61
+ - Creates '/app/validators' directory if it doesnt exist.
62
+ - Installs new application validator class in '/app/validator' with the name 'ApplicationValidator' in file '/app/services/application_validator.rb.' which inherits from ActiveModel::EachValidator.
63
+ - Installs new validator class in '/app/validators' with the class name 'TargetValidator' in the file /app/validators/target_validator.rb. This will inherit from /app/services/application_validator.rb.'
64
+ - Creates '/test/validators' directory if it doesnt exist.
65
+ - Installs new test class in '/test/validators' with the name 'TargetValidatorTest' in the file '/test/validators/target_validator_test.rb'.
66
+
67
+ Yeah I know there are other types of validators - pull requests gratefully received. I have only ever used EachValidators, and them many times..
68
+
52
69
  ### Null Object Classes
53
70
  (See this link for typical usage: https://medium.com/@kelseydh/using-the-null-object-pattern-with-ruby-on-rails-b645ebf79785 ):
54
71
 
@@ -0,0 +1,14 @@
1
+ Description:
2
+ Lays out a new service object under /app/decorators, with a test file under /test/decorators.
3
+ The service class will inherit from /app/decorators/application_decorator class which will be created.
4
+ if you use the generator to delete decorator classes, these will be removed together with directories once
5
+ the count of non abstract classes == 0.
6
+
7
+ Example:
8
+ `rails generate decorator Mydecorator`
9
+
10
+ This will create:
11
+ app/decorators/application_decorator.rb
12
+ app/decorators/my_decorator.rb
13
+ test/decorators/my_decorator_test.rb
14
+
@@ -0,0 +1,3 @@
1
+ class ApplicationValidator < ActiveModel::EachValidator
2
+
3
+ end
@@ -0,0 +1,11 @@
1
+ class <%= class_name %>Validator < ApplicationValidator
2
+
3
+ def validate_each(record, attribute, value)
4
+ return false if value.blank?
5
+ return true
6
+ end
7
+
8
+
9
+ private
10
+
11
+ end
@@ -0,0 +1,23 @@
1
+ require "test_helper"
2
+
3
+
4
+ class <%= class_name %>Validatable
5
+ include ActiveModel::Validations
6
+ attr_accessor :<%= class_name.downcase %>
7
+
8
+ validates :<%= class_name.downcase %>, <%= class_name.downcase %>: true
9
+
10
+ end
11
+
12
+
13
+ class <%= class_name %>ValidatorTest < ActiveSupport::TestCase
14
+ setup do
15
+ @testable = <%= class_name %>Validatable.new
16
+ end
17
+
18
+ test 'Confirms there is a value' do
19
+ @testable.<%= class_name.downcase %> = 1
20
+ assert @testable.valid?
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'rails/generators'
2
+ require 'fileutils'
3
+
4
+ template_dir = File.expand_path('templates', __dir__)
5
+
6
+ class ValidatorGenerator < Rails::Generators::NamedBase
7
+ include EasyGenGenerator
8
+
9
+ # bundle exec rails g service MyService
10
+ # bundle exec rails d service MyService
11
+
12
+ LOCATION = "validators"
13
+ TYPE = "validator"
14
+
15
+ source_root File.expand_path("templates", __dir__)
16
+
17
+ def main
18
+ copy_templates
19
+ end
20
+
21
+ private
22
+
23
+ end
@@ -1,3 +1,3 @@
1
1
  module EasyGen
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Stearn
@@ -45,6 +45,11 @@ files:
45
45
  - lib/easy_gen/strategy/templates/context_test.rb.tt
46
46
  - lib/easy_gen/strategy/templates/strategy.rb.tt
47
47
  - lib/easy_gen/strategy/templates/strategy_test.rb.tt
48
+ - lib/easy_gen/validator/USAGE
49
+ - lib/easy_gen/validator/templates/application_validator.rb.tt
50
+ - lib/easy_gen/validator/templates/validator.rb.tt
51
+ - lib/easy_gen/validator/templates/validator_test.rb.tt
52
+ - lib/easy_gen/validator/validator_generator.rb
48
53
  - lib/easy_gen/version.rb
49
54
  homepage: https://rubygems.org/gems/easy_gen
50
55
  licenses: