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
- #to_json ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize(string, options) ⇒ File
Returns a new instance of File.
17 18 19 20 21 22 |
# File 'lib/hsql/file.rb', line 17 def initialize(string, ) @string = string = .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 |
#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 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.
27 28 29 |
# File 'lib/hsql/file.rb', line 27 def self.parse(string, ) new(string, ).parse! end |
.parse_file(file, options) ⇒ Object
31 32 33 |
# File 'lib/hsql/file.rb', line 31 def self.parse_file(file, ) parse(file.read, ) end |
Instance Method Details
#metadata ⇒ Object
43 44 45 |
# File 'lib/hsql/file.rb', line 43 def ||= @front_matter ? ::YAML.load(@front_matter) : {} end |
#parse! ⇒ Object
51 52 53 54 55 |
# File 'lib/hsql/file.rb', line 51 def parse! split! interpolate_data! self end |
#queries ⇒ Object
47 48 49 |
# File 'lib/hsql/file.rb', line 47 def queries @queries ||= Query.parse(@rendered_sql) end |
#to_json ⇒ Object
39 40 41 |
# File 'lib/hsql/file.rb', line 39 def to_json .to_json end |
#to_yaml ⇒ Object
35 36 37 |
# File 'lib/hsql/file.rb', line 35 def to_yaml .to_yaml end |