Class: Squasher::Render

Inherits:
Object
  • Object
show all
Defined in:
lib/squasher/render.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config, database = nil) ⇒ Render

Returns a new instance of Render.



11
12
13
14
15
# File 'lib/squasher/render.rb', line 11

def initialize(name, config, database = nil)
  @name = name
  @config = config
  @database = database
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/squasher/render.rb', line 9

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/squasher/render.rb', line 9

def name
  @name
end

Class Method Details

.render(*args) ⇒ Object



5
6
7
# File 'lib/squasher/render.rb', line 5

def self.render(*args)
  new(*args).render
end

Instance Method Details

#each_schema_line(&block) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/squasher/render.rb', line 25

def each_schema_line(&block)
  File.open(config.schema_file(@database), 'r') do |stream|
    if @config.set?(:sql)
      stream_structure(stream, &block)
    else
      stream_schema(stream, &block)
    end
  end
end

#renderObject



17
18
19
20
21
22
23
# File 'lib/squasher/render.rb', line 17

def render
  if RUBY_VERSION < '2.6'
    ERB.new(template("#{ name }.rb"), nil, '-').result(binding)
  else
    ERB.new(template("#{ name }.rb"), trim_mode: '-').result(binding)
  end
end