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
- #gem_tag ⇒ 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
104 105 106 107 108 109 |
# File 'lib/cyborg/command.rb', line 104 def build(={}) puts Cyborg.production? ? 'Building for production…' : 'Building…' require_rails clean if Cyborg.production? Cyborg.plugin.build() end |
#clean ⇒ Object
89 90 91 92 93 |
# File 'lib/cyborg/command.rb', line 89 def clean FileUtils.rm_rf(Cyborg.rails_path('tmp/cache/')) FileUtils.rm_rf('.sass-cache') FileUtils.rm_rf(Cyborg.rails_path('.sass-cache')) end |
#dispatch(command, *args) ⇒ Object
Handles running threaded commands
97 98 99 100 101 |
# File 'lib/cyborg/command.rb', line 97 def dispatch(command, *args) @threads = [] send(command, *args) @threads.each { |thr| thr.join } end |
#from_root(command = nil, &blk) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/cyborg/command.rb', line 131 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
52 53 54 55 56 57 |
# File 'lib/cyborg/command.rb', line 52 def gem_build @production = true FileUtils.rm_rf('public') dispatch(:build) system "bundle exec rake build" end |
#gem_install ⇒ Object
59 60 61 62 63 64 |
# File 'lib/cyborg/command.rb', line 59 def gem_install @production = true FileUtils.rm_rf('public') dispatch(:build) system "bundle exec rake install" end |
#gem_release ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cyborg/command.rb', line 66 def gem_release @production = true FileUtils.rm_rf('public') dispatch(:build) if key = ENV['RUBYGEMS_API_KEY'] gem = "#{Cyborg.plugin.gem_name}-#{Cyborg.plugin.version}.gem" system "bundle exec rake build" system "curl --data-binary @./pkg/#{gem} -H 'Authorization:#{key}' https://rubygems.org/api/v1/gems" else system 'bundle exec rake release' end end |
#gem_tag ⇒ Object
80 81 82 83 |
# File 'lib/cyborg/command.rb', line 80 def gem_tag require './lib/tungsten/version.rb' system "git tag v#{Tungsten::VERSION}" end |
#production? ⇒ Boolean
48 49 50 |
# File 'lib/cyborg/command.rb', line 48 def production? @production == true end |
#require_rails ⇒ Object
85 86 87 |
# File 'lib/cyborg/command.rb', line 85 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 39 40 41 42 |
# 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 } when 'gem:release' from_root { gem_release } when 'gem:tag' from_root { gem_tag } else puts "Command `#{[:command]}` not recognized" end end |
#server(options = {}) ⇒ Object
Run rails server and watch assets
125 126 127 128 129 |
# File 'lib/cyborg/command.rb', line 125 def server(={}) [:port] ||= 3000 @threads << Thread.new { system "#{Cyborg.rails_path('bin/rails')} server -p #{[:port]}" } watch() if [:watch] end |
#version ⇒ Object
44 45 46 |
# File 'lib/cyborg/command.rb', line 44 def version puts "Cyborg version #{Cyborg::VERSION}\n\n" end |
#watch(options = {}) ⇒ Object
Watch assets for changes and build
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/cyborg/command.rb', line 112 def watch(={}) build() require 'listen' trap("SIGINT") { puts "\nCyborg watcher stopped. Have a nice day!" exit! } @threads.concat Cyborg.plugin.watch() end |