require 'rails/generators/active_record' module ActiveDataFrame class InstallGenerator < ActiveRecord::Generators::Base desc "Generates a new data_frame type" STREAM_TYPES = %w(bit byte integer long float double) # Commandline options can be defined here using Thor-like options: argument :type, :type => :string, :default => 'float', :desc => "DataFrame type. One of(#{STREAM_TYPES*" ,"})" argument :columns, :type => :numeric, :default => 512, :desc => "Number of columns" argument :inject, type: :array, default: [] def self.source_root @source_root ||= File.join(File.dirname(__FILE__), 'templates') end def generate_model invoke "active_record:model", ["blocks/#{singular_block_table_name}"], migration: false end def block_type "#{singular_table_name}_block".camelize end def block_table_name "#{singular_table_name}_blocks" end def singular_block_table_name "#{singular_table_name}_block" end def concern_name "Has#{singular_table_name.camelize}" end def concern_file_name "has_#{singular_table_name}" end def inject_concern_content inject.each do |inject_into| content = " include #{concern_name}\n" class_name = inject_into.camelize inject_into_class(self.class.path_for_model(inject_into), class_name, content) if self.class.model_exists?(inject_into, destination_root) end end def get_typecode case type when "float", "double" then M::Typecode::FLOAT when "integer", "long" then M::Typecode::INT when "bit", "byte" then M::Typecode::BYTE end end def inject_data_frame_helpers content = \ <