Sha256: 8131ff31bf7e8f681ea527759ddec426bcd3e26d5fd59a858161446fcffb7f69
Contents?: true
Size: 998 Bytes
Versions: 6
Compression:
Stored size: 998 Bytes
Contents
require "ledge/columns" module Ledge module UsesLedge extend ActiveSupport::Concern included do end module ClassMethods def uses_ledge options = {} cattr_accessor :field self.field = (options[:field] || :content).to_s include Ledge::UsesLedge::LocalInstanceMethods end end module LocalInstanceMethods def method_missing method, *args, &block if method.to_s == "#{self.field}_ledge" content = JSON.parse read_attribute(self.class.field) return Ledge::Columns.new content else super end end def respond_to? method if method.to_s == "#{self.field}_ledge" true else super end end def ledge_init self.content ||= '{"columns": [{"rows":[]}]}' end def initialize hash = {} super ledge_init end end end end ActiveRecord::Base.send :include, Ledge::UsesLedge
Version data entries
6 entries across 6 versions & 1 rubygems