diff --git a/.gitignore b/.gitignore index 77e711f..444ba05 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ #ruby version and gem .ruby-* + +#configs +config/database.yml diff --git a/Gemfile b/Gemfile index 8c9f838..407b394 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,13 @@ source 'https://rubygems.org' ruby '2.2.3' gem 'rack-fiber_pool', :require => 'rack/fiber_pool' + gem 'grape' gem 'grape-swagger' +gem 'grape-activerecord' + +gem 'rake' +gem 'mysql2' + gem 'pry' gem 'awesome_print' diff --git a/Gemfile.lock b/Gemfile.lock index 3fae940..b4e358f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,20 @@ GEM remote: https://rubygems.org/ 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) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + arel (6.0.3) awesome_print (1.6.1) axiom-types (0.1.1) descendants_tracker (~> 0.0.4) @@ -29,6 +37,10 @@ GEM rack-accept rack-mount 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) activesupport multi_json (>= 1.3.2) @@ -36,6 +48,8 @@ GEM grape (>= 0.8.0) grape-entity hashie (3.4.3) + hashie-forbidden_attributes (0.1.1) + hashie (>= 3.0) i18n (0.7.0) ice_nine (0.11.1) json (1.8.3) @@ -43,6 +57,7 @@ GEM minitest (5.8.3) multi_json (1.11.2) multi_xml (0.5.5) + mysql2 (0.4.1) pry (0.10.3) coderay (~> 1.1.0) method_source (~> 0.8.1) @@ -53,6 +68,7 @@ GEM rack-fiber_pool (0.9.3) rack-mount (0.8.3) rack (>= 1.0.0) + rake (10.4.2) slop (3.6.0) thread_safe (0.3.5) tzinfo (1.2.2) @@ -69,9 +85,12 @@ PLATFORMS DEPENDENCIES awesome_print grape + grape-activerecord grape-swagger + mysql2 pry rack-fiber_pool + rake BUNDLED WITH 1.10.6 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..ecc6f0f --- /dev/null +++ b/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 diff --git a/app/api/notes.rb b/app/api/notes.rb index 1cf0729..dc05865 100644 --- a/app/api/notes.rb +++ b/app/api/notes.rb @@ -1,7 +1,7 @@ class Notes < Grape::API version 'v1', using: :header, vendor: 'tonymadbrain' - format :json + format :json resource 'notes' do diff --git a/app/core.rb b/app/core.rb index 746ce77..1315b8f 100644 --- a/app/core.rb +++ b/app/core.rb @@ -1,3 +1,4 @@ +RACK_ENV = (ENV['RACK_ENV'] || 'development').to_sym require 'rubygems' require 'bundler' Bundler.require diff --git a/config.ru b/config.ru index b9aae53..3979266 100644 --- a/config.ru +++ b/config.ru @@ -5,6 +5,8 @@ require 'grape' require './app/core' require './app/api/notes' +use ActiveRecord::ConnectionAdapters::ConnectionManagement + run Notes use Rack::Static, diff --git a/config/database-sample.yml b/config/database-sample.yml new file mode 100644 index 0000000..5f44b31 --- /dev/null +++ b/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"] %>