Sha256: 3aaf270ce4630d34f9174e33bfe9271d443bb216d18cdf06479e68d7be3065ad
Contents?: true
Size: 1.74 KB
Versions: 1
Compression:
Stored size: 1.74 KB
Contents
module Clearest class TemplatesGenerator < AbstractGenerator def initialize(_options = {}) super _options fullpath = "#{@options[:target_path]}" @options[:test_db_filename] ||= '/tmp/clearest.db' @options[:template_map].each do |template,list| file_target = (@options[:table_name])? template.sub('TABLE_NAME', @options[:table_name]) : template generator = Template::new :list_token => list, :template_file => "#{@template_root}/#{template}.tpl" @options[:model_name] = DataMapper::Inflector.singularize _options[:table_name].capitalize if _options[:table_name] _data = @options.dup _data.each {|item,value| _data.delete item unless list.include? item.to_sym} if template == 'models/TABLE_NAME.rb' then models = @@dm.auto_genclass! :storages => @options[:table_name], :scope => Object _data[:model_definition] = models.first.to_source end fixtures = AutoFixtures::new(_options) if _options[:table_name] if template == 'spec/TABLE_NAME_spec.rb' then [:first_obj,:second_obj].each do |obj| _data[obj] = fixtures.to_s end field,type = fixtures.get_field new_fixture = fixtures.get_value_for :field => field _data[:updated_field] = ":#{field.to_s}" if ['Float','Decimal','Integer'].include? type then _data[:new_value] = "#{new_fixture}" else _data[:new_value] = "'#{new_fixture}'" end end generator.map _data puts " #{'staging'.colorize(:light_green)} (template) #{fullpath}/#{file_target}" File.open("#{fullpath}/#{file_target}", 'w') { |file| file.write(generator.output) } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
clearest-0.0.1a | lib/clearest/generators/5_templates.rb |