Class: Capigen::Config

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

Overview

Configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



14
15
# File 'lib/capigen/config.rb', line 14

def initialize
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



7
8
9
# File 'lib/capigen/config.rb', line 7

def application
  @application
end

#db_hostObject

Returns the value of attribute db_host.



8
9
10
# File 'lib/capigen/config.rb', line 8

def db_host
  @db_host
end

#db_nameObject

Returns the value of attribute db_name.



8
9
10
# File 'lib/capigen/config.rb', line 8

def db_name
  @db_name
end

#db_passObject

Returns the value of attribute db_pass.



8
9
10
# File 'lib/capigen/config.rb', line 8

def db_pass
  @db_pass
end

#db_portObject

Returns the value of attribute db_port.



8
9
10
# File 'lib/capigen/config.rb', line 8

def db_port
  @db_port
end

#db_userObject

Returns the value of attribute db_user.



8
9
10
# File 'lib/capigen/config.rb', line 8

def db_user
  @db_user
end

#deploy_toObject

Returns the value of attribute deploy_to.



7
8
9
# File 'lib/capigen/config.rb', line 7

def deploy_to
  @deploy_to
end

#domain_nameObject

Returns the value of attribute domain_name.



12
13
14
# File 'lib/capigen/config.rb', line 12

def domain_name
  @domain_name
end

#mongrel_portObject

Returns the value of attribute mongrel_port.



11
12
13
# File 'lib/capigen/config.rb', line 11

def mongrel_port
  @mongrel_port
end

#mongrel_sizeObject

Returns the value of attribute mongrel_size.



11
12
13
# File 'lib/capigen/config.rb', line 11

def mongrel_size
  @mongrel_size
end

#recipesObject

Returns the value of attribute recipes.



10
11
12
# File 'lib/capigen/config.rb', line 10

def recipes
  @recipes
end

#repositoryObject

Returns the value of attribute repository.



10
11
12
# File 'lib/capigen/config.rb', line 10

def repository
  @repository
end

#sphinx_hostObject

Returns the value of attribute sphinx_host.



9
10
11
# File 'lib/capigen/config.rb', line 9

def sphinx_host
  @sphinx_host
end

#sphinx_portObject

Returns the value of attribute sphinx_port.



9
10
11
# File 'lib/capigen/config.rb', line 9

def sphinx_port
  @sphinx_port
end

#userObject

Returns the value of attribute user.



7
8
9
# File 'lib/capigen/config.rb', line 7

def user
  @user
end

#web_hostObject

Returns the value of attribute web_host.



7
8
9
# File 'lib/capigen/config.rb', line 7

def web_host
  @web_host
end

Instance Method Details

#ask(message, property, options = {}, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/capigen/config.rb', line 22

def ask(message, property, options = {}, &block)    
  # Options
  default = options[:default] || nil    
  answer_type = options[:answer_type] || String
  auto_apply = options[:auto_apply]
  
  # Default to existing or default if set
  existing = send(property.to_sym)
  default = existing || default
  
  unless auto_apply and !existing.blank?
    result = HighLine.new.ask(message, answer_type) { |q| 
      q.default = default unless default.blank?
      yield q if block_given?
    }

    send("#{property}=", result)
  end
end

#ask_all(auto_apply = false) ⇒ Object

Build config from asking



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
# File 'lib/capigen/config.rb', line 52

def ask_all(auto_apply = false)
  
  options = { :auto_apply => auto_apply }
  
  ask("Application name: ", "application", options)
  ask("User (to run application as): ", "user", options.merge({ :default => application }))
  
  ask("Deploy to: ", "deploy_to", options.merge({ :default => "/var/www/apps/#{application}" }))  
  ask("Web host: ", "web_host", options)
  
  ask("Database host: ", "db_host", options.merge({ :default => web_host }))
  ask("Database user: ", "db_user", options.merge({ :default => user }))
  ask("Database password: ", "db_pass", options)
  ask("Database name: ", "db_name", options.merge({ :default => application }))

  ask("Database port: ", "db_port", options.merge({ :default => 3306, :answer_type => Integer }))
  
  ask("Sphinx host: ", "sphinx_host", options.merge({ :default => "127.0.0.1" }))
  ask("Sphinx port: ", "sphinx_port", options.merge({ :default => 3312, :answer_type => Integer }))
  
  default_repos = YAML.load(`svn info`)["URL"] rescue nil
  ask("Repository uri: ", "repository", options.merge({ :default => default_repos }))
  
  ask("Mongrel starting port: ", "mongrel_port", options.merge({ :answer_type => Integer }))
  ask("Number of mongrels: ", "mongrel_size", options.merge({ :answer_type => Integer }))
  
  ask("Domain name (for nginx vhost; no www prefix): ", "domain_name", options)    
  
  # Load default recipes if not set
  set_default("recipes", YAML.load_file(File.dirname(__FILE__) + "/recipes.yml"))    
end

#get_bindingObject

Expose the binding



18
19
20
# File 'lib/capigen/config.rb', line 18

def get_binding
  binding
end

#save(path) ⇒ Object



47
48
49
# File 'lib/capigen/config.rb', line 47

def save(path)
  File.open(path, "w") { |f| f.puts self.to_yaml }
end

#set_default(property, value) ⇒ Object



42
43
44
45
# File 'lib/capigen/config.rb', line 42

def set_default(property, value)
  v = send(property.to_sym)
  send("#{property}=", value) if v.blank?
end