Class: HSQL::File
- Inherits:
-
Object
- Object
- HSQL::File
- Defined in:
- lib/hsql/file.rb
Overview
HSQL::File parses the input file and provides reader methods to the hash of YAML data from the front matter section and a list of the queries in the SQL portion.
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#rendered_sql ⇒ Object
readonly
Returns the value of attribute rendered_sql.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
- .parse(source, options) ⇒ Object
-
.parse_file(filename, options) ⇒ Object
Given a SQL file with YAML front matter (see README for an example) this will return a HSQL::File object providing access to the parts of that file.
Instance Method Summary collapse
-
#initialize(string, options) ⇒ File
constructor
A new instance of File.
- #metadata ⇒ Object
- #parse! ⇒ Object
- #queries ⇒ Object
Constructor Details
#initialize(string, options) ⇒ File
Returns a new instance of File.
13 14 15 16 17 18 |
# File 'lib/hsql/file.rb', line 13 def initialize(string, ) @string = string @timestamp = .fetch(:timestamp, Time.current) @environment = [:environment] @verbose = [:verbose] end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
11 12 13 |
# File 'lib/hsql/file.rb', line 11 def environment @environment end |
#rendered_sql ⇒ Object (readonly)
Returns the value of attribute rendered_sql.
11 12 13 |
# File 'lib/hsql/file.rb', line 11 def rendered_sql @rendered_sql end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
11 12 13 |
# File 'lib/hsql/file.rb', line 11 def string @string end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
11 12 13 |
# File 'lib/hsql/file.rb', line 11 def @timestamp end |
Class Method Details
.parse(source, options) ⇒ Object
27 28 29 |
# File 'lib/hsql/file.rb', line 27 def self.parse(source, ) new(source, ).parse! end |
.parse_file(filename, options) ⇒ Object
Given a SQL file with YAML front matter (see README for an example) this will return a HSQL::File object providing access to the parts of that file.
23 24 25 |
# File 'lib/hsql/file.rb', line 23 def self.parse_file(filename, ) parse(::File.read(filename), ) end |
Instance Method Details
#metadata ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/hsql/file.rb', line 35 def @metadata ||= begin hash = @front_matter ? ::YAML.load(@front_matter) : {} environments = hash.delete('environments') || {} hash.merge(environments[environment] || {}) end end |
#parse! ⇒ Object
47 48 49 50 51 |
# File 'lib/hsql/file.rb', line 47 def parse! split! self end |