Class: HSQL::File

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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, options)
  @string = string
  @timestamp = options.fetch(:timestamp, Time.current)
  @environment = options[:environment]
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



9
10
11
# File 'lib/hsql/file.rb', line 9

def environment
  @environment
end

#stringObject (readonly)

Returns the value of attribute string.



9
10
11
# File 'lib/hsql/file.rb', line 9

def string
  @string
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



9
10
11
# File 'lib/hsql/file.rb', line 9

def timestamp
  @timestamp
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, options)
  new(string, options).parse!
end

.parse_file(file, options) ⇒ Object



28
29
30
# File 'lib/hsql/file.rb', line 28

def self.parse_file(file, options)
  parse(file.read, options)
end

Instance Method Details

#metadataObject



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

#queriesObject



36
37
38
# File 'lib/hsql/file.rb', line 36

def queries
  @queries ||= Query.parse(@rendered_sql)
end