gemstrapper 1.0.0 → 1.1.0

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: 4e95bdaee08f3ec61e4862ab445eb88985586002
4
- data.tar.gz: 3eee2eb775807f7d2c5b9033fdb602514cc86a8b
3
+ metadata.gz: 6bd83d7ece0c77d21e7a07136d7424fb77398b1f
4
+ data.tar.gz: 357a33835fe9126494a32a91cff4303fa72976ea
5
5
  SHA512:
6
- metadata.gz: bc79d530f531fb473923846a8a831f43636dcaaf429232b3a7418b68183118eb577cc900529e311b6531cf56c42d9eec962459649b51bc8709ffc88b9fa92fdb
7
- data.tar.gz: f09e32bd22623a2d73e146e451e1c7268a8b8c5b02b70068143a1f114f0fd3156243884279e34463833f2762c832b732ac851aba7d68283a97552d4853c70755
6
+ metadata.gz: 5f824ff41b16b80683a8de14dfc4b72acef26b10c8b2eb1b58291751b9cd6cbea384b9129f8a7793d23981d6a1608b15db91400c8d4066dca61d80cd6b9022a2
7
+ data.tar.gz: d88ca86ae1cebf63da836469e5997767be6b2871201199e00e0852c193da1031cfcabce064a4825c1751c6c4746b3e2452a2635eade972ccccee66fbf8e80e6b
data/bin/gemstrapper CHANGED
@@ -32,20 +32,36 @@ class OptionsParser
32
32
  subcommands = {
33
33
  'init' => OptionParser.new do |opts|
34
34
  opts.banner = "Usage: init <folder_name>"
35
+
36
+ opts.on("-e", "--executable", "Configures gem to be executable") do |e|
37
+ options[:executable] = e
38
+ end
35
39
  end
36
40
  }
37
41
 
38
42
  global.order!
39
43
  command = args.shift
40
- project_name = args.shift
41
44
 
42
- unless command and project_name
45
+
46
+
47
+ unless (command and subcommands.has_key? command)
43
48
  puts "Invalid argument: Command should be: gemstrapper init <project_name>"
44
49
  exit(1)
45
50
  end
46
51
 
47
- options.update(project_name: project_name)
48
52
  subcommands[command].order!
53
+ project_name = args.shift
54
+ # doing this a second time in case the first argument is the project_name, in which case
55
+ # OptsParse will nondisruptively fail on that value and not add the executable flag to the
56
+ # options hash
57
+ subcommands[command].order!
58
+
59
+ unless project_name
60
+ puts "Invalid argument: Command should be: gemstrapper init <project_name>"
61
+ exit(1)
62
+ end
63
+
64
+ options.update(project_name: project_name)
49
65
 
50
66
  return command, options
51
67
  end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## Your executable code here!
@@ -0,0 +1,6 @@
1
+ require '<%= options[:project_name] %>/version'
2
+
3
+ module <%= options[:module_name] %>
4
+ include <%= options[:module_name] %>::VERSION
5
+
6
+ end
@@ -4,11 +4,19 @@ Gem::Specification.new do |s|
4
4
  s.name = '<%= options[:project_name] %>'
5
5
  s.version = <%= options[:module_name] %>::VERSION
6
6
  s.license = 'MIT'
7
+ s.platform = Gem::Platform::RUBY
7
8
  s.summary = "short summary here"
8
9
  s.description = "longer description here"
9
10
  s.author = 'user'
10
11
  s.email = 'user@example.com'
11
12
  s.require_paths = ['lib']
13
+ <% if options[:executable] %>
14
+ s.bindir = 'bin'
15
+ s.executables << '<%= options[:project_file_name] %>'
16
+ <% end %>
12
17
  s.files = Dir['lib/**/*']
18
+ <% if options[:executable] %>
19
+ s.files += Dir['bin/*']
20
+ <% end %>
13
21
  s.homepage = 'home page here'
14
22
  end
@@ -12,6 +12,14 @@ module Utility
12
12
  def module_name_for(string)
13
13
  string.split(/[-,_]/).map {|w| w.capitalize}.join('')
14
14
  end
15
+
16
+ ##
17
+ # Converts a given string into a string that follow Ruby conventions for file names
18
+ # @param [String] string the string to convert
19
+ # @return [String] The given string converted into a file name
20
+ def filename_for(string)
21
+ string.gsub('-', '_')
22
+ end
15
23
  end
16
24
  end
17
25
  end
@@ -1,5 +1,5 @@
1
1
  module Gemstrapper
2
2
  ##
3
3
  # Version Constant. Called as part of the gemspec definition
4
- VERSION = '1.0.0' unless defined? VERSION
4
+ VERSION = '1.1.0' unless defined? VERSION
5
5
  end
