Class: MercuryConfig

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

Constant Summary collapse

JQUERY =
"jquery"
SENCHA =
"sencha"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ MercuryConfig

Returns a new instance of MercuryConfig.



7
8
9
10
11
12
13
14
# File 'lib/mercury_config.rb', line 7

def initialize(args)
  @project = args.first
  @stack = JQUERY
  if args.first and args.first.split(':')[0] == "stack"
    @project = args.last
    @stack = args.first.split(':')[1] == SENCHA ? SENCHA : JQUERY
  end
end

Instance Attribute Details

#projectObject

Returns the value of attribute project.



5
6
7
# File 'lib/mercury_config.rb', line 5

def project
  @project
end

#stackObject

Returns the value of attribute stack.



5
6
7
# File 'lib/mercury_config.rb', line 5

def stack
  @stack
end

Instance Method Details

#apply_stackObject



28
29
30
31
32
33
34
# File 'lib/mercury_config.rb', line 28

def apply_stack
  if @stack == SENCHA
    FileUtils.cp_r File.dirname(__FILE__) + '/../lib/sencha/.', FileUtils.pwd + "/#{@project}/wwwroot"
  else
    FileUtils.cp_r File.dirname(__FILE__) + '/../lib/public/.', FileUtils.pwd + "/#{@project}/wwwroot"
  end
end

#create_projectObject



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

def create_project
  # Build Directory and add setup files
  FileUtils.mkdir_p @project
  FileUtils.mkdir_p File.join(@project, 'wwwroot')
  FileUtils.mkdir_p File.join(@project, 'tmp')

  config_ru = ["require 'mercury'","log = File.new('tmp/mercury.log', 'a+')", "$stdout.reopen(log)", "$stderr.reopen(log)", "run Mercury"].join("\n")
  File.open(File.join(@project, 'config.ru'),'w').write(config_ru)
  gemfile = ['source :gemcutter', "gem 'thin'", "gem 'mercury'"].join("\n")
  File.open(File.join(@project, 'Gemfile'),'w').write(gemfile)
end