makanai 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: e90461a7d5e372f93f13f282e5f20b0410db84438b4eb9cbb587f0e739bd0c19
4
- data.tar.gz: a3dbff0cd0661110d7503889d768e6e277d8b3bf1241fcb13c62589ca8133d9d
3
+ metadata.gz: c35e25ab94dce7eb78c2e81cd7d1086ba736c81d99ba81c17ae85cfaa88dcd25
4
+ data.tar.gz: fa52e627e552253a97ce59065ab456406e75901667c093fb7c160ac243bb5a35
5
5
  SHA512:
6
- metadata.gz: 83066b43bf8207fdc6cc99763cd546504a324420e679c09c5aad6d98f65b7fb308cfd034af1b3e8508735de9693fb93919f55424b3ef04b53e45d5ae7ec8655f
7
- data.tar.gz: 047dcbdf9ed4afe1c4991b0355ba58f469d63211f840c7f6f28c24f47be07b6a20f595e6eb19636e018152f636f44acffd9ede2cf7993e4a143b0663d7a8a9ec
6
+ metadata.gz: 8b2661b6a8e5df30a371e60ad9123b3814df7db48f02c91a2eae1e3e2acb3961b711aa5880aa70c103b0d78345ffbd9e4b097196e519e12821dd81951c554552
7
+ data.tar.gz: 0b91f2e2a8a3a03406506d8323ff05dccd22be62bf1d5ddb254b32771b8f99488094457bde8d5dd63367d73ac325d7d41a0e0d930ba4e5d7da75127e93118ab2
data/.rubocop.yml CHANGED
@@ -2,12 +2,7 @@ AllCops:
2
2
  TargetRubyVersion: 2.7.0
3
3
  Exclude:
4
4
  - './makanai.gemspec'
5
-
6
- Style/Documentation:
7
- Enabled: false
8
-
9
- Metrics/LineLength:
10
- Max: 90
5
+ - 'vendor/**/*'
11
6
 
12
7
  Metrics/ClassLength:
13
8
  Max: 120
@@ -17,8 +12,23 @@ Metrics/BlockLength:
17
12
  - 'spec/**/*'
18
13
  - 'lib/makanai/rake_tasks.rb'
19
14
 
15
+ Style/Documentation:
16
+ Enabled: false
17
+
20
18
  Style/ParallelAssignment:
21
19
  Enabled: false
22
20
 
21
+ Style/HashEachMethods:
22
+ Enabled: true
23
+
24
+ Style/HashTransformKeys:
25
+ Enabled: true
26
+
27
+ Style/HashTransformValues:
28
+ Enabled: true
29
+
30
+ Layout/LineLength:
31
+ Max: 90
32
+
23
33
  Layout/EmptyLineAfterGuardClause:
24
34
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -13,3 +13,9 @@
13
13
  * :sparkles: add `Makanai::Model#first`.
14
14
  execute `SELECT * FROM table_name ORDER BY prymary_key asc limit 1` and return record object.
15
15
  https://github.com/Madogiwa0124/makanai/commit/8949796bf7428f5e2d854041b35397ef4d442ee6
16
+
17
+ ## :gift: 2020/02/22 `v0.1.2` released.
18
+ * :sparkles: use config object by Makanai::Settings for replaceable app config.
19
+ Changed the setting so that it is retained by the Class variable, and made it configurable.
20
+ The big advantage is that you can use any web server(ex. puma) except WEBrick.
21
+ https://github.com/Madogiwa0124/makanai/pull/18/commits/e6ea10e596c685ef77c042fa1e8f0294c85166f2
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- makanai (0.1.1)
5
- rack (~> 2.0.7)
4
+ makanai (0.1.2)
5
+ rack (>= 2.0.7, < 2.3.0)
6
6
  rake (>= 10, < 14)
7
7
  sqlite3 (~> 1.4.1)
8
8
 
@@ -13,11 +13,12 @@ GEM
13
13
  diff-lcs (1.3)
14
14
  jaro_winkler (1.5.4)
15
15
  parallel (1.19.1)
16
- parser (2.7.0.0)
16
+ parser (2.7.0.2)
17
17
  ast (~> 2.4.0)
18
- rack (2.0.8)
18
+ rack (2.2.2)
19
19
  rainbow (3.0.0)
20
20
  rake (13.0.1)
21
+ rexml (3.2.4)
21
22
  rspec (3.9.0)
22
23
  rspec-core (~> 3.9.0)
