gris 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7a9d87376c3a34905e0ae62a2cf778917964e9a
4
- data.tar.gz: beb8cd90e47c105a9465cca0d212c09ee12e98ae
3
+ metadata.gz: cbd71571b5bfda09a79619eecef2b1e7bf959691
4
+ data.tar.gz: cf81127408c56950feb8a08908717706e9fd504f
5
5
  SHA512:
6
- metadata.gz: 9a4b903572ba4db5c49f94a7492881cbea0e31e2dfc90114f145f52150474790974d33d074c50bbdf2a09c4cad938ce097d2b5aec74cf938d530fb70cd2b5018
7
- data.tar.gz: bb006bd646aebde08d0fe1a313d975bdc4ae106fcec1965a11d5407b3141c2bccba335dc34e5ce5b067aaddc8c89742e24e85dd73f59aabb9bdbc3eaa3203b07
6
+ metadata.gz: efd0cfecb9e6c05bc34266586e708239a2e595b29f121f98a7989e34128331b433f8bd97c51a452f4bd820d3a3c6703d07ca9f3196fd6715807065cbbb0bbc18
7
+ data.tar.gz: e658cb42d8548d4db4abd82b954a4728a6589ac00b7770780e423c3000a7c30e9cf081dfdffb815a935f43b6701abfaef0ba7b324f0b6a370f52be1c8c4841da
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gris (0.1.6)
4
+ gris (0.1.7)
5
5
  activesupport (~> 4.2, >= 4.2.0)
6
+ chronic (~> 0.10.0)
6
7
  dotenv (~> 1.0.2, >= 1.0.2)
7
8
  git (~> 1.2, >= 1.2.8)
8
9
  grape (~> 0.11.0, >= 0.11.0)
@@ -47,6 +48,7 @@ GEM
47
48
  columnize (= 0.9.0)
48
49
  celluloid (0.16.0)
49
50
  timers (~> 4.0.0)
51
+ chronic (0.10.2)
50
52
  coderay (1.1.0)
51
53
  coercible (1.0.0)
52
54
  descendants_tracker (~> 0.0.1)
data/Rakefile CHANGED
@@ -9,6 +9,7 @@ RSpec::Core::RakeTask.new
9
9
  desc 'Run RuboCop'
10
10
  RuboCop::RakeTask.new(:rubocop) do |task|
11
11
  task.fail_on_error = true
12
+ task.options = %w(-D --auto-correct)
12
13
  end
13
14
 
14
15
  task default: [:rubocop, :spec]
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.add_dependency 'roar', '~> 1.0.1'
33
33
  s.add_dependency 'racksh', '~> 1.0'
34
34
  s.add_dependency 'hashie-forbidden_attributes', '~> 0.1.0'
35
+ s.add_dependency 'chronic', '~> 0.10.0'
35
36
 
36
37
  s.add_development_dependency 'bundler'
37
38
  s.add_development_dependency 'rspec', '~> 3.2'
@@ -17,6 +17,7 @@ require 'gris/deprecations'
17
17
  require 'gris/grape_extensions/crud_helpers'
18
18
  require 'gris/grape_extensions/error_helpers'
19
19
  require 'gris/grape_extensions/authentication_helpers'
20
+ require 'gris/grape_extensions/date_time_helpers'
20
21
  require 'gris/identity'
21
22
  require 'gris/middleware/health'
22
23
  require 'gris/output_formatters/paginated_presenter'
@@ -3,9 +3,9 @@
3
3
 
4
4
  SERVICE_NAME=<%= app_name %>
5
5
 
6
- DATABASE_USER='<%= @database_user %>'
6
+ DATABASE_USER='postgres'
7
7
  DATABASE_PASSWORD=''
8
8
  DATABASE_HOST=localhost
9
9
  DATABASE_NAME=<%= app_name.underscore %>_development
10
- BASE_URL=http://127.0.0.1:9292
10
+ BASE_URL=http://127.0.0.1:9393
11
11
  PERMITTED_TOKENS=replace-me
@@ -2,7 +2,8 @@
2
2
  .env
3
3
  .rspec
4
4
  .env
5
- !.env.test
5
+ .env.*
6
+ !.env.example
6
7
  !log/.keep
