Skip to content

Commit da736f1

Browse files
committed
convert to a web application
1 parent 9174c31 commit da736f1

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ WORKDIR /app
1010
ADD ./ ./
1111

1212
RUN bundle
13+

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ gem 'sqlite3'
44
gem 'pry-byebug'
55
gem 'activerecord', '~> 6.0', require: 'active_record'
66
gem 'activesupport', '~> 6.0', require: 'active_support'
7+
8+
gem 'sinatra'
9+

Gemfile.lock

+12-1
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,25 @@ GEM
1818
i18n (1.6.0)
1919
concurrent-ruby (~> 1.0)
2020
method_source (0.9.2)
21-
minitest (5.12.0)
21+
minitest (5.12.2)
22+
mustermann (1.0.3)
2223
pry (0.12.2)
2324
coderay (~> 1.1.0)
2425
method_source (~> 0.9.0)
2526
pry-byebug (3.7.0)
2627
byebug (~> 11.0)
2728
pry (~> 0.10)
29+
rack (2.0.7)
30+
rack-protection (2.0.7)
31+
rack
32+
sinatra (2.0.7)
33+
mustermann (~> 1.0)
34+
rack (~> 2.0)
35+
rack-protection (= 2.0.7)
36+
tilt (~> 2.0)
2837
sqlite3 (1.4.1)
2938
thread_safe (0.3.6)
39+
tilt (2.0.10)
3040
tzinfo (1.2.5)
3141
thread_safe (~> 0.1)
3242
zeitwerk (2.1.10)
@@ -38,6 +48,7 @@ DEPENDENCIES
3848
activerecord (~> 6.0)
3949
activesupport (~> 6.0)
4050
pry-byebug
51+
sinatra
4152
sqlite3
4253

4354
BUNDLED WITH

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
## Use ActiveRecord in plain ruby code
1+
## Plain ruby code application
22

3-
We usually have to create plain ruby code needing a database dependency. This code is an starting point for this.
3+
We usually have to create plain ruby code or microservices using a database dependency. This code is an starting point for this. The magic in this repo consists in including the power of Rake tasks and ActiveRecord library.
44

5-
It uses the power of Rails tasks and ActiveRecord library, using just what it is really needed.
5+
E.g., whether you need to create an API, you can start with the code in `bin/serve` where you will find a sinatra web endpoint responding the content of a database table.
66

77
### Instalation
88

@@ -24,6 +24,4 @@ Just create a migration file in 'db/migrate' folder, using numerical order at th
2424

2525
```sh
2626
docker-compose run web rake db:create db:migrate db:seed
27-
```
28-
29-
###
27+
```

bin/serve

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'sinatra'
4+
5+
set :port, 8888
6+
7+
require File.expand_path('../../lib/app', __FILE__) # require the application
8+
9+
get '/' do
10+
content_type :json
11+
Pet.all.to_json
12+
end
13+

docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
version: '3.5'
22
services:
33
app:
4-
command: bash
4+
command: "bin/serve -o 0.0.0.0"
55
build:
66
context: ./
77
dockerfile: Dockerfile
88
volumes:
99
- ./:/app
10+
ports:
11+
- "8888:8888"

0 commit comments

Comments
 (0)