Sha256: 29d90e69a0415a00b3c83c39fc79bd03c8480913360596a70e8878e6bb755185

Contents?: true

Size: 1.59 KB

Versions: 21

Compression:

Stored size: 1.59 KB

Contents

require_relative 'destroy-controller'
require_relative 'destroy-helper'
require_relative 'destroy-model'
require 'eucalypt/app'
require 'eucalypt/helpers'

module Eucalypt
  class Destroy < Thor
    include Eucalypt::Helpers
    using Colorize

    desc "scaffold [NAME]", "Destroys a scaffold".colorize(:grey)
    def scaffold(name = nil)
      directory = File.expand_path('.')
      if Eucalypt.app? directory
        scaffolds = Dir[File.join directory, 'app', '{controllers,models,helpers}', '*.rb'].map do |f|
          File.basename(f).split(?_).first.split(?.).first
        end

        scaffolds.reject!{|f|f == 'application'}
        scaffolds.uniq!

        if scaffolds.empty?
          Eucalypt::Error.no_scaffolds
          return
        end

        if name

          if scaffolds.include? name
            controller(name)
            helper(name)
            model(name)
          else
            Eucalypt::Error.no_scaffolds
          end

        else

          scaffolds_hash = {}
          scaffold_numbers = []

          scaffolds.each_with_index do |scaffold, i|
            scaffold_numbers << (i+1).to_s
            scaffolds_hash[(i+1).to_s.to_sym] = scaffold
            puts "\e[1m#{i+1}\e[0m: #{scaffold}"
          end

          scaffold_number = ask("\nEnter the number of the scaffold to delete:", limited_to: scaffold_numbers)
          scaffold_name = scaffolds_hash[scaffold_number.to_sym]

          controller(scaffold_name)
          helper(scaffold_name)
          model(scaffold_name)

        end

      else
        Eucalypt::Error.wrong_directory
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
eucalypt-0.5.4 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.5.3 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.5.2 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.5.1 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.5.0 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.4.2 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.4.1 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.4.0 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.3.5 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.3.4 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.3.3 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.3.2 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.3.1 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.3.0 lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.2.2 lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.2.1 lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.2.0 lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.1.3 lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.1.2 lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-scaffold.rb
eucalypt-0.1.1 lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-scaffold.rb