Class: Solargraph::Rails::Annotate
- Inherits:
-
Object
- Object
- Solargraph::Rails::Annotate
- Defined in:
- lib/solargraph/rails/annotate.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Annotate
constructor
A new instance of Annotate.
- #process(source_map, ns) ⇒ Object
Constructor Details
#initialize ⇒ Annotate
Returns a new instance of Annotate.
12 13 14 |
# File 'lib/solargraph/rails/annotate.rb', line 12 def initialize @schema_present = File.exist?('db/schema.rb') end |
Class Method Details
.instance ⇒ Object
4 5 6 |
# File 'lib/solargraph/rails/annotate.rb', line 4 def self.instance @instance ||= self.new end |
.reset ⇒ Object
8 9 10 |
# File 'lib/solargraph/rails/annotate.rb', line 8 def self.reset @instance = nil end |
Instance Method Details
#process(source_map, ns) ⇒ Object
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 |
# File 'lib/solargraph/rails/annotate.rb', line 16 def process(source_map, ns) return [] if @schema_present return [] unless Model.valid_filename?(source_map.filename) pins = [] walker = Walker.from_source(source_map.source) walker.comments.each do |_, snip| name, type = snip.text.gsub(/[\(\),:\d]/, '').split[1..2] next unless name && type ruby_type = Schema::RUBY_TYPES[type.to_sym] next unless ruby_type pins << Util.build_public_method( ns, name, types: [ruby_type], location: Solargraph::Location.new(source_map.filename, snip.range) ) end pins end |