rapp 0.1.0 → 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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41d0cf6c0f28404a0ff147a8410d0839fa829be2
4
- data.tar.gz: 19000ad06894dcf3cf151f285e1db8faad7730bf
3
+ metadata.gz: 5760f2902c04d2f3457c56168c00b37f5f94c9d5
4
+ data.tar.gz: ab6132b2099f0f6f1d854d965766bbe5a14ff429
5
5
  SHA512:
6
- metadata.gz: f75920e664cf117ad3e6ac442321e09820f41ad79b03179f4b0c1e59b1944dc76c2db74751b5e013ae3d17a3b69b84def24b67169dbfed3756d0a093f8191d2e
7
- data.tar.gz: b8b6533125946fda5d95d00c9ee83e46c7f8680c0beed694f18532768de33fa3c4b7ab550dd4dd7a663db84e415865687763862d2ec963dc2f4b93aa3dc7e482
6
+ metadata.gz: e4f54bfd0662b4f6b935a527fcf3922b4ba44866317ef1f457b9a3688cbc73a2ef6c932c700d69636b7231000228e469bb3fa38542298a650e634d8c63a6128f
7
+ data.tar.gz: 86c326f983fe0ccbb7460d0f94af8f2ea6dc8ed59585a4944c41d47f6b4b48a8d08368b6009dc50556430291187727b1eb41f42b1ee5505824d80252f397f75a
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Rapp - The Ruby App Scaffolder
4
4
 
5
+ ## Note
6
+
7
+ Prior to this incarnation, there was an older, similar gem named Rapp which was abandoned. I have obtained the authors permission both for use of the name, as well as for use of the project on Ruby Gems.
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -22,11 +26,11 @@ Or install it yourself as:
22
26
 
23
27
  Using Rapp is incredibly simple. It's designed to work like familiar scaffolders / builders in the ruby community (think `rails new`).
24
28
 
25
- Currently, Rapp is in early development, and additional features are forthcoming. There is a Roadmap at the bottom of the Readme to highlight some of the work I feel is important to prioritize before a full v1 release. In addition to features, this includes the internal organization of the code as well, as the current state is more prototypical than it is final release quality.
29
+ Currently, Rapp is in early development, and additional features are forthcoming. There is a Roadmap at the bottom of the Readme to highlight some of the work I feel is important to prioritize before a full v1 release. In addition to features, this includes the internal organization of the code as well.
26
30
 
27
31
  ### Ethos
28
32
 
29
- Rapp is not a framework for running an app or building an app from pieces-parts. In the future, there may be additional helpers to configure very common components in the ruby community, but the overall goal is to hand you a working application with a few common niceties, then get out of your way. Once you've generated the Rapp, the project is yours to do with as you see fit - the gem itself is not a dependencty of the app you create.
33
+ Rapp is not a framework for running an app. In the future, there may be additional helpers to configure very common components in the ruby community, but the overall goal is to hand you a working application with a few common niceties, then get out of your way. Once you've generated the Rapp, the project is yours to do with as you see fit - the gem itself is not a dependency of the app you create.
30
34
 
31
35
  Rapps are shells to house your app, in a familiar layout, to prevent you from having to write the same boring boilerplate time and time again.
32
36
 
@@ -117,12 +121,21 @@ Mostly reserved for future use, this is where both Rapp specific specs to ensure
117
121
 
118
122
  Currently, Rapp comes with 1 predefined rake task, which is "console". This will boot up irb while loading your {app_name}.rb, which will load the rest of your app. This is aliased to "c" for convenience.
119
123
 
124
+ ### Specs
125
+
126
+ Optionally you can generate specs for your app to test the underpinnings of what Rapp has created. You can do this by specifying the ```--specs``` or ```-s``` flags on the command line.
127
+
128
+ These specs aim to not be in the way of you writing your own specs, and so the spec_helper is sparse, and the generated specs attempt to not include a test for {app_name}, but rather {app_name}_base, so that you can do any {app_name} specific testing in that file yourself.
129
+
130
+ Mainly, these are here to help you make changes to a Rapp project once it's been generated if you so need, being able to verify that the core behaviors still function.
131
+
120
132
  ## Roadmap
121
133
 
122
134
  At the moment, this gem serves to fit a need that I found myself having and figured others might be as well. To that end, my main goals are to provide a simple, stable core ruby app intended to be run as a simple cli program, daemonized process, or otherwise. Currently, my primary roadmap for development is:
123
135
 
124
- 1. Generate specs for the users application
125
- 2. Test ease of use integrating Chore / Sidekiq like job systems
136
+ 1. Generate increased / improved specs for the users application
137
+ 2. General code cleanup. Much of the code is prototypical and is not as DRY as it could be (ex: the builder class)
138
+ 3. Test ease of use integrating Chore / Sidekiq like job systems
126
139
 
