cuba-generator 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a24fdbf4bf0d88e6cc34b511f106b4d09cf7952
4
- data.tar.gz: eac6e9a26964284e52de58fe65c24e37286c1160
3
+ metadata.gz: 12eb0c60bfc006bd14d7f8937e28f15dde444c4a
4
+ data.tar.gz: c11128134f0c716dbd85959cd9157f02ab6740eb
5
5
  SHA512:
6
- metadata.gz: 557625f97ed98ea6f9f5e4462b78b153f2ee1b6de5ac280b7a3b4a171ed9e5025ac7c0b3645a372071b2bf352c12dfd5c85c8a3b05907937cd8164cb8e966a4b
7
- data.tar.gz: 10a464aaba4eb0d3264a643e0b5122ae7a33dedab4970a887902dc7fd0e69d5c59feb7b0ce3f8b76a7801f26e4fb38cb737ba4cf2c8f8a87863b96150107ba0e
6
+ metadata.gz: aeaa6cb72593544d964be28ba024d5a067b40bf8e95f17d18d8810b65c92eee072d3051566a169494d5a4e6e076c5c79622925d92e8210023d4f6d95355659b6
7
+ data.tar.gz: 5c580137e357bd3759c165c534396d4d7d7113c58319ecbd13b91c5b36f43abd09748adeabfd05dd7da679ba0557e3ec2be3cdd2cf33a8aa370a75b87373675a
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/cuba-generator.svg)](http://badge.fury.io/rb/cuba-generator)
1
2
  # cuba-generator
2
3
 
3
4
  cuba-generator is a generator to help creating Cuba projects.
@@ -6,16 +7,21 @@ cuba-generator is a generator to help creating Cuba projects.
6
7
 
7
8
  ## Installation
8
9
 
9
- $ gem install cuba-generator
10
+ gem install cuba-generator
10
11
 
11
12
  ## Usage
12
13
 
13
- $ cuba new [projectName]
14
+ cuba new [projectName] [options]
14
15
 
15
- This will create your cuba project with its 2 files:
16
+ Additionally you can specify the type of your app via ***--type*** . E.g to generate an API starting point.
16
17
 
17
- * The config.ru to ```rackup```your project.
18
- * The projectname.rb file that contains your project config and routes.
18
+ cuba new [projectName] --type api
19
+
20
+ To generate an application with a Postgresql configuration setup use ***-database*** option (via Datamapper)
21
+
22
+ cuba new [projectName] --database postgresql
23
+
24
+ By default ***--type*** is 'app'.
19
25
 
20
26
  ## Contributing
21
27
 
@@ -15,11 +15,14 @@ module Cuba
15
15
  c.syntax = 'cuba new [options]'
16
16
  c.description = 'Creates a new Cuba app'
17
17
  c.option '--type STRING', String, 'Creates an app with preferred type'
18
+ c.option '--database STRING', String, 'Setups a database configuration with DataMapper'
18
19
  c.action do |args, options|
19
20
  if options.type
20
- Cuba::Generator.new(ARGV[1], options.type)
21
+ generator = Cuba::Generator.new(ARGV[1], options.type)
22
+ generator.create_database_file if options.database == 'postgresql'
21
23
  else
22
- Cuba::Generator.new(ARGV[1], :app)
24
+ generator = Cuba::Generator.new(ARGV[1], :app)
25
+ generator.create_database_file if options.database == 'postgresql'
23
26
  end
24
27
  end
25
28
  end
@@ -1,5 +1,5 @@
1
1
  module Cuba
2
2
  class Generator
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -32,20 +32,40 @@ module Cuba
32
32
  end
33
33
  end
34
34
 
35
+ def create_database_file
36
+ File.open("./#{@project_name}/database.rb", 'w+') do |file|
37
+ file.write setup_database
38
+ end
39
+ File.open("./#{@project_name}/Gemfile", 'w+') do |file|
40
+ file.write setup_gemfile
41
+ end
42
+ end
43
+
35
44
  private
36
45
 
37
46
  def setup_cuba
38
- path = if @type.to_sym == :app
39
- File.read File.join(APPROOT, './templates/app.erb')
47
+ if @type.to_sym == :app
48
+ create_template 'app'
40
49
  elsif @type.to_sym == :api
41
- File.read File.join(APPROOT, './templates/api.erb')
50
+ create_template 'api'
42
51
  end
43
- erb(path, {project_name: @project_name})
44
52
  end
45
53
 
46
54
  def setup_config
47
- path = File.read File.join(APPROOT, './templates/rack_config.erb')
48
- erb(path, {project_name: @project_name})
55
+ create_template 'rack_config'
56
+ end
57
+
58
+ def setup_database
59
+ create_template 'db'
60
+ end
61
+
62
+ def setup_gemfile
63
+ create_template 'gemfile'
64
+ end
65
+
66
+ def create_template(name)
67
+ template = File.read File.join(APPROOT, 'templates/', "#{name}.erb")
68
+ erb(template, {project_name: @project_name})
49
69
  end
50
70
 
51
71
  def erb(template, vars)
@@ -0,0 +1,22 @@
1
+ <%=
2
+ <<-TEMPLATE
3
+
4
+ require 'data_mapper'
5
+
6
+ DataMapper.setup(:default, 'postgres://username@localhost/db_name')
7
+
8
+ # Here's an example User model
9
+ # class User
10
+ # include DataMapper::Resource
11
+ #
12
+ # property :id, Serial # An auto-increment integer key
13
+ # property :email, String # A varchar type string, for short strings
14
+ # property :created_at, DateTime # A DateTime, for any date you might like.
15
+ # property :updated_at, DateTime
16
+ # end
17
+
18
+ DataMapper.finalize
19
+ DataMapper.auto_upgrade!
20
+
21
+ TEMPLATE
22
+ %>
@@ -0,0 +1,11 @@
1
+ <%=
2
+ <<-TEMPLATE
3
+
4
+ source "https://rubygems.org"
5
+
6
+ gem 'cuba'
7
+ gem 'data_mapper'
8
+ gem 'dm-postgres-adapter'
9
+
10
+ TEMPLATE
11
+ %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuba-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serdar Dogruyol
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-11 00:00:00.000000000 Z
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -101,6 +101,8 @@ files:
101
101
  - lib/cuba/generator/version.rb
102
102
  - lib/cuba/templates/api.erb
103
103
  - lib/cuba/templates/app.erb
104
+ - lib/cuba/templates/db.erb
105
+ - lib/cuba/templates/gemfile.erb
104
106
  - lib/cuba/templates/rack_config.erb
105
107
  - spec/cuba_generator_spec.rb
106
108
  homepage: ''