7
8
  log/*
8
9
  tmp/*
@@ -16,6 +16,7 @@ gem 'puma'
16
16
 
17
17
  group :development, :test do
18
18
  gem 'pry'
19
+ gem 'hyperclient', '0.7.0'
19
20
  end
20
21
 
21
22
  group :development do
@@ -1,3 +1,29 @@
1
- # Welcome to <%= app_name %>
1
+ <%= app_name %>
2
+ ====
3
+
4
+ This is a Grape + Rack ([Gris](http://github.com/dylanfareed/gris)) hypermedia API service.
5
+
6
+
7
+ Set-Up for Development
8
+ ---
9
+
10
+ - Fork this repo
11
+ - Clone your fork locally
12
+ - Bundle
13
+ ```
14
+ cd your-fork-directory
15
+ bundle
16
+ ```
17
+ - `DATABASE_NAME` and `PERMITTED_TOKENS` are required environment variables. Prior to executing rake tasks, running the gris console or booting the application, set up your environment by doing **one** of the following:
18
+ * Use [Dotenv](https://github.com/bkeepers/dotenv)—copy `.env.example` to `.env` and `.env.test` and modify it where appropriate
19
+ * Export the minimum required environment variables `DATABASE_NAME` and `PERMITTED_TOKENS`
20
+ - Set up the database
21
+ ```
22
+ DATABASE_NAME= PERMITTED_TOKENS= bundle exec rake db:create
23
+ DATABASE_NAME= PERMITTED_TOKENS= bundle exec rake db:migrate
24
+ ```
25
+ - Verify that [Rubocop](https://github.com/bbatsov/rubocop) and specs pass.
26
+ ```
27
+ DATABASE_NAME= PERMITTED_TOKENS= bundle exec rake
28
+ ```
2
29
 
3
- TODO: Add an awesome README that explains how all this stuff works!
@@ -1,8 +1,17 @@
1
1
  #!/usr/bin/env rake
2
- require 'gris/setup'
3
- Gris.load_environment
4
-
5
- require File.expand_path('../config/application.rb', __FILE__)
6
- require 'json'
2
+ require File.expand_path('../config/boot', __FILE__)
7
3
 
8
4
  Dir.glob('./lib/tasks/*.rake').each { |r| import r }
5
+
6
+ require 'rspec/core/rake_task'
7
+ require 'rubocop/rake_task'
8
+
9
+ RSpec::Core::RakeTask.new
10
+
11
+ desc 'Run RuboCop'
12
+ RuboCop::RakeTask.new(:rubocop) do |task|
13
+ task.fail_on_error = true
14
+ task.options = %w(-D --auto-correct)
15
+ end
16
+
17
+ task default: [:rubocop, :spec]
@@ -1,5 +1,12 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
+ # autoload initalizers
4
+ Dir['./config/initializers/**/*.rb'].map { |file| require file }
5
+
6
+ # autoload app
7
+ relative_load_paths = %w(app/endpoints app/presenters app/models)
8
+ ActiveSupport::Dependencies.autoload_paths += relative_load_paths
9
+
3
10
  module <%= app_name.classify %>
4
11
  class Application < Gris::Application
5
12
  # config.use_health_middleware = false
@@ -1,16 +1,7 @@
1
1
  # load bundler
2
2
  require 'bundler/setup'
3
- Bundler.setup(:default)
4
-
5
3
  require 'gris/setup'
4
+
6
5
  Bundler.require(:default, Gris.env.to_sym)
7
6
 
8
- # load environment
9
7
  Gris.load_environment
10
-
11
- # autoload initalizers
12
- Dir['./config/initializers/**/*.rb'].map { |file| require file }
13
-
14
- # autoload app
15
- relative_load_paths = %w(app/endpoints app/presenters app/models)
16
- ActiveSupport::Dependencies.autoload_paths += relative_load_paths
@@ -1,4 +1,8 @@
1
1
  require 'erb'
2
- db = YAML.load(ERB.new(File.read('./config/database.yml')).result)[Gris.env]
3
- ActiveRecord::Base.establish_connection(db)
2
+ if ENV['DATABASE_URL']
3
+ ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
4
+ else
5
+ db = YAML.load(ERB.new(File.read('./config/database.yml')).result)[Gris.env]
6
+ ActiveRecord::Base.establish_connection(db)
7
+ end
4
8
  ActiveRecord::Base.include_root_in_json = false
@@ -17,6 +17,7 @@ module Gris
17
17
 
18
18
  def permitted_params(options = {})
19
19
  options = { include_missing: false }.merge(options)
20
+ process_datetime_params(params) if keys_to_convert
20
21
  declared(params, options)
21
22
  end
22
23
 
