activeadmin_decorator 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: 9066952cd77bd579269b0bf534618271ad135a974fdf9d837ea35e416c8508d6
4
- data.tar.gz: 93750f0e9c841dbf9408c5463d9453895c8f796e059290faf761fdad14123001
3
+ metadata.gz: 1aa3d5c6a44294b75d34898242260a457d281767f805e171b34f96fa0c22a441
4
+ data.tar.gz: ed311ac3f20aebac9af7e5a10e4e0ac576c2da717edaa0df8e061bedd56ab0b4
5
5
  SHA512:
6
- metadata.gz: 351b713fde7f9a5c868861cb75e1ed6d91646d5657f07955a1c6ab0b0ea6af8e45b13121cfeba35bfbe5d809cc07861dd6b688d4a78752c0fff6b036a983ad21
7
- data.tar.gz: f812a8602b9365810bc9d8da56c40d09b677e4622ee8bc102f11b4bbdbf4c660596e2309b90630cdcfd05f0c2f1e5f6407459dc54cf75dfbd65efa9d02b7f84f
6
+ metadata.gz: d39774cfbfafec1065209ce73b89ba98caeb2221385f70f4ecf1628a6466a225834b03bc5fc83a4ee38d45098b15710953cab11b0342de38204b6c5d4d6053d9
7
+ data.tar.gz: 9a06ba36f44a9476eed1e7a4241d3d5eba2fd4ec4ff06632a3f5ca6949ad7b43117d795171b5afaa86693a609038ad085dc7e78bc0b17641b7418f0a408f984b
data/README.md CHANGED
@@ -39,6 +39,9 @@ end
39
39
  Each decorated association will be available as a method on the decorator,
40
40
  you can still access the original association with `model.association_name`.
41
41
 
42
+ The association decorator class name will be auto-detected from the relation result and current decorator name if not given.
43
+ Example for `:comments` association on `Decorators::UserDecorator` it will be `Decorators::CommentDecorator`.
44
+
42
45
  ### ArbreDecorator
43
46
 
44
47
  With `ActiveAdmin::ArbreDecorator` you can keep your show/index blocks in AA clean and use Arbre DSL in decorator:
@@ -52,6 +55,7 @@ class UserDecorator < ActiveAdmin::ArbreDecorator
52
55
  end
53
56
  end
54
57
  ```
58
+ This is done by using including `Arbre::Element::BuilderMethods` and new `arbre_context`.
55
59
 
56
60
  Also included: `ActionView::Helpers` and `Rails.application.routes.url_helpers`,
57
61
  so you can:
@@ -16,7 +16,7 @@ module ActiveAdmin
16
16
  end
17
17
 
18
18
  # use in decorator to decorate association
19
- def decorates_association(association, relation: association, with: "Decorators::#{association.to_s.singularize.classify}")
19
+ def decorates_association(association, relation: association, with: nil)
20
20
  define_method(association) do
21
21
  associated =
22
22
  case relation
@@ -24,10 +24,13 @@ module ActiveAdmin
24
24
  when Proc then relation.call(model)
25
25
  else raise ArgumentError, "relation must be a Symbol or Proc"
26
26
  end
27
- with = with.constantize if with.is_a?(String)
28
27
  if associated.is_a?(ActiveRecord::Relation)
28
+ with ||= decorator_class_name_for(associated.klass)
29
+ with = with.constantize if with.is_a?(String)
29
30
  associated = associated.map { |item| with.new(item) }
30
31
  else
32
+ with ||= decorator_class_name_for(associated.class)
33
+ with = with.constantize if with.is_a?(String)
31
34
  associated = with.new(associated)
32
35
  end
33
36
  associated
@@ -38,5 +41,14 @@ module ActiveAdmin
38
41
  def model = __getobj__
39
42
 
40
43
  def nil? = model.nil?
44
+
45
+ private
46
+
47
+ # autodetect decorator class name for association
48
+ def decorator_class_name_for(klass)
49
+ @prefix ||= self.class.name.split('::')[0...-1].freeze
50
+ @suffix ||= self.class.name.split('::')[-1].sub(/^#{model.class.name}/, '').freeze
51
+ [*@prefix, klass].join('::').concat(@suffix)
52
+ end
41
53
  end
42
54
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveadminDecorator
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_decorator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Papis