Class: Soca::CLI
Instance Attribute Summary collapse
-
#appdir ⇒ Object
Returns the value of attribute appdir.
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#debug ⇒ Object
Returns the value of attribute debug.
Instance Method Summary collapse
- #autopush(env = 'default') ⇒ Object
- #build(env = 'default') ⇒ Object
- #compact(env = 'default') ⇒ Object
- #generate(to = nil) ⇒ Object
- #init(to = nil) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #json(env = 'default') ⇒ Object
- #open(env = 'default') ⇒ Object
- #purge(env = 'default') ⇒ Object
- #push(env = 'default') ⇒ Object
- #url(env = 'default') ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/soca/cli.rb', line 34 def initialize(*) super if [:version] say "soca #{Soca::VERSION}", :red exit end self.appdir = [:appdir] || File.(Dir.pwd) self.config_file = [:config] self.debug = [:debug] if debug Soca.debug = true logger.level = Logger::DEBUG end self.source_paths << File.(File.join(File.dirname(__FILE__), 'templates')) end |
Instance Attribute Details
#appdir ⇒ Object
Returns the value of attribute appdir.
8 9 10 |
# File 'lib/soca/cli.rb', line 8 def appdir @appdir end |
#config_file ⇒ Object
Returns the value of attribute config_file.
8 9 10 |
# File 'lib/soca/cli.rb', line 8 def config_file @config_file end |
#debug ⇒ Object
Returns the value of attribute debug.
8 9 10 |
# File 'lib/soca/cli.rb', line 8 def debug @debug end |
Instance Method Details
#autopush(env = 'default') ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/soca/cli.rb', line 132 def autopush(env = 'default') push = pusher(env) files = {} compact = [:compact] times = 0 loop do changed = false Dir.glob(push.app_dir + '**/**') do |file| ctime = File.ctime(file).to_i if ctime != files[file] files[file] = ctime changed = true break end end if changed say "Running push at #{Time.now}", :yellow begin push.push! rescue => e say "Error running push #{e}", :red end Dir.glob(push.app_dir + '**/**') do |file| ctime = File.ctime(file).to_i if ctime != files[file] files[file] = ctime end end times += 1 if compact && times % compact == 0 say "pushed #{times} times, running a compact", :yellow push.compact! end say "Waiting for a file change", :green say "-------------------------" end sleep 1 end end |
#build(env = 'default') ⇒ Object
114 115 116 117 |
# File 'lib/soca/cli.rb', line 114 def build(env = 'default') require 'pp' pp pusher(env).build end |
#compact(env = 'default') ⇒ Object
120 121 122 |
# File 'lib/soca/cli.rb', line 120 def compact(env = 'default') pusher(env).compact! end |
#generate(to = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/soca/cli.rb', line 72 def generate(to = nil) self.appdir = to if to self.destination_root = appdir directory('hooks') directory('js') directory('css') directory('db') template('Jimfile') template('index.html.erb', 'index.html') @dir_mappings = { "config.js" => "", "index.html" => "_attachments/index.html", "css" => "_attachments/css", "images" => "_attachments/images", "sass" => false, "js" => "_attachments/js", "templates" => "_attachments/templates", "db" => "", "Jimfile" => false, "hooks" => false } template('config.js.erb', 'config.js') template('couchapprc.erb', '.couchapprc') end |
#init(to = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/soca/cli.rb', line 55 def init(to = nil) self.appdir = to if to self.destination_root = appdir @dir_mappings = {} Dir[appdir + '*'].each do |filename| basename = File.basename(filename) @dir_mappings[basename] = "_attachments/#{basename}" end template('config.js.erb', 'config.js') template('couchapprc.erb', '.couchapprc') end |
#json(env = 'default') ⇒ Object
125 126 127 |
# File 'lib/soca/cli.rb', line 125 def json(env = 'default') say pusher(env).json end |
#open(env = 'default') ⇒ Object
104 105 106 |
# File 'lib/soca/cli.rb', line 104 def open(env = 'default') `open #{pusher(env).app_url}` end |
#purge(env = 'default') ⇒ Object
176 177 178 179 |
# File 'lib/soca/cli.rb', line 176 def purge(env = 'default') push = pusher(env) push.purge! end |
#push(env = 'default') ⇒ Object
109 110 111 |
# File 'lib/soca/cli.rb', line 109 def push(env = 'default') pusher(env).push! end |
#url(env = 'default') ⇒ Object
99 100 101 |
# File 'lib/soca/cli.rb', line 99 def url(env = 'default') say pusher(env).app_url end |