contracts-stringy 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aea6ae6522c56709788368626ae3c66b8ea35f4cd31ef9b3b86a14b2e36c9757
4
+ data.tar.gz: 28b7d890f7c1e69bb06e3211c94f9214ed6b84befc5e9b066925ec32866688bf
5
+ SHA512:
6
+ metadata.gz: aacdc1b26791c7cc672d24b9fff4fb54b2ff8169f70f3910f516f2a3f4d8abcc934c26384af41dfb552cf6d6dcb1689e869ae8af48a0d67d40a714c5a1647d1c
7
+ data.tar.gz: b846076f69a259ddf4207bcade7c5a5296b12c138d32ffda6aebe42321c2d8cd019172c5d777447b1c26e7d439955e5c921ab26792ccc97fb7bf5267ab6c2835
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .rakeTasks
13
+ *.iml
14
+ tags
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem 'contracts-gen', path: '../contracts-gen'
5
+ gem 'gen-test', path: '../gen-test'
6
+ end
7
+
8
+ # Specify your gem's dependencies in contracts-stringy.gemspec
9
+ gemspec
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: ../contracts-gen
3
+ specs:
4
+ contracts-gen (0.1.0)
5
+ contracts (~> 0.16.0)
6
+ faker (~> 1.9.6)
7
+ gen-test (~> 0.1.0)
8
+
9
+ PATH
10
+ remote: ../gen-test
11
+ specs:
12
+ gen-test (0.1.1)
13
+ faker (~> 1.9.6)
14
+ regexp-examples (~> 1.5.0)
15
+
16
+ PATH
17
+ remote: .
18
+ specs:
19
+ contracts-stringy (0.1.0)
20
+ contracts (~> 0.16.0)
21
+ contracts-gen (~> 0.1.0)
22
+ faker (~> 1.9.6)
23
+ gen-test (~> 0.1.0)
24
+
25
+ GEM
26
+ remote: https://rubygems.org/
27
+ specs:
28
+ concurrent-ruby (1.1.5)
29
+ contracts (0.16.0)
30
+ diff-lcs (1.3)
31
+ faker (1.9.6)
32
+ i18n (>= 0.7)
33
+ i18n (1.6.0)
34
+ concurrent-ruby (~> 1.0)
35
+ rake (10.5.0)
36
+ regexp-examples (1.5.1)
37
+ rspec (3.8.0)
38
+ rspec-core (~> 3.8.0)
39
+ rspec-expectations (~> 3.8.0)
40
+ rspec-mocks (~> 3.8.0)
41
+ rspec-core (3.8.2)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-expectations (3.8.4)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.8.0)
46
+ rspec-mocks (3.8.1)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.8.0)
49
+ rspec-support (3.8.2)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler (~> 2.0)
56
+ contracts-gen!
57
+ contracts-stringy!
58
+ gen-test!
59
+ rake (~> 10.0)
60
+ rspec (~> 3.0)
61
+
62
+ BUNDLED WITH
63
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Delon Newman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # Contracts::Stringy
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'contracts-stringy'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install contracts-stringy
18
+
19
+ ## License
20
+
21
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,39 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "contracts/stringy/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "contracts-stringy"
7
+ spec.version = Contracts::Stringy::VERSION
8
+ spec.authors = ["Delon Newman"]
9
+ spec.email = ["contact@delonnewman.name"]
10
+
11
+ spec.summary = %q{Contracts for string coercion}
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/delonnewman/contracts-stringy"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ spec.metadata["changelog_uri"] = "#{spec.homepage}#changelog"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_runtime_dependency "contracts", "~> 0.16.0"
32
+ spec.add_runtime_dependency "contracts-gen", "~> 0.1.0"
33
+ spec.add_runtime_dependency "gen-test", "~> 0.1.0"
34
+ spec.add_runtime_dependency "faker", "~> 1.9.6"
35
+
36
+ spec.add_development_dependency "bundler", "~> 2.0"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
@@ -0,0 +1,105 @@
1
+ require 'contracts/gen'
2
+ require 'gen/test'
3
+
4
+ # Some contracts to deal with string values that can be coerced appropriately by ActiveRecord
5
+ module Contracts
6
+ module Stringy
7
+ INTEGER_REGEX = /\A[\-+]?\d+\z/
8
+ FLOAT_REGEX = /\A[\-+]?\d+\.\d+\z/
9
+ POS_REGEX = /\A\d+\z/
10
+ UUID_REGEX = /\A[0-9a-f]{8}\-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i
11
+ URLSAFE_REGEX = /\A[ \-\+\w]+\z/
12
+
13
+ # A string that looks like an integer
14
+ # @see INTEGER_REGEX
15
+ class Int
16
+ def self.valid?(value)
17
+ value.is_a? String and (value =~ INTEGER_REGEX) != nil
18
+ end
19
+
20
+ def self.generate(*args)
21
+ Contracts::Builtin::Int.generate(*args).to_s
22
+ end
23
+ end
24
+
25
+ class Float
26
+ def self.valid?(value)
27
+ value.is_a? String and (value =~ FLOAT_REGEX) != nil
28
+ end
29
+
30
+ def self.generate(*args)
31
+ ::Float.generate(*args).to_s
32
+ end
33
+ end
34
+
35
+ # A string that looks like a positive integer
36
+ # @see POS_REGEX
37
+ class Pos
38
+ def self.valid?(value)
39
+ value.is_a? String and (value =~ POS_REGEX) != nil
40
+ end
41
+
42
+ def self.generate(*args)
43
+ Contracts::Builtin::Pos.generate(*args).to_s
44
+ end
45
+ end
46
+
47
+ # A string that is equal to either 'true', 'false', '0', or '1'.
48
+ class Bool
49
+ def self.valid?(value)
50
+ value.is_a? String and value == 'true' or value == 'false' or value == "0" or value == "1"
51
+ end
52
+
53
+ def self.generate(*args)
54
+ if Contracts::Builtin::Bool.generate
55
+ Contracts::Builtin::Bool.generate(*args) ? 'true' : '1'
56
+ else
57
+ Contracts::Builtin::Bool.generate(*args) ? 'false' : '0'
58
+ end
59
+ end
60
+ end
61
+
62
+ # A string that looks like a UUID
63
+ # @see UUID_REGEX
64
+ class UUID
65
+ def self.valid?(value)
66
+ value.is_a? String and (value =~ UUID_REGEX) != nil
67
+ end
68
+
69
+ def self.generate(*_args)
70
+ SecureRandom.uuid
71
+ end
72
+ end
73
+
74
+ # A url safe string
75
+ # @see URLSAFE_REGEX
76
+ class URLSafe
77
+ def self.valid?(value)
78
+ value.is_a? String and (value =~ URLSAFE_REGEX) != nil
79
+ end
80
+
81
+ def self.generate(*_args)
82
+ URLSAFE_REGEX.generate
83
+ end
84
+ end
85
+
86
+ class Name
87
+ # TODO: refine this
88
+ def self.valid?(value)
89
+ value.is_a? String
90
+ end
91
+
92
+ def self.generate
93
+ Faker::Name.unique.name
94
+ end
95
+ end
96
+ end
97
+
98
+ StrInt = Stringy::Int
99
+ StrFloat = Stringy::Float
100
+ StrPos = Stringy::Pos
101
+ StrBool = Stringy::Bool
102
+ StrUUID = Stringy::UUID
103
+ URLSafe = Stringy::URLSafe
104
+ Name = Stringy::Name
105
+ end
@@ -0,0 +1,5 @@
1
+ module Contracts
2
+ module Stringy
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contracts-stringy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Delon Newman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: contracts
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.16.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.16.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: contracts-gen
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: gen-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: faker
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.9.6
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.9.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: Contracts for string coercion
112
+ email:
113
+ - contact@delonnewman.name
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - contracts-stringy.gemspec
126
+ - lib/contracts/stringy.rb
127
+ - lib/contracts/stringy/version.rb
128
+ homepage: https://github.com/delonnewman/contracts-stringy
129
+ licenses:
130
+ - MIT
131
+ metadata:
132
+ allowed_push_host: https://rubygems.org
133
+ homepage_uri: https://github.com/delonnewman/contracts-stringy
134
+ source_code_uri: https://github.com/delonnewman/contracts-stringy
135
+ changelog_uri: https://github.com/delonnewman/contracts-stringy#changelog
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.0.6
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Contracts for string coercion
155
+ test_files: []