Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Example .vimrc projections, including projections for Active Model Serializers, Draper, and FactoryGirl

View .vimrc
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
let g:rails_projections = {
\ "config/projections.json": {
\ "command": "projections"
\ },
\ "spec/features/*_spec.rb": {
\ "command": "feature",
\ "template": "require 'spec_helper'\n\nfeature '%h' do\n\nend",
\ }}
 
let g:rails_gem_projections = {
\ "active_model_serializers": {
\ "app/serializers/*_serializer.rb": {
\ "command": "serializer",
\ "affinity": "model",
\ "test": "spec/serializers/%s_spec.rb",
\ "related": "app/models/%s.rb",
\ "template": "class %SSerializer < ActiveModel::Serializer\nend"
\ }
\ },
\ "draper": {
\ "app/decorators/*_decorator.rb": {
\ "command": "decorator",
\ "affinity": "model",
\ "test": "spec/decorators/%s_spec.rb",
\ "related": "app/models/%s.rb",
\ "template": "class %SDecorator < Draper::Decorator\nend"
\ }
\ },
\ "factory_girl_rails": {
\ "spec/factories.rb": {
\ "command": "factories",
\ "template": "FactoryGirl.define do\nend"
\ }
\ }}
pjg commented

For FactoryGirl I recommend a much more useful configuration:

let g:rails_projections = {
      \ "test/factories/*.rb": {
      \   "command":   "factory",
      \   "affinity":  "collection",
      \   "alternate": "app/models/%i.rb",
      \   "related":   "db/schema.rb#%s",
      \   "test":      "test/models/%i_test.rb",
      \   "template":  "FactoryGirl.define do\n  factory :%i do\n  end\nend",
      \   "keywords":  "factory sequence"
      \ },
      \ "spec/factories/*.rb": {
      \   "command":   "factory",
      \   "affinity":  "collection",
      \   "alternate": "app/models/%i.rb",
      \   "related":   "db/schema.rb#%s",
      \   "test":      "spec/models/%i_test.rb",
      \   "template":  "FactoryGirl.define do\n  factory :%i do\n  end\nend",
      \   "keywords":  "factory sequence"
      \ }
      \}

Reference: https://github.com/pjg/dotfiles/blob/ee204acfb3bcf21823ba75d8b738a05b30f26d55/.vimrc#L282-302

henrik commented

@pjg Does "related": "db/schema.rb#%s" work as expected? I assume it's meant to jump to that line.

I'm trying

  "app/models/*.rb": {
    "command": "model",
    "affinity": "model",
    "alternate": ["unit/models/%s_spec.rb", "spec/models/%s_spec.rb"],
    "related": "db/schema.rb#%s",
    "template": "class %S\nend"
  },

because I want custom test paths. :R opens schema.rb but doesn't jump to any line in particular.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.