class SBConstants::SwiftConstantWriter

Attributes

templates_dir[R]

Public Class Methods

new(data_source, swift_out, templates_dir) click to toggle source
Calls superclass method
# File lib/sbconstants/swift_constant_writer.rb, line 8
def initialize data_source, swift_out, templates_dir
  super data_source
  @swift_out = swift_out
  @templates_dir = templates_dir
end

Public Instance Methods

default_templates_dir() click to toggle source
# File lib/sbconstants/swift_constant_writer.rb, line 20
def default_templates_dir
  @default_templates_dir ||= File.dirname(__FILE__) + '/templates'
end
template_file_path(basename) click to toggle source
# File lib/sbconstants/swift_constant_writer.rb, line 31
def template_file_path basename
  if templates_dir && File.exist?("#{templates_dir}/#{basename}")
    "#{templates_dir}/#{basename}"
  else
    "#{default_templates_dir}/#{basename}"
  end
end
template_with_file(head, body) click to toggle source
# File lib/sbconstants/swift_constant_writer.rb, line 24
def template_with_file head, body
  @head = head
  @body = body
  pre_processed_template = ERB.new(File.open(template_file_path("swift_body.erb")).read, nil, '<>').result(binding)
  ERB.new(pre_processed_template, nil, '<>').result(binding)
end
write() click to toggle source
# File lib/sbconstants/swift_constant_writer.rb, line 14
def write
  head = %Q{\nimport Foundation"\n}
  body = %Q{    case <%= sanitise_key(constant) %>\n}
  @swift_out.puts template_with_file head, body
end