Top Level Namespace

Defined Under Namespace

Modules: Capifony, Capistrano

Instance Method Summary collapse

Instance Method Details

#deep_merge(hash1, hash2) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/capifony_symfony1.rb', line 58

def deep_merge(hash1, hash2)

    #if both 'all' and env keys are nil break
    if(hash1 == nil && hash2 == nil)
      return nil
    end

    #the config.yml may not have 'all' key but instead 'dev' 'prod' and so on
    if(hash1 == nil && hash2 != nil)
      return hash2 # no need to merge
    end

    #if only the 'all' key is specified
    #There might not be a second has to cascade to
    if(hash2 == nil && hash1 != nil)
      return hash1;
    end
    hash1.merge(hash2){|key, subhash1, subhash2|
        if (subhash1.is_a?(Hash) && subhash2.is_a?(Hash))
            next deep_merge(subhash1, subhash2)
        end
        subhash2
    }
end

#generate_sql_command(cmd_type, config) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/capifony_symfony1.rb', line 104

def generate_sql_command(cmd_type, config)
    db_type  = config['type']
    cmd_conf = {
      'mysql' => {
        'create' => "mysqladmin -u #{config['user']} --password='#{config['pass']}' create",
        'dump'   => "mysqldump -u #{config['user']} --password='#{config['pass']}'",
        'drop'   => "mysqladmin -f -u #{config['user']} --password='#{config['pass']}' drop",
        'import' => "mysql -u #{config['user']} --password='#{config['pass']}'"
      },
      'pgsql' => {
        'create' => "createdb -U #{config['user']}",
        'dump'   => "pg_dump -U #{config['user']}",
        'drop'   => "dropdb -U #{config['user']}",
        'import' => "psql -U #{config['user']} --password='#{config['pass']}'"
      }
    }

    cmd = cmd_conf[db_type][cmd_type]
    cmd+= " --host=#{config['host']}" if config['host']
    cmd+= " --port=#{config['port']}" if config['port']
    cmd+= " #{config['db']}"

    cmd
end

#guess_symfony_libObject



52
53
54
55
56
# File 'lib/capifony_symfony1.rb', line 52

def guess_symfony_lib
  symfony_version = capture("cd #{latest_release} && #{php_bin} ./symfony -V")

  /\((.*)\)/.match(symfony_version)[1]
end

#guess_symfony_ormObject



42
43
44
45
46
47
48
49
50
# File 'lib/capifony_symfony1.rb', line 42

def guess_symfony_orm
  databases = YAML::load(IO.read('config/databases.yml'))

  if databases[symfony_env_local]
    databases[symfony_env_local].keys[0].to_s
  else
    databases['all'].keys[0].to_s
  end
end

#load_database_config(data, env) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/capifony_symfony1.rb', line 83

def load_database_config(data, env)
  db_config = YAML::load(data)

  connections = deep_merge(db_config['all'], db_config[env.to_s])

  db_param = connections[connection]['param']

  dsn = db_param['dsn']
  host = dsn.match(/host=([^;$]+)/)[1] if dsn.match("host")
  port = dsn.match(/port=([0-9]+)/)[1] if dsn.match("port")

  {
    'type'  => /(\w+)\:/.match(db_param['dsn'])[1],
    'user'  => db_param['username'],
    'pass'  => db_param['password'],
    'db'    => dsn.match(/dbname=([^;$]+)/)[1],
    'host'  => host,
    'port'  => port
  }
end

#prompt_with_default(var, default, &block) ⇒ Object



12
13
14
15
16
17
# File 'lib/capifony.rb', line 12

def prompt_with_default(var, default, &block)
  set(var) do
    Capistrano::CLI.ui.ask("#{var} [#{default}] : ", &block)
  end
  set var, default if eval("#{var.to_s}.empty?")
end