diff options
| author | Teddy Wing | 2018-01-25 15:09:02 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-01-25 15:09:02 +0100 | 
| commit | 6a2eb87578fecbeb51eff7611405e641f2200871 (patch) | |
| tree | 360c81efa0f01efd96a39a477b3012d0f10b0871 | |
| parent | 65f2c76e78e1f96f66b48655b08fdf4fb5795f1e (diff) | |
| download | chouette-core-6a2eb87578fecbeb51eff7611405e641f2200871.tar.bz2 | |
ComplianceControlDecorator: Convert to new action links interface
* Decorate the `ComplianceControl` so we can show the action links from
  the decorator in the header.
* Add a `decorates` to get `object_class` to work inside the decorator.
* Define `AF83::Decorator.define_instance_class_method` in order to
  enable the `@compliance_control.class.METHOD` calls in the view to
  work. Thanks very much to Johan for figuring out a way to do that.
Refs #5586
| -rw-r--r-- | app/controllers/compliance_controls_controller.rb | 6 | ||||
| -rw-r--r-- | app/decorators/compliance_control_decorator.rb | 14 | ||||
| -rw-r--r-- | lib/af83/decorator.rb | 6 | 
3 files changed, 26 insertions, 0 deletions
| diff --git a/app/controllers/compliance_controls_controller.rb b/app/controllers/compliance_controls_controller.rb index dfbecaa71..73dc18f59 100644 --- a/app/controllers/compliance_controls_controller.rb +++ b/app/controllers/compliance_controls_controller.rb @@ -8,6 +8,12 @@ class ComplianceControlsController < ChouetteController      @sti_subclasses = ComplianceControl.subclasses    end +  def show +    show! do +      @compliance_control = @compliance_control.decorate +    end +  end +    def new      if params[:sti_class].blank?        flash[:notice] = I18n.t("compliance_controls.errors.mandatory_control_type") diff --git a/app/decorators/compliance_control_decorator.rb b/app/decorators/compliance_control_decorator.rb index a0445faa2..c57a7ccc7 100644 --- a/app/decorators/compliance_control_decorator.rb +++ b/app/decorators/compliance_control_decorator.rb @@ -1,4 +1,6 @@  class ComplianceControlDecorator < AF83::Decorator +  decorates ComplianceControl +    with_instance_decorator do |instance_decorator|      instance_decorator.show_action_link do |l|        l.content h.t('compliance_control_sets.actions.show') @@ -30,4 +32,16 @@ class ComplianceControlDecorator < AF83::Decorator        l.data confirm: h.t('compliance_controls.actions.destroy_confirm')      end    end + +  define_instance_class_method :predicate do +    object_class.predicate +  end + +  define_instance_class_method :prerequisite do +    object_class.prerequisite +  end + +  define_instance_class_method :dynamic_attributes do +    object_class.dynamic_attributes +  end  end diff --git a/lib/af83/decorator.rb b/lib/af83/decorator.rb index 1b9574053..f990555fe 100644 --- a/lib/af83/decorator.rb +++ b/lib/af83/decorator.rb @@ -32,6 +32,12 @@ class AF83::Decorator < ModelDecorator      instance_decorator.send(:define_method, method_name, &block)    end +  # Defines a class method on the decorated object's class. These +  # can be called like `object.class.my_method`. +  def self.define_instance_class_method method_name, &block +    instance_decorator.send(:define_singleton_method, method_name, &block) +  end +    class ActionLinks      attr_reader :options | 
