Class: DatabaseSchemaOwnership::Parser
- Inherits:
-
Object
- Object
- DatabaseSchemaOwnership::Parser
- Defined in:
- lib/database_schema_ownership/parser.rb,
lib/database_schema_ownership/parser/sql_parser.rb,
lib/database_schema_ownership/parser/ruby_parser.rb
Overview
:nodoc:
Direct Known Subclasses
Defined Under Namespace
Classes: RubyParser, SqlParser
Instance Attribute Summary collapse
-
#schema_path ⇒ Object
Returns the value of attribute schema_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(schema_path) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #schema ⇒ Object
Constructor Details
#initialize(schema_path) ⇒ Parser
Returns a new instance of Parser.
16 17 18 |
# File 'lib/database_schema_ownership/parser.rb', line 16 def initialize(schema_path) @schema_path = schema_path end |
Instance Attribute Details
#schema_path ⇒ Object
Returns the value of attribute schema_path.
14 15 16 |
# File 'lib/database_schema_ownership/parser.rb', line 14 def schema_path @schema_path end |
Class Method Details
.for(extension) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/database_schema_ownership/parser.rb', line 5 def self.for(extension) case extension when ".rb" then RubyParser when ".sql" then SqlParser else raise ArgumentError, "Unsupported schema extension: #{extension}" end end |
Instance Method Details
#parse ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/database_schema_ownership/parser.rb', line 24 def parse rules.flat_map do |rule| schema.scan(rule).map do |s| DatabaseSchemaOwnership::Entity.new(s[1], "#{s[0]}\n") end end end |
#schema ⇒ Object
20 21 22 |
# File 'lib/database_schema_ownership/parser.rb', line 20 def schema @schema ||= File.read(schema_path) end |