Skip to content

Dev #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Linters

on: pull_request

env:
FORCE_COLOR: 1

jobs:
rubocop:
name: Rubocop
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: 3.0.x
- name: Setup Rubocop
run: |
gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/
[ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ror/.rubocop.yml
- name: Rubocop Report
run: rubocop --color
60 changes: 60 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
AllCops:
NewCops: enable
Exclude:
- "db/**/*"
- "bin/*"
- "config/**/*"
- "Guardfile"
- "Rakefile"
- "node_modules/**/*"

DisplayCopNames: true

Layout/LineLength:
Max: 120
Metrics/MethodLength:
Include:
- "app/controllers/*"
- "app/models/*"
Max: 20
Metrics/AbcSize:
Include:
- "app/controllers/*"
- "app/models/*"
Max: 50
Metrics/ClassLength:
Max: 150
Metrics/BlockLength:
IgnoredMethods: ['describe']
Max: 30

Style/Documentation:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Style/EachForSimpleLoop:
Enabled: false
Style/AndOr:
Enabled: false
Style/DefWithParentheses:
Enabled: false
Style/FrozenStringLiteralComment:
EnforcedStyle: never

Layout/HashAlignment:
EnforcedColonStyle: key
Layout/ExtraSpacing:
AllowForAlignment: false
Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented
Lint/RaiseException:
Enabled: false
Lint/StructNewOverride:
Enabled: false
Style/HashEachMethods:
Enabled: false
Style/HashTransformKeys:
Enabled: false
Style/HashTransformValues:
Enabled: false
23 changes: 14 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
source "https://rubygems.org"
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.1.1"
ruby '3.1.1'

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.3"
gem 'rails', '~> 7.0.3'

# Use postgresql as the database for Active Record
gem "pg", "~> 1.1"
gem 'pg', '~> 1.1'

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"
gem 'puma', '~> 5.0'

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
# gem "jbuilder"

# Serialize data to JSON easily with Active Model Serializers
gem 'active_model_serializers'

# rack-cors gem for CORS support
gem 'rack-cors'

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

Expand All @@ -25,10 +31,10 @@ gem "puma", "~> 5.0"
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data"
gem 'tzinfo-data'

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false
gem 'bootsnap', require: false

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"
Expand All @@ -38,11 +44,10 @@ gem "bootsnap", require: false

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
gem 'debug', platforms: %i[mri mingw x64_mingw]
end

group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end

12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_model_serializers (0.10.13)
actionpack (>= 4.1, < 7.1)
activemodel (>= 4.1, < 7.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (7.0.3)
activesupport (= 7.0.3)
globalid (>= 0.3.6)
Expand All @@ -69,6 +74,8 @@ GEM
bootsnap (1.12.0)
msgpack (~> 1.2)
builder (3.2.4)
case_transform (0.2)
activesupport
concurrent-ruby (1.1.10)
crass (1.0.6)
debug (1.5.0)
Expand All @@ -83,6 +90,7 @@ GEM
io-console (0.5.11)
irb (1.4.1)
reline (>= 0.3.0)
jsonapi-renderer (0.2.2)
loofah (2.18.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -115,6 +123,8 @@ GEM
nio4r (~> 2.0)
racc (1.6.0)
rack (2.2.3.1)
rack-cors (1.1.1)
rack (>= 2.0.0)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (7.0.3)
Expand Down Expand Up @@ -162,10 +172,12 @@ PLATFORMS
x64-mingw-ucrt

DEPENDENCIES
active_model_serializers
bootsnap
debug
pg (~> 1.1)
puma (~> 5.0)
rack-cors
rails (~> 7.0.3)
tzinfo-data

Expand Down
105 changes: 92 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,103 @@
# README
![](https://img.shields.io/badge/Hello-blue)

This README would normally document whatever steps are necessary to get the
application up and running.
# Hello-rails-backend

Things you may want to cover:
> This is the hello api. Built with Rails

* Ruby version
# Built with
- Ruby
- Ruby on Rails
- Rubocop
- Gems
- rack-cors

* System dependencies
# Deployed on Heroku
[https://chello-frontend.herokuapp.com/](https://chello-frontend.herokuapp.com/)

# Front-end repo
[Hello-react-frontend](https://github.com/BertrandConxy/hello-react-frontend)

* Configuration
## Endpoints
- /api/v1/greetings

* Database creation

* Database initialization
# Get Started
Follow these steps below:

* How to run the test suite
## Pre-requisites

* Services (job queues, cache servers, search engines, etc.)
```bash
- Ruby
- Rails
- PostgreSQL
```

* Deployment instructions
## Setup
Clone the repo and run bundle install in the command line to install the dependencies

* ...
```bash
$ git clone https://github.com/BertrandConxy/hello-rails-backend.git
$ cd hello-rails-backend
```

## Install gems with:

```bash
$ bundle install
```

## Install style linters with
```bash
$ npm install
```

## Play with the code
```
rails c
```

## Populate the db with dummy data
```
rails db:migrate
rails db:seed
```

## Run linters
```
rubocop -A
```

## Start rails server (puma)

```bash
$ rails server
```

Open [http://localhost:3000/](http://localhost:3000/) in your browser


## Author

👤 **Bertrand Mutangana Ishimwe**

- GitHub: [@BertrandConxy](https://github.com/BertrandConxy)
- Twitter: [@Bconxy](https://twitter.com/BertrandMutanga)
- LinkedIn: [Bertrand Mutangana Ishimwe](https://www.linkedin.com/in/bertrandmutangana)

## 🤝 Contributing

Contributions, issues, and feature requests are welcome!

Feel free to check the [issues page](../../issues/).

## Show your support

Give a ⭐️ if you like this project!

## Acknowledgments
- Many thanks to Microverse
- Thanks to everyone whose ideas were used to achieve this project

## 📝 License

This project is [MIT](./MIT.md) licensed.
7 changes: 7 additions & 0 deletions app/controllers/api/v1/greetings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::GreetingsController < ApplicationController
def index
random_id = rand 1..Greeting.count
@greeting = Greeting.find(random_id)
render json: { status: 'SUCCESS', message: 'rendered successfully', data: @greeting }, status: :ok # 200
end
end
4 changes: 2 additions & 2 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
layout "mailer"
default from: '[email protected]'
layout 'mailer'
end
2 changes: 2 additions & 0 deletions app/models/greeting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Greeting < ApplicationRecord
end
3 changes: 3 additions & 0 deletions app/serializers/greeting_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class GreetingSerializer < ActiveModel::Serializer
attributes :id, :text
end
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is used by Rack-based servers to start the application.

require_relative "config/environment"
require_relative 'config/environment'

run Rails.application
Rails.application.load_server
19 changes: 3 additions & 16 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
# PostgreSQL. Versions 9.3 and up are supported.
#
# Install the pg driver:
# gem install pg
# On macOS with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On macOS with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem "pg"
#

default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: postgres
password: admin

development:
<<: *default
Expand Down
18 changes: 9 additions & 9 deletions config/initializers/cors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

# Read more: https://github.com/cyu/rack-cors

# Rails.application.config.middleware.insert_before 0, Rack::Cors do
# allow do
# origins "example.com"
#
# resource "*",
# headers: :any,
# methods: [:get, :post, :put, :patch, :delete, :options, :head]
# end
# end
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins "*"

resource "*",
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end
Loading