aspen 0.1.8 → 0.2.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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWQzMDZmM2U2MWEwZDM1ODhkNTI3ZDFjYmNmNzU3M2Q0YWE5M2ZhZA==
4
+ MjdkM2Y3OWUwZTM1MWMyZDU5YTRmMWE0MzRiZTE4ZmMyN2NmYjI5OQ==
5
5
  data.tar.gz: !binary |-
6
- MzM2YjRlMWUzMjc3MmM2MTk3ZTczMzRlZjdmOGNlMWYzZmI2NjZjZg==
6
+ YjAyOWIzYjc1ZjFiZGU2NmJhNmUwZThjNzc2OWNlZDIyODU3MGRmNQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ODAxOGJmNzNhZTcwMmNmMDZiMWM2ZTc1ZThlOGM1NGQxZDcwNzY1MDYwNzE5
10
- ODEwNmFiYjJlNTYwYjFkODdjNmY0OWI1ODJkOWI4NGUwNmUxNjMxNzJiODc0
11
- MjUyZGVmZmQyNjFmZmJjY2U0ZDkzZTAyNWFiZTg2NzU5NWFkMDc=
9
+ NDQ1YTcxMTY0MGRkM2EwZjA5NmFkOWNhNzM4MWUxMTIyMTQyNTk1Zjk5Nzc0
10
+ ZmViYjgyODhjOTQ4YzYyNzk1MmYxOGNlMDM2M2VjNGM0NjRmNGIzYzBkZTQ1
11
+ YmY1NzM5MGFkZDE1YTk4ODdjN2ZjYzJlM2I2ZDI3NGRhNTc2NGI=
12
12
  data.tar.gz: !binary |-
13
- ZDViZDc5MDQ2MWZiMWIyMjdiNzZlZjAyYjQ5MWQ5NTc5NTM2Y2EzYjRjNjI4
14
- M2QzMTZhNzgwZDc3YWY3ZThlNzIyZmU2NTMyMjdlYTYyMDNjMjUyOGI1NGIw
15
- MTZkMDQ0ZjFhYmY5OWMyNjk5YzNkMjVmYzc4YjFhZTE2ODhkNDY=
13
+ MTVmM2EyOGI1ZTA4ZDg0MzAyNzNjYWU1OWIyZDE0YmQ5Mzk5MjkxNzNhMWQ2
14
+ YTYwNWJhZmIyMjNhY2RlODYxMmE2OTdkMDBhMGViNDI2ZWViYzIyNDc5NTA5
15
+ NGQ2MmM0YzYzZTQzOGU4NmEzNmM0NmEyYmJhYTVlZDk4ZTBkMWU=
data/bin/aspen CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'aspen'
4
- Aspen.run(ARGV)
4
+ Aspen.run
@@ -0,0 +1,24 @@
1
+ require 'fileutils'
2
+ require 'rspec'
3
+ require 'pry'
4
+ require 'git'
5
+ require 'trollop'
6
+
7
+ AspenRoot = File.expand_path(File.dirname(__FILE__)).gsub("/config", "")
8
+
9
+ def get_reqs(current_dir)
10
+ Dir.foreach(current_dir) do |file|
11
+ next if file.start_with?('.') || file.start_with?("environment.rb")
12
+ if File.directory?("#{current_dir}/#{file}")
13
+ next if file.start_with?("templates")
14
+ get_reqs("#{current_dir}/#{file}")
15
+ else
16
+ require_relative "#{current_dir}/#{file}" if file.end_with?(".rb")
17
+ end
18
+ end
19
+ end
20
+
21
+ Dir.foreach(AspenRoot) do |file|
22
+ next if file.start_with?('.')
23
+ get_reqs("#{AspenRoot}/#{file}") if File.directory?("#{AspenRoot}/#{file}")
24
+ end
@@ -1,48 +1,82 @@
1
- require 'fileutils'
2
- require 'rspec'
1
+ require_relative '../config/environment'
3
2
 
4
3
  class Aspen
5
4
 
6
- AspenRoot = File.dirname(__FILE__)
5
+ @@mono_flags = [:git]
7
6
 
8
- DIRECTORIES = ["","/bin", "/config","/lib/models","/lib/concerns"]
7
+ @@args = Trollop::Parser.new do
8
+ opt :git, "Initialize a git repository"
9
+ opt :template, "Specify a template structure", :type => :string
10
+ opt :name, "Specify project name", :type => :strings
11
+ end
12
+
13
+ @@opts = Trollop::with_standard_exception_handling @@args do
14
+ raise Trollop::HelpNeeded if ARGV.empty? || !ARGV[0].start_with?("-")
15
+ @@args.parse ARGV
16
+ end
9
17
 
10
- def self.method_missing(method, *args, &block)
11
- puts "Invalid command - try again."
18
+ def self.directories
19
+ @@directories
12
20
  end
13
21
 
14
22
  def self.help
