Skip to content

Commit 33efd54

Browse files
authored
Refactor checks (#37)
1 parent c7dfdbd commit 33efd54

22 files changed

+76
-124
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1818
* replace
1919
* upsert
2020

21+
### Changed
22+
23+
* `checks` is disabled for internal functions by default
24+
2125
## [0.1.0] - 2020-09-23
2226

2327
### Added

crud-scm-1.rockspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ source = {
88
dependencies = {
99
'tarantool',
1010
'lua >= 5.1',
11-
'checks == 3.0.1-1',
11+
'checks == 3.1.0-1',
1212
'errors == 2.1.3-1',
1313
'vshard == 0.1.16-1',
1414
}

crud/common/call.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
local checks = require('checks')
21
local fiber = require('fiber')
32
local vshard = require('vshard')
43
local errors = require('errors')
54

5+
local dev_checks = require('crud.common.dev_checks')
66
local registry = require('crud.common.registry')
77
local utils = require('crud.common.utils')
88

@@ -23,7 +23,7 @@ local DEFAULT_VSHARD_CALL_TIMEOUT = 2
2323
--
2424
function call.init()
2525
local function call(opts)
26-
checks({
26+
dev_checks({
2727
func_name = 'string',
2828
func_args = '?table',
2929
})
@@ -63,7 +63,7 @@ local function call_on_replicaset(replicaset, channel, vshard_call, func_name, f
6363
end
6464

6565
local function call_impl(vshard_call, func_name, func_args, opts)
66-
checks('string', 'string', '?table', {
66+
dev_checks('string', 'string', '?table', {
6767
timeout = '?number',
6868
replicasets = '?table',
6969
})

crud/common/checkers.lua

Lines changed: 0 additions & 46 deletions
This file was deleted.

crud/common/dev_checks.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
local checks = require('checks')
2+
3+
local dev_checks = function() end
4+
5+
if os.getenv('DEV') == 'ON' then
6+
dev_checks = checks
7+
end
8+
9+
return dev_checks

crud/common/heap.lua

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
local checks = require('checks')
2-
3-
require('crud.common.checkers')
1+
local dev_checks = require('crud.common.dev_checks')
42

53
local Heap = {}
64
Heap.__index = Heap
75

86
function Heap.new(opts)
9-
checks({
7+
dev_checks({
108
comparator = 'function',
119
})
1210

@@ -45,7 +43,7 @@ function Heap:_ok(child_idx, parent_idx)
4543
end
4644

4745
function Heap:add(obj, meta)
48-
checks('table', '?', '?')
46+
dev_checks('table', '?', '?')
4947

5048
local node = {
5149
obj = obj,

crud/common/registry.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
local checks = require('checks')
21
local errors = require('errors')
32

4-
require('crud.common.checkers')
5-
63
local registry = {}
74

85
local registered_funcs = {}
@@ -17,8 +14,6 @@ local RegisterError = errors.new_class('Register')
1714
-- Should be passed as a {string: function} map.
1815
--
1916
function registry.add(funcs)
20-
checks('funcs_map')
21-
2217
for func_name in pairs(funcs) do
2318
if registry.is_registered(func_name) then
2419
return nil, RegisterError:new("Function %s is already registered", func_name)

crud/common/utils.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
local checks = require('checks')
21
local errors = require('errors')
32

3+
local dev_checks = require('crud.common.dev_checks')
4+
45
local FlattenError = errors.new_class("FlattenError", {capture_stack = false})
56
local UnflattenError = errors.new_class("UnflattenError", {capture_stack = false})
67
local ParseOperationsError = errors.new_class('ParseOperationsError', {capture_stack = false})
78

89
local utils = {}
910

1011
function utils.table_count(table)
11-
checks("table")
12+
dev_checks("table")
1213

1314
local cnt = 0
1415
for _, _ in pairs(table) do
@@ -19,7 +20,7 @@ function utils.table_count(table)
1920
end
2021

2122
function utils.format_replicaset_error(replicaset_uuid, msg, ...)
22-
checks("string", "string")
23+
dev_checks("string", "string")
2324

2425
return string.format(
2526
"Failed for %s: %s",

crud/delete.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local vshard = require('vshard')
55
local call = require('crud.common.call')
66
local registry = require('crud.common.registry')
77
local utils = require('crud.common.utils')
8+
local dev_checks = require('crud.common.dev_checks')
89

910
local DeleteError = errors.new_class('Delete', {capture_stack = false})
1011

@@ -13,7 +14,7 @@ local delete = {}
1314
local DELETE_FUNC_NAME = '__delete'
1415

1516
local function call_delete_on_storage(space_name, key)
16-
checks('string', '?')
17+
dev_checks('string', '?')
1718

1819
local space = box.space[space_name]
1920
if space == nil then

crud/get.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local vshard = require('vshard')
55
local call = require('crud.common.call')
66
local registry = require('crud.common.registry')
77
local utils = require('crud.common.utils')
8+
local dev_checks = require('crud.common.dev_checks')
89

910
local GetError = errors.new_class('Get', {capture_stack = false})
1011

@@ -13,7 +14,7 @@ local get = {}
1314
local GET_FUNC_NAME = '__get'
1415

1516
local function call_get_on_storage(space_name, key)
16-
checks('string', '?')
17+
dev_checks('string', '?')
1718

1819
local space = box.space[space_name]
1920
if space == nil then

0 commit comments

Comments
 (0)