validator_generator 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +1 -1
- data/README.md +2 -21
- data/lib/generators/validator/USAGE +4 -2
- data/lib/generators/validator/validator_generator.rb +4 -1
- data/lib/validator_generator/version.rb +1 -1
- metadata +4 -28
- data/lib/generators/validator/setup/USAGE +0 -8
- data/lib/generators/validator/setup/setup_generator.rb +0 -33
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -18,33 +18,14 @@ Then run bundle
|
|
18
18
|
|
19
19
|
## Features
|
20
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
21
|
* generates validator
|
43
22
|
|
44
23
|
カスタムvalidatorクラスのスケルトンファイルを作成する
|
45
24
|
|
46
25
|
$ rails g validator Email
|
47
26
|
create app/validators/email_validator.rb
|
27
|
+
invoke test_unit
|
28
|
+
create test/unit/email_validator_test.rb
|
48
29
|
|
49
30
|
$ cat app/validators/email_validator.rb
|
50
31
|
class EmailValidator < ActiveModel::EachValidator
|
@@ -1,8 +1,10 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
This generator generate a skeleton file for custom to app/validators directory.
|
3
3
|
|
4
4
|
Example:
|
5
5
|
rails generate validator Thing
|
6
6
|
|
7
7
|
This will create:
|
8
|
-
|
8
|
+
app/validators/thing_validator.rb
|
9
|
+
This also create test file:
|
10
|
+
test/unit/thing_test.rb
|
@@ -5,8 +5,11 @@ class ValidatorGenerator < Rails::Generators::NamedBase
|
|
5
5
|
# class_option :validator_type, :type => :string, :aliases => '-t',
|
6
6
|
# :desc => "Validator types. Available options are 'each', 'basic' and 'block'. Default: each"
|
7
7
|
|
8
|
-
desc "This generator generate a skeleton file for custom to app/validators directory."
|
9
8
|
def create_validator_files
|
10
9
|
template 'validator.rb', File.join('app/validators', class_path, "#{file_name}_validator.rb")
|
11
10
|
end
|
11
|
+
|
12
|
+
hook_for :test_framework, :as => :model do |instance, test_framework|
|
13
|
+
instance.invoke test_framework, ["#{instance.name}Validator"], :fixture => false
|
14
|
+
end
|
12
15
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validator_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: 0.0.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Kosuke Matsuda
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-04-22 00:00:00 +09:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,10 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ">="
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 3
|
30
|
-
- 0
|
31
|
-
- 0
|
32
24
|
version: 3.0.0
|
33
25
|
type: :runtime
|
34
26
|
version_requirements: *id001
|
@@ -40,10 +32,6 @@ dependencies:
|
|
40
32
|
requirements:
|
41
33
|
- - ">="
|
42
34
|
- !ruby/object:Gem::Version
|
43
|
-
segments:
|
44
|
-
- 1
|
45
|
-
- 0
|
46
|
-
- 0
|
47
35
|
version: 1.0.0
|
48
36
|
type: :development
|
49
37
|
version_requirements: *id002
|
@@ -55,10 +43,6 @@ dependencies:
|
|
55
43
|
requirements:
|
56
44
|
- - ">="
|
57
45
|
- !ruby/object:Gem::Version
|
58
|
-
segments:
|
59
|
-
- 3
|
60
|
-
- 0
|
61
|
-
- 0
|
62
46
|
version: 3.0.0
|
63
47
|
type: :development
|
64
48
|
version_requirements: *id003
|
@@ -79,8 +63,6 @@ files:
|
|
79
63
|
- README.md
|
80
64
|
- Rakefile
|
81
65
|
- lib/generators/validator/USAGE
|
82
|
-
- lib/generators/validator/setup/USAGE
|
83
|
-
- lib/generators/validator/setup/setup_generator.rb
|
84
66
|
- lib/generators/validator/templates/validator.rb
|
85
67
|
- lib/generators/validator/validator_generator.rb
|
86
68
|
- lib/validator_generator.rb
|
@@ -102,23 +84,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
84
|
requirements:
|
103
85
|
- - ">="
|
104
86
|
- !ruby/object:Gem::Version
|
105
|
-
segments:
|
106
|
-
- 0
|
107
87
|
version: "0"
|
108
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
89
|
none: false
|
110
90
|
requirements:
|
111
91
|
- - ">="
|
112
92
|
- !ruby/object:Gem::Version
|
113
|
-
segments:
|
114
|
-
- 1
|
115
|
-
- 3
|
116
|
-
- 6
|
117
93
|
version: 1.3.6
|
118
94
|
requirements: []
|
119
95
|
|
120
96
|
rubyforge_project: validator_generator
|
121
|
-
rubygems_version: 1.
|
97
|
+
rubygems_version: 1.5.0
|
122
98
|
signing_key:
|
123
99
|
specification_version: 3
|
124
100
|
summary: Rails 3 generator plugin that generates validator's skeleton files.
|
@@ -1,33 +0,0 @@
|
|
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
|