typespec 0.1.0.0 → 0.1.0.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: 89735c9c1f915fb52dcbbf55eb6d01875b4edac2
4
- data.tar.gz: 63067969f72f7b18b3b129e58c78c128f025f36b
3
+ metadata.gz: 6953ed715bd0d2db888067e9c7d744ea05f322e4
4
+ data.tar.gz: 118a5d11504bb2b12938973d4b38918d6f496a32
5
5
  SHA512:
6
- metadata.gz: b7414951bc78d23b602e6b5cabf7328c7da83bf72268f28fb824643aec3de3efb17f6425e415668b4284bc2629022f7355960e72fc70f8b224cbed5948f4d50d
7
- data.tar.gz: 1b12cb00d9639a1ace0e92b16e71b7b8ed6a49c587b1e580b4f2fd4d7adac9acdb844f742e5d2fd31ec1b75580c2a23e5fa78332f334f6201fed56c969e37fdf
6
+ metadata.gz: 79ab79b1fc3ba23add2a188b088bcec8cdda2822ca19c87f2290d49fb9a29e8d437d91b039abaa3d0536f5ea944e65a5b53cb04434b64158789eaea1fb843527
7
+ data.tar.gz: 36c7b7141dcd09a844103a5cbe948672c8ff8b1a15a9b37a6ab03d6a69fe964d3d6baed8406b9e160cce6ef2a58fc284804e380070ec481bee9ea9c16f88fe47
data/.gitignore CHANGED
@@ -1,5 +1,5 @@
1
- # Sublime Text 2/3
2
- *.sublime-workspace
3
-
4
- # RubyGems
5
- *.gem
1
+ # Sublime Text 2/3
2
+ *.sublime-workspace
3
+
4
+ # RubyGems
5
+ *.gem
data/AUTHORS CHANGED
@@ -1 +1 @@
1
- Michael Williams <m.t.williams@live.com>
1
+ Michael Williams <m.t.williams@live.com>
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source 'https://rubygems.org'
2
- gemspec
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE CHANGED
@@ -1 +1 @@
1
- Public Domain
1
+ Public Domain
data/README.md CHANGED
@@ -1,36 +1,36 @@
1
- # [Typespec](http://mtwilliams.github.io/typespec)
2
-
3
- [![Gem Version](https://img.shields.io/gem/v/typespec.svg)](https://rubygems.org/gems/typespec)
4
- [![Build Status](https://img.shields.io/travis/mtwilliams/typespec/master.svg)](https://travis-ci.org/mtwilliams/typespec)
5
- [![Code Climate](https://img.shields.io/codeclimate/github/mtwilliams/typespec.svg)](https://codeclimate.com/github/mtwilliams/typespec)
6
- [![Dependency Status](https://img.shields.io/gemnasium/mtwilliams/typespec.svg)](https://gemnasium.com/mtwilliams/typespec)
7
-
8
- :nut_and_bolt: Specify complex schema made of types or specific values.
9
-
10
- ```Ruby
11
- module Defines
12
- def self.typespec
13
- Typespec.hash[Typespec.string => Typespec.or[Typespec.nothing,
14
- Typespec.boolean,
15
- Typespec.number,
16
- Typespec.string]]
17
- end
18
- end
19
-
20
- Defines.typespec.matches?('YETI_LINKAGE' => 'YETI_LINKAGE_STATIC',
21
- '__YETI_IS_BEING_COMPILED__' => true,
22
- 'YETI_CONFIGURATION' => 'YETI_CONFIGURATION_DEBUG',
23
- '_HAS_EXCEPTIONS' => false,
24
- '_SCL_SECURE_NO_WARNINGS' => true,
25
- '_CRT_SECURE_NO_WARNINGS' => true,
26
- '_CRT_SECURE_NO_DEPRECATE' => true,
27
- '_SECURE_SCL_THROWS' => false,
28
- '_SILENCE_DEPRECATION_OF_SECURE_SCL_THROWS' => true,
29
- '_USING_V110_SDK71_' => true,
30
- '_DEBUG' => true,
31
- '_HAS_ITERATOR_DEBUGGING' => true,
32
- '_SECURE_SCL' => true)
33
-
34
- #=> true
35
- ```
36
-
1
+ # [Typespec](http://mtwilliams.github.io/typespec)
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/typespec.svg)](https://rubygems.org/gems/typespec)
4
+ [![Build Status](https://img.shields.io/travis/mtwilliams/typespec/master.svg)](https://travis-ci.org/mtwilliams/typespec)
5
+ [![Code Climate](https://img.shields.io/codeclimate/github/mtwilliams/typespec.svg)](https://codeclimate.com/github/mtwilliams/typespec)
6
+ [![Dependency Status](https://img.shields.io/gemnasium/mtwilliams/typespec.svg)](https://gemnasium.com/mtwilliams/typespec)
7
+
8
+ :nut_and_bolt: Specify complex schema made of types or specific values.
9
+
10
+ ```Ruby
11
+ module Defines
12
+ def self.typespec
13
+ Typespec.hash[Typespec.string => Typespec.or[Typespec.nothing,
14
+ Typespec.boolean,
15
+ Typespec.number,
16
+ Typespec.string]]
17
+ end
18
+ end
19
+
20
+ Defines.typespec.valid?('YETI_LINKAGE' => 'YETI_LINKAGE_STATIC',
21
+ '__YETI_IS_BEING_COMPILED__' => true,
22
+ 'YETI_CONFIGURATION' => 'YETI_CONFIGURATION_DEBUG',
23
+ '_HAS_EXCEPTIONS' => false,
24
+ '_SCL_SECURE_NO_WARNINGS' => true,
25
+ '_CRT_SECURE_NO_WARNINGS' => true,
26
+ '_CRT_SECURE_NO_DEPRECATE' => true,
27
+ '_SECURE_SCL_THROWS' => false,
28
+ '_SILENCE_DEPRECATION_OF_SECURE_SCL_THROWS' => true,
29
+ '_USING_V110_SDK71_' => true,
30
+ '_DEBUG' => true,
31
+ '_HAS_ITERATOR_DEBUGGING' => true,
32
+ '_SECURE_SCL' => true)
33
+
34
+ #=> true
35
+ ```
36
+
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/lib/typespec/gem.rb CHANGED
@@ -1,58 +1,58 @@
1
- require 'ostruct'
2
-
3
- module Typespec
4
- module Gem
5
- # The name of this Gem.
6
- def self.name
7
- "typespec"
8
- end
9
-
10
- # The name and email address of the primary author.
11
- def self.author
12
- self.authors.first
13
- end
14
-
15
- # The name and email addresses of all authors.
16
- def self.authors
17
- [["Michael Williams", "m.t.williams@live.com"]].map do |author|
18
- name, email = author
19
- OpenStruct.new(name: name, email: email)
20
- end
21
- end
22
-
23
- # This Gem's homepage URL.
24
- def self.homepage
25
- "http://github.com/mtwilliams/typespec"
26
- end
27
-
28
- # This Gem's URL.
29
- def self.url
30
- "https://rubygems.org/gems/#{self.name}"
31
- end
32
-
33
- # A short summary of this Gem.
34
- def self.summary
35
- "Specify complex schema made of types or specific values."
36
- end
37
-
38
- # A full description of this Gem.
39
- def self.description
40
- "Typespec is a way to specify complex schema made of types or specific values and validate against them."
41
- end
42
-
43
- module VERSION #:nodoc:
44
- MAJOR, MINOR, PATCH, PRE = [0, 1, 0, 0]
45
- STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
46
- end
47
-
48
- # The semantic version of the this Gem.
49
- def self.version
50
- Gem::VERSION::STRING
51
- end
52
-
53
- # The license covering this Gem.
54
- def self.license
55
- "Public Domain"
56
- end
57
- end
58
- end
1
+ require 'ostruct'
2
+
3
+ module Typespec
4
+ module Gem
5
+ # The name of this Gem.
6
+ def self.name
7
+ "typespec"
8
+ end
9
+
10
+ # The name and email address of the primary author.
11
+ def self.author
12
+ self.authors.first
13
+ end
14
+
15
+ # The name and email addresses of all authors.
16
+ def self.authors
17
+ [["Michael Williams", "m.t.williams@live.com"]].map do |author|
18
+ name, email = author
19
+ OpenStruct.new(name: name, email: email)
20
+ end
21
+ end
22
+
23
+ # This Gem's homepage URL.
24
+ def self.homepage
25
+ "http://github.com/mtwilliams/typespec"
26
+ end
27
+
28
+ # This Gem's URL.
29
+ def self.url
30
+ "https://rubygems.org/gems/#{self.name}"
31
+ end
32
+
33
+ # A short summary of this Gem.
34
+ def self.summary
35
+ "Specify complex schema made of types or specific values."
36
+ end
37
+
38
+ # A full description of this Gem.
39
+ def self.description
40
+ "Typespec is a way to specify complex schema made of types or specific values and validate against them."
41
+ end
42
+
43
+ module VERSION #:nodoc:
44
+ MAJOR, MINOR, PATCH, PRE = [0, 1, 0, 1]
45
+ STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
46
+ end
47
+
48
+ # The semantic version of the this Gem.
49
+ def self.version
50
+ Gem::VERSION::STRING
51
+ end
52
+
53
+ # The license covering this Gem.
54
+ def self.license
55
+ "Public Domain"
56
+ end
57
+ end
58
+ end
data/lib/typespec.rb CHANGED
@@ -1,181 +1,182 @@
1
- # ...
2
- module Typespec
3
- # TODO(mtwilliams): Perform sanity checks.
4
- # TODO(mtwilliams): Raise (custom) exceptions.
5
- # TODO(mtwilliams): Explain the Type-Value-Or sysem.
6
- # TODO(mtwilliams): Provide an example on how to rewrite exceptions.
7
- # TODO(mtwilliams): Document this monstrosity.
8
-
9
- # ...
10
- def self.any; Typespec::Any; end
11
-
12
- # ...
13
- class Any
14
- def self.valid?(_); true; end
15
- end
16
-
17
- # ...
18
- def self.t; Typespec::Type; end
19
-
20
- # ...
21
- class Type
22
- def initialize(type); @type = type; end
23
- def self.[](type); self.new(type); end
24
- def valid?(value); value.is_a?(@type); end
25
- end
26
-
27
- # ...
28
- def self.expects; Typespec::Value; end
29
-
30
- # ...
31
- class Value
32
- def initialize(value); @value = value; end
33
- def self.[](value); self.new(value); end
34
- def valid?(value) value.eql?(@value); end
35
- end
36
-
37
- # ...
38
- def self.or; Typespec::Or; end
39
-
40
- # ...
41
- class Or
42
- def initialize(expects); @expects = [*expects]; end
43
- def valid?(value); @expects.any?{|expects| expects.valid?(value)}; end
44
- end
45
-
46
- # ...
47
- def self.nil; Typespec.t[NilClass]; end
48
-
49
- # ...
50
- def self.boolean; Typespec.or[Typespec.t[TrueClass], Typespec.t[FalseClass]]; end
51
-
52
- # ...
53
- def self.number; Typespec.t[Numeric]; end
54
-
55
- # ...
56
- def self.integer; Typespec.t[Integer]; end
57
-
58
- # ...
59
- def self.float; Typespec.t[Float]; end
60
-
61
- # ...
62
- def self.rational; Typespec.t[Rational]; end
63
-
64
- # ...
65
- def self.string; Typespec.t[String]; end
66
-
67
- # ...
68
- def self.symbol; Typespec.t[Symbol]; end
69
-
70
- # ...
71
- def self.array; Typespec::Array; end
72
-
73
- # ...
74
- class Array
75
- def initialize(*elements)
76
- @element = Typespec.or[*elements]
77
- end
78
-
79
- def self.[](*elements)
80
- Typespec::Array.new(*elements)
81
- end
82
-
83
- def valid?(value)
84
- if value.is_a? Array
85
- value.all?{|element| @element.valid?(element)}
86
- else
87
- false
88
- end
89
- end
90
- end
91
-
92
- # ...
93
- def self.hash; Typespec::Hash; end
94
-
95
- # ...
96
- class Hash
97
- def initialize(**pairs)
98
- @pairs = pairs
99
- @pairs ||= {Typespec.any => Typespec.any}
100
- end
101
-
102
- def self.[](**pairs)
103
- Typespec::Hash.new(**pairs)
104
- end
105
-
106
- def valid?(value)
107
- if value.is_a? Hash
108
- value.all? do |k, v|
109
- @pairs.any? do |pair|
110
- pair.zip([k,v]).all? {|typespec, value| typespec.valid?(value)}
111
- end
112
- end
113
- else
114
- false
115
- end
116
- end
117
- end
118
-
119
- # ...
120
- def self.struct; Typespec::Struct; end
121
-
122
- # ...
123
- class Struct
124
- def initialize(*properties, **properties_with_spec)
125
- if !properties.empty?
126
- @properties = Hash[properties.map{|name| [name, Typespec.any]}]
127
- elsif properties_with_spec
128
- @properties = properties_with_spec
129
- else
130
- @properties = {}
131
- end
132
- end
133
-
134
- def self.[](*properties, **properties_with_spec)
135
- Typespec::Struct.new(*properties, **properties_with_spec)
136
- end
137
-
138
- def valid?(struct, opts={})
139
- if struct.instance_of? Object
140
- ignore_if_not_in_spec = opts.fetch(:ignore_if_not_in_spec, false)
141
- struct.instance_variables.all? do |property|
142
- undecorated = property.to_s[1..-1].to_sym
143
- if @properties.include?(undecorated)
144
- value = struct.instance_variable_get(property)
145
- @properties[undecorated].valid?(value)
146
- else
147
- ignore_if_not_in_spec
148
- end
149
- end
150
- else
151
- false
152
- end
153
- end
154
- end
155
-
156
- # ...
157
- def self.object; Typespec::Object; end
158
-
159
- # ...
160
- class Object < Struct
161
- def self.[](*properties, **properties_with_spec)
162
- Typespec::Object.new(*properties, **properties_with_spec)
163
- end
164
-
165
- def valid?(object, opts={})
166
- super(object, opts.merge({:ignore_if_not_in_spec => true}))
167
- end
168
- end
169
-
170
- # ...
171
- def self.enum; Typespec::Enum; end
172
-
173
- # ...
174
- class Enum
175
- def initialize(*can_take_on) @can_take_on = [*can_take_on] end
176
- def self.[](*can_take_on); Typespec::Enum.new(can_take_on); end
177
- def valid?(can_take_on) can_take_on.include?(@can_take_on); end
178
- end
179
- end
180
-
181
-
1
+ # ...
2
+ module Typespec
3
+ # TODO(mtwilliams): Perform sanity checks.
4
+ # TODO(mtwilliams): Raise (custom) exceptions.
5
+ # TODO(mtwilliams): Explain the Type-Value-Or sysem.
6
+ # TODO(mtwilliams): Provide an example on how to rewrite exceptions.
7
+ # TODO(mtwilliams): Document this monstrosity.
8
+
9
+ # ...
10
+ def self.any; Typespec::Any; end
11
+
12
+ # ...
13
+ class Any
14
+ def self.valid?(_); true; end
15
+ end
16
+
17
+ # ...
18
+ def self.t; Typespec::Type; end
19
+
20
+ # ...
21
+ class Type
22
+ def initialize(type); @type = type; end
23
+ def self.[](type); self.new(type); end
24
+ def valid?(value); value.is_a?(@type); end
25
+ end
26
+
27
+ # ...
28
+ def self.expects; Typespec::Value; end
29
+
30
+ # ...
31
+ class Value
32
+ def initialize(value); @value = value; end
33
+ def self.[](value); self.new(value); end
34
+ def valid?(value) value.eql?(@value); end
35
+ end
36
+
37
+ # ...
38
+ def self.or; Typespec::Or; end
39
+
40
+ # ...
41
+ class Or
42
+ def initialize(expects); @expects = [*expects]; end
43
+ def self.[](expects); self.new(expects); end
44
+ def valid?(value); @expects.any?{|expects| expects.valid?(value)}; end
45
+ end
46
+
47
+ # ...
48
+ def self.nil; Typespec.t[NilClass]; end
49
+
50
+ # ...
51
+ def self.boolean; Typespec.or[Typespec.t[TrueClass], Typespec.t[FalseClass]]; end
52
+
53
+ # ...
54
+ def self.number; Typespec.t[Numeric]; end
55
+
56
+ # ...
57
+ def self.integer; Typespec.t[Integer]; end
58
+
59
+ # ...
60
+ def self.float; Typespec.t[Float]; end
61
+
62
+ # ...
63
+ def self.rational; Typespec.t[Rational]; end
64
+
65
+ # ...
66
+ def self.string; Typespec.t[String]; end
67
+
68
+ # ...
69
+ def self.symbol; Typespec.t[Symbol]; end
70
+
71
+ # ...
72
+ def self.array; Typespec::Array; end
73
+
74
+ # ...
75
+ class Array
76
+ def initialize(*elements)
77
+ @element = Typespec.or[*elements]
78
+ end
79
+
80
+ def self.[](*elements)
81
+ Typespec::Array.new(*elements)
82
+ end
83
+
84
+ def valid?(value)
85
+ if value.is_a? Array
86
+ value.all?{|element| @element.valid?(element)}
87
+ else
88
+ false
89
+ end
90
+ end
91
+ end
92
+
93
+ # ...
94
+ def self.hash; Typespec::Hash; end
95
+
96
+ # ...
97
+ class Hash
98
+ def initialize(**pairs)
99
+ @pairs = pairs
100
+ @pairs ||= {Typespec.any => Typespec.any}
101
+ end
102
+
103
+ def self.[](**pairs)
104
+ Typespec::Hash.new(**pairs)
105
+ end
106
+
107
+ def valid?(value)
108
+ if value.is_a? Hash
109
+ value.all? do |k, v|
110
+ @pairs.any? do |pair|
111
+ pair.zip([k,v]).all? {|typespec, value| typespec.valid?(value)}
112
+ end
113
+ end
114
+ else
115
+ false
116
+ end
117
+ end
118
+ end
119
+
120
+ # ...
121
+ def self.struct; Typespec::Struct; end
122
+
123
+ # ...
124
+ class Struct
125
+ def initialize(*properties, **properties_with_spec)
126
+ if !properties.empty?
127
+ @properties = Hash[properties.map{|name| [name, Typespec.any]}]
128
+ elsif properties_with_spec
129
+ @properties = properties_with_spec
130
+ else
131
+ @properties = {}
132
+ end
133
+ end
134
+
135
+ def self.[](*properties, **properties_with_spec)
136
+ Typespec::Struct.new(*properties, **properties_with_spec)
137
+ end
138
+
139
+ def valid?(struct, opts={})
140
+ if struct.instance_of? Object
141
+ ignore_if_not_in_spec = opts.fetch(:ignore_if_not_in_spec, false)
142
+ struct.instance_variables.all? do |property|
143
+ undecorated = property.to_s[1..-1].to_sym
144
+ if @properties.include?(undecorated)
145
+ value = struct.instance_variable_get(property)
146
+ @properties[undecorated].valid?(value)
147
+ else
148
+ ignore_if_not_in_spec
149
+ end
150
+ end
151
+ else
152
+ false
153
+ end
154
+ end
155
+ end
156
+
157
+ # ...
158
+ def self.object; Typespec::Object; end
159
+
160
+ # ...
161
+ class Object < Struct
162
+ def self.[](*properties, **properties_with_spec)
163
+ Typespec::Object.new(*properties, **properties_with_spec)
164
+ end
165
+
166
+ def valid?(object, opts={})
167
+ super(object, opts.merge({:ignore_if_not_in_spec => true}))
168
+ end
169
+ end
170
+
171
+ # ...
172
+ def self.enum; Typespec::Enum; end
173
+
174
+ # ...
175
+ class Enum
176
+ def initialize(*can_take_on) @can_take_on = [*can_take_on] end
177
+ def self.[](*can_take_on); Typespec::Enum.new(can_take_on); end
178
+ def valid?(can_take_on) can_take_on.include?(@can_take_on); end
179
+ end
180
+ end
181
+
182
+
data/typespec.gemspec CHANGED
@@ -1,21 +1,21 @@
1
- $:.push File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
2
- require 'typespec/gem'
3
-
4
- Gem::Specification.new do |s|
5
- s.name = Typespec::Gem.name
6
- s.version = Typespec::Gem.version
7
- s.platform = Gem::Platform::RUBY
8
- s.author = Typespec::Gem.author.name
9
- s.email = Typespec::Gem.author.email
10
- s.homepage = Typespec::Gem.homepage
11
- s.summary = Typespec::Gem.summary
12
- s.description = Typespec::Gem.description
13
- s.license = Typespec::Gem.license
14
-
15
- s.required_ruby_version = '>= 1.9.3'
16
-
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = %w(lib)
21
- end
1
+ $:.push File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
2
+ require 'typespec/gem'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = Typespec::Gem.name
6
+ s.version = Typespec::Gem.version
7
+ s.platform = Gem::Platform::RUBY
8
+ s.author = Typespec::Gem.author.name
9
+ s.email = Typespec::Gem.author.email
10
+ s.homepage = Typespec::Gem.homepage
11
+ s.summary = Typespec::Gem.summary
12
+ s.description = Typespec::Gem.description
13
+ s.license = Typespec::Gem.license
14
+
15
+ s.required_ruby_version = '>= 1.9.3'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = %w(lib)
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typespec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.0
4
+ version: 0.1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-12 00:00:00.000000000 Z
11
+ date: 2015-11-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Typespec is a way to specify complex schema made of types or specific
14
14
  values and validate against them.