Sha256: 20ff3592591a9e9efabe19e602505f6de673bdbeb966c3a830442d7dba840914
Contents?: true
Size: 1.04 KB
Versions: 12
Compression:
Stored size: 1.04 KB
Contents
module Spina module Embeddable extend ActiveSupport::Concern included do class_attribute :embed_attributes, default: [] class_attribute :icon, default: nil end class_methods do def from_json(json) begin attributes = JSON.parse(json) attributes.transform_keys!(&:to_sym) new(attributes) rescue Rails.logger.error "[#{self.class.name}] Couldn't parse JSON" nil end end def attributes(*names) attr_accessor(*names.map(&:to_sym)) self.embed_attributes += names.map(&:to_sym) end # Give it an icon def heroicon(name) self.icon = name end end def initialize(attributes = {}) attributes.slice(*self.class.embed_attributes).each do |key, value| instance_variable_set("@#{key}", value) end end def to_fields_path "#{to_partial_path}_fields" end def to_trix_partial_path to_partial_path end end end
Version data entries
12 entries across 12 versions & 1 rubygems