class ActiveQuery::SQLTemplate

Attributes

config[RW]
templates[R]

Public Class Methods

new(config = Configuration.new) click to toggle source
# File lib/active_query/sql_template.rb, line 16
def initialize(config = Configuration.new)
  @config = config
  @templates = []
end

Public Instance Methods

load!() click to toggle source
# File lib/active_query/sql_template.rb, line 21
def load!
        template_path = @config.template_path
        unless File.directory?(template_path) 
                raise TemplatePathError, "error: #{template_path} template path is invalid, please make sure it exists."
        else 
                Find.find(template_path) do |path| 
                        if File.basename(path) =~ /sql$/
                                sql = parse_sql(path)
                                @templates << sql if sql 
                        end
                end
        end
end

Private Instance Methods

parse_sql(path) click to toggle source
# File lib/active_query/sql_template.rb, line 45
def parse_sql(path)
        sql_template = read_sql_file(path: path) 
        begin
                ActiveQuery::SQLParser.parse_query(sql_template)
        rescue ActiveQuery::SQLParser::SyntaxError => err
          $stderr.puts "%p %s:" % [ err.class, err.message ]
        end

end
read_sql_file(path:) click to toggle source
# File lib/active_query/sql_template.rb, line 41
def read_sql_file(path:)
        open(path, "r") { |t| ERB.new(t.read).result(binding) } 
end