127
140
  ## Contributing
128
141
 
@@ -131,3 +144,7 @@ At the moment, this gem serves to fit a need that I found myself having and figu
131
144
  3. Commit your changes (`git commit -am 'Add some feature'`)
132
145
  4. Push to the branch (`git push origin my-new-feature`)
133
146
  5. Create a new Pull Request
147
+
148
+ # Contact
149
+
150
+ Comments? Criticisms? Concerns? Open an issue on Github, or simply tweet at me. I'm @StabbyCutyou on Twitter.
data/lib/rapp/builder.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'erb'
3
3
  require 'ostruct'
4
+ require 'rapp/version'
4
5
 
5
6
  module Rapp
6
7
  DirectoryStructure = [
@@ -14,13 +15,17 @@ module Rapp
14
15
  "config/initializers",
15
16
  "lib",
16
17
  "lib/tasks",
17
- "spec"
18
+ ]
19
+
20
+ SpecStructure = [
21
+ "spec",
22
+ "spec/app_name_base"
18
23
  ]
19
24
  class Builder
20
25
  class << self
21
26
  def new_app(opts={})
22
27
  # Get name
23
- raise ArgumentError.new("You must provide a name") unless app_name = opts.delete(:name)
28
+ raise ArgumentError.new("You must provide a name") unless app_name = opts[:name]
24
29
  # Check if folder exists
25
30
  root_dir = "#{`pwd`.strip}/#{app_name}"
26
31
  raise ArgumentError.new("Directory #{root_dir} already exists") if File.directory?(root_dir)
@@ -34,11 +39,17 @@ module Rapp
34
39
  end
35
40
 
36
41
  # For each template, render it, place it in the folder structure it corresponds to
37
- template_root = File.join(File.dirname(__FILE__), 'templates')
38
42
 
39
43
  # Construct the data object
40
- template_binding = OpenStruct.new({:name=>app_name, :class_name=>classify(app_name)})
41
- Dir["#{template_root}/**/*"].reject { |p| File.directory? p }.each do |template|
44
+ template_binding = OpenStruct.new(
45
+ { :name=>app_name,
46
+ :class_name=>classify(app_name),
47
+ :rapp_version=>Rapp::VERSION
48
+ })
49
+
50
+ # Skip spec dirs unless they said they wanted it
51
+ # My intention here is to use "or" specifically, because it does not short-circuit. The second check is very important
52
+ Dir["#{template_root}/**/*"].reject { |p| puts "#{p} -#{p.include?('spec')}"; File.directory? p or p.include?('spec') }.each do |template|
42
53
  template_data = File.read(template)
43
54
  relative_name = template.split("templates/")[1][0..-5]
44
55
  # Hack to make the entry point ruby file share the same name as the app
@@ -50,13 +61,55 @@ module Rapp
50
61
  File.write("#{root_dir}/#{relative_name}", result)
51
62
  end
52
63
 
64
+ # If set on the cli, build the spec stuff
65
+ add_specs(root_dir, opts) if opts[:specs]
66
+
53
67
  puts "Finished creating #{app_name}"
54
68
  puts "#{`find ./#{app_name}`}"
55
69
  end
56
70
 
71
+ def add_specs(root_dir, options)
72
+ app_name = options[:name]
73
+ #add rspec to the gemfile
74
+ open("#{root_dir}/Gemfile", 'a') do |f|
75
+ f.puts 'gem "rspec", "~>3.1.0"'
76
+ end
77
+
78
+ # Create the directory structrue
79
+ SpecStructure.each do |dir|
80
+ puts "dir is #{dir}"
81
+ name = dir.gsub!('app_name', app_name) if dir.include?("app_name")
82
+ puts "name is #{name}"
83
+ dir_name = "#{root_dir}/#{name}"
84
+ #puts "dirname #{dir_name}"
85
+ FileUtils.mkdir_p(dir_name) unless File.directory?(dir_name)
86
+ end
87
+
88
+ # Construct the data object
89
+ template_binding = OpenStruct.new(
90
+ { :name=>app_name,
91
+ :class_name=>classify(app_name),
92
+ :rapp_version=>Rapp::VERSION
93
+ })
94
+
95
+ # Get all the spec templates
96
+ Dir["#{template_root}/spec/**/*"].reject {|p| File.directory? p }.each do |template|
97
+ template_data = File.read(template)
98
+ relative_name = template.split("templates/")[1][0..-5]
99
+ relative_name = relative_name.gsub!('app_name', app_name) if relative_name.include?("app_name")
100
+ puts "template #{template} rel path #{relative_name}"
101
+ result = ERB.new(template_data).result(template_binding.instance_eval {binding})
102
+ File.write("#{root_dir}/#{relative_name}", result)
103
+ end
104
+ end
105
+
57
106
  def classify(string)
