-
Notifications
You must be signed in to change notification settings - Fork 1
/
ruby.snippets
113 lines (91 loc) · 1.76 KB
/
ruby.snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
priority -50
# Config
global !p
def fileNameTitleized(snip):
name = snip.fn.split(".")
return re.sub(r'[_\-]', '', "".join(name[:-1]).title())
def specFileNameTitleized(snip):
name = snip.fn.split(".")
name = "".join(name[:-1]).title()
name = re.sub(r'[_\-]', '', name)
return re.sub(r'Spec$', '', name)
endglobal
# Snippets
snippet mod "module ... end"
module ${1:`!p snip.rv = fileNameTitleized(snip)`}
$0
end
endsnippet
snippet cla "class ... end"
class ${1:`!p snip.rv = fileNameTitleized(snip)`}
$0
end
endsnippet
snippet cn "Class name"
`!p snip.rv = specFileNameTitleized(snip)`
endsnippet
snippet "\b(de)?f" "def <name>..." r
def ${1:function_name}${2:(${3:*args})}
$0
end
endsnippet
snippet rdes "rspec: describe class"
require "rails_helper"
RSpec.describe `!p snip.rv = specFileNameTitleized(snip)` do
$0
end
endsnippet
snippet des "rspec: describe block"
describe "$1" do
${0:${VISUAL:# assertions...}}
end
endsnippet
snippet con "rspec: context block"
context "$1" do
${0:${VISUAL:# assertions...}}
end
endsnippet
snippet it "rspec: it block"
it "$1" do
${0:${VISUAL:# assertions...}}
end
endsnippet
snippet fm "rspec: factory method"
def $1
@$1 ||= create(:$1$0)
end
endsnippet
snippet fv "RSpec: Factory variable"
${2:$1} = create(:$1$0)
endsnippet
snippet let "RSpec: let"
let(:$1) { $0 }
endsnippet
snippet rubocopdisable "rubocop disable"
# rubocop:disable $1
endsnippet
snippet rubocopenable "rubocop enable"
# rubocop:enable $1
endsnippet
snippet ar "attr_reader"
attr_reader :
endsnippet
snippet pry "binding.pry"
binding.pry
endsnippet
snippet rpry "binding.pry_remote"
binding.pry_remote
endsnippet
snippet mv "memoized var"
@$1 ||= $1
$0
endsnippet
snippet @ "ivar"
@$1 = $1
$0
endsnippet
snippet sql "<<~SQL"
<<~SQL
$0
SQL
endsnippet