contentful_rails 0.3.0 → 0.4.0

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: 5f17d46dad767afc329cec1d2b6dac3edf06cdd1
4
- data.tar.gz: 4f234bc62f1f847a330be9e7c805a3cf84fa01d8
3
+ metadata.gz: 287f62b00e44548213d22bc2bd365a1f961324a6
4
+ data.tar.gz: 280b863df836812bb18113e5ecab529f060c7007
5
5
  SHA512:
6
- metadata.gz: 7e9b5df096a58ed1fb80c03609509f7939601cd2f41d00adf53c69037989f364b5234e79dba31faca26fecda011913f43acb88ddbdf95831604a04485f049d91
7
- data.tar.gz: dd9bfcbc384b5e767799f0c63425fc0bba7a0d1b05b0c28c3b4bf24c0c5daf6548a13cb76e2d4a01448699b6c8755577b0d32a9c882a931bb8f84b7ecf184d86
6
+ metadata.gz: 6d19254615f19e2d81439f30d165c4d78a444d8dfaa9c93e66652b9b6b4c9818656db82f43712a8440966d30ad602e0ca531e05a2939dc101f4124674ded03cb
7
+ data.tar.gz: 40857c4ba6cb0565dab16183d8c57d27556a3d0ae6233cd5b2e50da6618466c46e99395767a4b3a6912ed86c13c2f3020a94f2fde7bb696884e1a149ea229cdf
@@ -1,10 +1,16 @@
1
1
  class ContentfulRails::WebhooksController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+
2
4
  if ContentfulRails.configuration.authenticate_webhooks
3
5
  http_basic_authenticate_with name: ContentfulRails.configuration.webhooks_username,
4
6
  password: ContentfulRails.configuration.webhooks_password
5
7
  end
6
-
7
- skip_before_filter :verify_authenticity_token, :only => [:create]
8
+ params = [:verify_authenticity_token, {:only => [:create], raise: false}]
9
+ if Rails::VERSION::MAJOR > 4
10
+ skip_before_action *params
11
+ else
12
+ skip_before_filter *params
13
+ end
8
14
 
9
15
  #this is where we receive a webhook, via a POST
10
16
  def create
@@ -39,4 +45,4 @@ class ContentfulRails::WebhooksController < ActionController::Base
39
45
 
40
46
 
41
47
 
42
- end
48
+ end
@@ -4,12 +4,8 @@ module ContentfulRails
4
4
  # to check the cache for its timestamp before making an expensive API call.
5
5
  # Also includes a module method to remove an existing timestamp.
6
6
  module Timestamps
7
- def self.included(base)
7
+ def self.prepended(base)
8
8
  base.extend ClassMethods
9
- base.class_eval do
10
- alias_method_chain :updated_at, :caching
11
- alias_method_chain :cache_key, :preview
12
- end
13
9
  end
14
10
 
15
11
  module ClassMethods
@@ -26,31 +22,28 @@ module ContentfulRails
26
22
  end
27
23
  end
28
24
 
25
+ def timestamp_cache_key
26
+ self.class.timestamp_cache_key(id)
27
+ end
28
+
29
29
 
30
- # A replacement method for updated_at(), called when this module is included in ContentfulModel::Base
31
- def updated_at_with_caching
30
+ def updated_at
32
31
  if ContentfulRails.configuration.perform_caching && !ContentfulModel.use_preview_api
33
32
  Rails.cache.fetch(self.timestamp_cache_key) do
34
- updated_at_without_caching
33
+ super
35
34
  end
36
35
  else
37
- updated_at_without_caching
36
+ super
38
37
  end
39
38
  end
40
39
 
41
- def timestamp_cache_key
42
- self.class.timestamp_cache_key(id)
43
- end
44
-
45
- def cache_key_with_preview
40
+ def cache_key
46
41
  if ContentfulModel.use_preview_api
47
- "preview/#{cache_key_without_preview}"
42
+ "preview/#{super}"
48
43
  else
49
- cache_key_without_preview
44
+ super
50
45
  end
51
46
  end
52
-
53
-
54
47
  end
55
48
  end
56
49
  end
@@ -23,8 +23,10 @@ module ContentfulRails
23
23
  #Iterate through all models which inherit from ContentfulModel::Base
24
24
  #and add an entry mapping for them, so calls to the Contentful API return
25
25
  #the appropriate classes
26
+ #If eager_load_entry_mapping is false, engine assumes entry mapping is set manually by
27
+ #ContentfulRails.contentful_options[:entry_mapping] (passed through to Contentful.entry_mapping config)
26
28
  initializer "add_entry_mappings", after: :configure_contentful do
27
- if defined?(ContentfulModel)
29
+ if defined?(ContentfulModel) && ContentfulRails.configuration.eager_load_entry_mapping
28
30
  Rails.application.eager_load!
29
31
  ContentfulModel::Base.descendents.each do |klass|
30
32
  klass.send(:add_entry_mapping)
@@ -48,8 +50,19 @@ module ContentfulRails
48
50
  end
49
51
  end
50
52
 
53
+ initializer "prepend_timestamps_module", after: :subscribe_to_webhook_events do
54
+ if defined?(::ContentfulModel)
55
+ ContentfulModel::Base.send(:prepend, ContentfulRails::Caching::Timestamps)
56
+ end
57
+ end
58
+
51
59
  initializer "add_contentful_mime_type" do
52
- Mime::Type.register "application/json", :json, ["application/vnd.contentful.management.v1+json"]
60
+ content_type = "application/vnd.contentful.management.v1+json"
61
+ Mime::Type.register content_type, :contentful_json, [content_type]
62
+ default_parsers = Rails::VERSION::MAJOR > 4 ? ActionDispatch::Http::Parameters::DEFAULT_PARSERS : ActionDispatch::ParamsParser::DEFAULT_PARSERS
63
+ default_parsers[Mime::Type.lookup(content_type)] = lambda do |body|
64
+ JSON.parse(body)
65
+ end
53
66
  end
54
67
 
55
68
  initializer "add_preview_support" do
@@ -57,12 +70,5 @@ module ContentfulRails
57
70
  include ContentfulRails::Preview
58
71
  end
59
72
  end
60
-
61
- config.to_prepare do
62
- if defined?(::ContentfulModel)
63
- ContentfulModel::Base.send(:include, ContentfulRails::Caching::Timestamps)
64
- end
65
- end
66
-
67
73
  end
68
74
  end
@@ -1,3 +1,3 @@
1
1
  module ContentfulRails
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -34,12 +34,14 @@ module ContentfulRails
34
34
  :preview_username,
35
35
  :preview_password,
36
36
  :preview_domain,
37
- :enable_preview_domain
37
+ :enable_preview_domain,
38
+ :eager_load_entry_mapping
38
39
 
39
40
  def initialize
40
41
  @authenticate = true
41
42
  @slug_delimiter = "-"
42
43
  @perform_caching = Rails.configuration.action_controller.perform_caching
44
+ @eager_load_entry_mapping = true
43
45
  @contentful_options = {}
44
46
  end
45
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Error Creative Studio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-26 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contentful_model