class Json2erb::Commands

Public Class Methods

new(args = [], options = {}, config = {}) click to toggle source
Calls superclass method
# File lib/json2erb/commands.rb, line 9
def initialize(args = [], options = {}, config = {})
  super(args, options, config)
  @global_options = config[:shell].base.options
end

Public Instance Methods

inline() click to toggle source
# File lib/json2erb/commands.rb, line 17
def inline
  erb = options['erb']
  buffer = options['json'].nil? ? STDIN.read : File.read(options['json'])
  @data = parse_json(buffer)
  puts ERB.new(File.read(erb), nil, '-').result(binding)
end

Private Instance Methods

parse_json(buffer) click to toggle source
# File lib/json2erb/commands.rb, line 26
def parse_json(buffer)
  begin
    data = Yajl::Parser.parse(buffer)
  rescue => e
    data = []
    buffer.split("\n").each do |line|
      data << Yajl::Parser.parse(line)
    end
  end
  data
end