joe_utils 0.0.12 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 296e5990da73b7ce54c8d1c9ce8aa2a9080d172a
4
- data.tar.gz: 7bf22e58dc70b4725942e933222b025d2eac7f5f
3
+ metadata.gz: 7984b7a7471a9f017e74521a599611bc187eb17c
4
+ data.tar.gz: 6487c0b7dde312f85b030e881967923066e63621
5
5
  SHA512:
6
- metadata.gz: bd94fdbe0788a4f1aadc2a27c81fac41042a7cb91702cdf305d34dddf2e68e7bc6558f96696f359254c1ad598334ccafc17f5b80f6a4ba60821924d506d80763
7
- data.tar.gz: 049682ab6a9d1335de9026cc43a72f0a02c45723656b8cc8259792cd26eb8486a44f8b11d2c452b83ceeb333b0e3bc694e61f9366558385aebeeb68439904fc5
6
+ metadata.gz: e53feb4103157a3007d1a47efb9e2f5a2aec564878fde34c1e18b7fdfde0eb035f8238ea273acb57dd6434a89145b7bf22f67d729a84dac8d68cfde208a6177e
7
+ data.tar.gz: 0e14ac6d89019d1abb44198ee11b6fff47ebb0e9994d9ccbced30056d6cf826826ede01214e4278c40702025229182f360b2f28e077de844e30decaeb4a8cee2
@@ -1,56 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'joe_utils'
3
+ require 'joe_utils/utils/project_utility'
4
4
 
5
- class ProjU
6
-
7
- include CLIHelper
8
- include RegExpHelper
9
-
10
- HELP_TEXT = 'Provide me with the name of the gem, you also can add options:
11
- i for installing the gem locally, p for pushing the gem to rubygems.org, h for help.',
12
- INCLUDE_GEM_NAME = 'You did not enter a gem name.
13
- Please include it as an argument to the script or hard code it as a variable in the script.',
14
-
15
- def process_input(input, options = {})
16
- message = nil
17
- input.each do |arg|
18
- if message
19
- options[:message] = arg
20
- next
21
- end
22
- case arg
23
- when '-g', '--github'
24
- options[:github] = true
25
- when '-h', '--heroku'
26
- options[:heroku] = true
27
- when '-gh'
28
- options[:github] = options[:heroku] = true
29
- when '-i', '--install'
30
- options[:install] = true
31
- when '-p', '--push'
32
- options[:push] = true
33
- when '-h', '--help'
34
- puts HELP_TEXT
35
- exit
36
- when '-ip'
37
- options[:install] = options[:push] = true
38
- when '-m'
39
- message = true
40
- else
41
- options[:gem_name] = arg
42
- end
43
- end
44
- options
45
- end
46
-
47
- def run
48
- options = process_input(ARGV)
49
- commit_git(options[:message])
50
- commit_github if options[:github]
51
- deploy_heroku if options[:heroku]
52
- build_gem(options[:gem_name], options) if options[:gem_name]
53
- end
54
- end
55
-
56
- ProjectUtility.new.run
5
+ ProjectUtility.new.run(['-s', 'Test proj_util'])
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'joe_utils'
3
- s.version = '0.0.12'
3
+ s.version = '0.1.6'
4
4
  s.executables = %w(proj_util)
5
5
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ['Josef Erneker']
@@ -1,11 +1,12 @@
1
- require 'joe_utils/config_helper'
2
- require 'joe_utils/console_helper'
3
- require 'joe_utils/files_helper'
4
- require 'joe_utils/name_helper'
5
- require 'joe_utils/script_editor_helper'
1
+ require 'joe_utils/helpers/config_helper'
2
+ require 'joe_utils/helpers/console_helper'
3
+ require 'joe_utils/helpers/files_helper'
4
+ require 'joe_utils/helpers/name_helper'
5
+ require 'joe_utils/helpers/script_editor_helper'
6
6
  require 'joe_utils/script_renderer'
7
7
  require 'joe_utils/script'
