makanai 0.1.0 → 0.1.1

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: 045d01dcb6633aa95bb5e62f1714b477e80d9df4b29bb225f70ee22ce0b62677
4
- data.tar.gz: 66dd196776a842b881097bf686e658054e0a32377dc1fea5564f540275030763
3
+ metadata.gz: e90461a7d5e372f93f13f282e5f20b0410db84438b4eb9cbb587f0e739bd0c19
4
+ data.tar.gz: a3dbff0cd0661110d7503889d768e6e277d8b3bf1241fcb13c62589ca8133d9d
5
5
  SHA512:
6
- metadata.gz: 7fbceba802f6ae1b6edd0477afa1e13dc0ca73f182527f616a013e23d32b72577eba0e42e65798b0ba3c9452c75638b47da153cd6f40aa42ff6644ca1803413d
7
- data.tar.gz: 86fd67e171f26715f21e6725e18c5d564267387334e519d6ea2f7bffa7c002ba786300b79edf61b0f96f38f6745a81748909fe5aedc13b086bf3cd6b13ae9a12
6
+ metadata.gz: 83066b43bf8207fdc6cc99763cd546504a324420e679c09c5aad6d98f65b7fb308cfd034af1b3e8508735de9693fb93919f55424b3ef04b53e45d5ae7ec8655f
7
+ data.tar.gz: 047dcbdf9ed4afe1c4991b0355ba58f469d63211f840c7f6f28c24f47be07b6a20f595e6eb19636e018152f636f44acffd9ede2cf7993e4a143b0663d7a8a9ec
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6.3
2
+ TargetRubyVersion: 2.7.0
3
3
  Exclude:
4
4
  - './makanai.gemspec'
5
5
 
@@ -15,6 +15,7 @@ Metrics/ClassLength:
15
15
  Metrics/BlockLength:
16
16
  Exclude:
17
17
  - 'spec/**/*'
18
+ - 'lib/makanai/rake_tasks.rb'
18
19
 
19
20
  Style/ParallelAssignment:
20
21
  Enabled: false
data/.travis.yml CHANGED
@@ -3,5 +3,5 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.6.3
6
+ - 2.7.0
7
7
  before_install: gem install bundler -v 2.0.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # CHANGELOG
2
+
3
+ ## :gift: 2019/10/22 `v0.1.0` released.
4
+
5
+ * :tada: first release
6
+
7
+ ## :gift: 2019/12/28 `v0.1.1` released.
8
+
9
+ * :sparkles: add Makanai app genarator.
10
+ Added `makanai init` command for initialize makanai application.
11
+ https://github.com/Madogiwa0124/makanai/pull/5
12
+
13
+ * :sparkles: add `Makanai::Model#first`.
14
+ execute `SELECT * FROM table_name ORDER BY prymary_key asc limit 1` and return record object.
15
+ https://github.com/Madogiwa0124/makanai/commit/8949796bf7428f5e2d854041b35397ef4d442ee6
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- makanai (0.1.0)
4
+ makanai (0.1.1)
5
5
  rack (~> 2.0.7)
6
- rake (~> 10.0)
6
+ rake (>= 10, < 14)
7
7
  sqlite3 (~> 1.4.1)
8
8
 
9
9
  GEM
@@ -11,27 +11,27 @@ GEM
11
11
  specs:
12
12
  ast (2.4.0)
13
13
  diff-lcs (1.3)
14
- jaro_winkler (1.5.3)
15
- parallel (1.17.0)
16
- parser (2.6.3.0)
14
+ jaro_winkler (1.5.4)
15
+ parallel (1.19.1)
16
+ parser (2.7.0.0)
17
17
  ast (~> 2.4.0)
18
- rack (2.0.7)
18
+ rack (2.0.8)
19
19
  rainbow (3.0.0)
