pretty_validation 0.2.1 → 0.3.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
  SHA1:
3
- metadata.gz: fda915b9b6ed9d477e8c294ce3e206725bae23d9
4
- data.tar.gz: 89b1e6901617d3695c8196e9fbf155e0be025457
3
+ metadata.gz: 8a8fa6e7da479b5228e04cb3432020d3c6f77ba7
4
+ data.tar.gz: 97a749917dc6c75bb0bf8372bc0d4066e3aee0ab
5
5
  SHA512:
6
- metadata.gz: 056595519659cd5f8a9b6edc56a300eaa323052a7cd37f6999b5b2f781cf2214bfb3492438ae03b337a9092ce64943b69096a83079e259718a964b00f066c93f
7
- data.tar.gz: 398fec36686d4fa7c235a6a12c308e7f101262936eb0b1116236c54c2c0cd4893e8d97aab901146fa2f669400e92552e11631552918f6175a0a2ac5d29e6500f
6
+ metadata.gz: 53080e0bbb4d5b92bf4168f2af66e6134ba94699cd968b312c56c9d093fbcb8a0ca1433a962cf8f22657f1a81801cf4b86bbc8381e60c3fe02143f34a07205d5
7
+ data.tar.gz: f1da051c28ead8e3afb0e483f54863314af9e2593b97572c2a0bd9893b001ca504bcf774e6a8812c554957099ac7f0a25d3da926d4395f3fd0d3a68f404d3495
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in pretty_validation.gemspec
4
4
  gemspec
