melodiest 0.3.0 → 0.4.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: fcb354a2aa73158378af93b4f18bf9d397f6b0da
4
- data.tar.gz: b29f697ff27ba0ea4095382e41177bd47354b942
3
+ metadata.gz: 93b02593c830fd50c38d34209b6f17ed12526729
4
+ data.tar.gz: 03253903a834bb4a6ecea68be9c3a10e2271025a
5
5
  SHA512:
6
- metadata.gz: 951a2c2a88bcbcd9432fa667ac753a98663f88a19805a98564746e9d78bb7752f4f21065e64acb7d4ad6ad4811a1ae9abe57a65e67de5a40adabe707a63a3469
7
- data.tar.gz: 5560623ecda83e4834900fffabf61960a3e8ca08a879cb339a39181c571b320857ec6706cc07cde608f72b52c2bf6df95ffbd41a97657f1af847441a189e5e1f
6
+ metadata.gz: 591c75d518583203dbf71107496474c838c59c661871213a7c5cf8a6ceea1c3c4a8b6a080ed7fd8397c4a9f237faf3d2b672cafd0d4941429578956b782aa073
7
+ data.tar.gz: cb2ef996bafaa561fcac7a5fe5b81856a1a631339a7d75687c00fc33cebd90ed6c43bb6e6db68c14125c96c97b4c05ab27b0971332ced5686f5b73c4dc41bed6
@@ -1,3 +1,9 @@
1
+ 0.4.0:
2
+ * add SQL logger to development environment
3
+ * generate public dir when running generator
4
+ * use tux as Sinatra console
5
+ * when has no option, melodiest command will use --help option
6
+
1
7
  0.3.0:
2
8
 
3
9
  * remove Melodiest::Auth::Http module, it's better to use sinatra-authorization extension
