Module: HW::Actions

Extended by:
Thor::Actions
Included in:
Packages, Sources
Defined in:
lib/hw/actions.rb

Instance Method Summary collapse

Instance Method Details

#bundleObject



19
20
21
22
# File 'lib/hw/actions.rb', line 19

def bundle
  header "Bundling gems"
  run "bundle install --quiet"
end

#error(msg) ⇒ Object



11
# File 'lib/hw/actions.rb', line 11

def error msg;   say_status "error",   msg, :red;    end

#git(commands = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/hw/actions.rb', line 52

def git(commands={})
  if commands.is_a?(Symbol)
    run "git #{commands}"
  else
    commands.each do |cmd, options|
      run "git #{cmd} #{options}"
    end
  end
end

#header(msg) ⇒ Object



5
6
7
# File 'lib/hw/actions.rb', line 5

def header msg
  say_status ">>>", "\e[36m#{msg}\e[0m", :cyan
end

#info(msg) ⇒ Object



9
# File 'lib/hw/actions.rb', line 9

def info msg;    say_status "info",    msg, :white;  end

#migrate(options = {}) ⇒ Object



24
25
26
27
28
# File 'lib/hw/actions.rb', line 24

def migrate(options={})
  header "Migrating the database"
  env = options[:env] || 'development'
  rake("db:migrate", env: env, silence: true)
end

#migration(filename, data = nil, &block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/hw/actions.rb', line 30

def migration filename, data=nil, &block
  last_migration  = ActiveRecord::Migrator.migrations('db/migrate').last
  number          = last_migration ? last_migration.version + 1 : 0
  timestamp       = [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % number].max.to_i

  create_file("db/migrate/#{timestamp}_#{filename.underscore}.rb", data, verbose: false, &block)
end

#pbcopy(input) ⇒ Object



62
63
64
65
66
# File 'lib/hw/actions.rb', line 62

def pbcopy(input)
  str = input.to_s
  IO.popen('pbcopy', 'w') { |f| f << str }
  str
end

#pbpasteObject



68
69
70
# File 'lib/hw/actions.rb', line 68

def pbpaste
  `pbpaste`
end

#rake(command, options = {}) ⇒ Object



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

def rake(command, options={})
  env     = options[:env] || 'development'
  capture = options[:silence] || false
  sudo    = options[:sudo] ? 'sudo ' : ''

  #run  rake db:create from "./testing"
  #success
  run("#{sudo}rake #{command} RAILS_ENV=#{env}", verbose: false, capture: capture)
end

#replace_file(destination, data = nil, config = {}, &block) ⇒ Object



14
15
16
17
# File 'lib/hw/actions.rb', line 14

def replace_file(destination, data = nil, config = {}, &block)
  remove_file(destination)
  create_file(destination, (data || block.call()), config)
end

#success(msg) ⇒ Object



10
# File 'lib/hw/actions.rb', line 10

def success msg; say_status "success", msg, :green;  end

#warn(msg) ⇒ Object



12
# File 'lib/hw/actions.rb', line 12

def warn msg;    say_status "warning", msg, :yellow; end

#worker(filename, data = nil, &block) ⇒ Object



38
39
40
# File 'lib/hw/actions.rb', line 38

def worker filename, data=nil, &block
  create_file("app/workers/#{filename}", data, verbose: false, &block)
end