Sha256: d23cb6225c2a1bdb18b54c28556cb28c66558bad6f8ba0e745c65e3535c3aa62
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
require 'nrb/commands/inside_group' module Nrb module Commands class Destroy < InsideGroup desc_with_warning "Destroy a generated resource" argument :resource, type: :string, required: true, desc: 'resource to destroy', banner: 'RESOURCE', enum: Nrb.config.directories.map(&:singularize) argument :name, type: :string, required: true, desc: 'name of the resource', banner: 'NAME' def valid_resource? valid_resources = Nrb.config.directories.map(&:singularize) return if valid_resources.include? resource say "RESOURCE must be one of: #{valid_resources.join(', ')}." exit end def generate_resource remove_file target("#{name.underscore}.rb") # Also remove the *_create_resource migration if resource == 'model' migration_file = Dir["db/migrate/*create_#{name.underscore.pluralize}.rb"].first remove_file migration_file if migration_file end end private def target(final = nil) File.join(File.expand_path(resource.pluralize), final.to_s) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nrb-1.0.0 | lib/nrb/commands/destroy.rb |