23
24
  rspec-expectations (~> 3.9.0)
@@ -31,16 +32,17 @@ GEM
31
32
  diff-lcs (>= 1.2.0, < 2.0)
32
33
  rspec-support (~> 3.9.0)
33
34
  rspec-support (3.9.0)
34
- rubocop (0.78.0)
35
+ rubocop (0.80.0)
35
36
  jaro_winkler (~> 1.5.1)
36
37
  parallel (~> 1.10)
37
- parser (>= 2.6)
38
+ parser (>= 2.7.0.1)
38
39
  rainbow (>= 2.2.2, < 4.0)
40
+ rexml
39
41
  ruby-progressbar (~> 1.7)
40
42
  unicode-display_width (>= 1.4.0, < 1.7)
41
43
  ruby-progressbar (1.10.1)
42
44
  sqlite3 (1.4.2)
43
- unicode-display_width (1.6.0)
45
+ unicode-display_width (1.6.1)
44
46
 
45
47
  PLATFORMS
46
48
  ruby
data/README.md CHANGED
@@ -76,10 +76,34 @@ root ┬ app.rb # main application file
76
76
  └ db # use Sqlite3 dabase file
77
77
  ```
78
78
 
79
+ ## override application config
80
+
81
+ You can overwrite the settings (`Makanai :: Settings`) with the created ruby ​​file(ex. app.rb).
82
+
83
+ ex) When overriding rack app settings.
84
+
85
+ ``` ruby
86
+ Makanai::Settings.rack_app_config = { handler: :webrick, host: '0.0.0.0', port: '8081' }
87
+ ```
88
+
89
+ ### use other application server
90
+
91
+ Add rack web server(ex. puma) gem in your Gemfile.
92
+
93
+ ``` ruby
94
+ gem 'puma'
95
+ ```
96
+
97
+ Overwrite the `handler` in `rack_app_config` with the created ruby ​​file(ex. app.rb).
98
+
99
+ ``` ruby
100
+ Makanai::Settings.rack_app_config = { handler: :puma, host: '0.0.0.0', port: '8080' }
101
+ ```
102
+
79
103
  ## routing
80
104
 
81
105
  ``` ruby
82
- require_relative '../lib/main.rb'
106
+ require 'makanai/main'
83
107
 
84
108
  # root path
85
109
  router.get '/' do
@@ -122,7 +146,7 @@ end
122
146
  Define instance variables used in the routing view.
123
147
 
124
148
  ``` ruby
125
- require_relative '../lib/main.rb'
149
+ require 'makanai/main'
126
150
 
127
151
  router.get '/index' do
128
152
  @title = 'Makanai title'
@@ -178,7 +202,7 @@ INFO: finished migration all
178
202
  It can be used by creating a class that inherits `Makanai::Model`.
179
203
 
180
204
  ``` ruby
181
- require_relative '../../lib/model.rb'
205
+ require 'makanai/model'
182
206
 
183
207
  class Resource < Makanai::Model
184
208
  # target table when executing sql.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "makanai"
4
+ require 'bundler/setup'
5
+ require 'makanai'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "makanai"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
data/exe/makanai CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'makanai'
4
5
  require 'makanai/rake_tasks'
5
6
 
6
- if ARGV[0] == 'init'
7
- Rake::Task['makanai:initialize:app'].execute
8
- end
7
+ Rake::Task['makanai:initialize:app'].execute if ARGV[0] == 'init'
@@ -3,6 +3,7 @@
3
3
  require 'json'
4
4
  require 'uri'
5
5
  require 'rack'
6
+ require_relative './settings.rb'
6
7
  require_relative './request.rb'
7
8
  require_relative './response.rb'
8
9
  require_relative './router.rb'
@@ -11,13 +12,18 @@ module Makanai
11
12
  class Application
12
13
  def initialize(router:)
13
14
  @router = router
14
- @handler = Rack::Handler::WEBrick
15
+ @config = Settings
15
16
  end
16
17
 
17
- attr_reader :router, :handler, :request, :response
18
+ attr_reader :router, :config, :request, :response
18
19
 
19
20
  def run!
20
- handler.run self
21
+ app_config = config.rack_app_config
22
+ handler = Rack::Handler.get(app_config[:handler])
23
+ handler.run(self, { Host: app_config[:host], Port: app_config[:port] })
24
+ rescue Interrupt
25
+ handler.shutdown
26
+ puts '==== Goodbye! :) ===='
21
27
  end
22
28
 
23
29
  def call(env)
