class Blueprinter::Generators::BlueprintGenerator

def association_blueprint(association_name)

def association_blueprint(association_name)
  ", blueprint: #{association_class(association_name)}"
end

def association_class(association_name)

def association_class(association_name)
  introspected_name = if introspected_associations[association_name].respond_to?(:klass)
                        introspected_associations[association_name].klass.to_s
                      end
  "#{introspected_name || association_name.camelcase}Blueprint"
end

def associations

def associations
  as = if options['detect_associations']
         Array.new(options['associations']).concat(introspected_associations.keys)
       else
         options['associations']
       end
  as.reject(&:blank?).uniq
end

def create_blueprint

def create_blueprint
  template 'blueprint.rb', File.join(path, "#{file_path}_blueprint.rb")
end

def ensure_blueprint_dir

def ensure_blueprint_dir
  FileUtils.mkdir_p(path) unless File.directory?(path)
end

def fields

def fields
  fs = if options['detect_fields']
         Array.new(options['fields']).concat(introspected_fields)
       else
         options['fields']
       end
  fs.reject(&:blank?).uniq
end

def formatted_fields

split at wrap_at chars, two indentations
def formatted_fields
  two_indents = indent * 2
  fields_string = fields.each_with_object([]) do |f, memo|
    if memo.last.nil?
      memo << " :#{f},"
    else
      now = "#{memo.last} :#{f},"
      if now.length > options['wrap_at'].to_i
        memo << ":#{f},"
      else
        memo[memo.length - 1] = now
      end
    end
  end.join("\n#{two_indents}")
  fields_string[0, fields_string.length - 1]
end

def identifier_symbol

def identifier_symbol
  return unless options['identifier']
  options['identifier'] == 'identifier' ? :id : options['identifier']
end

def indent

def indent
  user_intended = { two: '  ', four: '    ', tab: "\t" }[options['indentation'].intern]
  user_intended.nil? ? '  ' : user_intended
end

def introspected_associations

def introspected_associations
  class_name.constantize.reflections
end

def introspected_fields

def introspected_fields
  class_name.constantize.columns_hash.keys
end

def path

def path
  options['blueprints_dir']
end