Class: Blacklight::ActionBuilder
- Inherits:
-
Object
- Object
- Blacklight::ActionBuilder
- Defined in:
- app/builders/blacklight/action_builder.rb
Overview
Dynamically creates methods on the given controller (typically CatalogController) for handling configured show tools
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#build ⇒ Object
Define a simple action handler for the tool as long as the method doesn't already exist or the
:define_methodoption is notfalse. -
#initialize(klass, name, opts) ⇒ ActionBuilder
constructor
A new instance of ActionBuilder.
Constructor Details
#initialize(klass, name, opts) ⇒ ActionBuilder
Returns a new instance of ActionBuilder.
13 14 15 16 17 |
# File 'app/builders/blacklight/action_builder.rb', line 13 def initialize(klass, name, opts) @klass = klass @name = name @opts = opts end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
19 20 21 |
# File 'app/builders/blacklight/action_builder.rb', line 19 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'app/builders/blacklight/action_builder.rb', line 19 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
19 20 21 |
# File 'app/builders/blacklight/action_builder.rb', line 19 def opts @opts end |
Instance Method Details
#build ⇒ Object
Define a simple action handler for the tool as long as the method
doesn't already exist or the :define_method option is not false
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/builders/blacklight/action_builder.rb', line 23 def build # rubocop:disable Metrics/MethodLength return if skip? callback = opts.fetch(:callback, nil).inspect validator = opts.fetch(:validator, nil).inspect klass.class_eval <<EORUBY, __FILE__, __LINE__ + 1 def #{name} @documents = action_documents if request.post? && #{callback} if #{validator}.blank? || send(#{validator}) send(#{callback}, @documents) flash[:success] ||= I18n.t("blacklight.#{name}.success", default: nil) respond_to do |format| format.html do return render "#{name}_success", layout: false if request.xhr? redirect_to action_success_redirect_path end end else # Not valid respond_to do |format| format.html do return render layout: false, status: :unprocessable_entity if request.xhr? # Otherwise draw the full page end end end else respond_to do |format| format.html do return render layout: false if request.xhr? # Otherwise draw the full page end end end end EORUBY end |