Skip to content

Commit

Permalink
Fix rubocop issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgeneOskin committed Nov 9, 2015
1 parent 1d2270d commit 8634fc8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
23 changes: 10 additions & 13 deletions app/api/animal/api.rb
@@ -1,4 +1,5 @@
module Animal
# Class with grape api for Animal project.
class API < Grape::API
version 'v1', using: :path
format :json
Expand All @@ -19,20 +20,20 @@ def authenticate!
user.valid_password? password if user
end

desc 'Pet index.', {
params: Entities::Pet.documentation
}
desc 'Pet index.', params: Entities::Pet.documentation
get '/pet' do
authenticate!
pets = Pet.all
present pets, with: Entities::Pet, type: :full
end

desc 'Create a pet.', {
params: Entities::Pet.documentation
}
desc 'Create a pet.', params: Entities::Pet.documentation
params do
requires :all, except: [:id, :owner_email], using: Entities::Pet.documentation.except(:id, :owner_email)
requires(
:all,
except: [:id, :email],
using: Entities::Pet.documentation.except(:id, :email)
)
end
post '/pet' do
authenticate!
Expand All @@ -41,18 +42,14 @@ def authenticate!
end
end

desc 'Breed index.', {
params: Entities::Breed.documentation
}
desc 'Breed index.', params: Entities::Breed.documentation
get '/breed' do
authenticate!
breeds = Breed.all
present breeds, with: Entities::Breed, type: :full
end

desc 'Birth index.', {
params: Entities::Birth.documentation
}
desc 'Birth index.', params: Entities::Birth.documentation
get '/birth' do
authenticate!
births = Birth.all
Expand Down
8 changes: 7 additions & 1 deletion app/api/animal/entities.rb
@@ -1,26 +1,32 @@
module Animal
# Entities for Animal API.
module Entities
# General Entity with id, and timestamps.
class Id < Grape::Entity
expose :id
expose :created_at
expose :updated_at
end

# General Entity plus name field.
class Named < Id
expose :name
end

# Pet entity (Pet and Birth model).
class Pet < Named
expose :owner_email
expose :email, as: :owner_email
expose :breed_id
expose :gender
expose :father_id
expose :mother_id
end

# Breed entity like Breed model.
class Breed < Named
end

# Birth entity like Birth model.
class Birth < Id
expose :child_id
expose :father_id
Expand Down
4 changes: 1 addition & 3 deletions app/models/pet.rb
Expand Up @@ -10,9 +10,7 @@ class Pet < ActiveRecord::Base
validates :owner, presence: true
validates :gender, presence: true

def owner_email
owner.email
end
delegate :email, to: :owner

def birth
Birth.find_by child: self
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -6,6 +6,6 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable

def self.authorize!(env)
self.find_by email: env['REMOTE_USER']
find_by email: env['REMOTE_USER']
end
end
2 changes: 1 addition & 1 deletion config/application.rb
Expand Up @@ -31,7 +31,7 @@ class Application < Rails::Application
config.active_record.raise_in_transactional_callbacks = true

# Add REST API to app.
config.paths.add "app/api", glob: "**/*.rb"
config.paths.add 'app/api', glob: '**/*.rb'
config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
end
end

0 comments on commit 8634fc8

Please sign in to comment.