class Sqlpp11gen::Generators::TabGenerator
Public Class Methods
new(args, *options)
click to toggle source
Calls superclass method
# File lib/generators/sqlpp11gen/tab_generator.rb, line 20 def initialize(args, *options) super(args, *options) initialize_views_variables end
source_root()
click to toggle source
# File lib/generators/sqlpp11gen/tab_generator.rb, line 16 def self.source_root @source_root ||= File.join(File.dirname(__FILE__), 'templates') end
Public Instance Methods
create_cxx_header_file()
click to toggle source
# File lib/generators/sqlpp11gen/tab_generator.rb, line 25 def create_cxx_header_file tableklass = table_name.to_s.singularize.camelize.constantize ctx = ::CxxesContext.new ctx.tablename = table_name ctx.tableklass = tableklass ctx.cols = tableklass.columns template = File.read(File.join(File.dirname(__FILE__), "templates", "index.h.erb")) path = output_path || 'app/cxxes' prefix = filename_prefix || 'tab_' ext = filename_ext || 'hpp' create_file "#{path}/#{prefix}#{file_name}.#{ext}", ERB.new(template).result(ctx.template_binding) end
Protected Instance Methods
columns()
click to toggle source
# File lib/generators/sqlpp11gen/tab_generator.rb, line 49 def columns retrieve_columns.reject {|c| excluded?(c.name) }.map do |c| new_attribute(c.name, c.type.to_s) end end
excluded?(name)
click to toggle source
# File lib/generators/sqlpp11gen/tab_generator.rb, line 70 def excluded?(name) excluded_columns_names.include?(name) || excluded_columns_pattern.any? {|p| name =~ p } || excluded_columns.include?(name) end
excluded_columns()
click to toggle source
# File lib/generators/sqlpp11gen/tab_generator.rb, line 66 def excluded_columns options['excluded_columns']||[] end
excluded_columns_names()
click to toggle source
# File lib/generators/sqlpp11gen/tab_generator.rb, line 55 def excluded_columns_names %w[_id _type id created_at updated_at] end
excluded_columns_pattern()
click to toggle source
# File lib/generators/sqlpp11gen/tab_generator.rb, line 59 def excluded_columns_pattern [ /.*_checksum/, /.*_count/, ] end
initialize_views_variables()
click to toggle source
# File lib/generators/sqlpp11gen/tab_generator.rb, line 46 def initialize_views_variables end
new_attribute(name, type)
click to toggle source
# File lib/generators/sqlpp11gen/tab_generator.rb, line 88 def new_attribute(name, type) ::Rails::Generators::GeneratedAttribute.new(name, type) end
rescue_block(exception=Exception) { || ... }
click to toggle source
# File lib/generators/sqlpp11gen/tab_generator.rb, line 92 def rescue_block(exception=Exception) yield if block_given? rescue exception => e say e.message, :red exit end
retrieve_columns()
click to toggle source
# File lib/generators/sqlpp11gen/tab_generator.rb, line 76 def retrieve_columns if defined?(ActiveRecord) == "constant" && ActiveRecord.class == Module rescue_block ActiveRecord::StatementInvalid do @model_name.constantize.columns end else rescue_block do @model_name.constantize.fields.map {|c| c[1] } end end end