rubysierung 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -5
- data/lib/rubysierung/error.rb +4 -0
- data/lib/rubysierung/types.rb +33 -2
- data/lib/rubysierung/version.rb +1 -1
- data/lib/rubysierung.rb +17 -21
- data/test/test_rubysierung.rb +12 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 038d493ea5841626de91eeb6f134e7718fb6acf6
|
4
|
+
data.tar.gz: 1122c17da2a242e1cd6d8596ebe7f921e5b6feeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36b229c7d8aff827db09a889c841d125b97ffaa4566170cd1815502c9db22a8eee24abf8d9f30afa49888cd6bd9cca9d1ab9b0b88c66ab796ed976727c2c7eb2
|
7
|
+
data.tar.gz: 83169296e36c106e58ea7bdb9f04828241db5baeb1686cafa6f7a3877fbdc09f90047766575970fd00ee7a53ec82654d46e690324a6b16ae641c01689af16f02
|
data/README.md
CHANGED
@@ -25,6 +25,8 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
28
|
+
## Have a look at all available types in ./lib/rubysierung/types
|
29
|
+
|
28
30
|
```ruby
|
29
31
|
require 'CallBaecker'
|
30
32
|
require 'rubysierung'
|
@@ -41,7 +43,7 @@ class Example
|
|
41
43
|
|
42
44
|
# add custom Types
|
43
45
|
# [TypeClass, StandartDuckTypeAsSymbol, StrictDuckTypeAsSymbol]# TODO change to proper name
|
44
|
-
@
|
46
|
+
@__add_type[CustomTyp, :to_s, :to_str]
|
45
47
|
|
46
48
|
# define foo to respond to :to_s and bar to :to_i
|
47
49
|
def one(foo: String, bar: Integer)
|
@@ -74,10 +76,6 @@ def one(foo:, bar:)
|
|
74
76
|
end
|
75
77
|
```
|
76
78
|
|
77
|
-
## Roadmap
|
78
|
-
* add all Standard Types
|
79
|
-
* add feature to add a default argument for a specified Type
|
80
|
-
|
81
79
|
## Contributing
|
82
80
|
|
83
81
|
1. Fork it ( https://github.com/doodzik/rubysierung/fork )
|
data/lib/rubysierung/types.rb
CHANGED
@@ -1,4 +1,35 @@
|
|
1
|
+
|
2
|
+
module Rubysierung::Types
|
3
|
+
@types = [
|
4
|
+
# Type , Standard, Strict
|
5
|
+
[String, :to_s, :to_str],
|
6
|
+
[Integer, :to_i, :to_int],
|
7
|
+
[Array, :to_a, :to_ary],
|
8
|
+
[Complex, :to_c, :to_c],
|
9
|
+
[Float, :to_f, :to_f],
|
10
|
+
[Hash, :to_h, :to_hash],
|
11
|
+
[Rational, :to_r, :to_r],
|
12
|
+
#[Enum, :to_enum, :to_enum],
|
13
|
+
[IO, :to_io, :to_io],
|
14
|
+
[Proc, :to_proc, :to_proc],
|
15
|
+
#[Path, :to_path, :to_path],
|
16
|
+
#[JSON, :to_json, :to_json],
|
17
|
+
[Symbol, :to_sym, :to_sym],
|
18
|
+
[Thread, :join, :join]
|
19
|
+
]
|
20
|
+
|
21
|
+
class << self
|
22
|
+
attr_reader :types
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Make Strict types accessible in Global namespace
|
1
27
|
module Strict
|
2
|
-
class String;end
|
3
|
-
class Integer;end
|
4
28
|
end
|
29
|
+
|
30
|
+
strictEval = ""
|
31
|
+
|
32
|
+
Rubysierung::Types.types.map { |types| strictEval += "class #{types[0]} ;end;" }
|
33
|
+
Strict.module_eval strictEval
|
34
|
+
|
35
|
+
strictEval = nil
|
data/lib/rubysierung/version.rb
CHANGED
data/lib/rubysierung.rb
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
require "rubysierung/version"
|
2
2
|
require 'rubysierung/types'
|
3
|
-
|
3
|
+
require 'rubysierung/error'
|
4
4
|
|
5
5
|
module Rubysierung
|
6
|
-
module Error
|
7
|
-
class Standard < StandardError; end
|
8
|
-
class Strict < StandardError; end
|
9
|
-
end
|
10
|
-
|
11
6
|
def self.extended(base)
|
12
7
|
base.instance_variable_set :@__types_show, -> () do
|
13
8
|
puts @__types
|
14
9
|
end
|
15
10
|
|
16
|
-
base.instance_variable_set :@
|
17
|
-
@__types <<
|
11
|
+
base.instance_variable_set :@__add_type, -> (klass, standard, strict) do
|
12
|
+
@__types << [klass, standard, strict]
|
18
13
|
end
|
19
14
|
|
20
15
|
base.instance_variable_set :@__before_hook, -> (i,ii, callee) do
|
@@ -24,24 +19,18 @@ module Rubysierung
|
|
24
19
|
|
25
20
|
base.instance_variable_set :@__setup_instance_method, -> (_self, name) do
|
26
21
|
file, line = _self.instance_method(name.to_sym).source_location
|
27
|
-
|
28
|
-
@__error_data[:method_file] = file
|
29
|
-
@__error_data[:method_name] = name
|
30
|
-
@__error_data[:method_line] = line -1
|
22
|
+
set_error_data(_self: self, name: name, method_object: _self.name, file: file, line: line - 1)
|
31
23
|
get_default_hash_from_fileline(file: file, line: line-1)
|
32
24
|
end
|
33
25
|
|
34
26
|
base.instance_variable_set :@__setup_class_method, -> (_self, name) do
|
35
27
|
file, line = _self.method(name.to_sym).source_location
|
36
|
-
|
37
|
-
@__error_data[:method_file] = file
|
38
|
-
@__error_data[:method_name] = name
|
39
|
-
@__error_data[:method_line] = line -1
|
28
|
+
set_error_data(_self: self, name: name, method_object: _self.name, file: file, line: line - 1)
|
40
29
|
get_default_hash_from_fileline(file: file, line: line-1)
|
41
30
|
end
|
42
31
|
end
|
43
32
|
|
44
|
-
@__types =
|
33
|
+
@__types = Rubysierung::Types.types
|
45
34
|
@__error_data = {}
|
46
35
|
class << self
|
47
36
|
def get_default_hash_from_fileline(file:, line:)
|
@@ -65,19 +54,17 @@ module Rubysierung
|
|
65
54
|
def convert(klass:, value:)
|
66
55
|
strict = 0
|
67
56
|
@__types.map do |type|
|
68
|
-
strict
|
57
|
+
strict, klass = get_kind(klass: klass)
|
69
58
|
begin
|
70
59
|
if klass == type[0]
|
71
60
|
return value.send(type[1+strict])
|
72
61
|
end
|
73
62
|
rescue NoMethodError
|
63
|
+
# return argument, param, duck_type, calle/receiver -> file, line
|
74
64
|
if strict == 0
|
75
65
|
raise Rubysierung::Error::Standart, "Rubysierung::Error::Standart: Class:#{klass}, DuckType:#{type[2]}, Method:#{@__error_data[:method_object]}:#{@__error_data[:method_file]}#{@__error_data[:method_name]}:#{@__error_data[:method_line]} -- called on #{@__error_data[:caller]} with #{@__error_data[:var_sym]}:#{value} of #{value.class} doesn't respond to #{type[2]}"
|
76
|
-
|
77
66
|
else
|
78
|
-
# return argument, param, duck_type, calle/receiver -> file, line
|
79
67
|
raise Rubysierung::Error::Strict, "Rubysierung::Error::Strict: Class:#{klass}, DuckType:#{type[2]}, Method:#{@__error_data[:method_object]}:#{@__error_data[:method_file]}#{@__error_data[:method_name]}:#{@__error_data[:method_line]} -- called on #{@__error_data[:caller]} with #{@__error_data[:var_sym]}:#{value} of #{value.class} doesn't respond to #{type[2]}"
|
80
|
-
|
81
68
|
end
|
82
69
|
end
|
83
70
|
end
|
@@ -92,5 +79,14 @@ module Rubysierung
|
|
92
79
|
[0, klass]
|
93
80
|
end
|
94
81
|
end
|
82
|
+
|
83
|
+
def set_error_data(_self:, name:, method_object:, file:, line:)
|
84
|
+
err_data = _self.instance_variable_get :@__error_data
|
85
|
+
err_data[:method_object] = method_object
|
86
|
+
err_data[:method_file] = file
|
87
|
+
err_data[:method_name] = name
|
88
|
+
err_data[:method_line] = line
|
89
|
+
_self.instance_variable_set :@__error_data, err_data
|
90
|
+
end
|
95
91
|
end
|
96
92
|
end
|
data/test/test_rubysierung.rb
CHANGED
@@ -9,7 +9,7 @@ class Setup
|
|
9
9
|
extend Rubysierung
|
10
10
|
include CallBaecker
|
11
11
|
|
12
|
-
@
|
12
|
+
@__add_type[CustomTyp, :to_s, :to_str]
|
13
13
|
|
14
14
|
def example1(foo: String, bar: Integer)
|
15
15
|
[foo, bar]
|
@@ -32,6 +32,11 @@ class Setup
|
|
32
32
|
def self.example5(foo: Strict::String, bar: Integer)
|
33
33
|
[foo, bar]
|
34
34
|
end
|
35
|
+
|
36
|
+
# Default
|
37
|
+
# def self.example6(foo: Default.new(String, 'bar'), bar: Default.new(String, 'foo'))
|
38
|
+
# [foo, bar]
|
39
|
+
# end
|
35
40
|
end
|
36
41
|
|
37
42
|
class RubysierungTest < Minitest::Test
|
@@ -97,4 +102,10 @@ class RubysierungTest < Minitest::Test
|
|
97
102
|
assert_equal(true, true)
|
98
103
|
end
|
99
104
|
end
|
105
|
+
|
106
|
+
# def test_example_6_default_value
|
107
|
+
# foo, bar = Setup.example5(bar: 'bar')
|
108
|
+
# assert_equal('bar', bar)
|
109
|
+
# assert_equal('bar', foo)
|
110
|
+
# end
|
100
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysierung
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- doodzik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- lib/rubysierung.rb
|
83
|
+
- lib/rubysierung/error.rb
|
83
84
|
- lib/rubysierung/types.rb
|
84
85
|
- lib/rubysierung/version.rb
|
85
86
|
- rubysierung.gemspec
|