lib/generators/effective/helpers.rb in effective_developer-0.0.9 vs lib/generators/effective/helpers.rb in effective_developer-0.0.10

- old
+ new

@@ -34,11 +34,11 @@ def invoked_attributes_args invoked_attributes.present? ? (['--attributes'] + invoked_attributes) : [] end - def klass_attributes + def klass_attributes(verbose: true) klass = class_name.safe_constantize return [] unless klass begin attributes = klass.new().attributes @@ -52,16 +52,23 @@ end begin attributes = klass.new().attributes rescue => e - puts "Unable to call #{class_name}.new().attributes. Continuing with empty attributes." + puts "Unable to call #{class_name}.new().attributes. Continuing with empty attributes." if verbose return [] end - (attributes.keys - [klass.primary_key, 'created_at', 'updated_at']).map do |attr| - "#{attr}:#{klass.column_for_attribute(attr).type || 'string'}" + attribute_names = attributes.keys - [klass.primary_key, 'created_at', 'updated_at'] + attribute_names -= ['site_id'] if klass.respond_to?(:is_site_specific) + + attribute_names.map do |attr| + if klass.respond_to?(:column_for_attribute) # Rails 4+ + "#{attr}:#{klass.column_for_attribute(attr).try(:type) || 'string'}" + else + "#{attr}:#{klass.columns_hash[attr].try(:type) || 'string'}" + end end end def parent_class_name options[:parent] || (Rails::VERSION::MAJOR > 4 ? 'ApplicationRecord' : 'ActiveRecord::Base') @@ -92,22 +99,22 @@ singular_name.classify.pluralize end end def index_path - [namespace_path.underscore.presence, plural_name].compact.join('_') + '_path' + [namespace_path.underscore.presence, plural_name, 'path'].compact.join('_') end def new_path - ['new', namespace_path.underscore.presence, singular_name].compact.join('_') + '_path' + ['new', namespace_path.underscore.presence, singular_name, 'path'].compact.join('_') end def edit_path "edit_#{show_path}" end def show_path - [namespace_path.underscore.presence, singular_name].compact.join('_') + "_path(@#{singular_name})" + [namespace_path.underscore.presence, singular_name, 'path', "(@#{singular_name})"].compact.join('_') end end end end