validator_generator 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in validator_generator.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,13 @@
1
+ ValidatorGenerator
2
+ ==================
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) 2011 [name of plugin creator], released under the MIT license
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # ValidatorGenerator
2
+
3
+ Rails3でカスタムvalidatorのスケルトンファイルを生成するプラグイン
4
+
5
+ ## Requirements
6
+
7
+ * Rails >= 3.0.0
8
+
9
+ ## installation
10
+
11
+ In your Gemfile, add this line
12
+
13
+ gem 'validator_generator'
14
+
15
+ Then run bundle
16
+
17
+ $ bundle
18
+
19
+ ## Features
20
+
21
+ * setup
22
+
23
+ autoload_pathsにvalidatorを配置するパスを設定、もしくは追加する
24
+
25
+ $ rails g validator:setup
26
+
27
+ autoload_pathsにまだ何も設定されていない場合
28
+
29
+ module MyApp
30
+ class Application < Rails::Application
31
+
32
+ # config.autoload_paths += %W(#{config.root}/extras)
33
+ config.autoload_paths += %W(#{config.root}/app/validators)
34
+
35
+ autoload_pathsに設定されている場合は、最後に追加する
36
+
37
+ module MyApp
38
+ class Application < Rails::Application
39
+
40
+ config.autoload_paths += %W(#{config.root}/extras #{config.root}/app/validators)
41
+
42
+ * generates validator
43
+
44
+ カスタムvalidatorクラスのスケルトンファイルを作成する
45
+
46
+ $ rails g validator Email
47
+ create app/validators/email_validator.rb
48
+
49
+ $ cat app/validators/email_validator.rb
50
+ class EmailValidator < ActiveModel::EachValidator
51
+ def validate_each(record, attribute, value)
52
+ end
53
+ end
54
+
55
+
56
+ Copyright (c) 2011 Kosuke Matsuda, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate validator Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate validator Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,33 @@
1
+ module Validator
2
+ class SetupGenerator < ::Rails::Generators::Base
3
+ COMMENTED_AUTOLOAD_PATH_REGEXP = /\n *#+ *config\.autoload_paths.*/
4
+ UNCOMMENTED_AUTOLOAD_PATH_REGEXP = /\n *[^#]*config\.autoload_paths \+= %W\([^)]*/
5
+
6
+ desc "This generator add validators' path to 'config.autoload_paths.'"
7
+ def main
8
+ generate_configuration
9
+ end
10
+
11
+ private
12
+ def generate_configuration
13
+ return if Rails::Application.config.autoload_paths.any?{ |load_path| load_path =~ /app\/validators$/ }
14
+ log 'updating application.rb...'
15
+ add_validators_path File.read(Rails.root.join('config/application.rb'))
16
+ end
17
+
18
+ def add_validators_path(config_contents)
19
+ validators_path = '#{config.root}/app/validators'
20
+ new_line = "\n config.autoload_paths += %W(#{validators_path})"
21
+
22
+ if config_contents =~ COMMENTED_AUTOLOAD_PATH_REGEXP
23
+ log %q|enable config.autoload_paths and add validators's path|
24
+ insert_into_file 'config/application.rb', new_line, :after => COMMENTED_AUTOLOAD_PATH_REGEXP
25
+ elsif config_contents =~ UNCOMMENTED_AUTOLOAD_PATH_REGEXP
26
+ log %q|add validators's path|
27
+ gsub_file 'config/application.rb', UNCOMMENTED_AUTOLOAD_PATH_REGEXP do |match|
28
+ match << " #{validators_path}"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ class <%= class_name %>Validator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ end
4
+ end
@@ -0,0 +1,12 @@
1
+ class ValidatorGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ check_class_collision :suffix => "Validator"
5
+ # class_option :validator_type, :type => :string, :aliases => '-t',
6
+ # :desc => "Validator types. Available options are 'each', 'basic' and 'block'. Default: each"
7
+
8
+ desc "This generator generate a skeleton file for custom to app/validators directory."
9
+ def create_validator_files
10
+ template 'validator.rb', File.join('app/validators', class_path, "#{file_name}_validator.rb")
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module ValidatorGenerator
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ module ValidatorGenerator
2
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class ValidatorGeneratorTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "validator_generator/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "validator_generator"
7
+ s.version = ValidatorGenerator::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Kosuke Matsuda"]
10
+ s.email = ["hi@matsuda.me"]
11
+ s.homepage = "https://github.com/matsuda/validator_generator"
12
+ s.summary = %q{Rails 3 generator plugin that generates validator's skeleton files.}
13
+ s.description = %q{Rails 3 generator plugin that generates validator's skeleton files.}
14
+
15
+ s.rubyforge_project = "validator_generator"
16
+ s.required_rubygems_version = ">= 1.3.6"
17
+
18
+ s.add_dependency "railties", ">= 3.0.0"
19
+ s.add_development_dependency "bundler", ">= 1.0.0"
20
+ s.add_development_dependency "rails", ">= 3.0.0"
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validator_generator
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Kosuke Matsuda
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-28 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: railties
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
32
+ version: 3.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 0
47
+ version: 1.0.0
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rails
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 3
60
+ - 0
61
+ - 0
62
+ version: 3.0.0
63
+ type: :development
64
+ version_requirements: *id003
65
+ description: Rails 3 generator plugin that generates validator's skeleton files.
66
+ email:
67
+ - hi@matsuda.me
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ extra_rdoc_files: []
73
+
74
+ files:
75
+ - .gitignore
76
+ - Gemfile
77
+ - MIT-LICENSE
78
+ - README
79
+ - README.md
80
+ - Rakefile
81
+ - lib/generators/validator/USAGE
82
+ - lib/generators/validator/setup/USAGE
83
+ - lib/generators/validator/setup/setup_generator.rb
84
+ - lib/generators/validator/templates/validator.rb
85
+ - lib/generators/validator/validator_generator.rb
86
+ - lib/validator_generator.rb
87
+ - lib/validator_generator/version.rb
88
+ - test/test_helper.rb
89
+ - test/validator_generator_test.rb
90
+ - validator_generator.gemspec
91
+ has_rdoc: true
92
+ homepage: https://github.com/matsuda/validator_generator
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 1
115
+ - 3
116
+ - 6
117
+ version: 1.3.6
118
+ requirements: []
119
+
120
+ rubyforge_project: validator_generator
121
+ rubygems_version: 1.3.7
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Rails 3 generator plugin that generates validator's skeleton files.
125
+ test_files:
126
+ - test/test_helper.rb
127
+ - test/validator_generator_test.rb