Sha256: c0a9559d4886f98c64fee87edc2d3f94322c4a7ba614f3dd78fec46dc868c0b1

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require 'moblues/version'
require 'moblues/data_model'
require 'moblues/reader'
require 'moblues/generator'

module Moblues
  extend self

  def generate(model, human_dir, machine_dir, lang = :objc)
    mkdir([human_dir, machine_dir])
    reader    = Moblues::Reader::Model.new
    generator = generator(human_dir, machine_dir, lang)
    entities  = reader.model(model)
    generator.generate(entities)
  end

  private
  def mkdir(dirs)
    dirs.each do |dir|
      Dir.mkdir(dir) unless Dir.exists?(dir)
    end
  end

  def generator(human_dir, machine_dir, lang)
    base_params = { human_dir:   human_dir,
                    machine_dir: machine_dir }
    case lang
    when :swift
      additional_params = { human:   Moblues::Generator::Swift::Human.new,
                            machine: Moblues::Generator::Swift::Machine.new }
    when :objc
      additional_params = { human:   Moblues::Generator::Objc::Human.new,
                            machine: Moblues::Generator::Objc::Machine.new }
    else
      raise ArgumentError.new("Language #{lang} is not supported")
    end
    Moblues::Generator::Base::Model.new(base_params.merge(additional_params))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
moblues-0.4.0 lib/moblues.rb
moblues-0.3.0 lib/moblues.rb
moblues-0.2.0 lib/moblues.rb