How to use Ruby API for defining

The following features have been implemented, and how to use them?  Thanks!

  • Ruby API for defining dynamic types
  • Ruby API for defining native sources
Comment actions Permalink
  • Ruby API for defining native sources

Sorry I didn't understand this

  • Ruby API for defining dynamic types

Ok I'll show you how to map type to existing method (1) and how to define dynamic method (2).
1. RM cannot infer type of method Date.strptime thus let's fix it
2. Lets add to autocompletion/resolve our be_rubymine fake RSpec matcher

Picture 6.png
(On the screenshot autocompletion doesn't work after date.<caret> (line 5) and be_rubymine isn't in autocompletion (line 12)

# type for method require 'date' dob = "08/04/1975" date = Date.strptime(dob, "%m/%d/%Y") puts date.month # dynamic method require 'spec' describe "doo" do   it "should smth" do     be_rubymine   end end


1. Let's create some folder(e.g. rm_ext) and RubyMine project for it.
2. Let's create ruby script  (e.g. scripts/dynamic_defs.rb) which will contain definitions for types/dynamic methods

Picture 7.png
3. Now let's ask RubyMine to load dynamic_defs.rb file on each startup. For this add folder  rm_ext/scripts to  File | Settings | Script Folders

Picture 8.png
4. Now let's register dynamic types and methods. Open "dynamic_defs.rb"
At current moment RubyMine doesn't add api folder to load path, but we will fix in next builds.
So let's add string

$: << "/Applications/idea/RubyMine 2.0"

5. Then ask RubyMine's code insight to use extended load path. Add "/Applications/idea/RubyMine 2.0" to File | Settings | Project Structure | Load Path
Picture 9.png

require 'code_insight/code_insight_helper'

7. Register type for existing method Date.strptime

describe "Date" do   set_return_type "strptime" => "Date" end

8. Register dynamic method "be_rubymine" and link to existing

describe "Spec::Matchers" do   set_dynamic_methods :methods => "be_rubymine", :method_to_resolve => "" end

Picture 10.png

9. Restart RubyMine

10. Let's create test file "foo_spec.rb" mentioned after tasks #1, #2. And all works!

Place caret after "date."
Picture 15.png
Place caret on "date" and invoke Quick Documentation Lookup
Picture 12.png

Picture 13.png
Invoke Quick Definition Lookup on be_rubymine
Picture 16.png

Also you can consider as examples:

RubyMine 2.0
RubyMine 2.0

Comment actions Permalink

It is great, thanks.   I will take a try.

Comment actions Permalink


$: << "/Applications/idea/RubyMine 2.0"

wont be required in next RM 2.0 build

Comment actions Permalink


RubyMine 2.0.1 will automatically extend extension scripts load path with [RubyMine]/rb/api and [RubyMine]/rb/scripts directories


Please sign in to leave a comment.