8
- require 'joe_utils/socket_helper'
9
- require 'joe_utils/cli_helper'
10
- require 'joe_utils/regexp_helper'
8
+ require 'joe_utils/helpers/socket_helper'
9
+ require 'joe_utils/helpers/cli_helper'
10
+ require 'joe_utils/helpers/regexp_helper'
11
+
11
12
 
@@ -0,0 +1,84 @@
1
+ module CLIHelper
2
+
3
+ MESSAGES = {
4
+ add_git: 'Adding to git...',
5
+ commit_git: 'Commiting to git...',
6
+ push_rubygems: 'Pushing to rubygems.org...',
7
+ install_gem: 'Installing gem and jgem locally...',
8
+ build_gem: 'Building gem...',
9
+ build_gem_failed: 'The gem build failed. Please confirm the gem name and try again.',
10
+ deploy_heroku: 'Deploying to heroku.',
11
+ commit_github: 'Commiting to github.',
12
+ commit_default_message: 'Commit by script',
13
+ rake_test: 'Running tests...',
14
+ }
15
+
16
+ # Commits to git
17
+ # @return [Boolean]
18
+ def commit_git(message)
19
+ execute(:add_git, 'git add -u') &&
20
+ execute(:commit_git, "git commit -m \"#{message || MESSAGES[:commit_default_message]}\"")
21
+ end
22
+
23
+ # Builds the named gem locally, in case of provided options pushes and installs the gem
24
+ # @param [String] gem_name
25
+ # @param [Hash] options, supported options: :push for pushing to rubygems.org, :install for installing the gem locally
26
+ # @return [Boolean]
27
+ def build_gem(gem_name, options = {})
28
+ puts MESSAGES[:build_gem]
29
+ success = true
30
+ puts(gem_built_name = `gem build "#{gem_name}.gemspec"`)
31
+ gem_built_name = gem_built_name.match(/File: /).post_match
32
+ if gem_built_name && !gem_built_name.empty?
33
+ success = push_rubygems(gem_built_name) if options[:push]
34
+ options[:install] ? install_gem(gem_built_name) && install_jgem(gem_built_name) && success : success
35
+ else
36
+ puts MESSAGES[:build_gem_failed]
37
+ end
38
+ end
39
+
40
+ # Pushes the named gem to rubygems.org
41
+ # @param [String] gem_built_name
42
+ # @return [Boolean]
43
+ def push_rubygems(gem_built_name)
44
+ execute(:push_rubygems, "gem push #{gem_built_name}")
45
+ end
46
+
47
+ # Installs the named gem locally
48
+ # @param [String] gem_built_name
49
+ # @return [Boolean]
50
+ def install_gem(gem_built_name)
51
+ execute(:install_gem, "gem install #{gem_built_name}")
52
+ end
53
+
54
+ # Installs the named jgem locally
55
+ # @param [String] gem_built_name
56
+ # @return [Boolean]
57
+ def install_jgem(gem_built_name)
58
+ execute(:install_jgem, "jgem install #{gem_built_name}")
59
+ end
60
+
61
+ # @return [Boolean]
62
+ def commit_github
63
+ execute(:commit_github, 'git push origin master')
64
+ end
65
+
66
+ # @return [Boolean]
67
+ def deploy_heroku
68
+ execute(:deploy_heroku, 'git push heroku master')
69
+ end
70
+
71
+ # @return [Boolean]
72
+ def rake_test
73
+ execute(:rake_test, 'rake test')
74
+ end
75
+
76
+ # @param [Symbol] message_key
77
+ # @param [String] command
78
+ # @return [Boolean]
79
+ def execute(message_key, command, no_success_pattern = nil)
80
+ puts MESSAGES[message_key] if message_key
81
+ puts (result = `#{command}`)
82
+ result !~ no_success_pattern || RegExpHelper::NO_SUCCESS
83
+ end
84
+ end
@@ -5,6 +5,14 @@ require 'zip'
5
5
 
6
6
  module FilesHelper
7
7
 
8
+ def get_current_address
9
+ Dir.pwd
10
+ end
11
+
12
+ def get_current_folder
13
+ File.basename(Dir.pwd)
14
+ end
15
+
8
16
  def dir_exists?(location)
