Module: Cyborg::Command
Instance Method Summary collapse
-
#build(options = {}) ⇒ Object
Build assets.
- #clean ⇒ Object
-
#dispatch(command, *args) ⇒ Object
Handles running threaded commands.
- #from_root(command = nil, &blk) ⇒ Object
- #gem_build ⇒ Object
- #gem_install ⇒ Object
- #gem_release ⇒ Object
- #production? ⇒ Boolean
- #require_rails ⇒ Object
- #run(options) ⇒ Object
-
#server(options = {}) ⇒ Object
Run rails server and watch assets.
- #version ⇒ Object
-
#watch(options = {}) ⇒ Object
Watch assets for changes and build.
Instance Method Details
#build(options = {}) ⇒ Object
Build assets
81 82 83 84 85 |
# File 'lib/cyborg/command.rb', line 81 def build(={}) puts Cyborg.production? ? 'Building for production…' : 'Building…' require_rails @threads.concat Cyborg.plugin.build() end |
#clean ⇒ Object
67 68 69 70 |
# File 'lib/cyborg/command.rb', line 67 def clean require_rails Cyborg.plugin.clean end |
#dispatch(command, *args) ⇒ Object
Handles running threaded commands
74 75 76 77 78 |
# File 'lib/cyborg/command.rb', line 74 def dispatch(command, *args) @threads = [] send(command, *args) @threads.each { |thr| thr.join } end |
#from_root(command = nil, &blk) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/cyborg/command.rb', line 106 def from_root(command=nil, &blk) unless dir = Cyborg.gem_path abort "Command must be run from the root of a Cyborg Plugin (adjacent to the gemspec)." end Dir.chdir(dir) do if command system command else blk.call end end end |
#gem_build ⇒ Object
48 49 50 51 |
# File 'lib/cyborg/command.rb', line 48 def gem_build dispatch(:build) system "bundle exec rake build" end |
#gem_install ⇒ Object
53 54 55 56 |
# File 'lib/cyborg/command.rb', line 53 def gem_install dispatch(:build) system "bundle exec rake install" end |
#gem_release ⇒ Object
58 59 60 61 |
# File 'lib/cyborg/command.rb', line 58 def gem_release dispatch(:build) system "bundle exec rake release" end |
#production? ⇒ Boolean
44 45 46 |
# File 'lib/cyborg/command.rb', line 44 def production? @production == true end |
#require_rails ⇒ Object
63 64 65 |
# File 'lib/cyborg/command.rb', line 63 def require_rails require File.join(Dir.pwd, Cyborg.rails_path('config/application')) end |
#run(options) ⇒ Object
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 36 37 38 |
# File 'lib/cyborg/command.rb', line 9 def run() @production = [:production] if [:help] version puts [:help] return end case [:command] when 'new', 'n' Scaffold.new() when 'build', 'b' from_root { dispatch(:build, ) } when 'watch', 'w' from_root { dispatch(:watch, ) } when 'server', 's' from_root { dispatch(:server, ) } when 'clean', 'c' from_root { clean } when 'version' version when 'gem:build' from_root { gem_build } when 'gem:install' from_root { gem_install } else puts "Command `#{options[:command]}` not recognized" end end |
#server(options = {}) ⇒ Object
Run rails server and watch assets
101 102 103 104 |
# File 'lib/cyborg/command.rb', line 101 def server(={}) @threads << Thread.new { system "#{Cyborg.rails_path('bin/rails')} server" } watch() if [:watch] end |
#version ⇒ Object
40 41 42 |
# File 'lib/cyborg/command.rb', line 40 def version puts "Cyborg version #{Cyborg::VERSION}\n\n" end |
#watch(options = {}) ⇒ Object
Watch assets for changes and build
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cyborg/command.rb', line 88 def watch(={}) build() require 'listen' trap("SIGINT") { puts "\nCyborg watcher stopped. Have a nice day!" exit! } @threads.concat Cyborg.plugin.watch() end |