kortype 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.md +4 -4
- data/lib/kortype.rb +19 -0
- data/lib/kortype/type.rb +12 -0
- data/lib/kortype/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 639c2724b37fd7da3ee21433a8eda9079aab4272
|
4
|
+
data.tar.gz: c8a6796bf8feea71b9b9047fec2860ef66df540a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9413bca99e2bb44253f28289b3647e07de6a2f074417d645b77f69b7c50c6dce1a6af8f38d0b081fab528ba81cd0789f62628a56de8f6fab9b3317f85cb8ad6
|
7
|
+
data.tar.gz: 6b94e15d950b3ede325b12d79d76859fd235b72332eba66d153edfc3e34a4b9a30dd2f8624e612b262f2837fd8213a0473d5608a75fe1375860115c66a5bc18f
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Kortype
|
2
2
|
[![Build
|
3
|
-
Status](https://travis-ci.org/arnkorty/kortype.svg?branch=master)](https://travis-ci.org/arnkorty/kortype) [![Code Climate](https://codeclimate.com/github/arnkorty/kortype/badges/gpa.svg)](https://codeclimate.com/github/arnkorty/kortype) [![Dependency Status](https://gemnasium.com/arnkorty/kortype.svg)](https://gemnasium.com/arnkorty/kortype)
|
3
|
+
Status](https://travis-ci.org/arnkorty/kortype.svg?branch=master)](https://travis-ci.org/arnkorty/kortype) [![Code Climate](https://codeclimate.com/github/arnkorty/kortype/badges/gpa.svg)](https://codeclimate.com/github/arnkorty/kortype) [![Dependency Status](https://gemnasium.com/arnkorty/kortype.svg)](https://gemnasium.com/arnkorty/kortype) [![Test Coverage](https://codeclimate.com/github/arnkorty/kortype/badges/coverage.svg)](https://codeclimate.com/github/arnkorty/kortype/coverage)
|
4
4
|
|
5
|
-
a ruby type force for class.
|
5
|
+
a simple ruby type force for class.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -52,13 +52,13 @@ b.file = 'Gemfile' # = File.new 'Gemfile'
|
|
52
52
|
|
53
53
|
## Development
|
54
54
|
|
55
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
56
|
|
57
57
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
58
|
|
59
59
|
## Contributing
|
60
60
|
|
61
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/arnkorty/kortype. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://github.com/arnkorty/kortype/graphs/contributors) code of conduct.
|
62
62
|
|
63
63
|
|
64
64
|
## License
|
data/lib/kortype.rb
CHANGED
@@ -2,6 +2,7 @@ require "kortype/version"
|
|
2
2
|
require 'kortype/type_error'
|
3
3
|
require 'kortype/parse'
|
4
4
|
require 'kortype/type'
|
5
|
+
require 'pry'
|
5
6
|
|
6
7
|
#require 'active_support/concern'
|
7
8
|
#require 'active_support/hash_with_indifferent_access'
|
@@ -22,6 +23,24 @@ module Kortype
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
26
|
+
def valid?
|
27
|
+
!kortype_columns.values.any?{|s| !s.valid?}
|
28
|
+
end
|
29
|
+
|
30
|
+
def errors
|
31
|
+
kortype_columns.values.select{|s| !s.valid?}
|
32
|
+
end
|
33
|
+
|
34
|
+
def valid_for?(col)
|
35
|
+
kortype_columns[col.to_sym].valid?
|
36
|
+
end
|
37
|
+
|
38
|
+
def error_msg_for(col)
|
39
|
+
if !valid_for?(col)
|
40
|
+
kortype_columns[col.to_sym].options[:error_msg]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
25
44
|
module ClassMethods
|
26
45
|
def kortype_columns
|
27
46
|
@kortype_columns ||= {}
|
data/lib/kortype/type.rb
CHANGED
@@ -46,6 +46,18 @@ module Kortype
|
|
46
46
|
@value
|
47
47
|
end
|
48
48
|
|
49
|
+
def valid?
|
50
|
+
return false if !@value && @options[:required]
|
51
|
+
if @value && @options[:validate]
|
52
|
+
if Regexp === @options[:validate]
|
53
|
+
return !!(@value =~ @options[:validate])
|
54
|
+
elsif Proc === @options[:validate]
|
55
|
+
return @options[:validate].call(@value)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
49
61
|
# def dup
|
50
62
|
#Kortype::Type.new @name, @type, @options
|
51
63
|
#end
|
data/lib/kortype/version.rb
CHANGED