@@ -0,0 +1,34 @@
1
+ require 'chronic'
2
+
3
+ module Gris
4
+ module DateTimeHelpers
5
+ extend ActiveSupport::Concern
6
+
7
+ # define keys that need to be converted from strings
8
+ # to datetime via Chronic
9
+ def datetime_params(*keys_to_convert)
10
+ @datetime_keys_to_convert = Set.new(keys_to_convert)
11
+ end
12
+
13
+ def keys_to_convert
14
+ @datetime_keys_to_convert
15
+ end
16
+
17
+ def process_datetime_params(params)
18
+ params.keys.each do |key|
19
+ if keys_to_convert.include?(key)
20
+ params[key] = string_to_datetime(params[key])
21
+ end
22
+ end
23
+ end
24
+
25
+ def string_to_datetime(string)
26
+ return string if string.blank?
27
+ if string.to_s =~ /^\d+$/
28
+ Time.at(string.to_i).to_datetime.utc
29
+ else
30
+ Chronic.parse(string).try(:utc)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  module Gris
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
 
4
4
  class Version
5
5
  class << self
@@ -35,9 +35,9 @@ describe Gris::Generators::ScaffoldGenerator do
35
35
  expect(Dir).to exist(app_path)
36
36
  end
37
37
 
38
- it 'creates a .env file with with a development database name' do
39
- expect(File).to exist("#{app_path}/.env")
40
- env_file = File.read("#{app_path}/.env")
38
+ it 'creates a .env.example file with with a development database name' do
39
+ expect(File).to exist("#{app_path}/.env.example")
40
+ env_file = File.read("#{app_path}/.env.example")
41
41
  expect(env_file).to match(/#{app_name}_development/)
42
42
  end
43
43
 
@@ -47,10 +47,10 @@ describe Gris::Generators::ScaffoldGenerator do
47
47
  expect(env_file).to match(/web: bundle exec puma/)
48
48
  end
49
49
 
50
- it 'creates a .env.test file with a test database name' do
51
- expect(File).to exist("#{app_path}/.env.test")
52
- env_test_file = File.read("#{app_path}/.env.test")
53
- expect(env_test_file).to match(/#{app_name}_test/)
50
+ it 'creates a .env.example file with a development database name' do
51
+ expect(File).to exist("#{app_path}/.env.example")
52
+ env_test_file = File.read("#{app_path}/.env.example")
53
+ expect(env_test_file).to match(/#{app_name}_development/)
54
54
  end
55
55
 
56
56
  it 'selects postgresql as the default database adapter' do
@@ -2,4 +2,22 @@ require 'spec_helper'
2
2
  require 'gris/grape_extensions/crud_helpers'
3
3
 
4
4
  describe Gris::CrudHelpers do
5
+ before do
6
+ @helper = SpecCrudHelper.new
7
+ end
8
+
9
+ it 'returns permitted_params' do
10
+ @helper.params = { id: 1 }
11
+ expect(@helper.permitted_params).to eq(id: 1)
12
+ end
13
+
14
+ it 'uses date time helpers' do
15
+ @helper.datetime_params :created_at
16
+ @helper.params = { message: 'hi', created_at: 1_293_901_200 }
17
+ expected = {
18
+ created_at: 'Sat, 01 Jan 2011 17:00:00 +0000',
19
+ message: 'hi'
20
+ }
21
+ expect(@helper.permitted_params).to eq(expected)
22
+ end
5
23
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'gris/grape_extensions/date_time_helpers'
3
+
4
+ describe Gris::DateTimeHelpers do
5
+ before do
6
+ @helper = Class.new do
7
+ include Gris::DateTimeHelpers
8
+ end.new
9
+ end
10
+
11
+ it 'parses a date string' do
12
+ MY_TIME = '2011-01-02 17:00:23 UTC'
13
+ actual = @helper.string_to_datetime(MY_TIME)
14
+ expect(actual.to_s).to eq(MY_TIME)
15
+ end
16
+
17
+ it 'converts seconds since epoch' do
18
+ SECONDS = '1429823204'
19
+ actual = @helper.string_to_datetime(SECONDS)
20
+ expect(actual).to eq(Time.at(SECONDS.to_i))
21
+ end
22
+
23
+ it "returns '' for a blank string" do
24
+ expect(@helper.string_to_datetime('')).to eq('')
25
+ end
26
+
27
+ it 'returns nil for a nil string' do
28
+ expect(@helper.string_to_datetime(nil)).to be_nil
29
+ end
30
+
31
+ it 'sets the keys to be converted' do
32
+ @helper.datetime_params :created_at, :updated_at
33
+ expect(@helper.keys_to_convert).to eq(Set.new([:created_at, :updated_at]))
34
+ end
35
+
36
+ it 'converts the correct keys' do
37
+ @helper.datetime_params :created_at, :updated_at
38
+ params = { message: 'hi', created_at: 1_293_901_200, updated_at: 1_325_397_600 }
39
+ @helper.process_datetime_params(params)
40
+ expect(params[:message]).to eq('hi')
41
+ expect(params[:created_at].strftime).to eq('2011-01-01T17:00:00+00:00')
42
+ expect(params[:updated_at].strftime).to eq('2012-01-01T06:00:00+00:00')
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ class SpecCrudHelper
2
+ include Gris::CrudHelpers
3
+ include Gris::DateTimeHelpers
4
+ attr_accessor :params
5
+
6
+ def declared(params, _options)
7
+ params
8
+ end
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Fareed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-17 00:00:00.000000000 Z
11
+ date: 2015-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -220,6 +220,20 @@ dependencies:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
222
  version: 0.1.0
223
+ - !ruby/object:Gem::Dependency
224
+ name: chronic
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: 0.10.0
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 0.10.0
223
237
  - !ruby/object:Gem::Dependency
224
238
  name: bundler
225
239
  requirement: !ruby/object:Gem::Requirement
@@ -330,8 +344,7 @@ files:
330
344
  - lib/gris/generators/templates/api/spec/models/%name_underscore%_spec.rb.tt
331
345
  - lib/gris/generators/templates/create_table_migration/%migration_filename%.rb.tt
332
346
  - lib/gris/generators/templates/migration/%migration_filename%.rb.tt
333
- - lib/gris/generators/templates/scaffold/.env.test.tt
334
- - lib/gris/generators/templates/scaffold/.env.tt
347
+ - lib/gris/generators/templates/scaffold/.env.example.tt
335
348
  - lib/gris/generators/templates/scaffold/.gitignore.tt
336
349
  - lib/gris/generators/templates/scaffold/.rspec.tt
337
350
  - lib/gris/generators/templates/scaffold/.rubocop.yml
@@ -354,6 +367,7 @@ files:
354
367
  - lib/gris/generators/templates/scaffold/spec/support/app_helper.rb.tt
355
368
  - lib/gris/grape_extensions/authentication_helpers.rb
356
369
  - lib/gris/grape_extensions/crud_helpers.rb
370
+ - lib/gris/grape_extensions/date_time_helpers.rb
357
371
  - lib/gris/grape_extensions/error_helpers.rb
358
372
  - lib/gris/identity.rb
359
373
  - lib/gris/middleware/health.rb
@@ -371,11 +385,13 @@ files:
371
385
  - spec/generators/scaffold_generator_spec.rb
372
386
  - spec/grape_extensions/authentication_helpers_spec.rb
373
387
  - spec/grape_extensions/crud_helpers_spec.rb
388
+ - spec/grape_extensions/date_time_helpers_spec.rb
374
389
  - spec/grape_extensions/error_helpers_spec.rb
375
390
  - spec/identity_spec.rb
376
391
  - spec/spec_helper.rb
377
392
  - spec/support/spec_api_auth_helper.rb
378
393
  - spec/support/spec_api_error_helper.rb
394
+ - spec/support/spec_crud_helper.rb
379
395
  - spec/support/spec_generators_helper.rb
380
396
  - spec/version_spec.rb
381
397
  homepage: http://github.com/dylanfareed/gris/
@@ -408,10 +424,12 @@ test_files:
408
424
  - spec/generators/scaffold_generator_spec.rb
409
425
  - spec/grape_extensions/authentication_helpers_spec.rb
410
426
  - spec/grape_extensions/crud_helpers_spec.rb
427
+ - spec/grape_extensions/date_time_helpers_spec.rb
411
428
  - spec/grape_extensions/error_helpers_spec.rb
412
429
  - spec/identity_spec.rb
413
430
  - spec/spec_helper.rb
414
431
  - spec/support/spec_api_auth_helper.rb
415
432
  - spec/support/spec_api_error_helper.rb
433
+ - spec/support/spec_crud_helper.rb
416
434
  - spec/support/spec_generators_helper.rb
417
435
  - spec/version_spec.rb
@@ -1,12 +0,0 @@
1
- # Uncomment when using Gris::Middleware::Authentication
2
- # HEADER_PASSWORD=''
3
-
4
- SERVICE_NAME=<%= app_name %>
5
- RACK_ENV=test
6
-
7
- DATABASE_USER=''
8
- DATABASE_PASSWORD=''
9
- DATABASE_HOST=localhost
10
- DATABASE_NAME=<%= app_name.underscore %>_test
11
- BASE_URL=http://127.0.0.1:9393
12
- PERMITTED_TOKENS=replace-me