data/lib/gemstrapper.rb CHANGED
@@ -8,6 +8,10 @@ require 'gemstrapper/utility/string_helpers'
8
8
  module Gemstrapper
9
9
  include Utility::StringHelpers
10
10
 
11
+ ##
12
+ # The absolute path of the directory containing all the templates needed for a new gem
13
+ TEMPLATES_DIRECTORY = File.expand_path('gemstrapper/templates', File.dirname(__FILE__))
14
+
11
15
  extend self
12
16
 
13
17
  ##
@@ -16,33 +20,40 @@ module Gemstrapper
16
20
  # @param [Hash] options The options passed in from the command line execution
17
21
  # @return [void]
18
22
  def init(options)
19
- @options = options
23
+ options = default_options(options[:project_name]).update(options)
20
24
 
21
25
  new_files = []
22
26
 
23
- @options[:module_name] = module_name_for(@options[:project_name])
24
- # Getting a list of folders to create based on folder structure within lib/templates
25
- templates_directory = File.expand_path('gemstrapper/templates', File.dirname(__FILE__))
27
+ files = template_files_for_gem(options)
26
28
 
27
- files = Dir.chdir(templates_directory) do
28
- Dir.glob('**/*.erb')
29
- end
29
+ #require 'pry';binding.pry
30
30
 
31
31
  files.each do |file|
32
32
  ## creates directories
33
33
  # converting project name placeholder to actual project name and stripping off erb extension
34
- new_file_path = file.gsub('project_name', @options[:project_name]).gsub('.erb', '')
34
+ new_file_path = file.gsub('project_name', options[:project_name]).gsub('.erb', '')
35
+
36
+ new_file_path.gsub!('project_file_name', options[:project_file_name])
37
+ # converting executable_name placeholder for any executable file names into valid names for the gem
38
+ new_file_path.gsub!('executable_name', options[:project_file_name])
39
+
35
40
  directory = File.dirname(new_file_path)
36
41
 
37
42
  unless File.exist? directory
38
43
  FileUtils.mkdir_p directory
39
44
  end
40
45
 
41
- data = process_template(File.join(templates_directory, file), options)
46
+ data = process_template(File.join(TEMPLATES_DIRECTORY, file), options)
42
47
  File.write(new_file_path, data)
43
48
  new_files << new_file_path
44
49
  end
45
50
 
51
+ ## modifying executable files to be executable
52
+ # TODO: Check windows compatibility with this feature
53
+ exe_files = new_files.select {|f| f.include? 'bin/'}.each do |file|
54
+ File.chmod(0755, file)
55
+ end
56
+
46
57
  #reporting
47
58
  new_files.each do |nf|
48
59
  puts "#{nf} created"
@@ -62,4 +73,38 @@ module Gemstrapper
62
73
 
63
74
  ERB.new(template_data).result binding
64
75
  end
76
+
77
+ ##
78
+ # default config options for the execution
79
+ # @param [String] project_name the name of the project. Used to create the default
80
+ # module name
81
+ # @return [Hash] the default options
82
+ def default_options(project_name)
83
+ {
84
+ module_name: module_name_for(project_name),
85
+ executable: false,
86
+ project_file_name: filename_for(project_name)
87
+ }
88
+ end
89
+
90
+ ##
91
+ # returns a list of template files to be processed and created for the new gem
92
+ # @param [Hash] options a list of the current execution options
93
+ # @return [Array] a list of template files
94
+ def template_files_for_gem(options)
95
+ files = []
96
+
97
+ Dir.chdir(TEMPLATES_DIRECTORY) do
98
+ files += Dir.glob('project_name/lib/**/*.erb') # library files
99
+ files << 'project_name/Gemfile.erb' # adding Gemfile
100
+ files << 'project_name/project_name.gemspec.erb' # adding Gemspec
101
+
102
+ if options[:executable]
103
+ files += Dir.glob('project_name/bin/*.erb') # executable files
104
+ end
105
+ end
106
+
107
+ files
108
+ end
109
+
65
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemstrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Hoiberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-26 00:00:00.000000000 Z
11
+ date: 2015-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -76,6 +76,8 @@ files:
76
76
  - bin/gemstrapper
77
77
  - lib/gemstrapper.rb
78
78
  - lib/gemstrapper/templates/project_name/Gemfile.erb
79
+ - lib/gemstrapper/templates/project_name/bin/executable_name.erb
80
+ - lib/gemstrapper/templates/project_name/lib/project_file_name.rb.erb
79
81
  - lib/gemstrapper/templates/project_name/lib/project_name/version.rb.erb
80
82
  - lib/gemstrapper/templates/project_name/project_name.gemspec.erb
81
83
  - lib/gemstrapper/utility/string_helpers.rb