module UiComponents::CellAttributes

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/ui_components/cell_attributes.rb, line 7
def initialize(*args)
  super
  options.except(:controller).each do |k, v|
    public_send(:"#{k}=", v) if respond_to?(:"#{k}=")
  end
  validate_mandatory_attributes
end

Public Instance Methods

attributes() click to toggle source
# File lib/ui_components/cell_attributes.rb, line 15
def attributes
  self.class.attributes.keys.map do |k|
    [k, public_send(k)]
  end.to_h
end

Private Instance Methods

attribute(name, options = {}) click to toggle source
# File lib/ui_components/cell_attributes.rb, line 35
def attribute(name, options = {})
  options = ActionController::Parameters.new(options)
  attributes << {
    name: name,
    mandatory: options[:mandatory] == true,
    description: options.require(:description)
  }
  attr_accessor name
end
validate_mandatory_attributes() click to toggle source
# File lib/ui_components/cell_attributes.rb, line 23
def validate_mandatory_attributes
  missing_attributes = self.class.attributes
    .select { |a| a[:mandatory] && public_send(a[:name]).nil? }
  return if missing_attributes.empty?
  raise MandatoryAttributeNotSet,
    'Following mandatory attribute(s) have not been provided: ' +
    missing_attributes.map { |m| m[:name] }.join(', ')
end