Sha256: 4f94ae3df6cd3f4d85b6df03000162e0de869f56075b2fdd80b580d71bbd4a4e

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

require 'annotatable'
require 'simpleton'
require 'radiant/admin_ui'

module Radiant
  class Extension
    include Simpleton
    include Annotatable

    annotate :version, :description, :url, :root, :extension_name
    
    attr_writer :active
    
    def active?
      @active
    end
      
    def enabled?
      meta.enabled?
    end
    
    def migrator
      ExtensionMigrator.new(self)
    end
  
    def admin
      AdminUI.instance
    end
  
    def meta
      self.class.meta
    end
    
    class << self

      def activate_extension
        return if instance.active?
        instance.activate if instance.respond_to? :activate
        ActionController::Routing::Routes.reload
        instance.active = true
      end
      alias :activate :activate_extension
      
      def deactivate_extension
        return unless instance.active?
        instance.active = false
        instance.deactivate if instance.respond_to? :deactivate
      end
      alias :deactivate :deactivate_extension
      
      def enable(enabled = true)
        deactivate_extension if active?
        meta.update_attribute(:enabled, enabled)
        activate_extension if enabled
        enabled
      end
      alias :enabled= :enable
      
      def define_routes(&block)
        route_definitions << block
      end
      
      def inherited(subclass)
        subclass.extension_name = subclass.name.to_name('Extension')
      end
      
      def meta
        Radiant::ExtensionMeta.find_or_create_by_name(extension_name)
      end
      
      def route_definitions
        @route_definitions ||= []
      end
      
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
radiant-0.6.0 lib/radiant/extension.rb
radiant-0.6.1 lib/radiant/extension.rb
radiant-0.6.2 lib/radiant/extension.rb