20
- rake (10.5.0)
21
- rspec (3.8.0)
22
- rspec-core (~> 3.8.0)
23
- rspec-expectations (~> 3.8.0)
24
- rspec-mocks (~> 3.8.0)
25
- rspec-core (3.8.2)
26
- rspec-support (~> 3.8.0)
27
- rspec-expectations (3.8.4)
20
+ rake (13.0.1)
21
+ rspec (3.9.0)
22
+ rspec-core (~> 3.9.0)
23
+ rspec-expectations (~> 3.9.0)
24
+ rspec-mocks (~> 3.9.0)
25
+ rspec-core (3.9.0)
26
+ rspec-support (~> 3.9.0)
27
+ rspec-expectations (3.9.0)
28
28
  diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.8.0)
30
- rspec-mocks (3.8.1)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-mocks (3.9.0)
31
31
  diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.8.0)
33
- rspec-support (3.8.2)
34
- rubocop (0.74.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-support (3.9.0)
34
+ rubocop (0.78.0)
35
35
  jaro_winkler (~> 1.5.1)
36
36
  parallel (~> 1.10)
37
37
  parser (>= 2.6)
@@ -39,7 +39,7 @@ GEM
39
39
  ruby-progressbar (~> 1.7)
40
40
  unicode-display_width (>= 1.4.0, < 1.7)
41
41
  ruby-progressbar (1.10.1)
42
- sqlite3 (1.4.1)
42
+ sqlite3 (1.4.2)
43
43
  unicode-display_width (1.6.0)
44
44
 
45
45
  PLATFORMS
@@ -52,4 +52,4 @@ DEPENDENCIES
52
52
  rubocop (~> 0.74)
53
53
 
54
54
  BUNDLED WITH
55
- 2.0.2
55
+ 2.1.2
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # Makanai
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/makanai.svg)](https://badge.fury.io/rb/makanai)
4
+ [![Build Status](https://travis-ci.com/Madogiwa0124/makanai.svg?branch=master)](https://travis-ci.com/Madogiwa0124/makanai)
5
+
2
6
  simple web application framework for learning.
3
7
 
4
8
  # Getting Start
@@ -29,20 +33,15 @@ Makanai depends on the following, so please install it in advance.
29
33
  Getting started with Makanai is easy.
30
34
 
31
35
  ```
32
- $ git clone https://github.com/Madogiwa0124/makanai.git
33
- $ bundle install
34
- $ cd makanai/sample
35
- $ be ruby app.rb
36
- [2019-09-09 23:20:05] INFO WEBrick 1.4.2
37
- [2019-09-09 23:20:05] INFO ruby 2.6.3 (2019-04-16) [x86_64-darwin18]
38
- [2019-09-09 23:20:05] INFO WEBrick::HTTPServer#start: pid=30871 port=8080
36
+ $ mkdir sample
37
+ $ cd sample
38
+ $ makanai init
39
+ $ ruby app.rb
40
+ [2019-12-28 12:27:13] INFO WEBrick 1.6.0
41
+ [2019-12-28 12:27:13] INFO ruby 2.7.0 (2019-12-25) [x86_64-darwin18]
42
+ [2019-12-28 12:27:13] INFO WEBrick::HTTPServer#start: pid=22676 port=8080
39
43
  ```
40
44
 
41
- ## How to customize
42
- You can customize the Makanai project by changing the sample directory. (You can also change the directory name from the sample.)
43
-
44
- To see what features are available, see Usage.
45
-
46
45
  # Usage
47
46
 
48
47
  create a ruby ​​file(ex. app.rb).
@@ -59,9 +58,9 @@ start server(WEBrick) at execute `$ ruby app.rb`.
59
58
 
60
59
  ```
61
60
  $ ruby app.rb
62
- [2019-08-12 20:44:20] INFO WEBrick 1.4.2
63
- [2019-08-12 20:44:20] INFO ruby 2.6.3 (2019-04-16) [x86_64-darwin18]
64
- [2019-08-12 20:44:20] INFO WEBrick::HTTPServer#start: pid=26043 port=8080
61
+ [2019-12-28 12:27:13] INFO WEBrick 1.6.0
62
+ [2019-12-28 12:27:13] INFO ruby 2.7.0 (2019-12-25) [x86_64-darwin18]
63
+ [2019-12-28 12:27:13] INFO WEBrick::HTTPServer#start: pid=22676 port=8080
65
64
  ```
66
65
 
67
66
  When accessing root, `Hello Makanai!` is displayed.
data/exe/makanai ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'makanai'
4
+ require 'makanai/rake_tasks'
5
+
6
+ if ARGV[0] == 'init'
7
+ Rake::Task['makanai:initialize:app'].execute
8
+ end
@@ -7,9 +7,9 @@ module Makanai
7
7
  class Database
8
8
  DATABASE_PATH = "#{Settings::APP_ROOT_PATH}#{Settings::DATABASE_PATH}"
9
9
 
10
- def initialize
10
+ def initialize(path: DATABASE_PATH)
11
11
  @handler = SQLite3::Database
12
- @db = handler.new DATABASE_PATH
12
+ @db = handler.new path
13
13
  db.tap { |db| db.results_as_hash = true }
14
14
  end
15
15
 
@@ -20,6 +20,8 @@ module Makanai
20
20
  db.execute(sql).tap { close_db }
21
21
  end
22
22
 
23
+ private
24
+
23
25
  def close_db
24
26
  db.close
25
27
  end
@@ -0,0 +1,4 @@
1
+ - db
2
+ - migration
3
+ - models
4
+ - views
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'makanai/main'
4
+
5
+ router.get '/' do
6
+ 'Hello Makanai!'
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'makanai/rake_tasks.rb'
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+ require 'yaml'
5
+ require_relative '../makanai.rb'
6
+
7
+ module Makanai
8
+ class Generator
9
+ ROOT_PATH = "#{Makanai.root}/lib/makanai/generator"
10
+ DIRECTORY_NAMES = YAML.load_file("#{ROOT_PATH}/application/directories.yaml")
11
+ APP_TEMPLATE = File.read("#{ROOT_PATH}/application/templates/app.erb")
12
+ RAKEFILE_TEMPLATE = File.read("#{ROOT_PATH}/application/templates/rakefile.erb")
13
+
14
+ def initialize(path = Dir.pwd)
15
+ @path = path
16
+ end
17
+
18
+ attr_reader :path
19
+
20
+ def create_app_directories(directory_names = DIRECTORY_NAMES)
21
+ directory_names.map do |name|
22
+ dir_path = File.join(path, name)
23
+ Dir.mkdir(dir_path)
24
+ file_path = File.join(dir_path, '.keep')
25
+ create_file(file_path, nil)
26
+ file_path
27
+ end
28
+ end
29
+
30
+ def create_app_rb(template = APP_TEMPLATE)
31
+ File.join(path, 'app.rb').tap do |file_path|
32
+ create_file(file_path, ERB.new(template).result)
33
+ end
34
+ end
35
+
36
+ def create_rakefile(template = RAKEFILE_TEMPLATE)
37
+ File.join(path, 'Rakefile').tap do |file_path|
38
+ create_file(file_path, ERB.new(template).result)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def create_file(file_path, content)
45
+ File.open(file_path, 'w') { |f| f.puts content }
46
+ end
47
+ end
48
+ end
@@ -5,10 +5,10 @@ require_relative './database.rb'
5
5
 
6
6
  module Makanai
7
7
  module Migration
8
- def execute_sql(sql_path:)
8
+ def execute_sql(sql_path:, db: Makanai::Database.new)
9
9
  sql = File.read(sql_path)
10
10
  puts "execute: #{sql_path}"
11
- Makanai::Database.new.execute_sql(sql)
11
+ db.execute_sql(sql)
12
12
  end
13
13
 
14
14
  def migration_root_path
data/lib/makanai/model.rb CHANGED
@@ -13,38 +13,45 @@ module Makanai
13
13
 
14
14
  attr_reader :origin_attributes
15
15
 
16
- def self.execute_sql(sql)
17
- Makanai::Database.new.execute_sql(sql)
16
+ def self.execute_sql(sql, db = Makanai::Database.new)
17
+ db.execute_sql(sql)
18
18
  end
19
19
 
20
- def self.all
21
- results = execute_sql("SELECT * FROM #{self::TABLE_NAME};")
20
+ def self.all(db = Makanai::Database.new)
21
+ results = execute_sql("SELECT * FROM #{self::TABLE_NAME};", db)
22
22
  results.map { |result| new(result) }
23
23
  end
24
24
 
25
- def self.find(key)
26
- results = execute_sql(
27
- <<~SQL
28
- SELECT *
29
- FROM #{self::TABLE_NAME}
30
- WHERE #{self::PRYMARY_KEY} = #{buid_sql_text(key)}
31
- LIMIT 1;
32
- SQL
33
- )
25
+ def self.find(key, db = Makanai::Database.new)
26
+ sql = <<~SQL
27
+ SELECT *
28
+ FROM #{self::TABLE_NAME}
29
+ WHERE #{self::PRYMARY_KEY} = #{buid_sql_text(key)}
30
+ LIMIT 1;
31
+ SQL
32
+ results = execute_sql(sql, db)
34
33
  raise Makanai::Model::NotFound if results.empty?
35
34
  new(results.pop)
36
35
  end
37
36
 
38
- def self.last
39
- results = execute_sql(
40
- <<~SQL
41
- SELECT *
42
- FROM #{self::TABLE_NAME}
43
- ORDER BY #{self::PRYMARY_KEY} DESC
44
- LIMIT 1;
45
- SQL
46
- )
47
- new(results.pop)
37
+ def self.first(db = Makanai::Database.new)
38
+ sql = <<~SQL
39
+ SELECT *
40
+ FROM #{self::TABLE_NAME}
41
+ ORDER BY #{self::PRYMARY_KEY} ASC
42
+ LIMIT 1;
43
+ SQL
44
+ new(execute_sql(sql, db).pop)
45
+ end
46
+
47
+ def self.last(db = Makanai::Database.new)
48
+ sql = <<~SQL
49
+ SELECT *
50
+ FROM #{self::TABLE_NAME}
51
+ ORDER BY #{self::PRYMARY_KEY} DESC
52
+ LIMIT 1;
53
+ SQL
54
+ new(execute_sql(sql, db).pop)
48
55
  end
49
56
 
50
57
  def self.buid_sql_text(value)
@@ -64,39 +71,36 @@ module Makanai
64
71
  origin_attributes.map { |key, _val| [key, send(key)] }.to_h
65
72
  end
66
73
 
67
- def create
68
- self.class.execute_sql(
69
- <<~SQL
70
- INSERT
71
- INTO #{self.class::TABLE_NAME}(#{clumns.join(',')})
72
- VALUES (#{insert_values.join(',')});
73
- SQL
74
- )
75
- @origin_attributes = self.class.last.attributes
74
+ def create(db = Makanai::Database.new)
75
+ sql = <<~SQL
76
+ INSERT
77
+ INTO #{self.class::TABLE_NAME}(#{clumns.join(',')})
78
+ VALUES (#{insert_values.join(',')});
79
+ SQL
80
+ self.class.execute_sql(sql, db)
81
+ @origin_attributes = attributes
76
82
  difine_attribute_methods
77
83
  self
78
84
  end
79
85
 
80
- def update
81
- self.class.execute_sql(
82
- <<~SQL
83
- UPDATE #{self.class::TABLE_NAME}
84
- SET #{update_values.join(',')}
85
- WHERE #{self.class::PRYMARY_KEY} = #{self.class.buid_sql_text(send(self.class::PRYMARY_KEY))};
86
- SQL
87
- )
86
+ def update(db = Makanai::Database.new)
87
+ sql = <<~SQL
88
+ UPDATE #{self.class::TABLE_NAME}
89
+ SET #{update_values.join(',')}
90
+ WHERE #{self.class::PRYMARY_KEY} = #{self.class.buid_sql_text(send(self.class::PRYMARY_KEY))};
91
+ SQL
92
+ self.class.execute_sql(sql, db)
88
93
  @origin_attributes = attributes
89
94
  difine_attribute_methods
90
95
  self
91
96
  end
92
97
 
93
- def delete
94
- self.class.execute_sql(
95
- <<~SQL
96
- DELETE FROM #{self.class::TABLE_NAME}
97
- WHERE #{self.class::PRYMARY_KEY} = #{self.class.buid_sql_text(send(self.class::PRYMARY_KEY))};
98
- SQL
99
- )
98
+ def delete(db = Makanai::Database.new)
99
+ sql = <<~SQL
100
+ DELETE FROM #{self.class::TABLE_NAME}
101
+ WHERE #{self.class::PRYMARY_KEY} = #{self.class.buid_sql_text(send(self.class::PRYMARY_KEY))};
102
+ SQL
103
+ self.class.execute_sql(sql, db)
100
104
  nil
101
105
  end
102
106
 
@@ -3,8 +3,21 @@
3
3
  require 'rake'
4
4
  require 'sqlite3'
5
5
  require_relative './migration.rb'
6
+ require_relative './generator.rb'
6
7
 
7
8
  namespace :makanai do
9
+ namespace :initialize do
10
+ desc 'create directies and files for makanai initialization.'
11
+ task :app do
12
+ generator = Makanai::Generator.new
13
+ puts 'INFO: start ganerate app'
14
+ puts generator.create_app_directories
15
+ puts generator.create_app_rb
16
+ puts generator.create_rakefile
17
+ puts 'INFO: finished ganerate app'
18
+ end
19
+ end
20
+
8
21
  namespace :db do
9
22
  desc 'execute migration'
10
23
  task :migration do
@@ -1,3 +1,3 @@
1
1
  module Makanai
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/makanai.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require "makanai/version"
2
2
 
3
3
  module Makanai
4
+ def self.root
5
+ File.dirname __dir__
6
+ end
7
+
4
8
  class Error < StandardError; end
5
9
  # Your code goes here...
6
10
  end
data/makanai.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_dependency "rake", "~> 10.0"
28
+ spec.add_dependency "rake", ">= 10", "< 14"
29
29
  spec.add_dependency "rack", "~> 2.0.7"
30
30
  spec.add_dependency "sqlite3", "~> 1.4.1"
31
31
  spec.add_development_dependency "rubocop", "~> 0.74"
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: makanai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Madogiwa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-22 00:00:00.000000000 Z
11
+ date: 2019-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '10'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '10.0'
22
+ version: '14'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '10'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '10.0'
32
+ version: '14'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rack
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -97,7 +103,8 @@ dependencies:
97
103
  description: simple web application framework for learning.
98
104
  email:
99
105
  - madogiwa0124@gmail.com
100
- executables: []
106
+ executables:
107
+ - makanai
101
108
  extensions: []
102
109
  extra_rdoc_files: []
103
110
  files:
@@ -105,6 +112,7 @@ files:
105
112
  - ".rspec"
106
113
  - ".rubocop.yml"
107
114
  - ".travis.yml"
115
+ - CHANGELOG.md
108
116
  - CODE_OF_CONDUCT.md
109
117
  - Gemfile
110
118
  - Gemfile.lock
@@ -113,10 +121,15 @@ files:
113
121
  - Rakefile
114
122
  - bin/console
115
123
  - bin/setup
124
+ - exe/makanai
116
125
  - lib/makanai.rb
117
126
  - lib/makanai/application.rb
118
127
  - lib/makanai/database.rb
119
128
  - lib/makanai/dsl.rb
129
+ - lib/makanai/generator.rb
130
+ - lib/makanai/generator/application/directories.yaml
131
+ - lib/makanai/generator/application/templates/app.erb
132
+ - lib/makanai/generator/application/templates/rakefile.erb
120
133
  - lib/makanai/main.rb
121
134
  - lib/makanai/migration.rb
122
135
  - lib/makanai/model.rb
@@ -155,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
168
  - !ruby/object:Gem::Version
156
169
  version: '0'
157
170
  requirements: []
158
- rubygems_version: 3.0.3
171
+ rubygems_version: 3.1.2
159
172
  signing_key:
160
173
  specification_version: 4
161
174
  summary: simple web application framework for learning.