data/README.md CHANGED
@@ -4,7 +4,6 @@ Melodiest is [Sinatra](http://www.sinatrarb.com/) application boilerplate. It pr
4
4
 
5
5
  ### Installation
6
6
 
7
-
8
7
  ```ruby
9
8
  gem install melodiest
10
9
  ```
@@ -17,14 +16,19 @@ gem 'melodiest'
17
16
 
18
17
  ### How to Use
19
18
  generate app in current directory without database
19
+
20
20
  ```
21
21
  melodiest -n my_app
22
22
  ```
23
+
23
24
  generate app in target directory without database
25
+
24
26
  ```
25
27
  melodiest -n my_app -t target/dir
26
28
  ```
29
+
27
30
  generate app in current directory with database. `-d` option will generate app with `Sequel` orm and PostgreSQL adapter.
31
+
28
32
  ```
29
33
  melodiest -n my_app -d
30
34
  ```
@@ -34,7 +38,6 @@ Because Melodiest is already required Sinatra, you don't have to require 'sinatr
34
38
 
35
39
  `Melodiest::Application` is subclass from `Sinatra::Application` and by default is using configuration from `Melodiest::Setting.setup` method.
36
40
 
37
-
38
41
  ```ruby
39
42
  # my_app.rb
40
43
 
@@ -43,65 +46,86 @@ class App < Melodiest::Application
43
46
  ...
44
47
  end
45
48
  ```
49
+
46
50
  ### Example Usage
47
- This example assume that PostgreSQL is already running and .
51
+ This example assume that PostgreSQL is already running and desired database is already exist.
52
+ For complete example see [github.com/kuntoaji/todo_melodiest](https://github.com/kuntoaji/todo_melodiest)
48
53
  1. run `melodiest -n my_app -d`
49
54
  2. cd `my_app`
50
55
  3. run `bundle install`
51
56
  4. create `config/database.yml` and configure your database setting
52
57
  5. create file `db/migrations/001_create_artists.rb` and put the following code:
53
- ```ruby
54
- Sequel.migration do
55
- up do
56
- create_table(:artists) do
57
- primary_key :id
58
- String :name, :null=>false
58
+
59
+ ```ruby
60
+ Sequel.migration do
61
+ up do
62
+ create_table(:artists) do
63
+ primary_key :id
64
+ String :name, :null=>false
65
+ end
59
66
  end
60
- end
61
67
 
62
- down do
63
- drop_table(:artists)
68
+ down do
69
+ drop_table(:artists)
70
+ end
64
71
  end
65
- end
66
- ```
72
+ ```
73
+
67
74
  6. run `rake db:migrate`
68
75
  7. create file `app/models/Artist.rb` and put the following code:
69
- ```ruby
70
- class Artist < Sequel::Model
71
- end
72
- ```
73
- 8. create file `app/routes/artists.rb` and put the following code:
74
- ```ruby
75
- class MyApp
76
- get '/' do
77
- "hello world!"
76
+
77
+ ```ruby
78
+ class Artist < Sequel::Model
78
79
  end
80
+ ```
81
+
82
+ 8. create file `app/routes/artists.rb` and put the following code:
83
+
84
+ ```ruby
85
+ class MyApp
86
+ get '/' do
87
+ "hello world!"
88
+ end
79
89
 
80
- get '/artists' do
81
- # for example purpose :)
82
- artist = Artist.new
83
- artist.name = 'Melody'
84
- artist.save
90
+ get '/artists' do
91
+ @artists = Artist.all
92
+ erb :"artists/index"
93
+ end
85
94
 
86
- @artists = Artist.all
87
- erb :"artists/index"
95
+ post '/artists' do
96
+ @artist = Artist.new
97
+ @artist.name = params[:name]
98
+ @artist.save
99
+
100
+ redirect '/artists'
101
+ end
88
102
  end
89
- end
90
- ```
103
+ ```
104
+
91
105
  9. create file `app/views/artists/index.erb` and put the following code:
92
- ```erb
93
- <h1>List of Artist</h1>
94
- <% @artists.each do |artist| %>
95
- <li><%= artist.name %></li>
96
- <% end %>
97
- ```
98
- 10. run the server `bundle exec rackup`
99
- 11. open url `localhost:9292/artists`
100
-
106
+
107
+ ```erb
108
+ <h1>List of Artist</h1>
109
+ <ul>
110
+ <% @artists.each do |artist| %>
111
+ <li><%= artist.name %></li>
112
+ <% end %>
113
+ </ul>
114
+
115
+ <form action="/artists" method="post">
116
+ <%= Rack::Csrf.tag(env) %>
117
+ <input type="text" name="name" />
118
+ <button>Submit</button>
119
+ </form>
120
+ ```
121
+
122
+ 10. run the server `bundle exec thin start`
123
+ 11. open url `localhost:3000/artists`
101
124
 
102
125
  ### Default Configuration
103
126
 
104
127
  * `Sinatra::Reloader` in development environment only
128
+ * `Thin` as default web server
105
129
  * `Rack::Session::EncryptedCookie`
106
130
  * `Rack::Csrf`
107
131
  * `Sequel` ORM
@@ -1,5 +1,4 @@
1
1
  require 'sinatra/base'
2
- require 'sinatra/reloader'
3
2
  require 'encrypted_cookie'
4
3
  require 'melodiest/setting'
5
4
 
@@ -9,6 +8,7 @@ module Melodiest
9
8
 
10
9
  # http://www.sinatrarb.com/contrib/reloader.html
11
10
  configure :development do
11
+ require 'sinatra/reloader'
12
12
  register Sinatra::Reloader
13
13
  end
14
14
  end
@@ -5,8 +5,9 @@ module Melodiest
5
5
 
6
6
  class Command
7
7
  def self.parse(options)
8
+ options = %w(--help) if options.empty? || options.nil?
8
9
  args = {}
9
- result = ""
10
+ result = nil
10
11
 
11
12
  option_parser = OptionParser.new do |opts|
12
13
  opts.banner = "Usage: melodiest [options]"
@@ -52,7 +53,7 @@ module Melodiest
52
53
  msg = "#{args[:name]} is successfully generated"
53
54
  msg << " in #{args[:target]}" if args[:target]
54
55
 
55
- msg
56
+ msg
56
57
  end
57
58
  end
58
59
 
@@ -26,6 +26,7 @@ module Melodiest
26
26
  f.write("source 'https://rubygems.org'\n\n")
27
27
  f.write("gem 'melodiest', '#{Melodiest::VERSION}'\n")
28
28
  f.write("gem 'thin'\n")
29
+ f.write("gem 'tux'\n")
29
30
  f.write("gem 'rack_csrf', require: 'rack/csrf'")
30
31
 
31
32
  if @with_database
@@ -52,10 +53,19 @@ module Melodiest
52
53
 
53
54
  if @with_database
54
55
  content[:yaml] = "require 'yaml'\n\n"
55
- content[:database] = " Sequel.connect YAML.load_file(File.expand_path(\"../config/database.yml\", __FILE__))[settings.environment.to_s]\n"
56
+ content[:database] = " configure :development, :test do\n"
57
+ content[:database] << " require 'logger'\n\n"
58
+ content[:database] << " Sequel.connect YAML.load_file(File.expand_path(\"../config/database.yml\", __FILE__))[settings.environment.to_s],\n"
59
+ content[:database] << " loggers: [Logger.new($stdout)]\n"
60
+ content[:database] << " end\n\n"
61
+ content[:database] << " configure :production do\n"
62
+ content[:database] << " Sequel.connect YAML.load_file(File.expand_path(\"../config/database.yml\", __FILE__))['production']\n"
63
+ content[:database] << " end\n"
56
64
  else
57
65
  content[:yaml] = nil
58
- content[:database] = " # Load up database and such\n"
66
+ content[:database] = " configure do\n"
67
+ content[:database] << " # Load up database and such\n"
68
+ content[:database] << " end\n"
59
69
  end
60
70
 
61
71
  File.open "#{@destination}/#{@app_name}.rb", "w" do |f|
@@ -65,9 +75,7 @@ module Melodiest
65
75
  f.write(" set :app_file, __FILE__\n")
66
76
  f.write(" set :views, Proc.new { File.join(root, \"app/views\") }\n\n")
67
77
  f.write(" use Rack::Csrf, raise: true\n\n")
68
- f.write(" configure do\n")
69
78
  f.write(content[:database])
70
- f.write(" end\n")
71
79
  f.write("end\n\n")
72
80
  f.write("%w{app/models app/routes}.each do |dir|\n")
73
81
  f.write(" Dir[File.join(dir, '**/*.rb')].each do |file|\n")
@@ -76,6 +84,8 @@ module Melodiest
76
84
  f.write("end\n")
77
85
  end
78
86
 
87
+ FileUtils.mkdir "#{@destination}/public"
88
+
79
89
  app_dir = "#{@destination}/app"
80
90
  ["", "/routes", "/models", "/views"].each do |dir|
81
91
  FileUtils.mkdir "#{app_dir}/#{dir}"
@@ -1,11 +1,7 @@
1
1
  module Melodiest
2
2
  module Setting
3
3
  def setup(cookie_secret, options={})
4
- settings = {
5
- server: 'thin'
6
- }.merge(options)
7
-
8
- settings.each do |key, value|
4
+ {server: 'thin'}.merge(options).each do |key, value|
9
5
  set key, value
10
6
  end
11
7
 
@@ -1,3 +1,3 @@
1
1
  module Melodiest
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
  s.name = 'melodiest'
5
5
  s.version = Melodiest::VERSION
6
6
  s.date = Date.today.to_s
7
- s.summary = "Sinatra application boilerplate"
8
- s.description = "Melodiest provides generator and contains minimalist configuration to develop application with Sinatra"
7
+ s.summary = "Sinatra application boilerplate generator"
8
+ s.description = "Melodiest provides generator and contains minimal configuration to develop application with Sinatra"
9
9
  s.author = 'Kunto Aji Kristianto'
10
10
  s.email = 'kunto.aji.kr@slackware-id.org'
11
11
  s.files = `git ls-files -z`.split("\x0")
@@ -51,7 +51,16 @@ describe Melodiest::Command do
51
51
  it "does nothing" do
52
52
  app = Melodiest::Command.parse %w(--target /tmp/melodiest)
53
53
 
54
- expect(app).to be_empty
54
+ expect(app).to be_nil
55
+ end
56
+ end
57
+
58
+ context "when has no option" do
59
+ it "uses --help option by default" do
60
+ help = Melodiest::Command.parse []
61
+
62
+ expect(help).to include "Usage: melodiest [options]"
63
+ expect(help).to include "Print this help"
55
64
  end
56
65
  end
57
66
  end
@@ -50,6 +50,7 @@ describe Melodiest::Generator do
50
50
  expect(file_content).to include "source 'https://rubygems.org'"
51
51
  expect(file_content).to include "gem 'melodiest', '#{Melodiest::VERSION}'"
52
52
  expect(file_content).to include "gem 'thin'"
53
+ expect(file_content).to include "gem 'tux'"
53
54
  expect(file_content).to include "gem 'rack_csrf', require: 'rack/csrf'"
54
55
  expect(file_content).to_not include "gem 'sequel'"
55
56
  expect(file_content).to_not include "gem 'sequel_pg'"
@@ -89,7 +90,7 @@ describe Melodiest::Generator do
89
90
  let(:secret) { "supersecretcookiefromgenerator" }
90
91
  before { allow(SecureRandom).to receive(:hex).with(32).and_return(secret) }
91
92
 
92
- it "generates <app_name>.rb" do
93
+ it "generates <app_name>.rb, public dir, and app dir" do
93
94
  FileUtils.rm_r @dest if Dir.exists?(@dest)
94
95
  generator.generate_app
95
96
  app_file = "#{target_dir}/my_app.rb"
@@ -119,6 +120,7 @@ DOC
119
120
 
120
121
  expect(File.exists?(app_file)).to be_truthy
121
122
  expect(file_content).to eq expected_file_content
123
+ expect(Dir.exists?("#{target_dir}/public")).to be_truthy
122
124
  expect(Dir.exists?("#{target_dir}/app")).to be_truthy
123
125
  expect(Dir.exists?("#{target_dir}/app/routes")).to be_truthy
124
126
  expect(Dir.exists?("#{target_dir}/app/models")).to be_truthy
@@ -144,8 +146,15 @@ class MyApp < Melodiest::Application
144
146
 
145
147
  use Rack::Csrf, raise: true
146
148
 
147
- configure do
148
- Sequel.connect YAML.load_file(File.expand_path("../config/database.yml", __FILE__))[settings.environment.to_s]
149
+ configure :development, :test do
150
+ require 'logger'
151
+
152
+ Sequel.connect YAML.load_file(File.expand_path("../config/database.yml", __FILE__))[settings.environment.to_s],
153
+ loggers: [Logger.new($stdout)]
154
+ end
155
+
156
+ configure :production do
157
+ Sequel.connect YAML.load_file(File.expand_path("../config/database.yml", __FILE__))['production']
149
158
  end
150
159
  end
151
160
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: melodiest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kunto Aji Kristianto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-17 00:00:00.000000000 Z
11
+ date: 2015-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,8 +94,8 @@ dependencies:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.0.4
97
- description: Melodiest provides generator and contains minimalist configuration to
98
- develop application with Sinatra
97
+ description: Melodiest provides generator and contains minimal configuration to develop
98
+ application with Sinatra
99
99
  email: kunto.aji.kr@slackware-id.org
100
100
  executables:
101
101
  - melodiest
@@ -122,7 +122,6 @@ files:
122
122
  - spec/melodiest/command_spec.rb
123
123
  - spec/melodiest/generator_spec.rb
124
124
  - spec/melodiest/setting_spec.rb
125
- - spec/melodiest_spec.rb
126
125
  - spec/spec_helper.rb
127
126
  homepage: http://github.com/kuntoaji/melodiest
128
127
  licenses:
@@ -147,5 +146,5 @@ rubyforge_project:
147
146
  rubygems_version: 2.4.5
148
147
  signing_key:
149
148
  specification_version: 4
150
- summary: Sinatra application boilerplate
149
+ summary: Sinatra application boilerplate generator
151
150
  test_files: []
@@ -1,7 +0,0 @@
1
- describe Melodiest::Application do
2
- context ".extensions" do
3
- it "has reloader extension" do
4
- expect(app.extensions.include?(Sinatra::Reloader)).to be_truthy
5
- end
6
- end
7
- end