Class: Capigen::Config
- Inherits:
-
Object
- Object
- Capigen::Config
- Defined in:
- lib/capigen/config.rb
Overview
Configuration
Instance Attribute Summary collapse
-
#application ⇒ Object
Returns the value of attribute application.
-
#db_host ⇒ Object
Returns the value of attribute db_host.
-
#db_name ⇒ Object
Returns the value of attribute db_name.
-
#db_pass ⇒ Object
Returns the value of attribute db_pass.
-
#db_port ⇒ Object
Returns the value of attribute db_port.
-
#db_user ⇒ Object
Returns the value of attribute db_user.
-
#deploy_to ⇒ Object
Returns the value of attribute deploy_to.
-
#domain_name ⇒ Object
Returns the value of attribute domain_name.
-
#mongrel_port ⇒ Object
Returns the value of attribute mongrel_port.
-
#mongrel_size ⇒ Object
Returns the value of attribute mongrel_size.
-
#recipes ⇒ Object
Returns the value of attribute recipes.
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#sphinx_host ⇒ Object
Returns the value of attribute sphinx_host.
-
#sphinx_port ⇒ Object
Returns the value of attribute sphinx_port.
-
#user ⇒ Object
Returns the value of attribute user.
-
#web_host ⇒ Object
Returns the value of attribute web_host.
Instance Method Summary collapse
- #ask(message, property, options = {}, &block) ⇒ Object
-
#ask_all(auto_apply = false) ⇒ Object
Build config from asking.
-
#get_binding ⇒ Object
Expose the binding.
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #save(path) ⇒ Object
- #set_default(property, value) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
14 15 |
# File 'lib/capigen/config.rb', line 14 def initialize end |
Instance Attribute Details
#application ⇒ Object
Returns the value of attribute application.
7 8 9 |
# File 'lib/capigen/config.rb', line 7 def application @application end |
#db_host ⇒ Object
Returns the value of attribute db_host.
8 9 10 |
# File 'lib/capigen/config.rb', line 8 def db_host @db_host end |
#db_name ⇒ Object
Returns the value of attribute db_name.
8 9 10 |
# File 'lib/capigen/config.rb', line 8 def db_name @db_name end |
#db_pass ⇒ Object
Returns the value of attribute db_pass.
8 9 10 |
# File 'lib/capigen/config.rb', line 8 def db_pass @db_pass end |
#db_port ⇒ Object
Returns the value of attribute db_port.
8 9 10 |
# File 'lib/capigen/config.rb', line 8 def db_port @db_port end |
#db_user ⇒ Object
Returns the value of attribute db_user.
8 9 10 |
# File 'lib/capigen/config.rb', line 8 def db_user @db_user end |
#deploy_to ⇒ Object
Returns the value of attribute deploy_to.
7 8 9 |
# File 'lib/capigen/config.rb', line 7 def deploy_to @deploy_to end |
#domain_name ⇒ Object
Returns the value of attribute domain_name.
12 13 14 |
# File 'lib/capigen/config.rb', line 12 def domain_name @domain_name end |
#mongrel_port ⇒ Object
Returns the value of attribute mongrel_port.
11 12 13 |
# File 'lib/capigen/config.rb', line 11 def mongrel_port @mongrel_port end |
#mongrel_size ⇒ Object
Returns the value of attribute mongrel_size.
11 12 13 |
# File 'lib/capigen/config.rb', line 11 def mongrel_size @mongrel_size end |
#recipes ⇒ Object
Returns the value of attribute recipes.
10 11 12 |
# File 'lib/capigen/config.rb', line 10 def recipes @recipes end |
#repository ⇒ Object
Returns the value of attribute repository.
10 11 12 |
# File 'lib/capigen/config.rb', line 10 def repository @repository end |
#sphinx_host ⇒ Object
Returns the value of attribute sphinx_host.
9 10 11 |
# File 'lib/capigen/config.rb', line 9 def sphinx_host @sphinx_host end |
#sphinx_port ⇒ Object
Returns the value of attribute sphinx_port.
9 10 11 |
# File 'lib/capigen/config.rb', line 9 def sphinx_port @sphinx_port end |
#user ⇒ Object
Returns the value of attribute user.
7 8 9 |
# File 'lib/capigen/config.rb', line 7 def user @user end |
#web_host ⇒ Object
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(, property, = {}, &block) # Options default = [:default] || nil answer_type = [:answer_type] || String auto_apply = [: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(, 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) = { :auto_apply => auto_apply } ask("Application name: ", "application", ) ask("User (to run application as): ", "user", .merge({ :default => application })) ask("Deploy to: ", "deploy_to", .merge({ :default => "/var/www/apps/#{application}" })) ask("Web host: ", "web_host", ) ask("Database host: ", "db_host", .merge({ :default => web_host })) ask("Database user: ", "db_user", .merge({ :default => user })) ask("Database password: ", "db_pass", ) ask("Database name: ", "db_name", .merge({ :default => application })) ask("Database port: ", "db_port", .merge({ :default => 3306, :answer_type => Integer })) ask("Sphinx host: ", "sphinx_host", .merge({ :default => "127.0.0.1" })) ask("Sphinx port: ", "sphinx_port", .merge({ :default => 3312, :answer_type => Integer })) default_repos = YAML.load(`svn info`)["URL"] rescue nil ask("Repository uri: ", "repository", .merge({ :default => default_repos })) ask("Mongrel starting port: ", "mongrel_port", .merge({ :answer_type => Integer })) ask("Number of mongrels: ", "mongrel_size", .merge({ :answer_type => Integer })) ask("Domain name (for nginx vhost; no www prefix): ", "domain_name", ) # Load default recipes if not set set_default("recipes", YAML.load_file(File.dirname(__FILE__) + "/recipes.yml")) end |
#get_binding ⇒ Object
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 |