9
17
  File.directory?(location) ? true : puts("Directory #{location} doesn't exist.")
10
18
  end
@@ -1,3 +1,4 @@
1
1
  module RegExpHelper
2
2
  CLI_MESSAGE_INPUT = /"[\s\w]+"/
3
+ NO_SUCCESS = /Failed|Error/
3
4
  end
@@ -0,0 +1,78 @@
1
+ require 'joe_utils.rb'
2
+
3
+ class ProjectUtility
4
+
5
+ include CLIHelper
6
+ include RegExpHelper
7
+ include FilesHelper
8
+
9
+ HELP_TEXT = 'Project utility:
10
+ executes basic administrative tasks with project, so far supported options:
11
+ s for skipping tests,
12
+ g for pushing to github,
13
+ e for pushing to heroku,
14
+ b for building a gem, notice, you need to be in the folder which is called as the .gemspec file of the gem,
15
+ p for pushing it to rubygems.org,
16
+ i for installing it locally,
17
+ h for help,
18
+ you can combine the options when it makes sense.
19
+ Text behind the command will be considered a message for git.'
20
+
21
+ def process_input(input, options = {})
22
+ input.each do |arg|
23
+ if arg[0..1] == '--'
24
+ case arg[2..-1]
25
+ when 'build'
26
+ options[:gem_name] ||= get_current_folder
27
+ when 'install'
28
+ options[:install] = true
29
+ when 'push'
30
+ options[:push] = true
31
+ when 'heroku'
32
+ options[:heroku] = true
33
+ when 'github'
34
+ options[:github] = true
35
+ else
36
+ puts HELP_TEXT
37
+ exit
38
+ end
39
+ elsif arg[0] == '-'
40
+ arg[1..-1].each_char do |letter|
41
+ case letter
42
+ when 's'
43
+ options[:skip_tests] = true
44
+ when 'g'
45
+ options[:github] = true
46
+ when 'e'
47
+ options[:heroku] = true
48
+ when 'b'
49
+ options[:gem_name] ||= get_current_folder
50
+ when 'i'
51
+ options[:install] = true
52
+ options[:gem_name] ||= get_current_folder
53
+ when 'p'
54
+ options[:push] = true
55
+ options[:gem_name] ||= get_current_folder
56
+ else
57
+ puts HELP_TEXT
58
+ exit
59
+ end
60
+ end
61
+ else
62
+ options[:message] = arg
63
+ end
64
+ end
65
+ options
66
+ end
67
+
68
+ def run(input = nil)
69
+ options = process_input(input || ARGV)
70
+ success = true
71
+ success = rake_test unless options[:skip_tests]
72
+ success &&= commit_git(options[:message])
73
+ success &&= commit_github if options[:github]
74
+ success &&= deploy_heroku if options[:heroku]
75
+ success &&= build_gem(options[:gem_name], options) if options[:gem_name]
76
+ success
77
+ end
78
+ end
@@ -0,0 +1,25 @@
1
+ require 'minitest/autorun'
2
+ require 'joe_utils/utils/project_utility.rb'
3
+
4
+ class JoeUtilsTest < Minitest::Test
5
+
6
+ # def test_commit
7
+ # assert(ProjectUtility.new.run(['-s', 'Test proj_util']), 'Commit not successful.')
8
+ # end
9
+ #
10
+ # def test_commit_build
11
+ # assert(ProjectUtility.new.run(['-bs', 'Test build proj_util']), 'Build not successful.')
12
+ # end
13
+ #
14
+ # def test_commit_install
15
+ # assert(ProjectUtility.new.run(['-is', 'Test build install proj_util']), 'Install not successful.')
16
+ # end
17
+ #
18
+ # def test_commit_push
19
+ # assert(ProjectUtility.new.run(['-ps', 'Test build push proj_util']), 'Push not successful.')
20
+ # end
21
+
22
+ def test_gem_util
23
+ assert(ProjectUtility.new.run(['-ips', 'Test build install push proj_util']), 'Something is wrong.')
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joe_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josef Erneker
@@ -44,16 +44,18 @@ files:
44
44
  - joe_utils.gemspec
