Sha256: 8e7808454fc725a7ba88dfb8c2d78a5951cdeb2348cb2bec0809f2ef4eda5e1d

Contents?: true

Size: 1011 Bytes

Versions: 12

Compression:

Stored size: 1011 Bytes

Contents

module ActiveAdminAddons
  class StateBuilder < CustomBuilder
    DEFAULT_CLASS_BINDINGS = {
      accepted: "ok",
      confirmed: "ok",
      ready: "ok",
      rejected: "error",
      canceled: "error"
    }

    def render
      raise "you need to install AASM gem first" unless defined? AASM
      raise "the #{attribute} is not an AASM state" unless state_attribute?
      context.status_tag(model.aasm(machine_name).human_state, class: status_class_for_model)
    end

    private

    def state_attribute?
      model.class.respond_to?(:aasm) &&
        attribute.present? &&
        model.class.aasm(machine_name).attribute_name == attribute.to_sym
    end

    def status_class_for_model
      class_bindings[data.to_sym] || data
    end

    def machine_name
      @machine_name ||= options.fetch(:machine, :default)
    end

    def class_bindings
      @class_bindings ||= DEFAULT_CLASS_BINDINGS.merge(options[:states] || {})
    end
  end
end

ActiveAdminAddons::StateBuilder.create_view_methods

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
activeadmin_addons-1.10.1 lib/activeadmin_addons/addons/state_builder.rb
activeadmin_addons-2.0.0.beta.0 lib/activeadmin_addons/addons/state_builder.rb
activeadmin_addons-1.10.0 lib/activeadmin_addons/addons/state_builder.rb
activeadmin_addons-1.9.0 lib/activeadmin_addons/addons/state_builder.rb
activeadmin_addons-1.8.3 lib/activeadmin_addons/addons/state_builder.rb
activeadmin_addons-1.8.2 lib/activeadmin_addons/addons/state_builder.rb
activeadmin_addons_rails6-1.7.2 lib/activeadmin_addons/addons/state_builder.rb
activeadmin_addons-1.7.1 lib/activeadmin_addons/addons/state_builder.rb
activeadmin_addons-1.7.0 lib/activeadmin_addons/addons/state_builder.rb
activeadmin_addons-1.6.0 lib/activeadmin_addons/addons/state_builder.rb
activeadmin_addons-1.5.0 lib/activeadmin_addons/addons/state_builder.rb
activeadmin_addons-1.4.0 lib/activeadmin_addons/addons/state_builder.rb