shamu 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 607eb630404b0977965af426db12d63821be992c
4
- data.tar.gz: 70638f256144a1b3b20984b5bb3950aee54cc76e
3
+ metadata.gz: 17d15280c07fb25429f25d595d1f30f7a5509f52
4
+ data.tar.gz: cf2f8593461815af79b589332bdc56569bef2de5
5
5
  SHA512:
6
- metadata.gz: 365c41405a527220f21112099997ddf023c1c7bfc8b93ddc1cdf7e6275302c103adf2bf79266a2a22661e576d095ed6899f49cda35a2293907ad28b7b18ed40c
7
- data.tar.gz: 6d657880be0470a380ba0c1a31718bf4877866c940a07e5c6780cd7c550c31db8a7992730bd3340e24cff610c9c1ac24e4723580f1a005c1674aa06f547b128f
6
+ metadata.gz: 4f954b06458d9728ccdd30636e478ab90e16cd24280a874fbf402c98bad9b59e67c1691895f80ee57643417f783bee7de16613bcdf0875b6cd036f94048798c9
7
+ data.tar.gz: 13f497d44a24128bbe7e479547efcb3da461b72cf3d06fb0ec3c2dd8190b73ff0c79937debbae8bbef6c58c47ea45b2ca516ec0275876563d9728eb3620d9275
@@ -0,0 +1,15 @@
1
+ require "generators/rspec"
2
+
3
+ module Shamu
4
+ module Generators
5
+ # @!visibility private
6
+ class ApiControllerGenerator < ::Rails::Generators::Base
7
+ desc "Generate the default api conroller for JSON API responses"
8
+ source_root File.expand_path("../templates", __FILE__)
9
+
10
+ def copy_api_controller_file
11
+ copy_file "api_controller.rb", "app/controllers/api_controller.rb"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ require "api_responder"
2
+
3
+ class ApiController < ApplicationController
4
+ include Shamu::Rails::JsonApi
5
+
6
+ self.responder = ::ApiResponder
7
+
8
+ respond_to :json, :json_api
9
+ end
@@ -0,0 +1,4 @@
1
+ class ApiResponder < ActionController::Responder
2
+ include Responders::HttpCacheResponder
3
+ include Shamu::Rails::JsonApiResponder
4
+ end
@@ -0,0 +1,15 @@
1
+ require "generators/rspec"
2
+
3
+ module Shamu
4
+ module Generators
5
+ # @!visibility private
6
+ class ApplicationPresenterGenerator < ::Rails::Generators::Base
7
+ desc "Generate the default application presenter"
8
+ source_root File.expand_path("../templates", __FILE__)
9
+
10
+ def copy_application_presenter_file
11
+ copy_file "application_presenter.rb", "app/presenters/application_presenter.rb"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ # Base {Shamu::JsonApi::Presenter} that all other presenters should
2
+ # inherit from.
3
+ class ApplicationPresenter < shamu::JsonApi::Presenter
4
+ include ::Rails.application.routes.url_helpers
5
+
6
+ # Override default_url_options in config/environments files.
7
+ self.default_url_options = Rails.application.config.shamu.json_api.default_url_options
8
+ end
@@ -0,0 +1,4 @@
1
+ module Shamu
2
+ module Generators
3
+ end
4
+ end
@@ -88,7 +88,7 @@ module Shamu
88
88
  # @raise [NoPresenter] if a presenter cannot be found.
89
89
  def find_presenter( resource )
90
90
  presenter = presenters[ resource.class ]
91
- presenter ||= find_namespace_presenter( resource )
91
+ presenter ||= presenters[ resource.class ] = find_namespace_presenter( resource )
92
92
 
93
93
  fail NoPresenter.new( resource, namespaces ) unless presenter
94
94
 
@@ -136,8 +136,7 @@ module Shamu
136
136
 
137
137
  namespaces.each do |namespace|
138
138
  begin
139
- scope = namespace.constantize
140
- return scope.const_get( name, false ) if scope.const_defined?( name, false )
139
+ return "#{ namespace }::#{ name }".constantize
141
140
  rescue NameError # rubocop:disable Lint/HandleExceptions
142
141
  end
143
142
  end
@@ -34,7 +34,7 @@ module Shamu
34
34
  response = build_json_response( context )
35
35
  response.resource resource, presenter
36
36
  yield response if block_given?
37
- response
37
+ response.to_json
38
38
  end
39
39
 
40
40
  # Builds a well-formed JSON API response for a collection of resources.
@@ -53,7 +53,7 @@ module Shamu
53
53
  response.collection resources, presenter
54
54
  json_paginate_resources response, resources, pagination
55
55
  yield response if block_given?
56
- response
56
+ response.to_json
57
57
  end
58
58
 
59
59
  # Add page-based pagination links for the resources to the builder.
@@ -89,7 +89,7 @@ module Shamu
89
89
  yield builder if block_given?
90
90
  end
91
91
 
92
- response
92
+ response.to_json
93
93
  end
94
94
 
95
95
  # Write all the validation errors from a record to the response.
@@ -102,7 +102,7 @@ module Shamu
102
102
  response = build_json_response( context )
103
103
  response.validation_errors errors, &block
104
104
 
105
- response
105
+ response.to_json
106
106
  end
107
107
 
108
108
  JSON_CONTEXT_KEYWORDS = [ :fields, :namespaces, :presenters ].freeze
@@ -13,6 +13,10 @@ module Shamu
13
13
  end
14
14
 
15
15
  initializer "shamu.configure" do
16
+ config.shamu = ActiveSupport::OrderedOptions.new
17
+ config.shamu.json_api = ActiveSupport::OrderedOptions.new
18
+ config.shamu.json_api.default_url_options = {}
19
+
16
20
  if defined? ::ActionController
17
21
  ::ActionController::Base.send :include, Shamu::Rails::Controller
18
22
  ::ActionController::Base.send :include, Shamu::Rails::Entity
data/lib/shamu/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Shamu
3
3
  # The primary version number
4
- VERSION_NUMBER = "0.0.5".freeze
4
+ VERSION_NUMBER = "0.0.7".freeze
5
5
 
6
6
  # Version suffix such as 'beta' or 'alpha'
7
7
  VERSION_SUFFIX = "".freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shamu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Alexander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-19 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -200,6 +200,12 @@ files:
200
200
  - Rakefile
201
201
  - circle.yml
202
202
  - config.ru
203
+ - lib/generators/shamu.rb
204
+ - lib/generators/shamu/api_controller/api_controller_generator.rb
205
+ - lib/generators/shamu/api_controller/templates/api_controller.rb
206
+ - lib/generators/shamu/api_controller/templates/api_responder.rb
207
+ - lib/generators/shamu/application_presenter/application_presenter_generator.rb
208
+ - lib/generators/shamu/application_presenter/templates/application_presenter.rb
203
209
  - lib/shamu.rb
204
210
  - lib/shamu/active_record.rb
205
211
  - lib/shamu/attributes.rb