Class: PgSync::Init

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/pgsync/init.rb

Instance Method Summary collapse

Methods included from Utils

#colorize, #config_file, #db_config_file, #log, #search_tree

Instance Method Details

#perform(opts) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pgsync/init.rb', line 5

def perform(opts)
  # needed for config_file method
  @options = opts.to_hash

  file = db_config_file(opts.arguments[0]) || config_file || ".pgsync.yml"

  if File.exist?(file)
    raise Error, "#{file} exists."
  else
    exclude =
      if rails_app?
        <<~EOS
          exclude:
            - schema_migrations
            - ar_internal_metadata
        EOS
      else
        <<~EOS
          # exclude:
          #   - schema_migrations
          #   - ar_internal_metadata
        EOS
      end

    # create file
    contents = File.read(__dir__ + "/../../config.yml")
    File.write(file, contents % {exclude: exclude})

    log "#{file} created. Add your database credentials."
  end
end

#rails_app?Boolean

TODO maybe check parent directories

Returns:

  • (Boolean)


38
39
40
# File 'lib/pgsync/init.rb', line 38

def rails_app?
  File.exist?("bin/rails")
end