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) ⇒ Render

Returns a new instance of Render.



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

def initialize(name, config)
  @name = name
  @config = config
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_lineObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/squasher/render.rb', line 20

def each_schema_line
  File.open(config.schema_file, 'r') do |stream|
    inside_schema = false
    stream.each_line do |line|
      if inside_schema
        next if line.empty?
        # reach eand of schema
        break if line.index("end") == 0
        yield line[2...-1]
      else
        inside_schema = true if line.include?("ActiveRecord::Schema")
      end
    end
  end
end

#renderObject



16
17
18
# File 'lib/squasher/render.rb', line 16

def render
  ERB.new(template("#{ name }.rb"), nil, '-').result(binding)
end