@@ -5,9 +5,7 @@ require_relative './settings.rb'
5
5
 
6
6
  module Makanai
7
7
  class Database
8
- DATABASE_PATH = "#{Settings::APP_ROOT_PATH}#{Settings::DATABASE_PATH}"
9
-
10
- def initialize(path: DATABASE_PATH)
8
+ def initialize(path: Settings.database_full_path)
11
9
  @handler = SQLite3::Database
12
10
  @db = handler.new path
13
11
  db.tap { |db| db.results_as_hash = true }
data/lib/makanai/dsl.rb CHANGED
@@ -5,8 +5,8 @@ require_relative './response.rb'
5
5
  require_relative './settings.rb'
6
6
 
7
7
  def render(path)
8
- template_root_path = "#{Dir.pwd}#{Makanai::Settings::TEMPLATE_ROOT_PATH}"
9
- full_path = "#{template_root_path}#{path}.erb"
8
+ template_root_path = Makanai::Settings.template_full_path
9
+ full_path = File.join(template_root_path, "#{path}.erb")
10
10
  Makanai::Template.new(path: full_path).render
11
11
  end
12
12
 
@@ -12,7 +12,7 @@ module Makanai
12
12
  end
13
13
 
14
14
  def migration_root_path
15
- "#{Settings::APP_ROOT_PATH}#{Settings::MIGRATION_ROOT_PATH}"
15
+ Settings.migration_full_path
16
16
  end
17
17
  end
18
18
  end
@@ -1,10 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rack'
4
+
3
5
  module Makanai
4
6
  class Settings
5
- APP_ROOT_PATH = Dir.pwd
6
- DATABASE_PATH = '/db/makanai.db'
7
- TEMPLATE_ROOT_PATH = '/views/'
8
- MIGRATION_ROOT_PATH = '/migration/'
7
+ DEFAULT_APP_ROOT_PATH = Dir.pwd
8
+ DEFAULT_DATABASE_PATH = '/db/makanai.db'
9
+ DEFAULT_TEMPLATE_ROOT_PATH = '/views/'
10
+ DEFAULT_MIGRATION_ROOT_PATH = '/migration/'
11
+ DEFAULT_RACK_APP_CONFIG = { handler: :webrick, host: '0.0.0.0', port: '8080' }.freeze
12
+
13
+ @app_root_path = DEFAULT_APP_ROOT_PATH
14
+ @database_path = DEFAULT_DATABASE_PATH
15
+ @template_root_path = DEFAULT_TEMPLATE_ROOT_PATH
16
+ @migration_root_path = DEFAULT_MIGRATION_ROOT_PATH
17
+ @rack_app_config = DEFAULT_RACK_APP_CONFIG
18
+
19
+ class << self
20
+ attr_accessor :app_root_path,
21
+ :database_path,
22
+ :template_root_path,
23
+ :migration_root_path,
24
+ :rack_app_config
25
+
26
+ def database_full_path
27
+ File.join(app_root_path, database_path)
28
+ end
29
+
30
+ def template_full_path
31
+ File.join(app_root_path, template_root_path)
32
+ end
33
+
34
+ def migration_full_path
35
+ File.join(app_root_path, migration_root_path)
36
+ end
37
+ end
9
38
  end
10
39
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Makanai
2
- VERSION = "0.1.1"
4
+ VERSION = '0.1.2'
3
5
  end
data/lib/makanai.rb CHANGED
@@ -1,4 +1,6 @@
1
- require "makanai/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'makanai/version'
2
4
 
3
5
  module Makanai
4
6
  def self.root
data/makanai.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
 
28
28
  spec.add_dependency "rake", ">= 10", "< 14"
29
- spec.add_dependency "rack", "~> 2.0.7"
29
+ spec.add_dependency "rack", ">= 2.0.7", "< 2.3.0"
30
30
  spec.add_dependency "sqlite3", "~> 1.4.1"
31
31
  spec.add_development_dependency "rubocop", "~> 0.74"
32
32
  spec.add_development_dependency "bundler", "~> 2.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: makanai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Madogiwa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-28 00:00:00.000000000 Z
11
+ date: 2020-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -34,16 +34,22 @@ dependencies:
34
34
  name: rack
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: 2.0.7
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 2.3.0
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
- - - "~>"
47
+ - - ">="
45
48
  - !ruby/object:Gem::Version
46
49
  version: 2.0.7
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.0
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: sqlite3
49
55
  requirement: !ruby/object:Gem::Requirement