Module: Teamster::CLI::ClassMethods

Defined in:
lib/teamster-cli.rb

Instance Method Summary collapse

Instance Method Details

#adapter_helper_placeholder_for(name) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/teamster-cli.rb', line 205

def adapter_helper_placeholder_for(name)
  "module Teamster\n  module Adapters\n    module \#{name.capitalize}Helper\ndef \#{name}_summary?\n  true\nend\n\ndef \#{name}_summary\n  erb :\#{name}_summary\nend\n    end\n  end\nend\n  CODE\nend\n"

#adapter_placeholder_for(name) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/teamster-cli.rb', line 175

def adapter_placeholder_for(name)
  "require_relative \\\"\#{name}/\#{name}_helper\\\"\n\n\\# NOTE: If the namespace is changed, please take care of the\n\\#       namespace of the sub-class and helper adapters.\n\nmodule Teamster\n  module Adapters\n    class \#{name.capitalize} < Sinatra::Base\n\\# Class methods that contain Teamster-Adapter specific helpers.\ninclude BaseAdapter\n\n\\# Stuff that needs to be done before registration with core.\nhas_helpers \#{name.capitalize}Helper \\# Add adapters here (comma separated) if there are helper adapters.\nviews_at \\\"\\#\\{File.dirname(__FILE__)\\}/\#{name}/views\\\"\nunder_development \\# Remove this line when development is finished.\n\n\\# Register this class so it can be used.\nregister self\n\nget '/\#{name}/?' do\n  erb :\#{name}\nend\n    end\n  end\nend\n  CODE\nend\n"

#ask_user(question) ⇒ Object



41
42
43
44
# File 'lib/teamster-cli.rb', line 41

def ask_user(question)
  print "#{question}: "
  STDIN.gets.strip
end

#ask_user_for(opt, question) ⇒ Object



35
36
37
38
39
# File 'lib/teamster-cli.rb', line 35

def ask_user_for(opt, question)
  unless @config[opt]
    @config[opt] = ask_user question
  end
end

#b64_enc(obj) ⇒ Object



31
32
33
# File 'lib/teamster-cli.rb', line 31

def b64_enc(obj)
  Base64.strict_encode64(obj)
end

#config_ruObject



159
160
161
162
163
164
165
# File 'lib/teamster-cli.rb', line 159

def config_ru
  "require 'teamster'\nDir.glob(\"lib/*.rb\").each {|file| require File.absolute_path(file)}\nrun Teamster::Core::App\n  CODE\nend\n"

#create_adapter_for(name) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/teamster-cli.rb', line 46

def create_adapter_for(name)
  puts "Creating placeholders for adapter #{name}...\n"
  FileUtils.mkdir_p "lib/teamster-adapters/#{name}/views"
  create_file "lib/teamster-adapters/#{name}.rb", "adapter_placeholder_for", name
  create_file "lib/teamster-adapters/#{name}/#{name}_helper.rb", "adapter_helper_placeholder_for", name
  create_file "lib/teamster-adapters/#{name}/views/#{name}.erb", "view_placeholder_for", name
  create_file "lib/teamster-adapters/#{name}/views/#{name}_summary.erb", "view_summary_placeholder_for", name
  puts "\nBasic adapter creation done!"
  puts "Controller   : \"lib/teamster-adapters/#{name}.rb\""
  puts "Helper       : \"lib/teamster-adapters/#{name}/#{name}_helper.rb\""
  puts "View         : \"lib/teamster-adapters/#{name}/views/#{name}.erb\""
  puts "Summary View : \"lib/teamster-adapters/#{name}/views/#{name}_summary.erb\""
end

#create_config(team_name) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/teamster-cli.rb', line 13

def create_config(team_name)
  if team_name
    @config[:title] = team_name
  else
    ask_user_for :title, "What is your team name"
  end
  File.open(CONFIG_FILE, 'w') {|fh| fh.write @config.to_yaml}
end

#create_file(filename, method, *args) ⇒ Object



89
90
91
92
93
94
95
96
97
# File 'lib/teamster-cli.rb', line 89

def create_file(filename, method, *args)
  case [File.exists?(filename), !!@config[:overwrite]]
  when [true, false]
    puts "File \"#{filename}\" exists. Run with --overwrite to overwrite file."
  else
    puts "Creating file #{filename}..."
    File.open(filename, "w") {|fh| fh.write(send(method.to_sym, *args))}
  end
end

#create_userObject



22
23
24
25
26
27
28
29
# File 'lib/teamster-cli.rb', line 22

def create_user
  puts "Creating default user.."
  users = [{"name" => "Administrator", "pass" => b64_enc(BCrypt::Password.create("password"))}]
  File.open("./data/users", "w") do |fh|
    fh.write({"users" => users}.to_yaml)
  end
  FileUtils.chmod 0600, './data/users'
end

#detailed_usageObject



120
121
122
123
124
125
126
127
128
129
130
131
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
# File 'lib/teamster-cli.rb', line 120

def detailed_usage
  "Teamster is a simple and extensible web portal for teams.\n\nCurrent version: \#{VERSION}\n\nUsage:\n  teamster [COMMAND] [OPTIONS]\n\nCommands:\n  init, start, stop, restart\n\nOptions (standalone):\n  --help                    Display this detailed help.\n  --version                 Version of the teamster used.\n  --create-adapter NAME      Creates a stub of a adapter\n  --import-adapter FILE      << PENDING IMPLEMENTATION >>\n  --export-adapter FILE      << PENDING IMPLEMENTATION >>\n\n\nOptions used with \\\"start\\\":\n  --prod                    Binds a unix socket to be used by a web\n                      server (eg. Nginx) and creates a state file\n                      that is used by the Puma app server.\n  --socket-file FILE        Relative/absolute path to the UNIX socket file.\n  --state-file FILE         Relative/absolute path to the Puma state file.\n\n\nOptions used with \\\"stop\\\":\n  --socket-file FILE        Relative/absolute path to the UNIX socket file.\n  --state-file FILE         Relative/absolute path to the Puma state file.\n\n\nOptions used with \\\"restart\\\":\n  --socket-file FILE        Relative/absolute path to the UNIX socket file.\n  --state-file FILE         Relative/absolute path to the Puma state file.\n"
end

#export_adapter_for(name) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/teamster-cli.rb', line 75

def export_adapter_for(name)
  puts "Exporting adapter: #{name}"
  zip_file = "#{name}.zip"
  puts "The following files will be zipped:"
  puts "- lib/teamster-adapters/#{name}.rb"
  puts '- Everything in folder lib/teamster-adapters/#{name}/'
  if `which zip`.length != 0
    `zip -r #{zip_file} lib/teamster-adapters/#{name}.rb lib/teamster-adapters/#{name}/`
    puts "\nExported to #{zip_file}!"
  else
    puts "\nUnable to export adapter. Export depends on cli tool \"zip\"."
  end
end

#import_adapter_for(name) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/teamster-cli.rb', line 60

def import_adapter_for(name)
  puts "Importing adapter: #{name}"
  zip_file = "#{name}.zip"
  if File.exists?(zip_file)
    if `which unzip`.length != 0
      `unzip #{zip_file}`
      puts "\nSuccessfully imported #{name}. Please restart teamster to use."
    else
      puts "\nUnable to import adapter. Export depends on cli tool \"unzip\"."
    end
  else
    puts "Unable to find file: #{zip_file}"
  end
end

#quit(msg, code = 0) ⇒ Object



8
9
10
11
# File 'lib/teamster-cli.rb', line 8

def quit(msg, code = 0)
  warn msg
  exit code
end

#show_versionObject



99
100
101
# File 'lib/teamster-cli.rb', line 99

def show_version
  "Current version of teamster: #{VERSION}"
end

#teamster_adaptersObject



167
168
169
170
171
172
173
# File 'lib/teamster-cli.rb', line 167

def teamster_adapters
  "Dir.glob(File.dirname(__FILE__) + '/teamster-adapters/*.rb').each do |mdl|\n  require mdl\nend\n  CODE\nend\n"

#usageObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/teamster-cli.rb', line 103

def usage
  "Initialize application:\n  teamster init\n\nRun web application:\n  teamster start\n\nRun web application in production (uses unix socket & state file):\n  teamster start --prod [--socket-file FILE] [--state-file FILE]\n\nVerify by opening browser and navigating to \"http://localhost:9292\".\n\nFor more detailed help, please run \"teamster --help\".\n  HELP\nend\n"

#view_placeholder_for(name) ⇒ Object



223
224
225
226
227
228
# File 'lib/teamster-cli.rb', line 223

def view_placeholder_for(name)
  "<h1 style='text-align: center'>PLACEHOLDER FOR \#{name.upcase}</h1>\n<p style='text-align: center'>Page under construction. Please check back later!</p>\n  CODE\nend\n"

#view_summary_placeholder_for(name) ⇒ Object



230
231
232
233
234
# File 'lib/teamster-cli.rb', line 230

def view_summary_placeholder_for(name)
  "<p>Under development right now..</p>\n  CODE\nend\n"