Class: Soca::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/soca/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

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 options[:version]
    say "soca #{Soca::VERSION}", :red
    exit
  end
  self.appdir      = options[:appdir] || File.expand_path(Dir.pwd)
  self.config_file = options[:config]
  self.debug       = options[:debug]
  if debug
    Soca.debug = true
    logger.level = Logger::DEBUG
  end
  self.source_paths << File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
end

Instance Attribute Details

#appdirObject

Returns the value of attribute appdir.



8
9
10
# File 'lib/soca/cli.rb', line 8

def appdir
  @appdir
end

#config_fileObject

Returns the value of attribute config_file.



8
9
10
# File 'lib/soca/cli.rb', line 8

def config_file
  @config_file
end

#debugObject

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 = options[: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