simple_assert_type 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1 @@
1
+ alone for github
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
@@ -0,0 +1 @@
1
+ simple_assert_type
@@ -0,0 +1 @@
1
+ ree
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_assert_type.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 zedtux
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # SimpleAssertType
2
+
3
+ Very simple assert_type method that you can use anywhere in order to check
4
+ a variable type.
5
+
6
+ In case the type is not the same, an `ArgumentError` is raised.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'simple_assert_type'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install simple_assert_type
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ ree-1.8.7-2012.02 :001 > assert_type 1, Fixnum
26
+ => true
27
+ ree-1.8.7-2012.02 :002 > assert_type 1, String
28
+ ArgumentError: String expected, got Fixnum
29
+ from /Users/guillaumeh/Developments/simple_assert_type/lib/simple_assert_type.rb:8:in `assert_type'
30
+ from (irb):2
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( http://github.com/<my-github-username>/simple_assert_type/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
@@ -0,0 +1,17 @@
1
+ require "simple_assert_type/version"
2
+
3
+ module SimpleAssertType
4
+ def self.extended(mod)
5
+ mod.module_eval do
6
+ def assert_type(value, type)
7
+ return true if value.is_a?(type)
8
+ raise ArgumentError, "#{type} expected, got #{value.class}"
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ # Extend the Ruby Kernel module
15
+ module Kernel
16
+ extend SimpleAssertType
17
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleAssertType
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_assert_type/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_assert_type"
8
+ spec.version = SimpleAssertType::VERSION
9
+ spec.authors = ["zedtux"]
10
+ spec.email = ["zedtux@zedroot.org"]
11
+ spec.summary = %q{Simple assert_type method for Ruby.}
12
+ spec.description = %q{Simple assert_type method in order to ensure that given parameters are of the right type.}
13
+ spec.homepage = "https://github.com/zedtux/simple_assert_type"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "simplecov"
25
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleAssertType do
4
+
5
+ describe 'assert_type' do
6
+ context 'passing a correct parameter' do
7
+ it 'should not raise an ArgumentError' do
8
+ expect { assert_type(1, Fixnum) }.to_not raise_error
9
+ end
10
+ end
11
+ context 'passing a String' do
12
+ context 'with a Fixnum type' do
13
+ it 'should raise an ArgumentError with message "Fixnum expected, got String"' do
14
+ expect { assert_type("1", Fixnum) }.to raise_error('Fixnum expected, got String')
15
+ end
16
+ end
17
+ context 'with an Array type' do
18
+ it 'should raise an ArgumentError with message "Array expected, got String"' do
19
+ expect { assert_type("1", Array) }.to raise_error('Array expected, got String')
20
+ end
21
+ end
22
+ context 'with a String type' do
23
+ it 'should not raise an ArgumentError' do
24
+ expect { assert_type("1", String) }.to_not raise_error
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ require "simplecov"
3
+ SimpleCov.start
4
+
5
+ ROOT_PATH = File.join(File.dirname(__FILE__), '..')
6
+ $:.unshift ROOT_PATH unless $:.include? ROOT_PATH
7
+
8
+ require "rubygems"
9
+ require "rspec"
10
+
11
+ require "lib/simple_assert_type"
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_assert_type
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - zedtux
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2014-02-27 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 5
28
+ segments:
29
+ - 1
30
+ - 5
31
+ version: "1.5"
32
+ prerelease: false
33
+ requirement: *id001
34
+ name: bundler
35
+ type: :development
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ prerelease: false
47
+ requirement: *id002
48
+ name: rake
49
+ type: :development
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ prerelease: false
61
+ requirement: *id003
62
+ name: rspec
63
+ type: :development
64
+ - !ruby/object:Gem::Dependency
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ prerelease: false
75
+ requirement: *id004
76
+ name: simplecov
77
+ type: :development
78
+ description: Simple assert_type method in order to ensure that given parameters are of the right type.
79
+ email:
80
+ - zedtux@zedroot.org
81
+ executables: []
82
+
83
+ extensions: []
84
+
85
+ extra_rdoc_files: []
86
+
87
+ files:
88
+ - .gitignore
89
+ - .gpairrc
90
+ - .rspec
91
+ - .ruby-gemset
92
+ - .ruby-version
93
+ - .travis.yml
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/simple_assert_type.rb
99
+ - lib/simple_assert_type/version.rb
100
+ - simple_assert_type.gemspec
101
+ - spec/simple_assert_type_spec.rb
102
+ - spec/spec_helper.rb
103
+ has_rdoc: true
104
+ homepage: https://github.com/zedtux/simple_assert_type
105
+ licenses:
106
+ - MIT
107
+ post_install_message:
108
+ rdoc_options: []
109
+
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ requirements: []
131
+
132
+ rubyforge_project:
133
+ rubygems_version: 1.6.2
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Simple assert_type method for Ruby.
137
+ test_files:
138
+ - spec/simple_assert_type_spec.rb
139
+ - spec/spec_helper.rb