vex 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1,2 +1,2 @@
1
- 0.2.8
1
+ 0.2.9
2
2
 
@@ -0,0 +1,109 @@
1
+ module CustomValidations
2
+ def validates_url(*args)
3
+ opts = {
4
+ :scheme => %w(http https)
5
+ }.update(args.extract_options!)
6
+
7
+ validates_each(args, opts) do |r, attr, value|
8
+ next unless msg = CustomValidations.invalid_url?(value, opts)
9
+ r.errors.add(attr, msg)
10
+
11
+ false
12
+ end
13
+ end
14
+
15
+ def self.invalid_url?(url, opts = {})
16
+ return if url.respond_to?(:blank?) && url.blank? && opts[:allow_nil]
17
+
18
+ uri = url.is_a?(URI) ? url : URI.parse(url)
19
+
20
+ if !uri.scheme
21
+ return "Missing URI protocol"
22
+ end
23
+
24
+ schemes = [ opts[:scheme] || %w(http https) ].flatten.compact
25
+
26
+ return if schemes.include?(:any) || schemes.empty?
27
+
28
+ if !schemes.include?(uri.scheme)
29
+ return "Unsupported protocol #{uri.scheme.inspect}, must be one of #{schemes.join(", ")}"
30
+ end
31
+ rescue URI::InvalidURIError
32
+ return $!.to_s
33
+ end
34
+
35
+ #
36
+ # custom pared.
37
+ #
38
+
39
+ def self.invalid_parsed?(value, opts, &block)
40
+ return if value.nil? && opts[:allow_nil]
41
+
42
+ begin
43
+ value = yield(value)
44
+ rescue
45
+ return $!.to_s
46
+ end
47
+
48
+ return "must be in #{opts[:in].inspect}" if opts[:in] && !opts[:in].include?(value)
49
+ return "Must be greater than #{opts[:gt].inspect}" if opts[:gt] && !(value > opts[:gt])
50
+ return "Must be >= #{opts[:ge].inspect}" if opts[:ge] && !(value >= opts[:ge])
51
+ return "Must be less than #{opts[:gt].inspect}" if opts[:lt] && !(value < opts[:lt])
52
+ return "Must be <= #{opts[:ge].inspect}" if opts[:le] && !(value <= opts[:le])
53
+ end
54
+
55
+ def validates_parsed(*args, &block)
56
+ opts = args.extract_options!
57
+
58
+ validates_each(args, opts) do |r, attr, value|
59
+ msg = CustomValidations.invalid_parsed?(value, opts, &block)
60
+ r.errors.add attr, msg if msg
61
+ !msg
62
+ end
63
+ end
64
+
65
+ def validates_texta(*args)
66
+ validates_parsed(*args) { |value|
67
+ begin
68
+ value.texta
69
+ rescue Texta::Error
70
+ raise "I do not understand: '#{$!.to_s}'"
71
+ end
72
+ }
73
+ end
74
+
75
+ def validates_integer(*args)
76
+ validates_parsed(*args) { |value| Integer(value) }
77
+ end
78
+
79
+ def validates_float(*args)
80
+ validates_parsed(*args) { |value| Float(value) }
81
+ end
82
+ end
83
+
84
+ ActiveRecord::Base.extend CustomValidations
85
+
86
+ module CustomValidations::Etest
87
+ class CVModel < ActiveRecord::Base
88
+ validates_url :url, :scheme => :any
89
+ end
90
+
91
+ def test_lite_table
92
+ CVModel.lite_table do
93
+ string :url
94
+ end
95
+
96
+ cv = CVModel.new :url => "http://xx.yy"
97
+ assert cv.valid?
98
+
99
+ cv = CVModel.new :url => "data://xx.yy"
100
+ assert cv.valid?
101
+
102
+ cv = CVModel.new :url => "file:xx.yy"
103
+ assert cv.valid?
104
+
105
+ cv = CVModel.new :url => "illegal"
106
+ assert !cv.valid?
107
+ end
108
+ end
109
+
@@ -1 +1 @@
1
- 3711.106710
1
+ 6761.106710
@@ -17,6 +17,10 @@ module StringExt
17
17
  !!(self =~ /^[a-z][a-z]+:/)
