class Katapult::Element
Constants
- UnknownFormattingError
- UnknownOptionError
Attributes
application_model[RW]
name[RW]
options[RW]
Public Class Methods
new(name, options = {}) { |self| ... }
click to toggle source
# File lib/katapult/element.rb, line 21 def initialize(name, options = {}) self.name = name.to_s self.options = options set_attributes(options) yield(self) if block_given? end
Private Instance Methods
set_attributes(options)
click to toggle source
Map options to attributes. Example: set_attributes
(foo: 123) sets the :foo attribute to 123 (via foo=) and raises UnknownOptionError
if the attribute does not exist.
# File lib/katapult/element.rb, line 55 def set_attributes(options) options.each_pair do |option, value| setter = "#{option}=" if respond_to? setter send(setter, value) else raise UnknownOptionError, "#{self.class.name} does not support option #{option.inspect}." end end end