15
- File.open(File.join(AspenRoot, "../help/help.txt")).each_line do |line|
16
- puts line
23
+ raise Trollop::HelpNeeded
24
+ end
25
+
26
+ def self.run
27
+ @@root_name = sterilize_project_name(@@opts[:name])
28
+ load_template
29
+ @@directories = AspenTemplate.tree(TEMPLATE)
30
+ project_init
31
+ end
32
+
33
+ def self.gem_init
34
+ current = FileUtils.pwd()
35
+ FileUtils.cd("#{@@root_name}")
36
+ yield
37
+ FileUtils.cd(current)
38
+ end
39
+
40
+ def self.git
41
+ gem_init { Git.init }
42
+ end
43
+
44
+ def self.process_flags
45
+ @@mono_flags.each do |flag|
46
+ if @@opts[flag] == true
47
+ self.send(flag)
48
+ end
17
49
  end
18
50
  end
19
51
 
20
- def self.run(args)
21
- if args[0].strip.downcase == '--help'
22
- return help
52
+ def self.load_template
53
+ if @@opts[:template] == nil
54
+ require_relative "#{AspenRoot}/lib/templates/default.rb"
55
+ else
56
+ Dir.foreach("#{AspenRoot}/lib/templates") do |file|
57
+ if file.start_with?("#{@@opts[:template].downcase.strip}")
58
+ require_relative "#{AspenRoot}/lib/templates/#{file}"
59
+ break
60
+ end
61
+ end
23
62
  end
24
- return method_missing(:run, args) if args == nil
25
- @@root_name = sterilize_project_name(args)
26
- return if @@root_name == nil
27
- project_init
63
+ end
64
+
65
+ def self.rspec_init
66
+ gem_init { RSpec::Core::ProjectInitializer.new.run }
28
67
  end
29
68
 
30
69
  def self.project_init
31
70
  directory_init
32
71
  rspec_init
33
- make_files
72
+ make_files if @@opts[:template] == nil || @@opts[:template] == "default"
34
73
  successful_creation
74
+ write_to_files
75
+ process_flags
35
76
  end
36
77
 
37
78
  def self.directory_init
38
- DIRECTORIES.each {|dir| FileUtils.mkdir_p("#{@@root_name}#{dir}", :verbose => true)}
39
- end
40
-
41
- def self.rspec_init
42
- current = FileUtils.pwd()
43
- FileUtils.cd("#{@@root_name}")
44
- system('rspec --init')
45
- FileUtils.cd(current)
79
+ self.directories.each {|dir| FileUtils.mkdir_p("#{@@root_name}#{dir}", :verbose => true)}
46
80
  end
47
81
 
48
82
  def self.make_files
@@ -50,13 +84,20 @@ class Aspen
50
84
  FileUtils.touch("#{@@root_name}/config/environment.rb")
51
85
  end
52
86
 
87
+ def self.write_to_files
88
+ File.open("#{@@root_name}/README.md", "w+") do |f|
89
+ f << "###{@@project_name}\n*thanks for using aspen - happy coding!*"
90
+ end
91
+ end
92
+
53
93
  def self.successful_creation
54
94
  puts "\nProject successfully created at:\n\t#{Dir.pwd}/#{@@root_name}\n"
55
95
  end
56
96
 
57
- def self.sterilize_project_name(args)
58
- name = (args.size == 1 ? args.first : args.join(" "))
97
+ def self.sterilize_project_name(name)
98
+ name = name.join(" ")
59
99
  if name.match(/^[a-z]/i)
100
+ @@project_name = name
60
101
  name.strip.downcase.gsub(/[\s\_]/,"-")
61
102
  else
62
103
  puts "Invalid project name: #{name}"
@@ -0,0 +1,19 @@
1
+ class AspenTemplate
2
+
3
+ def self.tree(hash)
4
+ self.tree_gen(hash).flatten.unshift("")
5
+ end
6
+
7
+
8
+ def self.tree_gen(hash, root="")
9
+ folders_array = hash.collect do |key, value|
10
+ if value.size == 0
11
+ "#{root}/#{key}"
12
+ else
13
+ self.tree_gen(value, "#{root}/#{key}")
14
+ end
15
+ end
16
+ end
17
+
18
+
19
+ end
@@ -0,0 +1,8 @@
1
+ TEMPLATE = {
2
+ :bin => {},
3
+ :config => {},
4
+ :lib => {
5
+ :models => {},
6
+ :concerns => {}
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ TEMPLATE = {
2
+ :hello => {},
3
+ :this_is_a => {},
4
+ :testing_template => {
5
+ :for => {},
6
+ :our_gem_aspen => {}
7
+ }
8
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aspen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan Hasson
@@ -27,16 +27,48 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
- description: Sets up a simple directory tree for Ruby projects
30
+ - !ruby/object:Gem::Dependency
31
+ name: git
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: trollop
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ description: Sets up a directory tree for coding projects based on customizable templates
31
59
  email: teamevalruby@gmail.com
32
60
  executables:
33
61
  - aspen
34
62
  extensions: []
35
63
  extra_rdoc_files: []
36
64
  files:
37
- - lib/aspen.rb
38
65
  - help/help.txt
39
66
  - bin/aspen
67
+ - config/environment.rb
68
+ - lib/aspen.rb
69
+ - lib/aspen_template.rb
70
+ - lib/templates/default.rb
71
+ - lib/templates/hello.rb
40
72
  homepage: http://rubygems.org/gems/aspen
41
73
  licenses:
42
74
  - MIT