Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#deep_merge(hash1, hash2) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/symfony1.rb', line 55

def deep_merge(hash1, hash2)

    #There might not be a second has to cascade to 
    if(hash2 == 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



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/symfony1.rb', line 90

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



49
50
51
52
53
# File 'lib/symfony1.rb', line 49

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

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

#guess_symfony_ormObject



39
40
41
42
43
44
45
46
47
# File 'lib/symfony1.rb', line 39

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

#guess_symfony_versionObject



103
104
105
# File 'lib/symfony2.rb', line 103

def guess_symfony_version
  capture("cd #{latest_release} && #{php_bin} #{symfony_console} --version |cut -d \" \" -f 3")
end

#load_database_config(data, env) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/symfony1.rb', line 69

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

#pretty_errorsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/symfony2/output.rb', line 29

def pretty_errors
  if !$pretty_errors_defined
    $pretty_errors_defined = true

    class << $stderr
      @@firstLine = true
      alias _write write

      def write(s)
        if @@firstLine
          s = '' << "\n" << s
          @@firstLine = false
        end

        _write(s.red)
        $error = true
      end
    end
  end
end

#pretty_print(msg) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/symfony2/output.rb', line 10

def pretty_print(msg)
  if logger.level == Logger::IMPORTANT
    pretty_errors

    msg << '.' * (55 - msg.size)
    print msg
  else
    puts msg.green
  end
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

#puts_okObject



21
22
23
24
25
26
27
# File 'lib/symfony2/output.rb', line 21

def puts_ok
  if logger.level == Logger::IMPORTANT && !$error
    puts ''.green
  end

  $error = false
end

#remote_command_exists?(command) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/symfony2.rb', line 111

def remote_command_exists?(command)
  'true' == capture("if [ -x \"$(which #{command})\" ]; then echo 'true'; fi").strip
end

#remote_file_exists?(full_path) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/symfony2.rb', line 107

def remote_file_exists?(full_path)
  'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
end