carb-types 1.0.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
+ SHA1:
3
+ metadata.gz: 89a3d80561e24e7132ccc3ff050ffefdf800e0f1
4
+ data.tar.gz: b9f4ef6f3fe980b051f88530f63aaf7163e73c45
5
+ SHA512:
6
+ metadata.gz: 4d96ecf6e0cfd04e39b24e2eef9dd3065147a511eef40648e7c3044fa0dd170416645a8eaf808dc4bab10453f23361bc775cb33df5a4b69bde8318d1545b1bd0
7
+ data.tar.gz: 2744c8ef37c2fe503a74624600b93904c8493735bbc4ba78572d0585ce43f17301e1b42455d27d4be9434433ae03dd85dec8adb6ae93d5886ad774c5d0d2ef9d
@@ -0,0 +1,39 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .project
12
+ .directory
13
+ *.swp
14
+ *~
15
+ .DS_Store
16
+ .idea
17
+ .envrc
18
+ .nvmrc
19
+ .ruby-gemset
20
+ .ruby-version
21
+ .rspec-local
22
+ public
23
+ *.backup
24
+ npm-debug.log
25
+
26
+ # Ignore bundler config
27
+ /.bundle
28
+ /vendor/bundle
29
+
30
+ # Ignore all logfiles and tempfiles.
31
+ /log/*.log
32
+ /tmp
33
+ /binstubs/
34
+
35
+ # Ignore user import data
36
+ /data
37
+
38
+ # YARD
39
+ .yardoc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in carb-types.gemspec
4
+ gemspec
@@ -0,0 +1,25 @@
1
+ The MIT License (MIT)
2
+ =====================
3
+
4
+ Copyright © `2016` `Predictable Revenue, Inc.`
5
+
6
+ Permission is hereby granted, free of charge, to any person
7
+ obtaining a copy of this software and associated documentation
8
+ files (the “Software”), to deal in the Software without
9
+ restriction, including without limitation the rights to use,
10
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the
12
+ Software is furnished to do so, subject to the following
13
+ conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # carb-types
2
+
3
+ A set of [dry-types](http://dry-rb.org/gems/dry-types/) to ensure type safety
4
+ for common objects.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'carb-types'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install carb-types
21
+
22
+ ## Usage
23
+
24
+ Please refer to [dry-types](http://dry-rb.org/gems/dry-types/) for usage. The
25
+ provided types are:
26
+
27
+ - `Carb::Types::Proc` ensures the object is a proc
28
+ - `Carb::Types::IndifferentSymbol` ensures the object is a symbol, even if
29
+ string passed
30
+ - `ArrayOfIndifferentSymbols` ensures the object is a valid array of
31
+ `IndifferentSymbol`
32
+ - `Carb::Types::StringHash` ensures a hash has only string keys
33
+ - `Carb::Types::UUID` ensures a string is a valid UUID
34
+ - `Carb::Types::PG::StringArray` ensures an array is a valid postgres text array
35
+ - `Carb::Types::PG::JSONB` ensures a hashmap, an array or an object are valid
36
+ JSON for postgres. `JSONBArray`, `JSONBHash` and `JSONBOp` are also provided,
37
+ ensuring the object is an Array, hash or basic object for JSON
38
+ - `Carb::Types::PG::Bytea` ensures the object is a valid blob for postgres
39
+ - `Carb::Types::PG::CoercibleJSONBHash` ensures the `JSONBHash` can be converted
40
+ to/from a ruby `Hash`
41
+ - `Carb::Types::PG::Tsvector` ensures the object is a valid postgres tsvector
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Carburetor/carb-types.
52
+
@@ -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,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "carb-types"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "carb/types/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "carb-types"
8
+ spec.version = Carb::Types::VERSION
9
+ spec.authors = ["Fire-Dragon-DoL"]
10
+ spec.email = ["francesco.belladonna@gmail.com"]
11
+
12
+ spec.summary = %q{Custom dry-types to ensure type safety}
13
+ spec.description = %q{Custom dry-types to ensure type safety}
14
+ spec.homepage = "https://github.com/Carburetor/carb-types"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "activesupport"
24
+ spec.add_dependency "carb-core", ">= 1.0.0"
25
+ spec.add_dependency "dry-types"
26
+ spec.add_development_dependency "bundler", "~> 1.13"
27
+ spec.add_development_dependency "rake", "~> 11.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "pry-byebug"
30
+ spec.add_development_dependency "pg"
31
+ spec.add_development_dependency "sequel"
32
+ end
@@ -0,0 +1 @@
1
+ require "carb/types"
@@ -0,0 +1,13 @@
1
+ require "carb"
2
+ require "carb/types/version"
3
+ require "carb/types/base"
4
+ require "carb/types/core"
5
+ require "carb/types/proc"
6
+ require "carb/types/uuid"
7
+ require "carb/types/indifferent_symbol"
8
+ require "carb/types/array_of_indifferent_symbols"
9
+ require "carb/types/string_hash"
10
+
11
+ module Carb::Types
12
+ include Core
13
+ end
@@ -0,0 +1,8 @@
1
+ require "dry-types"
2
+ require "carb"
3
+ require "carb/types/core"
4
+ require "carb/types/indifferent_symbol"
5
+
6
+ module Carb::Types
7
+ ArrayOfIndifferentSymbols = Core::Coercible::Array.member(IndifferentSymbol)
8
+ end
@@ -0,0 +1,8 @@
1
+ require "carb"
2
+ require "dry-types"
3
+
4
+ module Carb::Types
5
+ module Base
6
+ Proc = Dry::Types::Definition[::Proc].new(::Proc)
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ require "carb"
2
+ require "dry-types"
3
+
4
+ module Carb::Types
5
+ module Core
6
+ include Dry::Types.module
7
+
8
+ def self.type_define(klass)
9
+ Dry::Types::Definition[klass].new(klass)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require "dry-types"
2
+ require "carb"
3
+ require "carb/types/core"
4
+
5
+ module Carb::Types
6
+ IndifferentSymbol = Core::Strict::Symbol.constructor do |input|
7
+ unless input.respond_to?(:to_sym)
8
+ raise Dry::Types::ConstraintError.new("#to_sym", input)
9
+ end
10
+ input.to_sym
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require "pg"
2
+ require "sequel"
3
+ require "carb"
4
+
5
+ Sequel.extension(:pg_json_ops, :pg_array_ops, :pg_json, :pg_array)
6
+
7
+ module Carb::Types
8
+ module PG
9
+ end
10
+ end
11
+
12
+ require "carb/types/pg/raw"
13
+ require "carb/types/pg/core"
@@ -0,0 +1,37 @@
1
+ require "pg"
2
+ require "sequel"
3
+ require "carb"
4
+ require "carb/types/core"
5
+ require "carb/types/pg"
6
+ require "carb/types/pg/raw"
7
+
8
+ Sequel.extension(:pg_json_ops, :pg_array_ops, :pg_json, :pg_array)
9
+
10
+ module Carb::Types::PG
11
+ # Array
12
+ def self.Array(db_type)
13
+ Raw::Array.constructor(
14
+ ->(array) { Sequel.pg_array(array, db_type) }
15
+ ).meta(type: db_type)
16
+ end
17
+
18
+ StringArray = Raw::Array.constructor(
19
+ ->(input) { Sequel.pg_array(input.map(&:to_s), :text) }
20
+ ).meta(type: :text)
21
+
22
+ # JSONB
23
+ JSONBArray = Raw::JSONBArray.constructor(Sequel.method(:pg_jsonb))
24
+ JSONBHash = Raw::JSONBHash.constructor(Sequel.method(:pg_jsonb))
25
+ JSONBOp = Raw::JSONBOp.constructor(Sequel.method(:pg_jsonb))
26
+ JSONB = JSONBArray | JSONBHash | JSONBOp
27
+ Bytea = Raw::Bytea.constructor(Sequel::SQL::Blob.method(:new))
28
+
29
+ CoercibleJSONBHash = Raw::JSONBHash.constructor(
30
+ ->(input) { Sequel.pg_jsonb(input.to_h) }
31
+ )
32
+
33
+ # Tsvector
34
+ Tsvector = ::Carb::Types::Core::Coercible::String.constructor(
35
+ ->(input) { Sequel.function(:to_tsvector, input.to_s) }
36
+ )
37
+ end
@@ -0,0 +1,27 @@
1
+ require "dry-types"
2
+ require "pg"
3
+ require "sequel"
4
+ require "carb"
5
+ require "carb/types/pg"
6
+ require "carb/types/core"
7
+
8
+ Sequel.extension(:pg_json_ops, :pg_array_ops, :pg_json, :pg_array)
9
+
10
+ module Carb::Types::PG
11
+ module Raw
12
+ types = ::Carb::Types::Core
13
+
14
+ UUID = types::String
15
+ Array = types.type_define(Sequel::Postgres::PGArray)
16
+ JSONArray = types.type_define(Sequel::Postgres::JSONArray)
17
+ JSONHash = types.type_define(Sequel::Postgres::JSONHash)
18
+ JSONOp = types.type_define(Sequel::Postgres::JSONOp)
19
+ JSON = JSONArray | JSONHash | JSONOp
20
+ JSONBArray = types.type_define(Sequel::Postgres::JSONBArray)
21
+ JSONBHash = types.type_define(Sequel::Postgres::JSONBHash)
22
+ JSONBOp = types.type_define(Sequel::Postgres::JSONBOp)
23
+ JSONB = JSONBArray | JSONBHash | JSONBOp
24
+ Bytea = types.type_define(Sequel::SQL::Blob)
25
+ Money = types::Decimal
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ require "carb"
2
+ require "carb/types/base"
3
+
4
+ module Carb::Types
5
+ Proc = Base::Proc.constrained(type: ::Proc)
6
+ end
@@ -0,0 +1,10 @@
1
+ require "active_support/core_ext/hash/keys"
2
+ require "carb"
3
+ require "carb/types/core"
4
+
5
+ module Carb::Types
6
+ StringHash = Core::Coercible::Hash.constructor do |input|
7
+ input.to_h.deep_stringify_keys
8
+ end
9
+ end
10
+
@@ -0,0 +1,14 @@
1
+ require "carb"
2
+ require "carb/types/core"
3
+
4
+ module Carb::Types
5
+ UUID = Core::Strict::String.constrained(
6
+ format: /
7
+ \A[0-9a-fA-F]{8}
8
+ -[0-9a-fA-F]{4}
9
+ -4[0-9a-fA-F]{3}
10
+ -[89abAB][0-9a-fA-F]{3}
11
+ -[0-9a-fA-F]{12}\z
12
+ /ix
13
+ )
14
+ end
@@ -0,0 +1,5 @@
1
+ module Carb
2
+ module Types
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carb-types
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Fire-Dragon-DoL
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: carb-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '11.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '11.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pg
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sequel
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Custom dry-types to ensure type safety
140
+ email:
141
+ - francesco.belladonna@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE.md
151
+ - README.md
152
+ - Rakefile
153
+ - bin/console
154
+ - bin/setup
155
+ - carb-types.gemspec
156
+ - lib/carb-types.rb
157
+ - lib/carb/types.rb
158
+ - lib/carb/types/array_of_indifferent_symbols.rb
159
+ - lib/carb/types/base.rb
160
+ - lib/carb/types/core.rb
161
+ - lib/carb/types/indifferent_symbol.rb
162
+ - lib/carb/types/pg.rb
163
+ - lib/carb/types/pg/core.rb
164
+ - lib/carb/types/pg/raw.rb
165
+ - lib/carb/types/proc.rb
166
+ - lib/carb/types/string_hash.rb
167
+ - lib/carb/types/uuid.rb
168
+ - lib/carb/types/version.rb
169
+ homepage: https://github.com/Carburetor/carb-types
170
+ licenses: []
171
+ metadata: {}
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubyforge_project:
188
+ rubygems_version: 2.6.12
189
+ signing_key:
190
+ specification_version: 4
191
+ summary: Custom dry-types to ensure type safety
192
+ test_files: []