hangar 0.1.2 → 0.1.3

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: f05b5b510dbd66209f7ef7c0fe24a4a8cad6db88
4
- data.tar.gz: 060c44c51fb20fb1310a2108487990d589955e4b
3
+ metadata.gz: 00e3ca4a7ff8a99f24e0861983e9924dd2f11e0c
4
+ data.tar.gz: b9450473a33e006118801bb872e779a1aa16d024
5
5
  SHA512:
6
- metadata.gz: 84efc620eacb82804b64dca8422b5aea9251b22c82563f009d490f5a56f81713522caa1e454cd8ada4a25d46172f56867879678444acf561b247cd980fcc5312
7
- data.tar.gz: 15036949fca801d961a23199093d31d54ab39c8202f5861cd52bea05adc5e36d199dce85436c93ad6bbd77a2cfe674aab16fc0b0ac98b6b814700680035c9e52
6
+ metadata.gz: d6caac367be939b5859524e196a94cdd85e01cf03b31ede9f0394deb6e0601af62b35c7ddaa0a93e7884c1980a30db3c41913ee0ef3c8d06e374fa1ce2bc7686
7
+ data.tar.gz: 56b555eff7d4e9fc13c03667381e0360faaa0d01080ea01a4aec5b949adf93ebf7b5412bc69f58423c3f936eb3207964e2417e8e1cc69a9060834463d75a0ff8
@@ -1,20 +1,23 @@
1
1
  module Hangar
2
2
  class ResourcesController < ActionController::Base
3
3
 
4
+ rescue_from StandardError, :with => :error_render_method
5
+
4
6
  def create
5
- created = FactoryGirl.create resource, *traits, resource_attributes
7
+ created = FactoryBot.create resource, *traits, resource_attributes
6
8
  render json: created.as_json(include: includes.as_json)
7
9
  end
8
10
 
9
11
  def new
10
- attributes = FactoryGirl.attributes_for resource, *traits, resource_attributes
12
+ attributes = FactoryBot.attributes_for resource, *traits, resource_attributes
11
13
  render json: attributes
12
14
  end
13
15
 
14
16
  private
15
17
 
16
18
  def resource
17
- request.path.split('/')[1].singularize.to_sym
19
+ index = Hangar.route_namespace[:path].present? ? 2 : 1
20
+ request.path.split('/')[index].singularize.to_sym
18
21
  end
19
22
 
20
23
  def resource_attributes
@@ -28,5 +31,14 @@ module Hangar
28
31
  def includes
29
32
  @includes ||= params[:include].blank? ? [] : params.require(:include)
30
33
  end
34
+
35
+ def error_render_method(exception)
36
+ status_code = ActionDispatch::ExceptionWrapper.new(env, exception).status_code
37
+ respond_to do |type|
38
+ type.json { render :json => {error: exception.message}.to_json, :status => status_code}
39
+ type.all { throw exception }
40
+ end
41
+ true
42
+ end
31
43
  end
32
44
  end
data/config/routes.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  Rails.application.routes.draw do
2
2
  constraints Hangar::RouteConstraint.new do
3
- FactoryGirl.factories.map(&:name).map(&:to_s).map(&:pluralize).map(&:to_sym).each do |factory|
4
- resources factory, only: [:new, :create], controller: 'hangar/resources'
3
+ scope Hangar.route_namespace do
4
+ FactoryBot.factories.map { |factory| factory.name.to_s.pluralize.to_sym }.each do |factory|
5
+ resources factory, only: [:new, :create], controller: 'resources'
6
+ end
7
+ delete '/', to: 'records#delete'
5
8
  end
6
- delete '/', to: 'hangar/records#delete'
7
9
  end
8
10
  end
@@ -1,3 +1,3 @@
1
1
  module Hangar
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/hangar.rb CHANGED
@@ -5,14 +5,28 @@ require 'database_cleaner'
5
5
  module Hangar
6
6
  BadEnvironmentError = Class.new(StandardError)
7
7
 
8
- mattr_writer :do_not_delete
8
+ mattr_writer :do_not_delete, :route_namespace
9
9
  mattr_accessor :clean_strategy
10
+
10
11
  self.clean_strategy = :deletion
12
+ self.route_namespace = nil
11
13
 
12
14
  def self.do_not_delete
13
15
  Array.wrap(@@do_not_delete)
14
16
  end
15
17
 
18
+ def self.route_namespace
19
+ if(@@route_namespace.present?)
20
+ {
21
+ module: 'hangar',
22
+ path: @@route_namespace.to_s.pluralize,
23
+ as: @@route_namespace.to_s.singularize
24
+ }
25
+ else
26
+ { module: 'hangar' }
27
+ end
28
+ end
29
+
16
30
  def validate_environment
17
31
  Rails.env.test? or raise BadEnvironmentError, "Hangar should not be used in the #{Rails.env} environment"
18
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hangar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Rossmeissl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-02 00:00:00.000000000 Z
11
+ date: 2018-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails