gitpusshuten 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.bundle/config +2 -0
  2. data/.gitignore +4 -0
  3. data/Gemfile +9 -0
  4. data/Gemfile.lock +53 -0
  5. data/README.md +7 -0
  6. data/bin/gitpusshuten +4 -0
  7. data/bin/heavenly +4 -0
  8. data/bin/ten +4 -0
  9. data/gitpusshuten.gemspec +26 -0
  10. data/lib/gitpusshuten/cli.rb +78 -0
  11. data/lib/gitpusshuten/command.rb +147 -0
  12. data/lib/gitpusshuten/commands/base.rb +246 -0
  13. data/lib/gitpusshuten/commands/delete.rb +27 -0
  14. data/lib/gitpusshuten/commands/help.rb +36 -0
  15. data/lib/gitpusshuten/commands/initialize.rb +61 -0
  16. data/lib/gitpusshuten/commands/push.rb +54 -0
  17. data/lib/gitpusshuten/commands/remote.rb +29 -0
  18. data/lib/gitpusshuten/commands/user.rb +252 -0
  19. data/lib/gitpusshuten/commands/version.rb +21 -0
  20. data/lib/gitpusshuten/configuration.rb +122 -0
  21. data/lib/gitpusshuten/environment.rb +70 -0
  22. data/lib/gitpusshuten/gem.rb +33 -0
  23. data/lib/gitpusshuten/git.rb +111 -0
  24. data/lib/gitpusshuten/helpers/environment/installers.rb +59 -0
  25. data/lib/gitpusshuten/helpers/environment/packages.rb +21 -0
  26. data/lib/gitpusshuten/helpers/environment/scp.rb +57 -0
  27. data/lib/gitpusshuten/helpers/environment/ssh.rb +77 -0
  28. data/lib/gitpusshuten/helpers/environment/ssh_key.rb +79 -0
  29. data/lib/gitpusshuten/helpers/environment/user.rb +70 -0
  30. data/lib/gitpusshuten/helpers/spinner.rb +98 -0
  31. data/lib/gitpusshuten/hook.rb +26 -0
  32. data/lib/gitpusshuten/hooks.rb +147 -0
  33. data/lib/gitpusshuten/initializer.rb +95 -0
  34. data/lib/gitpusshuten/local.rb +35 -0
  35. data/lib/gitpusshuten/log.rb +83 -0
  36. data/lib/gitpusshuten/modules/active_record/hooks.rb +19 -0
  37. data/lib/gitpusshuten/modules/apache/command.rb +354 -0
  38. data/lib/gitpusshuten/modules/bundler/command.rb +43 -0
  39. data/lib/gitpusshuten/modules/bundler/hooks.rb +8 -0
  40. data/lib/gitpusshuten/modules/mysql/command.rb +192 -0
  41. data/lib/gitpusshuten/modules/nanoc/hooks.rb +9 -0
  42. data/lib/gitpusshuten/modules/nginx/command.rb +447 -0
  43. data/lib/gitpusshuten/modules/passenger/command.rb +310 -0
  44. data/lib/gitpusshuten/modules/passenger/hooks.rb +4 -0
  45. data/lib/gitpusshuten/modules/rvm/command.rb +277 -0
  46. data/lib/gitpusshuten.rb +21 -0
  47. data/lib/templates/config.rb +37 -0
  48. data/lib/templates/hooks.rb +40 -0
  49. data/spec/cli_spec.rb +83 -0
  50. data/spec/command_spec.rb +76 -0
  51. data/spec/configuration_spec.rb +45 -0
  52. data/spec/environment_spec.rb +64 -0
  53. data/spec/fixtures/combined_hooks.rb +23 -0
  54. data/spec/fixtures/config.rb +23 -0
  55. data/spec/fixtures/hooks.rb +37 -0
  56. data/spec/fixtures/passenger.json +1 -0
  57. data/spec/gem_spec.rb +28 -0
  58. data/spec/git_spec.rb +59 -0
  59. data/spec/gitpusshuten_spec.rb +9 -0
  60. data/spec/hook_spec.rb +48 -0
  61. data/spec/hooks_spec.rb +150 -0
  62. data/spec/initializer_spec.rb +26 -0
  63. data/spec/log_spec.rb +20 -0
  64. data/spec/spec_helper.rb +43 -0
  65. metadata +220 -0
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ module GitPusshuTen
3
+ module Commands
4
+ class Initialize < GitPusshuTen::Commands::Base
5
+ description "Initializes Git Pusshu Ten (プッシュ点) with the working directory."
6
+ usage "initialize"
7
+ example "heavenly initialize # Initializes Git Pusshu Ten (プッシュ点) with the working directory."
8
+
9
+ ##
10
+ # Initialize specific attributes/arguments
11
+ attr_accessor :working_directory
12
+
13
+ ##
14
+ # Incase template files already exist
15
+ attr_accessor :confirm_perform
16
+
17
+ def initialize(*objects)
18
+ super
19
+
20
+ @working_directory = Dir.pwd
21
+ @confirm_perform = true
22
+ end
23
+
24
+ ##
25
+ # Performs the Initialize command
26
+ def perform!
27
+ message "Would you like to initialize Git Pusshu Ten (プッシュ点) with #{working_directory}?"
28
+ if yes?
29
+ copy_templates!
30
+ if not git.initialized?
31
+ git.initialize!
32
+ end
33
+ git.ignore!
34
+ else
35
+ message "If you wish to initialize it elsewhere, please move into that directory and run #{y("heavenly initialize")} again."
36
+ end
37
+ end
38
+
39
+ ##
40
+ # Copies the "config.rb" and "hooks.rb" templates over
41
+ # to the .gitpusshuten inside the working directory
42
+ def copy_templates!
43
+ if File.directory?(File.join(working_directory, '.gitpusshuten'))
44
+ warning "Git Pusshu Ten (プッシュ点) is already initialized in #{y(working_directory)}."
45
+ warning "Re-initializing it will cause it to overwrite the current #{y("config.rb")} and #{y("hooks.rb")} files."
46
+ warning "Are you sure you wish to continue?"
47
+ @confirm_perform = yes?
48
+ end
49
+
50
+ if confirm_perform
51
+ local.execute("mkdir -p '#{working_directory}/.gitpusshuten'")
52
+ Dir[File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'templates', '*.rb'))].each do |template|
53
+ local.execute("cp '#{template}' '#{working_directory}/.gitpusshuten/#{template.split('/').last}'")
54
+ end
55
+ message "Git Pusshu Ten (プッシュ点) initialized in: #{y(working_directory)}!"
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,54 @@
1
+ module GitPusshuTen
2
+ module Commands
3
+ class Push < GitPusshuTen::Commands::Base
4
+ description "Pushes a branch, tag or ref to the specified environment."
5
+ usage "push <command> <type> to <environment>"
6
+ example "heavenly push branch develop to staging # Pushes the specified branch to the staging environment."
7
+ example "heavenly push tag 1.0.3 to staging # Pushes the specified tag to the staging environment."
8
+ example "heavenly push ref 2dbec02aa0b8604b8512e2fcbb8aac582c7f6a73 to production # Pushes the specified ref to the production environment."
9
+
10
+ attr_accessor :type
11
+
12
+ def initialize(*objects)
13
+ super
14
+ perform_hooks!
15
+
16
+ @command = cli.arguments.shift
17
+ @type = cli.arguments.shift
18
+
19
+ help if type.nil? or e.name.nil?
20
+
21
+ set_remote!
22
+ end
23
+
24
+ ##
25
+ # Pushes the specified branch to the remote environment.
26
+ def perform_branch!
27
+ message "Pushing branch #{y(type)} to the #{y(e.name)} environment."
28
+ git.push(:branch, type).to(e.name)
29
+ end
30
+
31
+ ##
32
+ # Pushes the specified tag to the remote environment.
33
+ def perform_tag!
34
+ message "Pushing tag #{y(type)} to the #{y(e.name)} environment."
35
+ git.push(:tag, type).to(e.name)
36
+ end
37
+
38
+ ##
39
+ # Pushes the specified ref to the remote environment.
40
+ def perform_ref!
41
+ message "Pushing ref #{y(type)} to the #{y(e.name)} environment."
42
+ git.push(:ref, type).to(e.name)
43
+ end
44
+
45
+ ##
46
+ # Adds the remote
47
+ def set_remote!
48
+ git.remove_remote(e.name) if git.has_remote?(e.name)
49
+ git.add_remote(e.name, "ssh://#{c.user}@#{c.ip}:#{c.port}/#{e.app_dir}")
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,29 @@
1
+ module GitPusshuTen
2
+ module Commands
3
+ class Remote < GitPusshuTen::Commands::Base
4
+ description "Performs a command on the remote server for the specified environment from the application root."
5
+ usage "remote command on <environment> '<command>'"
6
+ example "heavenly remote command on staging 'cat log/production.log' # Invokes 'cat log/production.log' in the staging environment."
7
+ example "heavenly remote command on production 'mkdir tmp; touch tmp/restart.txt' # Invokes 'mkdir tmp; touch tmp/restart.txt' in the production environment."
8
+
9
+ attr_accessor :command_to_execute
10
+
11
+ def initialize(*objects)
12
+ super
13
+
14
+ @command = cli.arguments.shift if cli.arguments.any?
15
+ @command_to_execute = cli.arguments.join(' ') if cli.arguments.any?
16
+
17
+ help if command.nil? or command_to_execute.nil? or e.name.nil?
18
+ end
19
+
20
+ ##
21
+ # Performs a unix command on the remote server
22
+ def perform_command!
23
+ message "Performing command on #{y(c.application)} (#{y(e.name)}) at #{y(c.ip)}!"
24
+ puts e.execute_as_user("cd #{e.app_dir}; #{command_to_execute}")
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,252 @@
1
+ module GitPusshuTen
2
+ module Commands
3
+ class User < GitPusshuTen::Commands::Base
4
+ description "Interacts with users, based on the <app_root>/.gitpusshuten/config.rb file."
5
+ usage "user <command> (to|for|from|on) <environment>"
6
+ example "heavenly user add to production # Sets up the user on the remote server for production."
7
+ example "heavenly user reconfigure for production # Reconfigures the user without removing applications."
8
+ example "heavenly user remove from production # Removes the user and all it's applications."
9
+ example "heavenly user install-ssh-key to staging # Installs your ssh key on the server for the user."
10
+ example "heavenly user install-root-ssh-key to staging # Installs your ssh key on the server for the root user."
11
+ example "$(heavenly user login to staging) # Logs the user in to the staging environment as user."
12
+ example "$(heavenly user login-root to production) # Logs the user in to the production environment as root."
13
+
14
+ def initialize(*objects)
15
+ super
16
+
17
+ @command = cli.arguments.shift
18
+
19
+ help if command.nil? or e.name.nil?
20
+
21
+ @command = command.underscore
22
+ end
23
+
24
+ ##
25
+ # Sets up a new UNIX user and configures it based on the .gitpusshuten/config.rb
26
+ def perform_add!
27
+ if not e.user_exists? # prompts root
28
+ ensure_git_installed!
29
+ message "It looks like #{y(c.user)} does not yet exist."
30
+ message "Would you like to add #{y(c.user)} to #{y(c.application)} (#{y(c.ip)})?"
31
+ if yes?
32
+ message "Adding #{y(c.user)} to #{y(c.ip)}.."
33
+ if e.add_user!
34
+ message "Successfully added #{y(c.user)} to #{y(c.application)} (#{y(c.ip)})!"
35
+ else
36
+ error "Failed to add user #{y(c.user)} to #{y(c.application)} (#{y(c.ip)})."
37
+ error "An error occurred. Is your configuration file properly configured?"
38
+ exit
39
+ end
40
+ end
41
+ else
42
+ error "User #{y(c.user)} already exists."
43
+ error "If you want to remove this user, run the following command:"
44
+ standard "\n\s\s#{y("heavenly user remove from #{e.name}")}\n\n"
45
+ error "If you just want to reconfigure the user without removing it, run the following ommand:"
46
+ standard "\n\s\s#{(y("heavenly user reconfigure for #{e.name}"))}"
47
+ exit
48
+ end
49
+
50
+ ##
51
+ # Configures the user
52
+ configure_user!
53
+
54
+ ##
55
+ # Finished adding user!
56
+ message "Finished adding and configuring #{y(c.user)}!"
57
+ message "You should now be able to push your application to #{y(c.application)} at #{y(c.ip)}."
58
+ end
59
+
60
+ ##
61
+ # Removes the user and home directory
62
+ def perform_remove!
63
+ if e.user_exists?
64
+ warning "Are you #{y('SURE')} you want to remove #{y(c.user)}?"
65
+ warning "Doing so will also remove #{y(e.home_dir)}, in which the #{y('applications')} of #{y(c.user)} are."
66
+ if yes?
67
+ warning "Are you #{y('REALLY')} sure?"
68
+ if yes?
69
+ message "Removing user #{y(c.user)} from #{y(c.ip)}."
70
+ if e.remove_user!
71
+ e.execute_as_root("rm -rf '#{e.home_dir}'")
72
+ message "User #{y(c.user)} has been removed from #{y(c.ip)}."
73
+ else
74
+ error "Failed to remove user #{y(c.user)} from #{y(c.ip)}."
75
+ error "An error occurred. Is your configuration file properly configured?"
76
+ exit
77
+ end
78
+ end
79
+ end
80
+ else
81
+ error "User #{y(c.user)} does not exist at #{y(c.ip)}."
82
+ end
83
+ end
84
+
85
+ ##
86
+ # Reconfigures the user without removing it or any applications
87
+ def perform_reconfigure!
88
+ if e.user_exists? # prompts root
89
+ configure_user!
90
+ else
91
+ error "User #{y(c.user)} does not exist at #{y(c.ip)}."
92
+ error "If you want to add #{y(c.user)}, run the following command:"
93
+ standard "\n\s\s#{y("heavenly user add to #{e.name}")}"
94
+ end
95
+ end
96
+
97
+ ##
98
+ # Returns a string which can be used to login the user
99
+ def perform_login!
100
+ if not e.user_exists?
101
+ error "Cannot login, #{y(c.user)} does not exist."
102
+ exit
103
+ end
104
+
105
+ puts "ssh #{c.user}@#{c.ip} -p #{c.port}"
106
+ end
107
+
108
+ ##
109
+ # Returns a string which can be used to login as root
110
+ def perform_login_root!
111
+ puts "ssh root@#{c.ip} -p #{c.port}"
112
+ end
113
+
114
+ ##
115
+ # Installs the ssh key for the application user
116
+ def perform_install_ssh_key!
117
+ unless e.has_ssh_key?
118
+ error "Could not find ssh key in #{y(e.ssh_key_path)}"
119
+ error "To create one, run: #{y('ssh-keygen -t rsa')}"
120
+ exit
121
+ end
122
+
123
+ unless e.ssh_key_installed? # prompts root
124
+ Spinner.return :message => "Installing SSH Key.." do
125
+ e.install_ssh_key!
126
+ g("Done!")
127
+ end
128
+ else
129
+ message "Your ssh has already been installed for #{y(c.user)} at #{y(c.ip)}."
130
+ end
131
+ end
132
+
133
+ ##
134
+ # Installs the ssh key for the root user
135
+ def perform_install_root_ssh_key!
136
+ unless e.has_ssh_key?
137
+ error "Could not find ssh key in #{y(e.ssh_key_path)}"
138
+ error "To create one, run: #{y('ssh-keygen -t rsa')}"
139
+ exit
140
+ end
141
+
142
+ unless e.root_ssh_key_installed? # prompts root
143
+ Spinner.return :message => "Installing SSH Key.." do
144
+ e.install_root_ssh_key!
145
+ g("Done!")
146
+ end
147
+ else
148
+ message "Your ssh has already been installed for #{y('root')} at #{y(c.ip)}."
149
+ end
150
+ end
151
+
152
+ ##
153
+ # Ensures that Git is installed on the remote server
154
+ def ensure_git_installed!
155
+ if not e.installed?('git') #prompts root
156
+ warning "It is required that you have #{y('Git')} installed at #{y(c.ip)}."
157
+ warning "Could not find #{y('Git')}, would you like to install it?"
158
+
159
+ if yes?
160
+ Spinner.return :message => "Installing #{y('Git')}.." do
161
+ e.install!('git-core')
162
+ @git_installed = e.installed?('git')
163
+ if @git_installed
164
+ g("Done!")
165
+ else
166
+ r("Unable to install Git.")
167
+ end
168
+ end
169
+ exit unless @git_installed
170
+ else
171
+ exit
172
+ end
173
+ end
174
+ end
175
+
176
+ ##
177
+ # Configures the user. Overwrites all current configurations (if any exist)
178
+ def configure_user!
179
+ message "Configuring #{y(c.user)}."
180
+
181
+ ##
182
+ # If the user has an SSH key and it hasn't been installed
183
+ # on the server under the current user then it'll go ahead and install it
184
+ if e.has_ssh_key? and not e.ssh_key_installed?
185
+ perform_install_ssh_key!
186
+ end
187
+
188
+ ##
189
+ # Configure .bashrc
190
+ Spinner.return :message => "Configuring #{y('.bashrc')}.." do
191
+ e.execute_as_root("echo -e \"export RAILS_ENV=production\nsource /etc/profile\" > '#{File.join(c.path, '.bashrc')}'")
192
+ g('Done!')
193
+ end
194
+
195
+ ##
196
+ # Creating .gemrc
197
+ Spinner.return :message => "Configuring #{y('.gemrc')}.." do
198
+ e.download_packages!(e.home_dir)
199
+ e.execute_as_root("cd #{e.home_dir}; cat gitpusshuten-packages/modules/rvm/gemrc > .gemrc")
200
+ e.clean_up_packages!(e.home_dir)
201
+ g('Done!')
202
+ end
203
+
204
+ ##
205
+ # Add user to sudoers file if not already in sudo'ers
206
+ if not e.user_in_sudoers?
207
+ Spinner.return :message => "Adding #{y(c.user)} to sudo-ers.." do
208
+ e.add_user_to_sudoers!
209
+ g('Done!')
210
+ end
211
+ end
212
+
213
+ ##
214
+ # Checks to see if the RVM group exists.
215
+ # If it does exist, perform RVM specific tasks.
216
+ Spinner.return :message => "Searching for #{y('RVM')} (Ruby version Manager).." do
217
+ @rvm_found = e.directory?("/usr/local/rvm")
218
+ if @rvm_found
219
+ g("Found!")
220
+ else
221
+ y("Not found, skipping.")
222
+ end
223
+ end
224
+ if @rvm_found
225
+ Spinner.return :message => "Adding #{y(c.user)} to the #{y('RVM')} group.." do
226
+ e.execute_as_root("usermod -G rvm '#{c.user}'")
227
+ g('Done!')
228
+ end
229
+ end
230
+
231
+ ##
232
+ # Installs the .gitconfig and minimum configuration
233
+ # if the configuration file does not exist.
234
+ Spinner.return :message => "Configuring #{y('Git')} for #{y(c.user)}." do
235
+ e.install_gitconfig!
236
+ e.install_pushand!
237
+ g('Done!')
238
+ end
239
+
240
+ ##
241
+ # Ensure home directory ownership is set to the user
242
+ Spinner.return :message => "Setting permissions.." do
243
+ e.execute_as_root("chown -R #{c.user}:#{c.user} '#{e.home_dir}'")
244
+ g('Done!')
245
+ end
246
+
247
+ message "Finished configuring #{y(c.user)}."
248
+ end
249
+
250
+ end
251
+ end
252
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ module GitPusshuTen
3
+ module Commands
4
+ class Version < GitPusshuTen::Commands::Base
5
+ description "Displays the current version of Git Pusshu Ten (プッシュ点)."
6
+
7
+ ##
8
+ # Initializes the Version command
9
+ def initialize(*objects)
10
+ super
11
+ end
12
+
13
+ ##
14
+ # Performs the Version command
15
+ def perform!
16
+ standard "Git Pusshu Ten (プッシュ点) version #{GitPusshuTen::VERSION}"
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,122 @@
1
+ module GitPusshuTen
2
+ class Configuration
3
+
4
+ ##
5
+ # Contains the Application's name which is extracted from
6
+ # the selected configuration in the configuration file
7
+ attr_accessor :application
8
+
9
+ ##
10
+ # Contains the environment on the remote server name which
11
+ # is extracted from the selected configuration in the configuration file
12
+ attr_accessor :environment
13
+
14
+ ##
15
+ # Returns true if the configuration has been found
16
+ attr_accessor :found
17
+ alias :found? :found
18
+
19
+ ##
20
+ # Contains the user, password, passphrase, ip and port for connecting
21
+ # and authorizing the user to the remote server
22
+ attr_accessor :user, :password, :passphrase, :ip, :port
23
+
24
+ ##
25
+ # Contains the path to where the application should be pushed
26
+ attr_accessor :path
27
+
28
+ ##
29
+ # Contains a list of modules
30
+ attr_accessor :additional_modules
31
+
32
+ ##
33
+ # A flag to force the parsing
34
+ attr_accessor :force_parse
35
+
36
+ ##
37
+ # Configure
38
+ # helper method for the pusshuten configuration method
39
+ def configure
40
+ yield self
41
+ end
42
+
43
+ ##
44
+ # Modules
45
+ # Helper method for adding modules
46
+ def modules
47
+ yield self
48
+ end
49
+
50
+ ##
51
+ # Modules - Add
52
+ # Helper method for the Modules helper to add modules to the array
53
+ def add(module_object)
54
+ @additional_modules << module_object
55
+ end
56
+
57
+ ##
58
+ # Pusshuten
59
+ # Helper method used to configure the configuration file
60
+ def pusshuten(application, *environment, &block)
61
+ environment.flatten!
62
+
63
+ environment.each do |env|
64
+ unless env.is_a?(Symbol)
65
+ GitPusshuTen::Log.error 'Please use symbols as environment name.'
66
+ exit
67
+ end
68
+ end
69
+
70
+ if environment.include?(@environment) or force_parse
71
+ @application = application
72
+ @found = true
73
+ block.call
74
+ end
75
+ end
76
+
77
+ ##
78
+ # Initializes a new configuration object
79
+ # takes the absolute path to the configuration file
80
+ def initialize(environment)
81
+ @environment = environment
82
+ @found = false
83
+ @force_parse = false
84
+
85
+ @additional_modules = []
86
+ end
87
+
88
+ ##
89
+ # Parses the configuration file and loads all the
90
+ # configuration values into the GitPusshuTen::Configuration instance
91
+ def parse!(configuration_file)
92
+ instance_eval(File.read(configuration_file))
93
+
94
+ ##
95
+ # If no configuration is found by environment then
96
+ # it will re-parse it in a forced manner, meaning it won't
97
+ # care about the environment and it will just parse everything it finds.
98
+ # This is done because we can then extract all set "modules" from the configuration
99
+ # file and display them in the "Help" screen so users can look up information/examples on them.
100
+ #
101
+ # This will only occur if no environment is found/specified. So when doing anything
102
+ # environment specific, it will never force the parsing.
103
+ if not found? and environment.nil?
104
+ @force_parse = true
105
+ instance_eval(File.read(configuration_file))
106
+ @additional_modules.uniq!
107
+ end
108
+
109
+ if not found? and not environment.nil?
110
+ GitPusshuTen::Log.error "Could not find any configuration for #{environment.to_s.color(:yellow)}."
111
+ exit
112
+ end
113
+
114
+ ##
115
+ # Default to port 22 if no port is specified
116
+ @port ||= '22'
117
+
118
+ self
119
+ end
120
+
121
+ end
122
+ end
@@ -0,0 +1,70 @@
1
+ Dir[File.expand_path(File.dirname(__FILE__) + '/helpers/environment/*.rb')].each do |helper|
2
+ require helper
3
+ end
4
+
5
+ module GitPusshuTen
6
+ class Environment
7
+
8
+ include GitPusshuTen::Helpers::Environment::SCP
9
+ include GitPusshuTen::Helpers::Environment::SSH
10
+ include GitPusshuTen::Helpers::Environment::SSHKeys
11
+ include GitPusshuTen::Helpers::Environment::Packages
12
+ include GitPusshuTen::Helpers::Environment::User
13
+ include GitPusshuTen::Helpers::Environment::Installers
14
+ include GitPusshuTen::Helpers::Environment::SCP
15
+
16
+ ##
17
+ # Stores the configuration
18
+ attr_accessor :configuration
19
+
20
+ ##
21
+ # Initializes the environment with the provided configuration
22
+ def initialize(configuration)
23
+ @configuration = configuration
24
+ end
25
+
26
+ ##
27
+ # Shorthand for the configuration object
28
+ def c
29
+ configuration
30
+ end
31
+
32
+ ##
33
+ # Returns the name of the environment
34
+ def name
35
+ c.environment
36
+ end
37
+
38
+ ##
39
+ # Users home directory
40
+ def home_dir
41
+ c.path
42
+ end
43
+
44
+ ##
45
+ # Returns the name of the application
46
+ def app_name
47
+ c.application
48
+ end
49
+
50
+ ##
51
+ # Returns the root of the application
52
+ def app_dir
53
+ File.join(home_dir, "#{sanitized_app_name}.#{name}")
54
+ end
55
+
56
+ ##
57
+ # Takes the application name from the configuration and
58
+ # replaces spaces with underscores and downcases capitalized characters
59
+ def sanitized_app_name
60
+ app_name.gsub(' ', '_').downcase
61
+ end
62
+
63
+ ##
64
+ # Deletes the current environment (application)
65
+ def delete!
66
+ execute_as_user("rm -rf #{app_dir}")
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,33 @@
1
+ module GitPusshuTen
2
+ class Gem
3
+
4
+ ##
5
+ # Stores the JSON gem object from RubyGems.org
6
+ attr_accessor :gem
7
+
8
+ ##
9
+ # Instantiages a new gem
10
+ def initialize(name)
11
+ @gem = JSON.parse(open(File.join(base_url, "#{name}.json")).read)
12
+ end
13
+
14
+ ##
15
+ # Returns the latest version of the gem
16
+ def latest_version
17
+ gem['version']
18
+ end
19
+
20
+ ##
21
+ # Checks to see if the provided version number is outdated
22
+ def outdated?(version)
23
+ version < latest_version
24
+ end
25
+
26
+ ##
27
+ # Returns the base url to the RubyGems API
28
+ def base_url
29
+ "http://rubygems.org/api/v1/gems/"
30
+ end
31
+
32
+ end
33
+ end