Class: Solargraph::Rails::Schema
- Inherits:
-
Object
- Object
- Solargraph::Rails::Schema
- Defined in:
- lib/solargraph/rails/schema.rb
Defined Under Namespace
Classes: ColumnData
Constant Summary collapse
- RUBY_TYPES =
{ decimal: 'BigDecimal', float: 'BigDecimal', integer: 'Integer', date: 'Date', datetime: 'ActiveSupport::TimeWithZone', string: 'String', boolean: 'Boolean', text: 'String', jsonb: 'Hash', json: 'Hash', bigint: 'Integer', uuid: 'String', inet: 'IPAddr', citext: 'String', binary: 'String', timestamp: 'ActiveSupport::TimeWithZone' }
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Schema
constructor
A new instance of Schema.
- #process(source_map, ns) ⇒ Object
Constructor Details
#initialize ⇒ Schema
Returns a new instance of Schema.
33 34 35 |
# File 'lib/solargraph/rails/schema.rb', line 33 def initialize @schema_present = File.exist?('db/schema.rb') end |
Class Method Details
.instance ⇒ Object
25 26 27 |
# File 'lib/solargraph/rails/schema.rb', line 25 def self.instance @instance ||= self.new end |
.reset ⇒ Object
29 30 31 |
# File 'lib/solargraph/rails/schema.rb', line 29 def self.reset @instance = nil end |
Instance Method Details
#process(source_map, ns) ⇒ Object
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 |
# File 'lib/solargraph/rails/schema.rb', line 37 def process(source_map, ns) return [] unless @schema_present return [] unless Model.valid_filename?(source_map.filename) table = find_table(source_map, ns) return [] unless table pins = table.map do |column, data| Util.build_public_method( ns, column, types: [RUBY_TYPES.fetch(data.type.to_sym)], location: Util.build_location(data.ast, 'db/schema.rb') ) end if pins.any? Solargraph.logger.debug( "[Rails][Schema] added #{pins.map(&:name)} to #{ns.path}" ) end pins end |