5
+
6
+ gem 'codecov', require: false
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 sinsoku
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -3,7 +3,8 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/pretty_validation.svg)](https://badge.fury.io/rb/pretty_validation)
4
4
  [![Build Status](https://travis-ci.org/sinsoku/pretty_validation.svg?branch=master)](https://travis-ci.org/sinsoku/pretty_validation)
5
5
  [![Code Climate](https://codeclimate.com/github/sinsoku/pretty_validation/badges/gpa.svg)](https://codeclimate.com/github/sinsoku/pretty_validation)
6
- [![Test Coverage](https://codeclimate.com/github/sinsoku/pretty_validation/badges/coverage.svg)](https://codeclimate.com/github/sinsoku/pretty_validation/coverage)
6
+ [![codecov.io](https://codecov.io/github/sinsoku/pretty_validation/coverage.svg?branch=master)](https://codecov.io/github/sinsoku/pretty_validation?branch=master)
7
+ [![Inline docs](http://inch-ci.org/github/sinsoku/pretty_validation.svg?branch=master)](http://inch-ci.org/github/sinsoku/pretty_validation)
7
8
 
8
9
  **"Make validations DRY"**
9
10
 
@@ -3,3 +3,5 @@ source 'https://rubygems.org'
3
3
  gem 'rails', '~> 4.0.0'
4
4
 
5
5
  gemspec :path => '../'
6
+
7
+ gem 'codecov', require: false
@@ -3,3 +3,5 @@ source 'https://rubygems.org'
3
3
  gem 'rails', '~> 4.1.0'
4
4
 
5
5
  gemspec :path => '../'
6
+
7
+ gem 'codecov', require: false
@@ -4,4 +4,4 @@ gem 'rails', '~> 4.2.0'
4
4
 
5
5
  gemspec :path => '../'
6
6
 
7
- gem 'codeclimate-test-reporter'
7
+ gem 'codecov', require: false
@@ -0,0 +1,2 @@
1
+ Description:
2
+ Create a validation file
@@ -0,0 +1,14 @@
1
+ require 'pretty_validation/renderer'
2
+
3
+ class ValidationGenerator < Rails::Generators::NamedBase
4
+ # Require to read a USAGE file
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ class_option :verbose, type: :boolean, default: false, aliases: '-v',
7
+ group: :runtime, desc: 'Show validation code on screen'
8
+
9
+ def create_validation
10
+ r = PrettyValidation::Renderer.new(file_name.tableize)
11
+ puts r.messages if options[:verbose]
12
+ create_file r.file_path, r.render
13
+ end
14
+ end
@@ -1,3 +1,4 @@
1
+ require 'rails'
2
+ require 'pretty_validation/config'
1
3
  require 'pretty_validation/railtie'
2
- require 'pretty_validation/validation_findable'
3
4
  require 'pretty_validation/version'
@@ -0,0 +1,16 @@
1
+ module PrettyValidation
2
+ def self.configure
3
+ yield config
4
+ end
5
+
6
+ def self.config
7
+ @config ||= Configuration.new
8
+ end
9
+
10
+ class Configuration
11
+ include ActiveSupport::Configurable
12
+
13
+ config_accessor(:auto_generate) { true }
14
+ config_accessor(:auto_injection) { true }
15
+ end
16
+ end
@@ -1,5 +1,3 @@
1
- require 'rails'
2
-
3
1
  module PrettyValidation
4
2
  class Railtie < Rails::Railtie
5
3
  rake_tasks do
@@ -7,8 +5,11 @@ module PrettyValidation
7
5
  end
8
6
 
9
7
  initializer 'pretty_validation' do
10
- ActiveSupport.on_load :active_record do
11
- ActiveRecord::Base.include PrettyValidation::ValidationFindable
8
+ if PrettyValidation.config.auto_injection
9
+ ActiveSupport.on_load :active_record do
10
+ require 'pretty_validation/validation_findable'
11
+ ActiveRecord::Base.include PrettyValidation::ValidationFindable
12
+ end
12
13
  end
13
14
  end
14
15
  end
@@ -1,3 +1,4 @@
1
+ require 'pretty_validation/config'
1
2
  require 'pretty_validation/schema'
2
3
  require 'pretty_validation/validation'
3
4
 
@@ -6,23 +7,32 @@ module PrettyValidation
6
7
  attr_reader :table_name
7
8
 
8
9
  def self.validations_path
9
- Rails.root.join('app', 'validations')
10
+ File.join('app', 'validations')
10
11
  end
11
12
 
12
- def self.generate
13
- FileUtils.mkdir_p validations_path unless File.directory? validations_path
13
+ def self.generate(dry_run: false)
14
+ if generate?(dry_run) && !File.directory?(validations_path)
15
+ FileUtils.mkdir_p validations_path
16
+ end
17
+
14
18
  Schema.table_names.each do |t|
15
19
  r = new t
16
- r.write! unless r.validations.empty?
20
+ next if r.validations.empty?
21
+
22
+ r.write! if generate?(dry_run)
17
23
  end
18
24
  end
19
25
 
26
+ def self.generate?(dry_run)
27
+ PrettyValidation.config.auto_generate && !dry_run
28
+ end
29
+
20
30
  def initialize(table_name)
21
31
  @table_name = table_name
22
32
  end
23
33
 
24
34
  def render
25
- <<-EOF
35
+ @render ||= <<-EOF
26
36
  module #{module_name}
27
37
  extend ActiveSupport::Concern
28
38
 
@@ -42,7 +52,7 @@ end
42
52
  end
43
53
 
44
54
  def file_path
45
- Renderer.validations_path.join(file_name)
55
+ File.join(Renderer.validations_path, file_name)
46
56
  end
47
57
 
48
58
  def write!
@@ -53,6 +63,15 @@ end
53
63
  sexy_validations + uniq_validations
54
64
  end
55
65
 
66
+ def messages
67
+ [
68
+ announce('generating'),
69
+ render,
70
+ announce('generated'),
71
+ "\n"
72
+ ].join
73
+ end
74
+
56
75
  private
57
76
 
58
77
  def sexy_validations
@@ -62,5 +81,11 @@ end
62
81
  def uniq_validations
63
82
  Validation.unique_validations(table_name)
64
83
  end
84
+
85
+ def announce(message)
86
+ text = "#{module_name}: #{message}"
87
+ length = [0, 75 - text.length].max
88
+ "== #{text} #{'=' * length}\n"
89
+ end
65
90
  end
66
91
  end
@@ -2,10 +2,11 @@ tasks = Rake.application.instance_variable_get '@tasks'
2
2
  original_db_dump = tasks.delete 'db:_dump'
3
3
 
4
4
  namespace :validation do
5
- desc 'Generate validations from database schema'
5
+ desc 'Generate validations from database schema (options: DRY_RUN=false)'
6
6
  task generate: :environment do
7
7
  require 'pretty_validation/renderer'
8
- PrettyValidation::Renderer.generate
8
+ dry_run = %w(true 1 on).include? ENV['DRY_RUN']
9
+ PrettyValidation::Renderer.generate dry_run: dry_run
9
10
  end
10
11
  end
11
12
 
@@ -1,3 +1,3 @@
1
1
  module PrettyValidation
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'rspec'
25
25
  spec.add_development_dependency 'sqlite3'
26
26
  spec.add_development_dependency 'rubocop'
27
+ spec.add_development_dependency 'generator_spec'
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pretty_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sinsoku
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-22 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: generator_spec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: PrettyValidation generate validation modules from database schema
98
112
  email:
99
113
  - sinsoku.listy@gmail.com
@@ -105,7 +119,9 @@ files:
105
119
  - ".rspec"
106
120
  - ".rubocop.yml"
107
121
  - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
108
123
  - Gemfile
124
+ - LICENSE.txt
109
125
  - README.md
110
126
  - Rakefile
111
127
  - bin/console
@@ -113,7 +129,10 @@ files:
113
129
  - gemfiles/rails_40.gemfile
114
130
  - gemfiles/rails_41.gemfile
115
131
  - gemfiles/rails_42.gemfile
132
+ - lib/generators/validation/USAGE
133
+ - lib/generators/validation/validation_generator.rb
116
134
  - lib/pretty_validation.rb
135
+ - lib/pretty_validation/config.rb
117
136
  - lib/pretty_validation/monkey/new_hash_syntax.rb
118
137
  - lib/pretty_validation/railtie.rb
119
138
  - lib/pretty_validation/renderer.rb