Sha256: e8e3632676e626fa3340343ecbf4a922ba10fceca57464a992ed978f809f35c3
Contents?: true
Size: 1.14 KB
Versions: 4
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true module Tiss::Generator class ModelGenerator < BaseGenerator class << self include ActiveSupport::Inflector end MODELS = {} def self.append(version, name, attributes, extension) model = ModelGenerator::MODELS[name.to_sym] || {} model[:attributes] = [] unless model[:attributes].present? model[:attributes] = model[:attributes] + attributes.compact.map { |item| item.merge(version: version) } if extension.present? model[:extension] = { class: extension, file: underscore(extension) } end ModelGenerator::MODELS[name.to_sym] = model end def call template = File.read(File.join(template_dir, 'model_template.erb')) models = ModelGenerator::MODELS models.each_key do |model_name| model_config = models[model_name] attributes = model_config[:attributes].compact.uniq.group_by { |item| item[:name] } file_content = ERB.new(template, nil, '-').result(binding) File.open("lib/tiss/models/#{underscore(model_name.to_s)}.rb", 'w+') do |f| f.write(file_content) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems