Sha256: 668047446479ecf910dc9a7c166331f6c0d3374de0f66ba520d775051b27c324

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

require 'ftools'
require File.dirname(__FILE__) + '/../lib/dconstants'

module Decoct

    include Decoct::Dconstants
    
    # move the creation into a module and just include that module
    class Dscript
      
      attr_accessor :app_name

      def initialize(app_name)
        fail "app name cannot be nil or empty!!!" if app_name.eql?(nil) || app_name.empty?
        @app_name = app_name      
      end

      def run
        create_app_dir
        create_lib
        create_spec
        create_views
        create_public
        copy_autotest_file
        copy_rspec_files
        create_app_file
      end
      
      def create_lib
        create_dir(Dconstants::LIB)  
      end

      def create_spec
        create_dir(Dconstants::SPEC)  
      end

      def create_views
        create_dir(Dconstants::VIEWS)  
      end

      def create_public
        create_dir(Dconstants::PUBLIC)  
      end
      
      def copy_autotest_file
        copy_file(".autotest", "#{app_name}/.autotest") 
      end
      
      def copy_rspec_files
        copy_file("spec/spec.opts", "#{app_name}/spec/spec.opts")
        copy_file("spec/rcov.opts", "#{app_name}/spec/rcov.opts")
        copy_file("spec/spec_helper.rb", "#{app_name}/spec/spec_helper.rb")
      end

      def create_app_file
        copy_file("generic_app.rb", "#{app_name}/#{app_name}.rb")        
      end
      
      def create_app_dir
        create_dir          
      end
      
      private

      def create_dir(value = '')
        path = "#{app_name}/#{value}"
        Dir.mkdir(path) if !test(?d, path) 
      end

      def copy_file(from, to)
        File.copy(Dconstants::TEMPLATES + from, to)
      end

    end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
andhapp-decoct-1.2.0 lib/dscript.rb
andhapp-decoct-1.3.0 lib/dscript.rb