Navigation Menu

Skip to content

Commit

Permalink
Added ActiveRecord with the grape-active-record gem
Browse files Browse the repository at this point in the history
  • Loading branch information
Antony Ryabov committed Nov 24, 2015
1 parent 8b9ec95 commit 412226f
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -20,3 +20,6 @@


#ruby version and gem #ruby version and gem
.ruby-* .ruby-*

#configs
config/database.yml
6 changes: 6 additions & 0 deletions Gemfile
Expand Up @@ -3,7 +3,13 @@ source 'https://rubygems.org'
ruby '2.2.3' ruby '2.2.3'


gem 'rack-fiber_pool', :require => 'rack/fiber_pool' gem 'rack-fiber_pool', :require => 'rack/fiber_pool'

gem 'grape' gem 'grape'
gem 'grape-swagger' gem 'grape-swagger'
gem 'grape-activerecord'

gem 'rake'
gem 'mysql2'

gem 'pry' gem 'pry'
gem 'awesome_print' gem 'awesome_print'
19 changes: 19 additions & 0 deletions Gemfile.lock
@@ -1,12 +1,20 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
activemodel (4.2.5)
activesupport (= 4.2.5)
builder (~> 3.1)
activerecord (4.2.5)
activemodel (= 4.2.5)
activesupport (= 4.2.5)
arel (~> 6.0)
activesupport (4.2.5) activesupport (4.2.5)
i18n (~> 0.7) i18n (~> 0.7)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (6.0.3)
awesome_print (1.6.1) awesome_print (1.6.1)
axiom-types (0.1.1) axiom-types (0.1.1)
descendants_tracker (~> 0.0.4) descendants_tracker (~> 0.0.4)
Expand All @@ -29,20 +37,27 @@ GEM
rack-accept rack-accept
rack-mount rack-mount
virtus (>= 1.0.0) virtus (>= 1.0.0)
grape-activerecord (1.1.2)
activerecord (~> 4.0)
grape (~> 0.1)
hashie-forbidden_attributes (~> 0.1.1)
grape-entity (0.4.8) grape-entity (0.4.8)
activesupport activesupport
multi_json (>= 1.3.2) multi_json (>= 1.3.2)
grape-swagger (0.10.2) grape-swagger (0.10.2)
grape (>= 0.8.0) grape (>= 0.8.0)
grape-entity grape-entity
hashie (3.4.3) hashie (3.4.3)
hashie-forbidden_attributes (0.1.1)
hashie (>= 3.0)
i18n (0.7.0) i18n (0.7.0)
ice_nine (0.11.1) ice_nine (0.11.1)
json (1.8.3) json (1.8.3)
method_source (0.8.2) method_source (0.8.2)
minitest (5.8.3) minitest (5.8.3)
multi_json (1.11.2) multi_json (1.11.2)
multi_xml (0.5.5) multi_xml (0.5.5)
mysql2 (0.4.1)
pry (0.10.3) pry (0.10.3)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.8.1) method_source (~> 0.8.1)
Expand All @@ -53,6 +68,7 @@ GEM
rack-fiber_pool (0.9.3) rack-fiber_pool (0.9.3)
rack-mount (0.8.3) rack-mount (0.8.3)
rack (>= 1.0.0) rack (>= 1.0.0)
rake (10.4.2)
slop (3.6.0) slop (3.6.0)
thread_safe (0.3.5) thread_safe (0.3.5)
tzinfo (1.2.2) tzinfo (1.2.2)
Expand All @@ -69,9 +85,12 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
awesome_print awesome_print
grape grape
grape-activerecord
grape-swagger grape-swagger
mysql2
pry pry
rack-fiber_pool rack-fiber_pool
rake


BUNDLED WITH BUNDLED WITH
1.10.6 1.10.6
9 changes: 9 additions & 0 deletions Rakefile
@@ -0,0 +1,9 @@
require "bundler/setup"
require "grape/activerecord/rake"

namespace :db do
# Some db tasks require your app code to be loaded, or at least your gems
task :environment do
require_relative "app/core"
end
end
2 changes: 1 addition & 1 deletion app/api/notes.rb
@@ -1,7 +1,7 @@
class Notes < Grape::API class Notes < Grape::API


version 'v1', using: :header, vendor: 'tonymadbrain' version 'v1', using: :header, vendor: 'tonymadbrain'
format :json format :json


resource 'notes' do resource 'notes' do


Expand Down
1 change: 1 addition & 0 deletions app/core.rb
@@ -1,3 +1,4 @@
RACK_ENV = (ENV['RACK_ENV'] || 'development').to_sym
require 'rubygems' require 'rubygems'
require 'bundler' require 'bundler'
Bundler.require Bundler.require
Expand Down
2 changes: 2 additions & 0 deletions config.ru
Expand Up @@ -5,6 +5,8 @@ require 'grape'
require './app/core' require './app/core'
require './app/api/notes' require './app/api/notes'


use ActiveRecord::ConnectionAdapters::ConnectionManagement

run Notes run Notes


use Rack::Static, use Rack::Static,
Expand Down
40 changes: 40 additions & 0 deletions config/database-sample.yml
@@ -0,0 +1,40 @@
# MySQL. Versions 5.0+ are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
#
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password:
host: 127.0.0.1
port: 3306
socket: /tmp/mysql.sock

development:
<<: *default
database: grape_rack_swagger_development

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: grape_rack_swagger_test

# Avoid production credentials in the repository,
# instead read the configuration from the environment.
#
# Example:
# mysql2://myuser:mypass@localhost/somedatabase
#
production:
url: <%= ENV["DATABASE_URL"] %>

0 comments on commit 412226f

Please sign in to comment.