Class: Decoct::Dscript

Inherits:
Object
  • Object
show all
Includes:
Dmeta
Defined in:
lib/decoct/dscript.rb

Constant Summary

Constants included from Dconstants

Decoct::Dconstants::LIB, Decoct::Dconstants::PUBLIC, Decoct::Dconstants::SPEC, Decoct::Dconstants::TEMPLATES, Decoct::Dconstants::VIEWS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Dmeta

#copy_file, included

Constructor Details

#initialize(app_name) ⇒ Dscript

Returns a new instance of Dscript.



11
12
13
14
# File 'lib/decoct/dscript.rb', line 11

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

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



7
8
9
# File 'lib/decoct/dscript.rb', line 7

def app_name
  @app_name
end

Instance Method Details

#copy_app_fileObject



47
48
49
50
# File 'lib/decoct/dscript.rb', line 47

def copy_app_file
  copy_file("generic_app.rb", "#{app_name}#{File::SEPARATOR}#{app_name}.rb")
  puts "\nCopied application file" 
end

#copy_autotest_fileObject



32
33
34
35
# File 'lib/decoct/dscript.rb', line 32

def copy_autotest_file
  copy_file(".autotest", "#{app_name}#{File::SEPARATOR}.autotest")
  puts "\nCopied autotest files" 
end

#copy_rspec_filesObject



37
38
39
40
41
42
43
44
45
# File 'lib/decoct/dscript.rb', line 37

def copy_rspec_files
	from = ["spec#{File::SEPARATOR}spec.opts", "spec#{File::SEPARATOR}rcov.opts", "spec#{File::SEPARATOR}spec_helper.rb", "spec#{File::SEPARATOR}app_spec.rb"]
	to = ["#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}spec.opts", "#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}rcov.opts", "#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}spec_helper.rb", "#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}#{app_name}_spec.rb"]
	copy_file(from, to)
  
  file_string = File.open("#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}spec_helper.rb") {|f| f.readlines.unshift("require '#{app_name}'\n").join } 
 File.open("#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}spec_helper.rb", "w") {|f| f << file_string}
	puts "\nCopied rspec files" 
end

#create_app_dirObject



27
28
29
30
# File 'lib/decoct/dscript.rb', line 27

def create_app_dir
  Dir.mkdir("#{app_name}") if !test(?d, "#{app_name}")
  puts "\nCreated application directory - #{app_name}"
end

#runObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/decoct/dscript.rb', line 16

def run
  create_app_dir
  create_lib
  create_spec
  create_views
  create_public
  copy_autotest_file
  copy_rspec_files
  copy_app_file
end