18
18
  end
19
19
 
20
+ def to_uri
21
+ URI.parse(self)
22
+ end
23
+
20
24
  def unhtml
21
25
  return self if blank?
22
26
  s = Sanitize.clean(self)
data/lib/vex/boot.rb CHANGED
@@ -2,7 +2,7 @@ module Vex
2
2
  ROOT=File.expand_path "#{File.dirname(__FILE__)}/../vex"
3
3
 
4
4
  def self.version
5
- @version ||= File.read("#{ROOT}/../../VERSION")
5
+ @version ||= File.read("#{ROOT}/../../VERSION").gsub(/\s+/, "")
6
6
  end
7
7
 
8
8
  #
data/vex.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{vex}
5
- s.version = "0.2.8"
5
+ s.version = "0.2.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["pboy"]
9
9
  s.date = %q{2010-03-17}
10
10
  s.description = %q{Vex: some ruby extensions}
11
11
  s.email = %q{eno-pboy@open-lab.org}
12
- s.extra_rdoc_files = ["CHANGELOG", "lib/nokogiri/nokogiri_ext.rb", "lib/vex.rb", "lib/vex/action_controller.rb", "lib/vex/action_controller/error.rb", "lib/vex/action_controller/verify_action.rb", "lib/vex/action_controller/verify_hostname.rb", "lib/vex/action_controller/whitelisted_actions.rb", "lib/vex/active_record.rb", "lib/vex/active_record/__init__.rb", "lib/vex/active_record/advisory_lock.rb", "lib/vex/active_record/advisory_lock/mysql_adapter.rb", "lib/vex/active_record/advisory_lock/sqlite_adapter.rb", "lib/vex/active_record/belongs_to_many.rb", "lib/vex/active_record/find_by_extension.rb", "lib/vex/active_record/gem.rb", "lib/vex/active_record/lite_table.rb", "lib/vex/active_record/lite_view.rb", "lib/vex/active_record/mass_load.rb", "lib/vex/active_record/mysql_backup.rb", "lib/vex/active_record/plugins/default_value_for/LICENSE.TXT", "lib/vex/active_record/plugins/default_value_for/README.rdoc", "lib/vex/active_record/plugins/default_value_for/Rakefile", "lib/vex/active_record/plugins/default_value_for/init.rb", "lib/vex/active_record/plugins/default_value_for/test.rb", "lib/vex/active_record/plugins/default_value_for/test.sqlite3", "lib/vex/active_record/random_id.rb", "lib/vex/active_record/resolver.rb", "lib/vex/active_record/serialize_hash.rb", "lib/vex/active_record/to_html.rb", "lib/vex/active_record/validate.rb", "lib/vex/active_record/validation_error_ext.rb", "lib/vex/base.rb", "lib/vex/base/app.rb", "lib/vex/base/array/at_random.rb", "lib/vex/base/array/avg.rb", "lib/vex/base/array/cross.rb", "lib/vex/base/array/each_batch.rb", "lib/vex/base/array/parallel_map.rb", "lib/vex/base/deprecation.rb", "lib/vex/base/enumerable/deep.rb", "lib/vex/base/enumerable/enumerable_ext.rb", "lib/vex/base/enumerable/progress.rb", "lib/vex/base/filesystem/fast_copy.rb", "lib/vex/base/filesystem/grep.rb", "lib/vex/base/filesystem/lock.rb", "lib/vex/base/filesystem/lock.rb.test.lck", "lib/vex/base/filesystem/lock.rb.test.pid", "lib/vex/base/filesystem/make_dirs.rb", "lib/vex/base/filesystem/parse_filename.rb", "lib/vex/base/filesystem/tmp_file.rb", "lib/vex/base/filesystem/write.rb", "lib/vex/base/hash/compact.rb", "lib/vex/base/hash/cross.rb", "lib/vex/base/hash/easy_access.rb", "lib/vex/base/hash/ensure_keys.rb", "lib/vex/base/hash/extract.rb", "lib/vex/base/hash/extras.rb", "lib/vex/base/hash/inspect.rb", "lib/vex/base/hash/simple_access_methods.rb", "lib/vex/base/invalid_argument/invalid_argument.rb", "lib/vex/base/local_conf.rb", "lib/vex/base/net/http_ext.rb", "lib/vex/base/net/socket_ext.rb", "lib/vex/base/object/insp.rb", "lib/vex/base/object/multiple_attributes.rb", "lib/vex/base/object/singleton_methods.rb", "lib/vex/base/object/with_benchmark.rb", "lib/vex/base/range_array.rb", "lib/vex/base/range_ext.rb", "lib/vex/base/safe_token.rb", "lib/vex/base/string/string_ext.rb", "lib/vex/base/system.rb", "lib/vex/base/thread/deferred.rb", "lib/vex/base/thread/sleep.rb", "lib/vex/base/time/date_ext.rb", "lib/vex/boot.rb", "lib/vex/boot/array.rb", "lib/vex/boot/blank.rb", "lib/vex/boot/string.rb", "tasks/echoe.rake", "tasks/validate_db.rake"]
13
- s.files = ["CHANGELOG", "Manifest", "NOTICE.txt", "Rakefile", "VERSION", "config/README", "config/dependencies.rb", "config/gem.yml", "init.rb", "lib/nokogiri/nokogiri_ext.rb", "lib/vex.rb", "lib/vex/action_controller.rb", "lib/vex/action_controller/error.rb", "lib/vex/action_controller/verify_action.rb", "lib/vex/action_controller/verify_hostname.rb", "lib/vex/action_controller/whitelisted_actions.rb", "lib/vex/active_record.rb", "lib/vex/active_record/__init__.rb", "lib/vex/active_record/advisory_lock.rb", "lib/vex/active_record/advisory_lock/mysql_adapter.rb", "lib/vex/active_record/advisory_lock/sqlite_adapter.rb", "lib/vex/active_record/belongs_to_many.rb", "lib/vex/active_record/find_by_extension.rb", "lib/vex/active_record/gem.rb", "lib/vex/active_record/lite_table.rb", "lib/vex/active_record/lite_view.rb", "lib/vex/active_record/mass_load.rb", "lib/vex/active_record/mysql_backup.rb", "lib/vex/active_record/plugins/default_value_for/LICENSE.TXT", "lib/vex/active_record/plugins/default_value_for/README.rdoc", "lib/vex/active_record/plugins/default_value_for/Rakefile", "lib/vex/active_record/plugins/default_value_for/init.rb", "lib/vex/active_record/plugins/default_value_for/test.rb", "lib/vex/active_record/plugins/default_value_for/test.sqlite3", "lib/vex/active_record/random_id.rb", "lib/vex/active_record/resolver.rb", "lib/vex/active_record/serialize_hash.rb", "lib/vex/active_record/to_html.rb", "lib/vex/active_record/validate.rb", "lib/vex/active_record/validation_error_ext.rb", "lib/vex/base.rb", "lib/vex/base/app.rb", "lib/vex/base/array/at_random.rb", "lib/vex/base/array/avg.rb", "lib/vex/base/array/cross.rb", "lib/vex/base/array/each_batch.rb", "lib/vex/base/array/parallel_map.rb", "lib/vex/base/deprecation.rb", "lib/vex/base/enumerable/deep.rb", "lib/vex/base/enumerable/enumerable_ext.rb", "lib/vex/base/enumerable/progress.rb", "lib/vex/base/filesystem/fast_copy.rb", "lib/vex/base/filesystem/grep.rb", "lib/vex/base/filesystem/lock.rb", "lib/vex/base/filesystem/lock.rb.test.lck", "lib/vex/base/filesystem/lock.rb.test.pid", "lib/vex/base/filesystem/make_dirs.rb", "lib/vex/base/filesystem/parse_filename.rb", "lib/vex/base/filesystem/tmp_file.rb", "lib/vex/base/filesystem/write.rb", "lib/vex/base/hash/compact.rb", "lib/vex/base/hash/cross.rb", "lib/vex/base/hash/easy_access.rb", "lib/vex/base/hash/ensure_keys.rb", "lib/vex/base/hash/extract.rb", "lib/vex/base/hash/extras.rb", "lib/vex/base/hash/inspect.rb", "lib/vex/base/hash/simple_access_methods.rb", "lib/vex/base/invalid_argument/invalid_argument.rb", "lib/vex/base/local_conf.rb", "lib/vex/base/net/http_ext.rb", "lib/vex/base/net/socket_ext.rb", "lib/vex/base/object/insp.rb", "lib/vex/base/object/multiple_attributes.rb", "lib/vex/base/object/singleton_methods.rb", "lib/vex/base/object/with_benchmark.rb", "lib/vex/base/range_array.rb", "lib/vex/base/range_ext.rb", "lib/vex/base/safe_token.rb", "lib/vex/base/string/string_ext.rb", "lib/vex/base/system.rb", "lib/vex/base/thread/deferred.rb", "lib/vex/base/thread/sleep.rb", "lib/vex/base/time/date_ext.rb", "lib/vex/boot.rb", "lib/vex/boot/array.rb", "lib/vex/boot/blank.rb", "lib/vex/boot/string.rb", "migration/create_request_log.rb", "script/console", "script/rebuild", "tasks/echoe.rake", "tasks/validate_db.rake", "test/ar.rb", "test/auto.rb", "test/base-tests/local_conf.rb", "test/base.rb", "test/boot.rb", "test/config/local.defaults.yml", "test/config/local.yml", "test/test_helper.rb", "vex.gemspec"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/nokogiri/nokogiri_ext.rb", "lib/vex.rb", "lib/vex/action_controller.rb", "lib/vex/action_controller/error.rb", "lib/vex/action_controller/verify_action.rb", "lib/vex/action_controller/verify_hostname.rb", "lib/vex/action_controller/whitelisted_actions.rb", "lib/vex/active_record.rb", "lib/vex/active_record/__init__.rb", "lib/vex/active_record/advisory_lock.rb", "lib/vex/active_record/advisory_lock/mysql_adapter.rb", "lib/vex/active_record/advisory_lock/sqlite_adapter.rb", "lib/vex/active_record/belongs_to_many.rb", "lib/vex/active_record/custom_validations.rb", "lib/vex/active_record/find_by_extension.rb", "lib/vex/active_record/gem.rb", "lib/vex/active_record/lite_table.rb", "lib/vex/active_record/lite_view.rb", "lib/vex/active_record/mass_load.rb", "lib/vex/active_record/mysql_backup.rb", "lib/vex/active_record/plugins/default_value_for/LICENSE.TXT", "lib/vex/active_record/plugins/default_value_for/README.rdoc", "lib/vex/active_record/plugins/default_value_for/Rakefile", "lib/vex/active_record/plugins/default_value_for/init.rb", "lib/vex/active_record/plugins/default_value_for/test.rb", "lib/vex/active_record/plugins/default_value_for/test.sqlite3", "lib/vex/active_record/random_id.rb", "lib/vex/active_record/resolver.rb", "lib/vex/active_record/serialize_hash.rb", "lib/vex/active_record/to_html.rb", "lib/vex/active_record/validate.rb", "lib/vex/active_record/validation_error_ext.rb", "lib/vex/base.rb", "lib/vex/base/app.rb", "lib/vex/base/array/at_random.rb", "lib/vex/base/array/avg.rb", "lib/vex/base/array/cross.rb", "lib/vex/base/array/each_batch.rb", "lib/vex/base/array/parallel_map.rb", "lib/vex/base/deprecation.rb", "lib/vex/base/enumerable/deep.rb", "lib/vex/base/enumerable/enumerable_ext.rb", "lib/vex/base/enumerable/progress.rb", "lib/vex/base/filesystem/fast_copy.rb", "lib/vex/base/filesystem/grep.rb", "lib/vex/base/filesystem/lock.rb", "lib/vex/base/filesystem/lock.rb.test.lck", "lib/vex/base/filesystem/lock.rb.test.pid", "lib/vex/base/filesystem/make_dirs.rb", "lib/vex/base/filesystem/parse_filename.rb", "lib/vex/base/filesystem/tmp_file.rb", "lib/vex/base/filesystem/write.rb", "lib/vex/base/hash/compact.rb", "lib/vex/base/hash/cross.rb", "lib/vex/base/hash/easy_access.rb", "lib/vex/base/hash/ensure_keys.rb", "lib/vex/base/hash/extract.rb", "lib/vex/base/hash/extras.rb", "lib/vex/base/hash/inspect.rb", "lib/vex/base/hash/simple_access_methods.rb", "lib/vex/base/invalid_argument/invalid_argument.rb", "lib/vex/base/local_conf.rb", "lib/vex/base/net/http_ext.rb", "lib/vex/base/net/socket_ext.rb", "lib/vex/base/object/insp.rb", "lib/vex/base/object/multiple_attributes.rb", "lib/vex/base/object/singleton_methods.rb", "lib/vex/base/object/with_benchmark.rb", "lib/vex/base/range_array.rb", "lib/vex/base/range_ext.rb", "lib/vex/base/safe_token.rb", "lib/vex/base/string/string_ext.rb", "lib/vex/base/system.rb", "lib/vex/base/thread/deferred.rb", "lib/vex/base/thread/sleep.rb", "lib/vex/base/time/date_ext.rb", "lib/vex/boot.rb", "lib/vex/boot/array.rb", "lib/vex/boot/blank.rb", "lib/vex/boot/string.rb", "tasks/echoe.rake", "tasks/validate_db.rake"]
13
+ s.files = ["CHANGELOG", "Manifest", "NOTICE.txt", "Rakefile", "VERSION", "config/README", "config/dependencies.rb", "config/gem.yml", "init.rb", "lib/nokogiri/nokogiri_ext.rb", "lib/vex.rb", "lib/vex/action_controller.rb", "lib/vex/action_controller/error.rb", "lib/vex/action_controller/verify_action.rb", "lib/vex/action_controller/verify_hostname.rb", "lib/vex/action_controller/whitelisted_actions.rb", "lib/vex/active_record.rb", "lib/vex/active_record/__init__.rb", "lib/vex/active_record/advisory_lock.rb", "lib/vex/active_record/advisory_lock/mysql_adapter.rb", "lib/vex/active_record/advisory_lock/sqlite_adapter.rb", "lib/vex/active_record/belongs_to_many.rb", "lib/vex/active_record/custom_validations.rb", "lib/vex/active_record/find_by_extension.rb", "lib/vex/active_record/gem.rb", "lib/vex/active_record/lite_table.rb", "lib/vex/active_record/lite_view.rb", "lib/vex/active_record/mass_load.rb", "lib/vex/active_record/mysql_backup.rb", "lib/vex/active_record/plugins/default_value_for/LICENSE.TXT", "lib/vex/active_record/plugins/default_value_for/README.rdoc", "lib/vex/active_record/plugins/default_value_for/Rakefile", "lib/vex/active_record/plugins/default_value_for/init.rb", "lib/vex/active_record/plugins/default_value_for/test.rb", "lib/vex/active_record/plugins/default_value_for/test.sqlite3", "lib/vex/active_record/random_id.rb", "lib/vex/active_record/resolver.rb", "lib/vex/active_record/serialize_hash.rb", "lib/vex/active_record/to_html.rb", "lib/vex/active_record/validate.rb", "lib/vex/active_record/validation_error_ext.rb", "lib/vex/base.rb", "lib/vex/base/app.rb", "lib/vex/base/array/at_random.rb", "lib/vex/base/array/avg.rb", "lib/vex/base/array/cross.rb", "lib/vex/base/array/each_batch.rb", "lib/vex/base/array/parallel_map.rb", "lib/vex/base/deprecation.rb", "lib/vex/base/enumerable/deep.rb", "lib/vex/base/enumerable/enumerable_ext.rb", "lib/vex/base/enumerable/progress.rb", "lib/vex/base/filesystem/fast_copy.rb", "lib/vex/base/filesystem/grep.rb", "lib/vex/base/filesystem/lock.rb", "lib/vex/base/filesystem/lock.rb.test.lck", "lib/vex/base/filesystem/lock.rb.test.pid", "lib/vex/base/filesystem/make_dirs.rb", "lib/vex/base/filesystem/parse_filename.rb", "lib/vex/base/filesystem/tmp_file.rb", "lib/vex/base/filesystem/write.rb", "lib/vex/base/hash/compact.rb", "lib/vex/base/hash/cross.rb", "lib/vex/base/hash/easy_access.rb", "lib/vex/base/hash/ensure_keys.rb", "lib/vex/base/hash/extract.rb", "lib/vex/base/hash/extras.rb", "lib/vex/base/hash/inspect.rb", "lib/vex/base/hash/simple_access_methods.rb", "lib/vex/base/invalid_argument/invalid_argument.rb", "lib/vex/base/local_conf.rb", "lib/vex/base/net/http_ext.rb", "lib/vex/base/net/socket_ext.rb", "lib/vex/base/object/insp.rb", "lib/vex/base/object/multiple_attributes.rb", "lib/vex/base/object/singleton_methods.rb", "lib/vex/base/object/with_benchmark.rb", "lib/vex/base/range_array.rb", "lib/vex/base/range_ext.rb", "lib/vex/base/safe_token.rb", "lib/vex/base/string/string_ext.rb", "lib/vex/base/system.rb", "lib/vex/base/thread/deferred.rb", "lib/vex/base/thread/sleep.rb", "lib/vex/base/time/date_ext.rb", "lib/vex/boot.rb", "lib/vex/boot/array.rb", "lib/vex/boot/blank.rb", "lib/vex/boot/string.rb", "migration/create_request_log.rb", "script/console", "script/rebuild", "tasks/echoe.rake", "tasks/validate_db.rake", "test/ar.rb", "test/auto.rb", "test/base-tests/local_conf.rb", "test/base.rb", "test/boot.rb", "test/config/local.defaults.yml", "test/config/local.yml", "test/test_helper.rb", "vex.gemspec"]
14
14
  s.homepage = %q{http://github.com/pboy/vex}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Vex"]
16
16
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - pboy
@@ -83,6 +83,7 @@ extra_rdoc_files:
83
83
  - lib/vex/active_record/advisory_lock/mysql_adapter.rb
84
84
  - lib/vex/active_record/advisory_lock/sqlite_adapter.rb
85
85
  - lib/vex/active_record/belongs_to_many.rb
86
+ - lib/vex/active_record/custom_validations.rb
86
87
  - lib/vex/active_record/find_by_extension.rb
87
88
  - lib/vex/active_record/gem.rb
88
89
  - lib/vex/active_record/lite_table.rb
@@ -174,6 +175,7 @@ files:
174
175
  - lib/vex/active_record/advisory_lock/mysql_adapter.rb
175
176
  - lib/vex/active_record/advisory_lock/sqlite_adapter.rb
176
177
  - lib/vex/active_record/belongs_to_many.rb
178
+ - lib/vex/active_record/custom_validations.rb
177
179
  - lib/vex/active_record/find_by_extension.rb
178
180
  - lib/vex/active_record/gem.rb
179
181
  - lib/vex/active_record/lite_table.rb