45
45
  - lib/joe_utils.rb
46
46
  - lib/joe_utils/Script.rb
47
- - lib/joe_utils/cli_helper.rb
48
- - lib/joe_utils/config_helper.rb
49
- - lib/joe_utils/console_helper.rb
50
- - lib/joe_utils/files_helper.rb
51
- - lib/joe_utils/name_helper.rb
52
- - lib/joe_utils/regexp_helper.rb
53
- - lib/joe_utils/script_editor_helper.rb
47
+ - lib/joe_utils/helpers/cli_helper.rb
48
+ - lib/joe_utils/helpers/config_helper.rb
49
+ - lib/joe_utils/helpers/console_helper.rb
50
+ - lib/joe_utils/helpers/files_helper.rb
51
+ - lib/joe_utils/helpers/name_helper.rb
52
+ - lib/joe_utils/helpers/regexp_helper.rb
53
+ - lib/joe_utils/helpers/script_editor_helper.rb
54
+ - lib/joe_utils/helpers/socket_helper.rb
54
55
  - lib/joe_utils/script_renderer.rb
55
- - lib/joe_utils/socket_helper.rb
56
+ - lib/joe_utils/utils/project_utility.rb
56
57
  - test/test_joe_utils.rb
58
+ - test/test_proj_util.rb
57
59
  homepage: http://rubygems.org/gems/joeutils
58
60
  licenses:
59
61
  - GPL-3.0
@@ -1,66 +0,0 @@
1
- module CLIHelper
2
-
3
- MESSAGES = {
4
- commit_git: 'Commiting to git...',
5
- push_rubygems: 'Pushing to rubygems.org...',
6
- install_gem: 'Installing gem and jgem locally...',
7
- build_gem: 'Building gem...',
8
- build_gem_failed: 'The gem build failed. Please confirm the gem name and try again.',
9
- deploy_heroku: 'Deploying to heroku.',
10
- commit_github: 'Commiting to github.',
11
- default_message: 'Commit by script'
12
- }
13
-
14
- # Commits to git
15
- # @return [nil]
16
- def commit_git(message)
17
- puts MESSAGES[:commit_git]
18
- puts `git add -u`
19
- puts `git commit -m "#{message || MESSAGES[:default_message]}"`
20
- end
21
-
22
- # Builds the named gem locally, in case of provided options pushes and installs the gem
23
- # @param [String] gem_name
24
- # @param [Hash] options, supported options: :push for pushing to rubygems.org, :install for installing the gem locally
25
- # @return [nil]
26
- def build_gem(gem_name, options = {})
27
- puts MESSAGES[:build_gem]
28
- puts(gem_built_name = `gem build "#{gem_name}.gemspec"`)
29
- gem_built_name = gem_built_name.match(/File: /).post_match
30
- if gem_built_name && !gem_built_name.empty?
31
- push_rubygems(gem_built_name) if options[:push]
32
- install_gem(gem_built_name) if options[:install]
33
- else
34
- puts MESSAGES[:build_gem_failed]
35
- end
36
- end
37
-
38
- # Pushes the named gem to rubygems.org
39
- # @param [String] gem_built_name
40
- # @return [nil]
41
- def push_rubygems(gem_built_name)
42
- puts MESSAGES[:push_rubygems]
43
- puts `gem push #{gem_built_name}`
44
- end
45
-
46
- # Installs the named gem locally
47
- # @param [String] gem_built_name
48
- # @return [nil]
49
- def install_gem(gem_built_name)
50
- puts MESSAGES[:install_gem]
51
- puts `gem install #{gem_built_name}`
52
- puts `jgem install #{gem_built_name}`
53
- end
54
-
55
- # @return [nil]
56
- def commit_github
57
- puts MESSAGES[:commit_github]
58
- puts `git push origin master`
59
- end
60
-
61
- # @return [nil]
62
- def deploy_heroku
63
- puts MESSAGES[:deploy_heroku]
64
- puts `git push heroku master`
65
- end
66
- end