act_a 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +2 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +8 -0
- data/.travis.yml +23 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +147 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +4 -0
- data/act_a.gemspec +30 -0
- data/lib/act_a.rb +134 -0
- data/lib/act_a/version.rb +3 -0
- data/lib/tasks/acting_validator_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/model.rb +20 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +37 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.def.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/db/migrate/20150707011840_create_models.rb +16 -0
- data/spec/dummy/db/schema.rb +28 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/boolean_validator.rb +5 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/libs/acting_validator_spec.rb +69 -0
- data/spec/rails_helper.rb +61 -0
- data/spec/spec_helper.rb +95 -0
- metadata +227 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 686317201ceafae45f7090b8323d256cff79d9c8
|
4
|
+
data.tar.gz: cb2e69ebeca2360b62bd5c103293ceb36b822112
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5baeb03193d28db1119e961d83ed6023b6bc30be0bd15876430afb8987df981c1e4fa4a21247ddc4dc6535e900d816ef2e762f18828e9c595c7cc5c5ca24855
|
7
|
+
data.tar.gz: 4423e6c4b291504cf1400a4c8a3e4a23fa2847d9a21f80b24677d7e01752bba9226900e2213a66c2d4b6d39709704054c3d198bbb6f2a8109abe3d2f27fa8bf0
|
data/.codeclimate.yml
ADDED
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.5
|
4
|
+
- 2.2.2
|
5
|
+
env:
|
6
|
+
- DB=sqlite
|
7
|
+
before_install:
|
8
|
+
- gem install bundler -v 1.10.3
|
9
|
+
install:
|
10
|
+
- bundle install
|
11
|
+
cache:
|
12
|
+
directories:
|
13
|
+
- vendor/bundle
|
14
|
+
before_script:
|
15
|
+
- cp spec/dummy/config/database.def.yml spec/dummy/config/database.yml
|
16
|
+
script:
|
17
|
+
- cd spec/dummy
|
18
|
+
- bundle install
|
19
|
+
- bundle exec rake db:create RAILS_ENV=test
|
20
|
+
- bundle exec rake db:migrate RAILS_ENV=test
|
21
|
+
- bundle exec rake db:test:prepare
|
22
|
+
- cd ../../
|
23
|
+
- bundle exec rake
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in act_a.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use debugger
|
14
|
+
# gem 'debugger'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
act_a (0.0.1)
|
5
|
+
rails (~> 4.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (4.0.13)
|
11
|
+
actionpack (= 4.0.13)
|
12
|
+
mail (~> 2.5, >= 2.5.4)
|
13
|
+
actionpack (4.0.13)
|
14
|
+
activesupport (= 4.0.13)
|
15
|
+
builder (~> 3.1.0)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
rack (~> 1.5.2)
|
18
|
+
rack-test (~> 0.6.2)
|
19
|
+
activemodel (4.0.13)
|
20
|
+
activesupport (= 4.0.13)
|
21
|
+
builder (~> 3.1.0)
|
22
|
+
activerecord (4.0.13)
|
23
|
+
activemodel (= 4.0.13)
|
24
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
25
|
+
activesupport (= 4.0.13)
|
26
|
+
arel (~> 4.0.0)
|
27
|
+
activerecord-deprecated_finders (1.0.4)
|
28
|
+
activesupport (4.0.13)
|
29
|
+
i18n (~> 0.6, >= 0.6.9)
|
30
|
+
minitest (~> 4.2)
|
31
|
+
multi_json (~> 1.3)
|
32
|
+
thread_safe (~> 0.1)
|
33
|
+
tzinfo (~> 0.3.37)
|
34
|
+
arel (4.0.2)
|
35
|
+
builder (3.1.4)
|
36
|
+
coveralls (0.8.2)
|
37
|
+
json (~> 1.8)
|
38
|
+
rest-client (>= 1.6.8, < 2)
|
39
|
+
simplecov (~> 0.10.0)
|
40
|
+
term-ansicolor (~> 1.3)
|
41
|
+
thor (~> 0.19.1)
|
42
|
+
diff-lcs (1.2.5)
|
43
|
+
docile (1.1.5)
|
44
|
+
domain_name (0.5.24)
|
45
|
+
unf (>= 0.0.5, < 1.0.0)
|
46
|
+
erubis (2.7.0)
|
47
|
+
factory_girl (4.5.0)
|
48
|
+
activesupport (>= 3.0.0)
|
49
|
+
factory_girl_rails (4.5.0)
|
50
|
+
factory_girl (~> 4.5.0)
|
51
|
+
railties (>= 3.0.0)
|
52
|
+
http-cookie (1.0.2)
|
53
|
+
domain_name (~> 0.5)
|
54
|
+
i18n (0.7.0)
|
55
|
+
json (1.8.3)
|
56
|
+
mail (2.6.3)
|
57
|
+
mime-types (>= 1.16, < 3)
|
58
|
+
mime-types (2.6.1)
|
59
|
+
mini_portile (0.6.2)
|
60
|
+
minitest (4.7.5)
|
61
|
+
multi_json (1.11.2)
|
62
|
+
netrc (0.10.3)
|
63
|
+
nokogiri (1.6.6.2)
|
64
|
+
mini_portile (~> 0.6.0)
|
65
|
+
rack (1.5.5)
|
66
|
+
rack-test (0.6.3)
|
67
|
+
rack (>= 1.0)
|
68
|
+
rails (4.0.13)
|
69
|
+
actionmailer (= 4.0.13)
|
70
|
+
actionpack (= 4.0.13)
|
71
|
+
activerecord (= 4.0.13)
|
72
|
+
activesupport (= 4.0.13)
|
73
|
+
bundler (>= 1.3.0, < 2.0)
|
74
|
+
railties (= 4.0.13)
|
75
|
+
sprockets-rails (~> 2.0)
|
76
|
+
railties (4.0.13)
|
77
|
+
actionpack (= 4.0.13)
|
78
|
+
activesupport (= 4.0.13)
|
79
|
+
rake (>= 0.8.7)
|
80
|
+
thor (>= 0.18.1, < 2.0)
|
81
|
+
rake (10.4.2)
|
82
|
+
rest-client (1.8.0)
|
83
|
+
http-cookie (>= 1.0.2, < 2.0)
|
84
|
+
mime-types (>= 1.16, < 3.0)
|
85
|
+
netrc (~> 0.7)
|
86
|
+
rspec (3.3.0)
|
87
|
+
rspec-core (~> 3.3.0)
|
88
|
+
rspec-expectations (~> 3.3.0)
|
89
|
+
rspec-mocks (~> 3.3.0)
|
90
|
+
rspec-core (3.3.1)
|
91
|
+
rspec-support (~> 3.3.0)
|
92
|
+
rspec-expectations (3.3.0)
|
93
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
94
|
+
rspec-support (~> 3.3.0)
|
95
|
+
rspec-html-matchers (0.7.0)
|
96
|
+
nokogiri (~> 1)
|
97
|
+
rspec (~> 3)
|
98
|
+
rspec-mocks (3.3.1)
|
99
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
100
|
+
rspec-support (~> 3.3.0)
|
101
|
+
rspec-rails (3.3.2)
|
102
|
+
actionpack (>= 3.0, < 4.3)
|
103
|
+
activesupport (>= 3.0, < 4.3)
|
104
|
+
railties (>= 3.0, < 4.3)
|
105
|
+
rspec-core (~> 3.3.0)
|
106
|
+
rspec-expectations (~> 3.3.0)
|
107
|
+
rspec-mocks (~> 3.3.0)
|
108
|
+
rspec-support (~> 3.3.0)
|
109
|
+
rspec-support (3.3.0)
|
110
|
+
simplecov (0.10.0)
|
111
|
+
docile (~> 1.1.0)
|
112
|
+
json (~> 1.8)
|
113
|
+
simplecov-html (~> 0.10.0)
|
114
|
+
simplecov-html (0.10.0)
|
115
|
+
sprockets (3.2.0)
|
116
|
+
rack (~> 1.0)
|
117
|
+
sprockets-rails (2.3.2)
|
118
|
+
actionpack (>= 3.0)
|
119
|
+
activesupport (>= 3.0)
|
120
|
+
sprockets (>= 2.8, < 4.0)
|
121
|
+
sqlite3 (1.3.10)
|
122
|
+
term-ansicolor (1.3.2)
|
123
|
+
tins (~> 1.0)
|
124
|
+
thor (0.19.1)
|
125
|
+
thread_safe (0.3.5)
|
126
|
+
tins (1.5.4)
|
127
|
+
tzinfo (0.3.44)
|
128
|
+
unf (0.1.4)
|
129
|
+
unf_ext
|
130
|
+
unf_ext (0.0.7.1)
|
131
|
+
|
132
|
+
PLATFORMS
|
133
|
+
ruby
|
134
|
+
|
135
|
+
DEPENDENCIES
|
136
|
+
act_a!
|
137
|
+
bundler (~> 1.10)
|
138
|
+
coveralls
|
139
|
+
factory_girl_rails
|
140
|
+
rake (~> 10.0)
|
141
|
+
rspec
|
142
|
+
rspec-html-matchers
|
143
|
+
rspec-rails
|
144
|
+
sqlite3
|
145
|
+
|
146
|
+
BUNDLED WITH
|
147
|
+
1.10.3
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 YOURNAME
|
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.rdoc
ADDED
data/Rakefile
ADDED
data/act_a.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "act_a/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "act_a"
|
9
|
+
spec.version = ActA::VERSION
|
10
|
+
spec.authors = ["mmmpa"]
|
11
|
+
spec.email = ["mmmpa.mmmpa@gmail.com"]
|
12
|
+
spec.homepage = "http://mmmpa.net"
|
13
|
+
spec.summary = "Validate values from outside."
|
14
|
+
spec.description = "Validate values from outside."
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split("\n")
|
17
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.add_dependency "rails", "~> 4.0.0"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "sqlite3"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "rspec-rails"
|
27
|
+
spec.add_development_dependency "rspec-html-matchers"
|
28
|
+
spec.add_development_dependency "factory_girl_rails"
|
29
|
+
spec.add_development_dependency "coveralls"
|
30
|
+
end
|
data/lib/act_a.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
module ActA
|
2
|
+
class << self
|
3
|
+
def call(*args)
|
4
|
+
new(*args)
|
5
|
+
end
|
6
|
+
|
7
|
+
def new(klass)
|
8
|
+
Base.new(klass)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
class Base
|
14
|
+
def initialize(klass)
|
15
|
+
self.klass = klass
|
16
|
+
end
|
17
|
+
|
18
|
+
def apply(key_and_values = {})
|
19
|
+
self.keys = key_and_values.keys
|
20
|
+
self.record = klass.new(key_and_values)
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def errors
|
25
|
+
record.errors
|
26
|
+
end
|
27
|
+
|
28
|
+
def messages
|
29
|
+
record.errors.try(:messages)
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid?
|
33
|
+
validate
|
34
|
+
errors.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
def valid_brutally?
|
38
|
+
validate_brutally
|
39
|
+
errors.empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
def validate
|
43
|
+
keys.each do |attribute_name|
|
44
|
+
validators(attribute_name).each do |validator|
|
45
|
+
duplicate_validator(validator, attribute_name).validate(record)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
rescue
|
49
|
+
# do nothing
|
50
|
+
ensure
|
51
|
+
reject_not_target
|
52
|
+
return self
|
53
|
+
end
|
54
|
+
|
55
|
+
def validate!
|
56
|
+
if valid?
|
57
|
+
self
|
58
|
+
else
|
59
|
+
raise ActiveRecord::RecordInvalid, record
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def validate_brutally
|
64
|
+
record.valid?
|
65
|
+
rescue
|
66
|
+
# do nothing
|
67
|
+
ensure
|
68
|
+
reject_not_target
|
69
|
+
return self
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate_brutally!
|
73
|
+
if valid_brutally?
|
74
|
+
self
|
75
|
+
else
|
76
|
+
raise ActiveRecord::RecordInvalid, record
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
attr_accessor :record, :keys, :klass
|
82
|
+
|
83
|
+
def validators(attribute_name)
|
84
|
+
klass._validators[attribute_name.to_sym]
|
85
|
+
end
|
86
|
+
|
87
|
+
def duplicate_validator(validator, attribute_name)
|
88
|
+
validator.class.new(validator.options.merge(attributes: attribute_name))
|
89
|
+
end
|
90
|
+
|
91
|
+
def reject_not_target
|
92
|
+
return unless record.errors
|
93
|
+
record.errors.messages.reject! { |attribute| !keys.include?(attribute) }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
=begin
|
99
|
+
[
|
100
|
+
:_validators,
|
101
|
+
:_validate_callbacks,
|
102
|
+
:_validate_callbacks?,
|
103
|
+
:_validate_callbacks=,
|
104
|
+
:_validators?,
|
105
|
+
:_validators=,
|
106
|
+
:_validation_callbacks,
|
107
|
+
:_validation_callbacks?,
|
108
|
+
:_validation_callbacks=,
|
109
|
+
:before_validation,
|
110
|
+
:after_validation,
|
111
|
+
:validates_associated,
|
112
|
+
:validates_uniqueness_of,
|
113
|
+
:validates_presence_of,
|
114
|
+
:validates_absence_of,
|
115
|
+
:validates_format_of,
|
116
|
+
:validates_inclusion_of,
|
117
|
+
:validates_length_of,
|
118
|
+
:validates_size_of,
|
119
|
+
:validates_confirmation_of,
|
120
|
+
:validates_exclusion_of,
|
121
|
+
:validates_numericality_of,
|
122
|
+
:validates_acceptance_of,
|
123
|
+
:validates_each,
|
124
|
+
:validate,
|
125
|
+
:validators,
|
126
|
+
:clear_validators!,
|
127
|
+
:validators_on,
|
128
|
+
:validates_with,
|
129
|
+
:validates,
|
130
|
+
:validates!,
|
131
|
+
:_validates_default_keys,
|
132
|
+
:_parse_validates_options
|
133
|
+
]
|
134
|
+
=end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|