class SBConstants::ObjcConstantWriter

Attributes

templates_dir[R]

Public Class Methods

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

Public Instance Methods

default_templates_dir() click to toggle source
# File lib/sbconstants/objc_constant_writer.rb, line 20
def default_templates_dir
  @default_templates_dir ||= File.dirname(__FILE__) + '/templates'
end
header() click to toggle source
# File lib/sbconstants/objc_constant_writer.rb, line 24
def header
  template_with_file "@import Foundation;\n\n", File.open(template_file_path("objc_header.erb")).read
end
implementation() click to toggle source
# File lib/sbconstants/objc_constant_writer.rb, line 28
def implementation
  head = %Q{#import "<%= File.basename(options.output_path) %>.h"\n\n}
  template_with_file head, File.open(template_file_path("objc_implementation.erb")).read
end
present_constants(section) click to toggle source
# File lib/sbconstants/objc_constant_writer.rb, line 40
def present_constants(section)
  section.constants.map { |constant| [ sanitise_key(constant), constant ] }
end
template_file_path(basename) click to toggle source
# File lib/sbconstants/objc_constant_writer.rb, line 44
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/objc_constant_writer.rb, line 33
def template_with_file head, body
  @head = head
  @body = body
  pre_processed_template = ERB.new(File.open(template_file_path("objc_body.erb")).read, nil, '<>').result(binding)
  ERB.new(pre_processed_template, nil, '<>').result(binding)
end
write() click to toggle source
# File lib/sbconstants/objc_constant_writer.rb, line 15
def write
  @int_out.puts header
  @imp_out.puts implementation
end