roda-project 0.1.13 → 0.1.15

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
  SHA256:
3
- metadata.gz: 3156e8ffc1fbf7c48c30c1224bfccd2bf66c775b90cb802ada325c2ef2a5607e
4
- data.tar.gz: 02e04e9cb18a32f82cad2fceb59f1d567d33fe61330f1f0a26bb6e38ebf3b618
3
+ metadata.gz: 5c22151c8712cbc374521e061d5c91e5b4dae3b55ab5d55fc3227fbf57ef49c6
4
+ data.tar.gz: 31f190125960494423689e00f70fe16fb32c05da6ea5a5c356fa33b99792d8f3
5
5
  SHA512:
6
- metadata.gz: b2a91d0af7f801951d65f288a3fcbc0012b3779e6736dfdd94d7703377834cad15d8a8680293b1800a8293e90cfb59d8d3f971e1e67abedf682b32a432e9920a
7
- data.tar.gz: b80916d58cdd4a167f8be8a9e5e43f4c56730457818b6cfee081ac4946d1e353284c7b6d087f9d030a03d7a705426e78fe871610dd5438dfe3c1c9bb1d426563
6
+ metadata.gz: 5533eef1235cbbf17bdee8305595a2eee7b32f298960a2b70b080f3ef633f329115d96ae8dcad13490cdfcbc03e092b1ed4559df1fb696604b482e3283ac0ef1
7
+ data.tar.gz: 74c4da7361e380d5eb8af1c16f61f06c7540e5fd5464b9df12c184aa4bea4b171f9903e8800bba8c99fcca5f792b67b1b914c1a9a65a86a360fb49c7ec6e586f
@@ -96,12 +96,10 @@ class Roda
96
96
  end
97
97
 
98
98
  def parse_args
99
- @parse_args ||= begin
100
- if %w[module class].include?(@args[0].to_s.downcase)
101
- { type: @args[0].to_s.downcase, name: @args[1].to_s }
102
- else
103
- { type: "class", name: @args[0].to_s }
104
- end
99
+ @parse_args ||= if %w[module class].include?(@args[0].to_s.downcase)
100
+ {type: @args[0].to_s.downcase, name: @args[1].to_s}
101
+ else
102
+ {type: "class", name: @args[0].to_s}
105
103
  end
106
104
  end
107
105
 
@@ -63,10 +63,9 @@ class <%= context.const_project_name %> < Roda
63
63
  <% end %>
64
64
  def config = @config ||= Config.get
65
65
 
66
- route do |r|
67
- r.hash_branches<% if context.fullstack? %>
68
- # session[:locale] = 'pt-br'
69
- # r.i18n_set_locale_from(:session)<% end %>
66
+ route do |r|<% if context.fullstack? %>
67
+ r.i18n_set_locale_from(:http)<% end %>
68
+ r.hash_branches
70
69
  <% if context.rodauth? %>
71
70
  r.rodauth
72
71
  <% end %>
@@ -21,8 +21,8 @@ loader.collapse("#{__dir__}/services")
21
21
  # end
22
22
  loader.setup
23
23
 
24
- require "debug" if NOT_PRODUCTION
25
-
26
24
  Oj.mimic_JSON
27
25
 
26
+ require "debug" if NOT_PRODUCTION
27
+
28
28
  require_relative "app"
@@ -5,14 +5,14 @@ module Config
5
5
  secret: ENV["SESSION_SECRET"] || 'DEV-ONLY-8<FQF8HiF)>l0hbPk£vBQ#IrYsoO}14k\l+-/gIU[j}l0hbPk£vBQ#IrY',
6
6
  environment:,<% if context.rodauth? %>
7
7
  hmac_secret: ENV["RODAUTH_HMAC_SECRET"] || 'DEV-ONLY',