58
107
  string.gsub(/(?<=_|^)(\w)/){$1.upcase}.gsub(/(?:_)(\w)/,'\1')
59
108
  end
109
+
110
+ def template_root
111
+ File.join(File.dirname(__FILE__), 'templates')
112
+ end
60
113
  end
61
114
  end
62
115
  end
data/lib/rapp/cli.rb CHANGED
@@ -7,6 +7,10 @@ module Rapp
7
7
 
8
8
  OptionParser.new do |opts|
9
9
  opts.banner = "Usage: rapp [app_name]"
10
+
11
+ opts.on("-s", "--specs", "Generate basic validation specs for the app you build") do
12
+ options[:specs] = true
13
+ end
10
14
  end.parse!
11
15
 
12
16
  options
@@ -2,6 +2,8 @@ require 'env'
2
2
 
3
3
  module <%= class_name %>Base
4
4
 
5
+ RAPP_VERSION="<%= rapp_version %>"
6
+
5
7
  def self.included(base) #:nodoc:
6
8
  base.extend(ClassMethods)
7
9
  <%= class_name%>Base.boot!
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %>::Env do
4
+ context 'when in production mode' do
5
+ subject {<%= class_name%>::Env.new('production') }
6
+
7
+ context '#production?' do
8
+ it 'should be true' do
9
+ expect(subject.production?).to eq(true)
10
+ end
11
+ end
12
+
13
+ context '#development?' do
14
+ it 'should be false' do
15
+ expect(subject.development?).to eq(false)
16
+ end
17
+ end
18
+ end
19
+
20
+ context 'when in development mode' do
21
+ subject {<%= class_name%>::Env.new('development') }
22
+
23
+ context '#production?' do
24
+ it 'should be true' do
25
+ expect(subject.production?).to eq(false)
26
+ end
27
+ end
28
+
29
+ context '#development?' do
30
+ it 'should be false' do
31
+ expect(subject.development?).to eq(true)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %>Base do
4
+ context '#RAPP_VERSION' do
5
+ it 'should be <%= rapp_version%>' do
6
+ expect(subject::RAPP_VERSION).to eq("<%=rapp_version %>")
7
+ end
8
+ end
9
+
10
+ context '#env' do
11
+ before :each do
12
+ # clear this before each run, restore to it's original value after. Kind of hacky, but dont wanna lose the app_env the user may have set
13
+ @former_app_env = ENV['APP_ENV']
14
+ ENV['APP_ENV'] = nil
15
+
16
+ # We also need to reset the env in the <%=class_name%> each time, so it tries to create a new Env object and picks up the new ENV value. Also kind of hacky
17
+ <%= class_name%>.instance_variable_set('@env',nil)
18
+
19
+ # These specs are made slightly more hacky to set up because I purposfully chose to have the Env be set once, and not make it automatically detect changes to APP_ENV. When the app boots up, it should detect it's environment once, and thats it.
20
+ end
21
+
22
+ after :each do
23
+ ENV['APP_ENV'] = @former_app_env
24
+ end
25
+
26
+ context 'when no environment is specified' do
27
+ it 'defaults to development' do
28
+ expect(<%= class_name%>.env.to_s).to eq('development')
29
+ end
30
+ end
31
+
32
+ it 'should get the configured environment from ENV' do
33
+ ENV['APP_ENV'] = 'production'
34
+ expect(<%= class_name%>.env.to_s).to eq('production')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
2
+
3
+ require 'rspec'
4
+ require '<%= app_name %>'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
data/lib/rapp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rapp
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/rapp.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.1.0"
23
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - StabbyCutyou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-17 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
41
55
  description: rapp helps you build native ruby apps with a familiar structure and a
42
56
  handful of familiar conventions.
43
57
  email:
@@ -65,6 +79,9 @@ files:
65
79
  - lib/rapp/templates/config/environments/test.rb.erb
66
80
  - lib/rapp/templates/env.rb.erb
67
81
  - lib/rapp/templates/lib/tasks/console.rake.erb
82
+ - lib/rapp/templates/spec/app_name_base/env_spec.rb.erb
83
+ - lib/rapp/templates/spec/app_name_base_spec.rb.erb
84
+ - lib/rapp/templates/spec/spec_helper.rb.erb
68
85
  - lib/rapp/version.rb
69
86
  - rapp.gemspec
70
87
  homepage: https://github.com/StabbyCutyou/rapp