Module: HW::Actions
Instance Method Summary collapse
- #bundle ⇒ Object
- #error(msg) ⇒ Object
- #git(commands = {}) ⇒ Object
- #header(msg) ⇒ Object
- #info(msg) ⇒ Object
- #migrate(options = {}) ⇒ Object
- #migration(filename, data = nil, &block) ⇒ Object
- #pbcopy(input) ⇒ Object
- #pbpaste ⇒ Object
- #rake(command, options = {}) ⇒ Object
- #replace_file(destination, data = nil, config = {}, &block) ⇒ Object
- #success(msg) ⇒ Object
- #warn(msg) ⇒ Object
- #worker(filename, data = nil, &block) ⇒ Object
Instance Method Details
#bundle ⇒ Object
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, | run "git #{cmd} #{}" 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(={}) header "Migrating the database" env = [: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 = [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % number].max.to_i create_file("db/migrate/#{}_#{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 |
#pbpaste ⇒ Object
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, ={}) env = [:env] || 'development' capture = [:silence] || false sudo = [: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 |