8
- jwt_secret: ENV["JWT_SECRET"] || 'DEV-ONLY'<% end %><% if context.fullstack? %>,
8
+ jwt_secret: ENV["JWT_SECRET"] || 'DEV-ONLY',<% end %><% if context.fullstack? %>
9
9
  i18n: {
10
- translations: ["app/config/locales", "app/config/locales/foo"],
10
+ translations: [File.expand_path("locales", __dir__)],
11
11
  locale: ["en", "pt-br"]
12
- }<% end %><% if context.database? %>,
12
+ },<% end %><% if context.database? %>
13
13
  db: {
14
14
  url: not_production? ? <%= context.default_db_url %> : ENV["DATABASE_URL"]
15
- }<% end %><% if context.fullstack? %>,
15
+ },<% end %><% if context.fullstack? %>
16
16
  render: {
17
17
  layout: "./layout",
18
18
  assume_fixed_locals: true, # Optimize plugin by assuming all templates use fixed locals
@@ -39,34 +39,29 @@ class Db < Thor
39
39
  [:drop, :create].each do |action|
40
40
  desc action.to_s, "#{action.capitalize} the database"
41
41
  define_method(action) do
42
- require_db_deps
43
- require_relative "../app/config/config"<% if context.postgresql? %>
44
- db_config =
45
- PG::Connection
46
- .conninfo_parse(Config.get[:db][:url])
47
- .each_with_object({}) { |h, o|
48
- o[h[:keyword].to_sym] = h[:val] if h[:val]
49
- }
50
- ok = system("PGPASSWORD='#{db_config[:password]}' #{action}db -h #{db_config[:host]} -p #{db_config[:port]} -U #{db_confi
51
- g[:user]} #{db_config[:dbname]}")<% end %><% if context.mysql? %>
42
+ require "<%= context.db_gem %>"
43
+ require "uri"
44
+ require_relative "../app/config/config"
52
45
  uri = URI.parse(Config.get[:db][:url])
53
- db_config = {
54
- host: uri.host,
55
- port: uri.port,
56
- user: uri.user,
57
- password: uri.password,
58
- dbname: uri.path.tr('/', '') # removes leading slash
59
- }
46
+ dbname = uri.path.to_s.delete_prefix("/")<% if context.postgresql? %>
47
+ env = {}
48
+ env["PGPASSWORD"] = uri.password if uri.password
49
+ args = ["#{action}db"]
50
+ args.push("-h", uri.host) if uri.host
51
+ args.push("-p", uri.port.to_s) if uri.port
52
+ args.push("-U", uri.user) if uri.user
53
+ args << dbname
54
+ ok = system(env, *args)<% end %><% if context.mysql? %>
60
55
  sql = action == :create ?
61
- "CREATE DATABASE IF NOT EXISTS `#{db_config[:dbname]}`;" :
62
- "DROP DATABASE IF EXISTS `#{db_config[:dbname]}`;"
56
+ "CREATE DATABASE IF NOT EXISTS `#{dbname}`;" :
57
+ "DROP DATABASE IF EXISTS `#{dbname}`;"
63
58
  flags = []
64
- flags << "-h#{db_config[:host]}" if db_config[:host]
65
- flags << "-P#{db_config[:port]}" if db_config[:port]
66
- flags << "-u#{db_config[:user]}" if db_config[:user]
67
- env = { "MYSQL_PWD" => db_config[:password] }.compact
59
+ flags << "-h#{uri.host}" if uri.host
60
+ flags << "-P#{uri.port}" if uri.port
61
+ flags << "-u#{uri.user}" if uri.user
62
+ env = { "MYSQL_PWD" => uri.password }.compact
68
63
  ok = system(env, "mysql", *flags, "-e", sql)<% end %>
69
- puts "* #{action} database #{db_config[:dbname]} ✓" if ok
64
+ puts "* #{action} database #{dbname} ✓" if ok
70
65
  end
71
66
  end
72
67
  <% end %>
@@ -22,7 +22,6 @@ loader.collapse("#{__dir__}/app/models")<% end %>
22
22
  # loader.push_dir("#{__dir__}/app/#{path}")
23
23
  # end
24
24
  loader.setup
25
- require "debug" if Config.not_production?
26
25
 
27
26
  Oj.mimic_JSON
28
27
 
@@ -34,8 +33,9 @@ Providers::Logger.boot
34
33
  # Consts<% if context.database %>
35
34
  DB = Providers::DB::Conn.get
36
35
 
37
- # Automatic models annotations in dev environment
38
36
  if Config.not_production?
37
+ require "debug"
38
+ # Automatic models annotations in dev environment
39
39
  require 'sequel/annotate'
40
40
  Sequel::Annotate.annotate(Dir['app/models/*.rb'], position: :before, border: true) rescue nil
41
41
  end<% end %>
@@ -2,12 +2,13 @@ require_relative "../spec_helper"
2
2
 
3
3
  describe "hello" do
4
4
  it "test requests" do
5
- get "/"<% if context.rodauth? %>
6
- _(last_response.status).must_equal 302<% else %>
7
- _(last_response.status).must_equal 200<% end %>
5
+ get "/"
6
+ _(last_response.status).must_equal 200<% if context.fullstack? %>
7
+ _(last_response.body).must_include "Hello world"<% end %>
8
8
  end
9
9
  <% if context.rodauth? %>
10
10
  it "test models" do
11
+ # run "RACK_ENV=test bin/roda db migrate" to make this spec pass
11
12
  Account.create(email: "foo@bar.com")
12
13
 
13
14
  _(Account.count).must_equal 1
@@ -0,0 +1,9 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ describe "Routes for foo" do
4
+ it "responds to GET /foo/bar" do
5
+ get "/foo/bar"<% if context.rodauth? %>
6
+ _(last_response.status).must_equal 302<% else %>
7
+ _(last_response.status).must_equal 200<% end %>
8
+ end
9
+ end
@@ -11,7 +11,7 @@ class Minitest::HooksSpec
11
11
  include Rack::Test::Methods
12
12
 
13
13
  def app
14
- <%= context.const_project_name %>.freeze.app
14
+ <%= context.const_project_name %>.app
15
15
  end
16
16
  end
17
17
 
@@ -2,11 +2,12 @@ require_relative "../spec_helper"
2
2
 
3
3
  describe "hello" do
4
4
  it "test requests" do
5
- get "/"<% if context.rodauth? %>
6
- expect(last_response.status).to eq(302)<% else %>
7
- expect(last_response.status).to eq(200)<% end %>
5
+ get "/"
6
+ expect(last_response.status).to eq(200)<% if context.fullstack? %>
7
+ expect(last_response.body).to include("Hello world")<% end %>
8
8
  end
9
9
  <% if context.rodauth? %>
10
+ # run "RACK_ENV=test bin/roda db migrate" to make this spec pass
10
11
  it "test models" do
11
12
  Account.create(email: "foo@bar.com")
12
13
 
@@ -0,0 +1,9 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ describe "Routes for foo" do
4
+ it "responds to GET /foo/bar" do
5
+ get "/foo/bar"<% if context.rodauth? %>
6
+ expect(last_response.status).to eq(302)<% else %>
7
+ expect(last_response.status).to eq(200)<% end %>
8
+ end
9
+ end
@@ -14,6 +14,6 @@ RSpec.configure do |config|
14
14
  end
15
15
  <% end %>
16
16
  def app
17
- <%= context.const_project_name %>.freeze.app
17
+ <%= context.const_project_name %>.app
18
18
  end
19
19
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Roda
4
4
  module Project
5
- VERSION = "0.1.13"
5
+ VERSION = "0.1.15"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-project
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique F. Teixeira
@@ -142,12 +142,12 @@ files:
142
142
  - lib/roda/project/templates/tests/minimal/rspec/spec/app_spec.rb
143
143
  - lib/roda/project/templates/tests/minimal/rspec/spec/spec_helper.rb
144
144
  - lib/roda/project/templates/tests/minitest/spec/app/app_spec.rb.erb
145
- - lib/roda/project/templates/tests/minitest/spec/app/routes/foo_spec.rb
145
+ - lib/roda/project/templates/tests/minitest/spec/app/routes/foo_spec.rb.erb
146
146
  - lib/roda/project/templates/tests/minitest/spec/app/routes/test_branch_spec.rb
147
147
  - lib/roda/project/templates/tests/minitest/spec/app/views/html_spec.rb
148
148
  - lib/roda/project/templates/tests/minitest/spec/spec_helper.rb.erb
149
149
  - lib/roda/project/templates/tests/rspec/spec/app/app_spec.rb.erb
150
- - lib/roda/project/templates/tests/rspec/spec/app/routes/foo_spec.rb
150
+ - lib/roda/project/templates/tests/rspec/spec/app/routes/foo_spec.rb.erb
151
151
  - lib/roda/project/templates/tests/rspec/spec/app/routes/test_branch_spec.rb
152
152
  - lib/roda/project/templates/tests/rspec/spec/app/views/html_spec.rb
153
153
  - lib/roda/project/templates/tests/rspec/spec/spec_helper.rb.erb
@@ -1,8 +0,0 @@
1
- require_relative "../../spec_helper"
2
-
3
- describe "Routes for foo" do
4
- it "responds to GET /foo/bar" do
5
- get "/foo/bar"
6
- _(last_response.status).must_equal 200
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- require_relative "../../spec_helper"
2
-
3
- describe "Routes for foo" do
4
- it "responds to GET /foo/bar" do
5
- get "/foo/bar"
6
- expect(last_response.status).to eq(200)
7
- end
8
- end