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.
Defined Under Namespace
Classes: FormatError
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
-
.parse(string, options) ⇒ Object
Given the contents of 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.
- .parse_file(file, options) ⇒ Object
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.
15 16 17 18 19 |
# File 'lib/hsql/file.rb', line 15 def initialize(string, ) @string = string = .fetch(:timestamp, Time.current) @environment = [:environment] end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
9 10 11 |
# File 'lib/hsql/file.rb', line 9 def environment @environment end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
9 10 11 |
# File 'lib/hsql/file.rb', line 9 def string @string end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
9 10 11 |
# File 'lib/hsql/file.rb', line 9 def end |
Class Method Details
.parse(string, options) ⇒ Object
Given the contents of 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.
24 25 26 |
# File 'lib/hsql/file.rb', line 24 def self.parse(string, ) new(string, ).parse! end |
.parse_file(file, options) ⇒ Object
28 29 30 |
# File 'lib/hsql/file.rb', line 28 def self.parse_file(file, ) parse(file.read, ) end |
Instance Method Details
#metadata ⇒ Object
32 33 34 |
# File 'lib/hsql/file.rb', line 32 def ||= @front_matter ? ::YAML.load(@front_matter) : {} end |
#parse! ⇒ Object
40 41 42 43 44 |
# File 'lib/hsql/file.rb', line 40 def parse! split! interpolate_data! self end |
#queries ⇒ Object
36 37 38 |
# File 'lib/hsql/file.rb', line 36 def queries @queries ||= Query.parse(@rendered_sql) end |