Class: Cear::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/cear/project.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(__app_name = nil) ⇒ Project

Returns a new instance of Project.



23
24
25
# File 'lib/cear/project.rb', line 23

def initialize(__app_name = nil)
	@app_name = __app_name
end

Class Method Details

.run(__app_name) ⇒ Object



45
46
47
# File 'lib/cear/project.rb', line 45

def self.run(__app_name)
	Cear::Project.new(__app_name).run
end

Instance Method Details

#runObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cear/project.rb', line 49

def run
	if @app_name == nil
		@app_name = AskQuestion.new("What is the project name?").ask
	end
	CearConfig.include_pg      = AskQuestion.new("Do you want to include pg?", "N/y").ask == 'y'
	CearConfig.include_redis   = AskQuestion.new("Do you want to include redis?", "N/y").ask == 'y'
	CearConfig.include_rake    = AskQuestion.new("Do you want to include rake?", "N/y").ask == 'y'
	CearConfig.include_advance = AskQuestion.new("Do you want advance mode ? (included subdirectories 'app', 'log', 'tmp')", "N/y").ask == 'y'
	@app_name = @app_name.underscore.gsub(' ', '_')

	Dir.mkdir(@app_name) unless ::File.exists?(@app_name)
	Dir.chdir(@app_name) do |dir|
		Cear::File.run('Gemfile', header: false)
		Cear::File.run(@app_name + '.rb')
		Cear::File.run('console.rb')

		directories = ['config', 'lib']
		directories << 'db' if CearConfig.include_pg
		directories += ['app', 'log', 'tmp'] if CearConfig.include_advance
		puts "Create directories | #{directories.join(' - ')}".light_green

		directories.each do |subdirectory|
			Dir.mkdir(subdirectory) unless ::File.exists?(subdirectory)
		end

		Dir.chdir('config') do |dir|
			Cear::File.run('environment.rb')
			Cear::File.run('application.rb')
			Cear::File.run('database.yaml', header: false) if CearConfig.include_pg
		end

		if @include_rake
			Cear::File.run('Rakefile')
		end
		run_bundle
	end
end

#run_bundleObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cear/project.rb', line 27

def run_bundle
	puts "Run bundle install...".yellow
	begin
	  PTY.spawn("bundle") do |stdout, stdin, pid|
	    begin
	      # Do stuff with the output here. Just printing to show it works
	      stdout.each { |line| print line;STDOUT.flush }
	    rescue Errno::EIO
	      puts "Errno:EIO error, but this probably just means " +
	            "that the process has finished giving output"
	    end
	  end
	rescue PTY::ChildExited
	  puts "The child process exited!"
	end
	puts "Run bundle install OK".green
end