Git Product home page Git Product logo

solargraph-rails's Introduction

Solargraph::Rails - Help solargraph with Rails

Models

Given a typical Rails model like this:

# == Schema Information
#
# Table name: my_books
#
#  id         :integer          not null, primary key
#  author     :string
#  name       :string
#  created_at :datetime         not null
#  updated_at :datetime         not null
#
class MyBook < ApplicationRecord
  def my_method
    "hello"
  end

  ...

end

The various Ruby intellisense tools are ok at knowing that there is a MyBook constant, and some (including Solargraph) are aware that objects like MyBook.new have a method .my_method. But what about those magical dynamic attributes that ActiveRecord creates when Rails starts up? You can see these listed at the top of the file under # == Schema Information, the comments helpfully added by the Annotate gem.

Since these attributes are only created at runtime, static analysis alone can't identify them. Your editor has no idea that these attributes exist, but they're amongst the most common things that you will work with in any Rails app.

That's where this plugin for Solargraph comes in: it parses the database schema and YARD docs of various gems to give Solargraph some extra hints. For instance database attributes:

Go to attribute schema definition

... or ActiveRecord finders:

ActiveRecord method support

... or associations:

Association support

... or routes file:

Routes file support

and more!

Installation

Install solargraph and solargraph-rails

If you add them to your Gemfile, you'll have to tell your IDE plugin to use bundler to load the right version of solargraph.

Add solargraph-rails to your .solargraph.yml

(if you don't have a .solargraph.yml in your project root, you can run solargraph config to add one)

plugins:
  - solargraph-rails

Build YARD docs

In the project root, run yard gems.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/iftheshoefritz/solargraph_rails.

  1. create fork and clone the repo

  2. install gem deps bundle install

  3. install dummy rails app deps and build the yard cache:

$ cd spec/rails5
$ bundle install && yard gems
$ cd ../../

(and the same for rails 6 and rails 7)

  1. now tests should pass locally and you can try different changes

  2. sumbit PR

License

The gem is available as open source under the terms of the MIT License.

solargraph-rails's People

Contributors

alisnic avatar chiastolite avatar gracepetryk avatar grncdr avatar iftheshoefritz avatar isimluk avatar julianrubisch avatar mathias234 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.