/usr/share/vim/addons/snippets/ruby.snippets is in vim-snippets 1.0.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 | ########################################
# Ruby snippets - for Rails, see below #
########################################
# encoding for Ruby 1.9
snippet enc
# encoding: utf-8
# #!/usr/bin/env ruby
snippet #!
#!/usr/bin/env ruby
# encoding: utf-8
# New Block
snippet =b
=begin rdoc
${0}
=end
snippet prot
protected
${0}
snippet priv
private
${0}
snippet y
:yields: ${0:arguments}
snippet rb
#!/usr/bin/env ruby -wKU
snippet beg
begin
${0}
rescue ${1:Exception} => ${2:e}
end
snippet req require
require "${1}"
snippet reqr
require_relative "${1}"
snippet #
# =>
snippet end
__END__
snippet case
case ${1:object}
when ${2:condition}
${0}
end
snippet when
when ${1:condition}
${0}
snippet def
def ${1:method_name}
${0}
end
snippet deft
def test_${1:case_name}
${0}
end
snippet descendants
class Class
def descendants
ObjectSpace.each_object(::Class).select {|klass| klass < self }
end
end
snippet if
if ${1:condition}
${0}
end
snippet ife
if ${1:condition}
${2}
else
${0}
end
snippet eif
elsif ${1:condition}
${0}
snippet unless
unless ${1:condition}
${0}
end
snippet wh
while ${1:condition}
${0}
end
snippet for
for ${1:e} in ${2:c}
${0}
end
snippet until
until ${1:condition}
${0}
end
snippet cla class .. end
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
${0}
end
snippet cla class .. initialize .. end
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
def initialize(${2:args})
${0}
end
end
snippet cla class .. < ParentClass .. initialize .. end
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} < ${2:ParentClass}
def initialize(${3:args})
${0}
end
end
snippet cla ClassName = Struct .. do .. end
${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} = Struct.new(:${2:attr_names}) do
def ${3:method_name}
${0}
end
end
snippet cla class BlankSlate .. initialize .. end
class ${0:BlankSlate}
instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A__/ }
end
snippet cla class << self .. end
class << ${1:self}
${0}
end
# class .. < DelegateClass .. initialize .. end
snippet cla-
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} < DelegateClass(${2:ParentClass})
def initialize(${3:args})
super(${4:del_obj})
${0}
end
end
snippet mod module .. end
module ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
${0}
end
snippet mod module .. module_function .. end
module ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
module_function
${0}
end
snippet mod module .. ClassMethods .. end
module ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
module ClassMethods
${0}
end
module InstanceMethods
end
def self.included(receiver)
receiver.extend ClassMethods
receiver.send :include, InstanceMethods
end
end
# attr_reader
snippet r
attr_reader :${0:attr_names}
# attr_writer
snippet w
attr_writer :${0:attr_names}
# attr_accessor
snippet rw
attr_accessor :${0:attr_names}
snippet atp
attr_protected :${0:attr_names}
snippet ata
attr_accessible :${0:attr_names}
snippet ana
accepts_nested_attributes_for :${0:association}
# ivc == instance variable cache
snippet ivc
@${1:variable_name} ||= ${0:cached_value}
# include Enumerable
snippet Enum
include Enumerable
def each(&block)
${0}
end
# include Comparable
snippet Comp
include Comparable
def <=>(other)
${0}
end
# extend Forwardable
snippet Forw-
extend Forwardable
# def self
snippet defs
def self.${1:class_method_name}
${0}
end
# def initialize
snippet definit
def initialize(${1:args})
${0}
end
# def method_missing
snippet defmm
def method_missing(meth, *args, &blk)
${0}
end
snippet defd
def_delegator :${1:@del_obj}, :${2:del_meth}, :${0:new_name}
snippet defds
def_delegators :${1:@del_obj}, :${0:del_methods}
snippet am
alias_method :${1:new_name}, :${0:old_name}
snippet app
if __FILE__ == $PROGRAM_NAME
${0}
end
# usage_if()
snippet usai
if ARGV.${1}
abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${0}
end
# usage_unless()
snippet usau
unless ARGV.${1}
abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${0}
end
snippet array
Array.new(${1:10}) { |${2:i}| ${0} }
snippet hash
Hash.new { |${1:hash}, ${2:key}| $1[$2] = ${0} }
snippet file File.foreach() { |line| .. }
File.foreach(${1:"path/to/file"}) { |${2:line}| ${0} }
snippet file File.read()
File.read(${1:"path/to/file"})
snippet Dir Dir.global() { |file| .. }
Dir.glob(${1:"dir/glob/*"}) { |${2:file}| ${0} }
snippet Dir Dir[".."]
Dir[${1:"glob/**/*.rb"}]
snippet dir
Filename.dirname(__FILE__)
snippet deli
delete_if { |${1:e}| ${0} }
snippet fil
fill(${1:range}) { |${2:i}| ${0} }
# flatten_once()
snippet flao
inject(Array.new) { |${1:arr}, ${2:a}| $1.push(*$2)}
snippet zip
zip(${1:enums}) { |${2:row}| ${0} }
# downto(0) { |n| .. }
snippet dow
downto(${1:0}) { |${2:n}| ${0} }
snippet ste
step(${1:2}) { |${2:n}| ${0} }
snippet tim
times { |${1:n}| ${0} }
snippet upt
upto(${1:1.0/0.0}) { |${2:n}| ${0} }
snippet loo
loop { ${0} }
snippet ea
each { |${1:e}| ${0} }
snippet ead
each do |${1:e}|
${0}
end
snippet eab
each_byte { |${1:byte}| ${0} }
snippet eac- each_char { |chr| .. }
each_char { |${1:chr}| ${0} }
snippet eac- each_cons(..) { |group| .. }
each_cons(${1:2}) { |${2:group}| ${0} }
snippet eai
each_index { |${1:i}| ${0} }
snippet eaid
each_index do |${1:i}|
${0}
end
snippet eak
each_key { |${1:key}| ${0} }
snippet eakd
each_key do |${1:key}|
${0}
end
snippet eal
each_line { |${1:line}| ${0} }
snippet eald
each_line do |${1:line}|
${0}
end
snippet eap
each_pair { |${1:name}, ${2:val}| ${0} }
snippet eapd
each_pair do |${1:name}, ${2:val}|
${0}
end
snippet eas-
each_slice(${1:2}) { |${2:group}| ${0} }
snippet easd-
each_slice(${1:2}) do |${2:group}|
${0}
end
snippet eav
each_value { |${1:val}| ${0} }
snippet eavd
each_value do |${1:val}|
${0}
end
snippet eawi
each_with_index { |${1:e}, ${2:i}| ${0} }
snippet eawid
each_with_index do |${1:e}, ${2:i}|
${0}
end
snippet eawo
each_with_object(${1:init}) { |${2:e}, ${3:var}| ${0} }
snippet eawod
each_with_object(${1:init}) do |${2:e}, ${3:var}|
${0}
end
snippet reve
reverse_each { |${1:e}| ${0} }
snippet reved
reverse_each do |${1:e}|
${0}
end
snippet inj
inject(${1:init}) { |${2:mem}, ${3:var}| ${0} }
snippet injd
inject(${1:init}) do |${2:mem}, ${3:var}|
${0}
end
snippet red
reduce(${1:init}) { |${2:mem}, ${3:var}| ${0} }
snippet redd
reduce(${1:init}) do |${2:mem}, ${3:var}|
${0}
end
snippet map
map { |${1:e}| ${0} }
snippet mapd
map do |${1:e}|
${0}
end
snippet mapwi-
enum_with_index.map { |${1:e}, ${2:i}| ${0} }
snippet sor
sort { |a, b| ${0} }
snippet sorb
sort_by { |${1:e}| ${0} }
snippet ran
sort_by { rand }
snippet all
all? { |${1:e}| ${0} }
snippet any
any? { |${1:e}| ${0} }
snippet cl
classify { |${1:e}| ${0} }
snippet col
collect { |${1:e}| ${0} }
snippet cold
collect do |${1:e}|
${0}
end
snippet det
detect { |${1:e}| ${0} }
snippet detd
detect do |${1:e}|
${0}
end
snippet fet
fetch(${1:name}) { |${2:key}| ${0} }
snippet fin
find { |${1:e}| ${0} }
snippet find
find do |${1:e}|
${0}
end
snippet fina
find_all { |${1:e}| ${0} }
snippet finad
find_all do |${1:e}|
${0}
end
snippet gre
grep(${1:/pattern/}) { |${2:match}| ${0} }
snippet sub
${1:g}sub(${2:/pattern/}) { |${3:match}| ${0} }
snippet sca
scan(${1:/pattern/}) { |${2:match}| ${0} }
snippet scad
scan(${1:/pattern/}) do |${2:match}|
${0}
end
snippet max
max { |a, b| ${0} }
snippet min
min { |a, b| ${0} }
snippet par
partition { |${1:e}| ${0} }
snippet pard
partition do |${1:e}|
${0}
end
snippet rej
reject { |${1:e}| ${0} }
snippet rejd
reject do |${1:e}|
${0}
end
snippet sel
select { |${1:e}| ${0} }
snippet seld
select do |${1:e}|
${0}
end
snippet lam
lambda { |${1:args}| ${0} }
# I'm pretty sure that ruby users expect do to expand to do .. end
snippet do
do
${0}
end
# this is for one or more variables. typing a ", " is that cheap that it may
# not be worth adding another snippet. should 0/1 placeholders change order?
# its a good idea to think about the var name, so use it first
snippet dov
do |${1:v}|
${2}
end
snippet :
:${1:key} => ${2:"value"}
snippet ope
open(${1:"path/or/url/or/pipe"}, "${2:w}") { |${3:io}| ${0} }
# path_from_here()
snippet fpath
File.join(File.dirname(__FILE__), *%2[${1:rel path here}])
# unix_filter {}
snippet unif
ARGF.each_line${1} do |${2:line}|
${0}
end
# option_parse {}
snippet optp
require "optparse"
options = {${0:default => "args"}}
ARGV.options do |opts|
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)}
snippet opt
opts.on( "-${1:o}", "--${2:long-option-name}", ${3:String},
"${4:Option description.}") do |${5:opt}|
${0}
end
snippet tc
require "test/unit"
require "${1:library_file_name}"
class Test${2:$1} < Test::Unit::TestCase
def test_${3:case_name}
${0}
end
end
snippet ts
require "test/unit"
require "tc_${1:test_case_file}"
require "tc_${2:test_case_file}"
snippet as
assert ${1:test}, "${2:Failure message.}"
snippet ase
assert_equal ${1:expected}, ${2:actual}
snippet asne
assert_not_equal ${1:unexpected}, ${2:actual}
snippet asid
assert_in_delta ${1:expected_float}, ${2:actual_float}, ${3:2 ** -20}
snippet asi
assert_includes ${1:collection}, ${2:object}
snippet asio
assert_instance_of ${1:ExpectedClass}, ${2:actual_instance}
snippet asko
assert_kind_of ${1:ExpectedKind}, ${2:actual_instance}
snippet asn
assert_nil ${1:instance}
snippet asnn
assert_not_nil ${1:instance}
snippet asm
assert_match /${1:expected_pattern}/, ${2:actual_string}
snippet asnm
assert_no_match /${1:unexpected_pattern}/, ${2:actual_string}
snippet aso
assert_operator ${1:left}, :${2:operator}, ${3:right}
snippet asr
assert_raise ${1:Exception} { ${0} }
snippet asrd
assert_raise ${1:Exception} do
${0}
end
snippet asnr
assert_nothing_raised ${1:Exception} { ${0} }
snippet asnrd
assert_nothing_raised ${1:Exception} do
${0}
end
snippet asrt
assert_respond_to ${1:object}, :${2:method}
snippet ass assert_same(..)
assert_same ${1:expected}, ${2:actual}
snippet ass assert_send(..)
assert_send [${1:object}, :${2:message}, ${3:args}]
snippet asns
assert_not_same ${1:unexpected}, ${2:actual}
snippet ast
assert_throws :${1:expected} { ${0} }
snippet astd
assert_throws :${1:expected} do
${0}
end
snippet asnt
assert_nothing_thrown { ${0} }
snippet asntd
assert_nothing_thrown do
${0}
end
snippet fl
flunk "${1:Failure message.}"
# Benchmark.bmbm do .. end
snippet bm-
TESTS = ${1:10_000}
Benchmark.bmbm do |results|
${0}
end
snippet rep
results.report("${1:name}:") { TESTS.times { ${0} }}
# Marshal.dump(.., file)
snippet Md
File.open(${1:"path/to/file.dump"}, "wb") { |${2:file}| Marshal.dump(${3:obj}, $2) }
# Mashal.load(obj)
snippet Ml
File.open(${1:"path/to/file.dump"}, "rb") { |${2:file}| Marshal.load($2) }
# deep_copy(..)
snippet deec
Marshal.load(Marshal.dump(${1:obj_to_copy}))
snippet Pn-
PStore.new(${1:"file_name.pstore"})
snippet tra
transaction(${1:true}) { ${0} }
# xmlread(..)
snippet xml-
REXML::Document.new(File.read(${1:"path/to/file"}))
# xpath(..) { .. }
snippet xpa
elements.each(${1:"//Xpath"}) do |${2:node}|
${0}
end
# class_from_name()
snippet clafn
split("::").inject(Object) { |par, const| par.const_get(const) }
# singleton_class()
snippet sinc
class << self; self end
snippet nam
namespace :${1:`vim_snippets#Filename()`} do
${0}
end
snippet tas
desc "${1:Task description}"
task :${2:task_name => [:dependent, :tasks]} do
${0}
end
# block
snippet b
{ |${1:var}| ${0} }
snippet begin
begin
raise 'A test exception.'
rescue Exception => e
puts e.message
puts e.backtrace.inspect
else
# other exception
ensure
# always executed
end
#debugging
snippet debug
require 'ruby-debug'; debugger; true;
snippet pry
require 'pry'; binding.pry
snippet strf
strftime("${1:%Y-%m-%d %H:%M:%S %z}")${0}
#############################################
# Rails snippets - for pure Ruby, see above #
#############################################
snippet art
assert_redirected_to ${1::action => "${2:index}"}
snippet artnp
assert_redirected_to ${1:parent}_${2:child}_path(${3:@$1}, ${0:@$2})
snippet artnpp
assert_redirected_to ${1:parent}_${2:child}_path(${0:@$1})
snippet artp
assert_redirected_to ${1:model}_path(${0:@$1})
snippet artpp
assert_redirected_to ${0:model}s_path
snippet asd
assert_difference "${1:Model}.${2:count}", ${3:1} do
${0}
end
snippet asnd
assert_no_difference "${1:Model}.${2:count}" do
${0}
end
snippet asre
assert_response :${1:success}, @response.body
snippet asrj
assert_rjs :${1:replace}, "${0:dom id}"
snippet ass assert_select(..)
assert_select '${1:path}', :${2:text} => '${3:inner_html' ${4:do}
snippet ba
before_action :${0:method}
snippet bf
before_filter :${0:method}
snippet bt
belongs_to :${0:association}
snippet btp
belongs_to :${1:association}, :polymorphic => true
snippet crw
cattr_accessor :${0:attr_names}
snippet defcreate
def create
@${1:model_class_name} = ${2:ModelClassName}.new(params[:$1])
respond_to do |format|
if @$1.save
flash[:notice] = '$2 was successfully created.'
format.html { redirect_to(@$1) }
format.xml { render :xml => @$1, :status => :created, :location => @$1 }
else
format.html { render :action => "new" }
format.xml { render :xml => @$1.errors, :status => :unprocessable_entity }
end
end
end
snippet defdestroy
def destroy
@${1:model_class_name} = ${2:ModelClassName}.find(params[:id])
@$1.destroy
respond_to do |format|
format.html { redirect_to($1s_url) }
format.xml { head :ok }
end
end
snippet defedit
def edit
@${1:model_class_name} = ${0:ModelClassName}.find(params[:id])
end
snippet defindex
def index
@${1:model_class_name} = ${2:ModelClassName}.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @$1s }
end
end
snippet defnew
def new
@${1:model_class_name} = ${2:ModelClassName}.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @$1 }
end
end
snippet defshow
def show
@${1:model_class_name} = ${2:ModelClassName}.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @$1 }
end
end
snippet defupdate
def update
@${1:model_class_name} = ${2:ModelClassName}.find(params[:id])
respond_to do |format|
if @$1.update_attributes(params[:$1])
flash[:notice] = '$2 was successfully updated.'
format.html { redirect_to(@$1) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @$1.errors, :status => :unprocessable_entity }
end
end
end
snippet dele delegate .. to
delegate :${1:methods}, :to => :${0:object}
snippet dele delegate .. to .. prefix .. allow_nil
delegate :${1:methods}, :to => :${2:object}, :prefix => :${3:prefix}, :allow_nil => ${0:allow_nil}
snippet flash
flash[:${1:notice}] = "${0}"
snippet habtm
has_and_belongs_to_many :${1:object}, :join_table => "${2:table_name}", :foreign_key => "${3}_id"
snippet hm
has_many :${0:object}
snippet hmd
has_many :${1:other}s, :class_name => "${2:$1}", :foreign_key => "${3:$1}_id", :dependent => :destroy
snippet hmt
has_many :${1:object}, :through => :${0:object}
snippet ho
has_one :${0:object}
snippet hod
has_one :${1:object}, dependent: :${0:destroy}
snippet i18
I18n.t('${1:type.key}')
snippet ist
<%= image_submit_tag("${1:agree.png}", :id => "${2:id}"${0} %>
snippet log
Rails.logger.${1:debug} ${0}
snippet log2
RAILS_DEFAULT_LOGGER.${1:debug} ${0}
snippet logd
logger.debug { "${1:message}" }
snippet loge
logger.error { "${1:message}" }
snippet logf
logger.fatal { "${1:message}" }
snippet logi
logger.info { "${1:message}" }
snippet logw
logger.warn { "${1:message}" }
snippet mapc
${1:map}.${2:connect} '${0:controller/:action/:id}'
snippet mapca
${1:map}.catch_all "*${2:anything}", :controller => "${3:default}", :action => "${4:error}"
snippet mapr
${1:map}.resource :${0:resource}
snippet maprs
${1:map}.resources :${0:resource}
snippet mapwo
${1:map}.with_options :${2:controller} => '${3:thing}' do |$3|
${0}
end
###############################
# model callback snippets #
###############################
# before callback
snippet mbv
before_validation :${0:method}
snippet mbc
before_create :${0:method}
snippet mbu
before_update :${0:method}
snippet mbs
before_save :${0:method}
snippet mbd
before_destroy :${0:method}
# after callback
snippet mav
after_validation :${0:method}
snippet maf
after_find :${0:method}
snippet mat
after_touch :${0:method}
snippet macr
after_create :${0:method}
snippet mau
after_update :${0:method}
snippet mas
after_save :${0:method}
snippet mad
after_destroy :${0:method}
# around callback
snippet marc
around_create :${0:method}
snippet maru
around_update :${0:method}
snippet mars
around_save :${0:method}
snippet mard
around_destroy :${0:method}
snippet mcht
change_table :${1:table_name} do |t|
${0}
end
snippet mp
map(&:${0:id})
snippet mrw
mattr_accessor :${0:attr_names}
snippet oa
order("${0:field}")
snippet od
order("${0:field} DESC")
snippet pa
params[:${1:id}]
snippet ra
render :action => "${0:action}"
snippet ral
render :action => "${1:action}", :layout => "${0:layoutname}"
snippet rest
respond_to do |format|
format.${1:html} { ${0} }
end
snippet rf
render :file => "${0:filepath}"
snippet rfu
render :file => "${1:filepath}", :use_full_path => ${0:false}
snippet ri
render :inline => "${0:<%= 'hello' %>}"
snippet ril
render :inline => "${1:<%= 'hello' %>}", :locals => { ${2::name} => "${3:value}"${0} }
snippet rit
render :inline => "${1:<%= 'hello' %>}", :type => ${0::rxml}
snippet rjson
render :json => ${0:text to render}
snippet rl
render :layout => "${0:layoutname}"
snippet rn
render :nothing => ${0:true}
snippet rns
render :nothing => ${1:true}, :status => ${0:401}
snippet rp
render :partial => "${0:item}"
snippet rpc
render :partial => "${1:item}", :collection => ${0:@$1s}
snippet rpl
render :partial => "${1:item}", :locals => { :${2:$1} => ${0:@$1}
snippet rpo
render :partial => "${1:item}", :object => ${0:@$1}
snippet rps
render :partial => "${1:item}", :status => ${0:500}
snippet rt
render :text => "${0:text to render}"
snippet rtl
render :text => "${1:text to render}", :layout => "${0:layoutname}"
snippet rtlt
render :text => "${1:text to render}", :layout => ${0:true}
snippet rts
render :text => "${1:text to render}", :status => ${0:401}
snippet ru
render :update do |${1:page}|
$1.${0}
end
snippet rxml
render :xml => ${0:text to render}
snippet sc
scope :${1:name}, -> { where(${2:field}: ${0:value}) }
snippet sl
scope :${1:name}, lambda do |${2:value}|
where("${3:field = ?}", ${0:bind var})
end
snippet sha1
Digest::SHA1.hexdigest(${0:string})
snippet sweeper
class ${1:ModelClassName}Sweeper < ActionController::Caching::Sweeper
observe $1
def after_save(${0:model_class_name})
expire_cache($2)
end
def after_destroy($2)
expire_cache($2)
end
def expire_cache($2)
expire_page
end
end
snippet va validates_associated
validates_associated :${0:attribute}
snippet va validates .., :acceptance => true
validates :${0:terms}, :acceptance => true
snippet vc
validates :${0:attribute}, :confirmation => true
snippet ve
validates :${1:attribute}, :exclusion => { :in => ${0:%w( mov avi )} }
snippet vf
validates :${1:attribute}, :format => { :with => /${0:regex}/ }
snippet vi
validates :${1:attribute}, :inclusion => { :in => %w(${0: mov avi }) }
snippet vl
validates :${1:attribute}, :length => { :in => ${2:3}..${0:20} }
snippet vn
validates :${0:attribute}, :numericality => true
snippet vp
validates :${0:attribute}, :presence => true
snippet vu
validates :${0:attribute}, :uniqueness => true
snippet format
format.${1:js|xml|html} { ${0} }
snippet wc
where(${1:"conditions"}${0:, bind_var})
snippet wf
where(${1:field} => ${0:value})
snippet xdelete
xhr :delete, :${1:destroy}, :id => ${2:1}
snippet xget
xhr :get, :${1:show}, :id => ${2:1}
snippet xpost
xhr :post, :${1:create}, :${2:object} => { ${0} }
snippet xput
xhr :put, :${1:update}, :id => ${2:1}, :${3:object} => { ${4} }
snippet test
test "should ${1:do something}" do
${0}
end
###########################
# migrations snippets #
###########################
snippet mac
add_column :${1:table_name}, :${2:column_name}, :${0:data_type}
snippet mai
add_index :${1:table_name}, :${0:column_name}
snippet mrc
remove_column :${1:table_name}, :${0:column_name}
snippet mrnc
rename_column :${1:table_name}, :${2:old_column_name}, :${0:new_column_name}
snippet mcc
change_column :${1:table}, :${2:column}, :${0:type}
snippet mnc
t.${1:string} :${2:title}${3:, null: false}
snippet mct
create_table :${1:table_name} do |t|
${0}
end
snippet migration class .. < ActiveRecord::Migration .. def up .. def down .. end
class ${1:class_name} < ActiveRecord::Migration
def up
${0}
end
def down
end
end
snippet migration class .. < ActiveRecord::Migration .. def change .. end
class ${1:class_name} < ActiveRecord::Migration
def change
${0}
end
end
snippet trc
t.remove :${0:column}
snippet tre
t.rename :${1:old_column_name}, :${2:new_column_name}
${0}
snippet tref
t.references :${0:model}
snippet tcb
t.boolean :${1:title}
${0}
snippet tcbi
t.binary :${1:title}, :limit => ${2:2}.megabytes
${0}
snippet tcd
t.decimal :${1:title}, :precision => ${2:10}, :scale => ${3:2}
${0}
snippet tcda
t.date :${1:title}
${0}
snippet tcdt
t.datetime :${1:title}
${0}
snippet tcf
t.float :${1:title}
${0}
snippet tch
t.change :${1:name}, :${2:string}, :${3:limit} => ${4:80}
${0}
snippet tci
t.integer :${1:title}
${0}
snippet tcl
t.integer :lock_version, :null => false, :default => 0
${0}
snippet tcr
t.references :${1:taggable}, :polymorphic => { :default => '${2:Photo}' }
${0}
snippet tcs
t.string :${1:title}
${0}
snippet tct
t.text :${1:title}
${0}
snippet tcti
t.time :${1:title}
${0}
snippet tcts
t.timestamp :${1:title}
${0}
snippet tctss
t.timestamps
${0}
##########################
# Rspec snippets #
##########################
snippet desc
describe ${1:`substitute(substitute(vim_snippets#Filename(), '_spec$', '', ''), '\(_\|^\)\(.\)', '\u\2', 'g')`} do
${0}
end
snippet descm
describe "${1:#method}" do
${0:pending "Not implemented"}
end
snippet cont
context "${1:message}" do
${0}
end
snippet bef
before :${1:each} do
${0}
end
snippet aft
after :${1:each} do
${0}
end
snippet let
let(:${1:object}) { ${0} }
snippet let!
let!(:${1:object}) { ${0} }
snippet subj
subject { ${0} }
snippet s.
subject.${0:method}
snippet spec
specify { subject.${0} }
snippet exp
expect(${1:object}).to ${0}
snippet expb
expect { ${1:object} }.to ${0}
snippet experr
expect { ${1:object} }.to raise_error ${2:StandardError}, /${0:message_regex}/
snippet shared
shared_examples ${0:"shared examples name"}
snippet ibl
it_behaves_like ${0:"shared examples name"}
snippet it
it "${1:spec_name}" do
${0}
end
snippet its
its(:${1:method}) { should ${0} }
snippet is
it { should ${0} }
snippet isn
it { should_not ${0} }
#ShouldaMatchers#ActionController
snippet isfp
it { should filter_param :${0:key} }
snippet isrt
it { should redirect_to ${0:url} }
snippet isrtp
it { should render_template ${0} }
snippet isrwl
it { should render_with_layout ${0} }
snippet isrf
it { should rescue_from ${0:exception} }
snippet isrw
it { should respond_with ${0:status} }
snippet isr
it { should route(:${1:method}, '${0:path}') }
snippet isss
it { should set_session :${0:key} }
snippet issf
it { should set_the_flash('${0}') }
#ShouldaMatchers#ActiveModel
snippet isama
it { should allow_mass_assignment_of :${0} }
snippet isav
it { should allow_value(${1}).for :${0} }
snippet isee
it { should ensure_exclusion_of :${0} }
snippet isei
it { should ensure_inclusion_of :${0} }
snippet isel
it { should ensure_length_of :${0} }
snippet isva
it { should validate_acceptance_of :${0} }
snippet isvc
it { should validate_confirmation_of :${0} }
snippet isvn
it { should validate_numericality_of :${0} }
snippet isvp
it { should validate_presence_of :${0} }
snippet isvu
it { should validate_uniqueness_of :${0} }
#ShouldaMatchers#ActiveRecord
snippet isana
it { should accept_nested_attributes_for :${0} }
snippet isbt
it { should belong_to :${0} }
snippet isbtcc
it { should belong_to(:${1}).counter_cache ${0:true} }
snippet ishbtm
it { should have_and_belong_to_many :${0} }
snippet isbv
it { should be_valid }
snippet ishc
it { should have_db_column :${0} }
snippet ishi
it { should have_db_index :${0} }
snippet ishm
it { should have_many :${0} }
snippet ishmt
it { should have_many(:${1}).through :${0} }
snippet isho
it { should have_one :${0} }
snippet ishro
it { should have_readonly_attribute :${0} }
snippet iss
it { should serialize :${0} }
snippet isres
it { should respond_to :${0} }
snippet isresw
it { should respond_to(:${1}).with(${0}).arguments }
snippet super_call
${1:super_class}.instance_method(:${0:method}).bind(self).call
|