kortype 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8f2aa8870331dc92d224441bb94cc4c7b2e6859
4
- data.tar.gz: 7c61c45772b0fd7a00898380764c00e396dc8b69
3
+ metadata.gz: 5e71fc6003d8296cb9c5e0ec28e7834ad6588d9f
4
+ data.tar.gz: 2904f338ad8198feb3ab7a784aa1f4e01bbb0130
5
5
  SHA512:
6
- metadata.gz: e096cd5742a63d2eb853f929340b22ff6137f79b021f959ca3cb98bebc38dd468db1f8fe5b3475ed31d75b2d4b16658f2b7518a2eda41ef01c2ae7b64837a282
7
- data.tar.gz: 33025902bdcb49ac4ffe76bc99519aa2d44ce88f25efe5b899f8ae8da98becd6d2eb232e6e4d5d61be17ec7a1315e77e4d3322c5f0670e30d4b0fbaa8b51d565
6
+ metadata.gz: a079d538d89f7220e3dd7564739d335e2b38d202b89c9be9c8378eb1c9b521c0754737dba221bc9a1876cc07c0bad91dceeb578ba806a1c247f2ebcd1401ed39
7
+ data.tar.gz: 04db08787f33fe41e18c141a91f7e07f9d3a371c411519f6554490a0e273c1487d1627f19ad81f2bcf316960ec187dc7e133821399bde042fa1bf1ec47dff63f
data/.travis.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.3
4
- before_install: gem install bundler -v 1.10.6
4
+ - 1.8.7
5
+ script:
6
+ - bundle exec rspec
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Kortype
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)
2
4
 
3
5
  a ruby type force for class.
4
6
 
@@ -27,7 +29,7 @@ class A
27
29
  kortype :num1, :num2, type: Fixnum
28
30
  end
29
31
  a = A.new
30
- a.foo = '2012-1-1'
32
+ a.foo = '2012-1-1'
31
33
  p a.foo # 2012-01-01 00:00:00 +0800
32
34
  a.foo = 'fsf' # will be raise a error
33
35
  a.bar = 233 # "233"
@@ -35,6 +37,19 @@ a.num1 = '232' # 232
35
37
  a.num2 = 'fsd' # 0
36
38
  ```
37
39
 
40
+ ```ruby
41
+ class B
42
+ include Kortype
43
+ kortype :bar, type: String, default: 'bar'
44
+ kortype :foo, type: String, default: ->{ Time.now.to_s }
45
+ kortype :file, type: File, parse: ->(file) { File.new file }
46
+ end
47
+ b = B.new
48
+ b.bar # 'bar'
49
+ b.foo # Time.now.to_s
50
+ b.file = 'Gemfile' # = File.new 'Gemfile'
51
+ ```
52
+
38
53
  ## Development
39
54
 
40
55
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -49,4 +64,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
49
64
  ## License
50
65
 
51
66
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
52
-
data/kortype.gemspec CHANGED
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "rake", "~> 10.0"
33
33
  spec.add_development_dependency "rspec", '~> 3.0'
34
34
  spec.add_development_dependency "pry", '~> 0.10'
35
+ spec.add_development_dependency "codeclimate-test-reporter", '~> 0.4'
35
36
  end
data/lib/kortype/type.rb CHANGED
@@ -13,12 +13,12 @@ module Kortype
13
13
 
14
14
  def value
15
15
  @value ||= if options[:default]
16
- if Proc === options[:default]
17
- options[:default].call
18
- else
19
- options[:default]
20
- end
21
- end
16
+ self.value = if Proc === options[:default]
17
+ options[:default].call
18
+ else
19
+ options[:default]
20
+ end
21
+ end
22
22
  end
23
23
 
24
24
  def value=(value)
@@ -31,7 +31,7 @@ module Kortype
31
31
  else
32
32
  if @type.respond_to? :parse
33
33
  begin
34
- @value = @type.parse value
34
+ @value = @type.parse value
35
35
  rescue
36
36
  raise Kortype::TypeError.new, "#{value} is not parse to a #{@type}"
37
37
  end
@@ -39,12 +39,15 @@ module Kortype
39
39
  @value = value
40
40
  end
41
41
  end
42
- raise Kortype::TypeError.new, "#{value} is not parse to a #{@type}" unless @type === @value
42
+ unless @type === @value
43
+ @value = nil
44
+ raise Kortype::TypeError.new, "#{value} is not parse to a #{@type}"
45
+ end
43
46
  @value
44
47
  end
45
48
 
46
49
  # def dup
47
- #Kortype::Type.new @name, @type, @options
50
+ #Kortype::Type.new @name, @type, @options
48
51
  #end
49
52
  end
50
53
  end
@@ -1,3 +1,3 @@
1
1
  module Kortype
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kortype
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - arnkorty
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-10 00:00:00.000000000 Z
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.4'
69
83
  description: a ruby force type for class
70
84
  email:
71
85
  - arnkorty.fu@gmail.com