active_decorator_with_decorate_associations 0.0.2 → 0.0.3

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: 00d55c76c85db0fbb13db08dc6896be8f695f667
4
- data.tar.gz: 5bbdff17711628b08f133c2e9f697c30336596e0
3
+ metadata.gz: 1ce61e6f92676a60254a628b4b650408d787919c
4
+ data.tar.gz: 291311be7e2253161cb68d0d9eb10d1bc9eb529b
5
5
  SHA512:
6
- metadata.gz: 83b9bf7e7e7d3519eba7b0aae4dba6173dfa8f765104dd57faf4cdaf29bb1a1cabc02ae54ae488a3ca4ae225e205da20778c8890290bc19a0d1e255928d456b8
7
- data.tar.gz: 3e1512c9951172ff4f47084b51ca148ba0feb832e974d28516d61ff47829eff64c0d1977a2329b4caf84a8287146977b331f6617eeb9057bdd6eba6d6171a7f0
6
+ metadata.gz: 8f7299b4c67f0f0df6ed6e74e814f3a9758fcf2020d20745300d9dd7a6331d21caa367af084f7fe06a68f7bfafbe04474c13afb5987969d70fb3b3431d862c81
7
+ data.tar.gz: fae9cbc2a55fc689e53238823b3f974e7e80427ea6cf8a713e458e76d594b83cd1297297e59d25c35769769c235be85cc8bf97b04046b600d68850219cfcf1c8
@@ -0,0 +1,12 @@
1
+ # TODO remove this class when merged either of these pull requests
2
+ # https://github.com/amatsuda/active_decorator/pull/15
3
+ # https://github.com/amatsuda/active_decorator/pull/59
4
+
5
+ module ActiveDecoratorExtension
6
+ def decorate(obj)
7
+ return if defined?(Jbuilder) && Jbuilder === obj
8
+ return if obj.nil?
9
+ super
10
+ obj
11
+ end
12
+ end
@@ -2,6 +2,6 @@ require "active_decorator_with_decorate_associations/decorator"
2
2
 
3
3
  module AssociationDecorator
4
4
  def target
5
- ActiveDecoratorWithDecorateAssociations::Decorator.instance.decorate(super)
5
+ ActiveDecoratorWithDecorateAssociations::Decorator.instance.decorate(owner, super)
6
6
  end
7
7
  end
@@ -5,13 +5,13 @@ module CollectionAssociationDecorator
5
5
  if Gem::Version.new(Rails.version) < Gem::Version.new("4.1")
6
6
 
7
7
  def first_or_last(*args)
8
- ActiveDecoratorWithDecorateAssociations::Decorator.instance.decorate(super)
8
+ ActiveDecoratorWithDecorateAssociations::Decorator.instance.decorate(owner, super)
9
9
  end
10
10
 
11
11
  else
12
12
 
13
13
  def first_nth_or_last(*args)
14
- ActiveDecoratorWithDecorateAssociations::Decorator.instance.decorate(super)
14
+ ActiveDecoratorWithDecorateAssociations::Decorator.instance.decorate(owner, super)
15
15
  end
16
16
 
17
17
  end
@@ -4,9 +4,12 @@ module ActiveDecoratorWithDecorateAssociations
4
4
  class Decorator
5
5
  include Singleton
6
6
 
7
- def decorate(target)
8
- ActiveDecorator::Decorator.instance.decorate(target)
9
- target
7
+ def decorate(owner, target)
8
+ if owner.is_a?(ActiveDecorator::Helpers)
9
+ ActiveDecorator::Decorator.instance.decorate(target)
10
+ else
11
+ target
12
+ end
10
13
  end
11
14
  end
12
15
  end
@@ -1,10 +1,14 @@
1
1
  require "rails"
2
+ require "active_decorator"
2
3
  require "active_decorator_with_decorate_associations/collection_association_decorator"
3
4
  require "active_decorator_with_decorate_associations/association_decorator"
5
+ require "active_decorator_with_decorate_associations/active_decorator_extension"
4
6
 
5
7
  module ActiveDecoratorWithDecorateAssociations
6
8
  class Railtie < ::Rails::Railtie
7
9
  initializer 'active_decorator_with_decorate_associations' do
10
+ ActiveDecorator::Decorator.send :prepend, ActiveDecoratorExtension
11
+
8
12
  ActiveRecord::Associations::CollectionAssociation.send :prepend, CollectionAssociationDecorator
9
13
  ActiveRecord::Associations::BelongsToAssociation.send :prepend, AssociationDecorator
10
14
  ActiveRecord::Associations::HasOneAssociation.send :prepend, AssociationDecorator
@@ -1,3 +1,3 @@
1
1
  module ActiveDecoratorWithDecorateAssociations
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_decorator_with_decorate_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuya Itakura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_decorator
@@ -96,6 +96,7 @@ files:
96
96
  - bin/console
97
97
  - bin/setup
98
98
  - lib/active_decorator_with_decorate_associations.rb
99
+ - lib/active_decorator_with_decorate_associations/active_decorator_extension.rb
99
100
  - lib/active_decorator_with_decorate_associations/association_decorator.rb
100
101
  - lib/active_decorator_with_decorate_associations/collection_association_decorator.rb
101
102
  - lib/active_decorator_with_decorate_associations/decorator.rb