module Kriangle::Generators::GeneratorHelpers
Some helpers for generating scaffolding
Constants
- Association
- Attribute
Attributes
attributes[RW]
options[RW]
Private Instance Methods
create_migration_file(migration_fname, fname, **options)
click to toggle source
# File lib/generators/kriangle/generator_helpers.rb, line 64 def create_migration_file(migration_fname, fname, **options) @options = options if @options[:skip_if_exist] && self.class.migration_exists?('db/migrate', fname.split('/').last.gsub('.rb', '')) say_status('skipped', "Migration '#{fname}' already exists") else migration_template migration_fname, fname, options end end
create_template(template_fname, fname, **options)
click to toggle source
# File lib/generators/kriangle/generator_helpers.rb, line 55 def create_template(template_fname, fname, **options) @options = options if @options[:skip_if_exist] && File.exist?(File.join(destination_root, fname)) say_status 'skipped', fname else template template_fname, fname end end
editable_attributes()
click to toggle source
# File lib/generators/kriangle/generator_helpers.rb, line 49 def editable_attributes attributes ||= model_columns_for_attributes.map do |column| Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s) end end
get_attribute_name(name, attribute_type)
click to toggle source
# File lib/generators/kriangle/generator_helpers.rb, line 81 def get_attribute_name(name, attribute_type) attribute_type == 'references' ? "#{name}_id" : name end
get_attribute_type(attribute_type)
click to toggle source
# File lib/generators/kriangle/generator_helpers.rb, line 89 def get_attribute_type(attribute_type) column_type = @@column_types[attribute_type.to_sym] column_type.present? ? column_type : attribute_type.to_s.camelcase end
get_record_invalid_exception()
click to toggle source
# File lib/generators/kriangle/generator_helpers.rb, line 77 def get_record_invalid_exception custom_orm == 'Mongoid' ? 'Mongoid::Errors::InvalidFind' : 'ActiveRecord::RecordInvalid' end
get_record_not_found_exception()
click to toggle source
# File lib/generators/kriangle/generator_helpers.rb, line 73 def get_record_not_found_exception custom_orm == 'Mongoid' ? 'Mongoid::Errors::DocumentNotFound' : 'ActiveRecord::RecordNotFound' end
model_columns_for_attributes()
click to toggle source
# File lib/generators/kriangle/generator_helpers.rb, line 43 def model_columns_for_attributes class_name.constantize.columns.reject do |column| column.name.to_s =~ /^(id|user_id|created_at|updated_at)$/ end end
require_or_optional(attribute)
click to toggle source
# File lib/generators/kriangle/generator_helpers.rb, line 85 def require_or_optional(attribute) attribute.validate_presence == 'true' ? 'requires' : 'optional' end