Class: Radiant::Extension

Inherits:
Object show all
Includes:
Annotatable, Simpleton
Defined in:
lib/radiant/extension.rb,
lib/radiant/extension/script.rb

Defined Under Namespace

Modules: Script

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Annotatable

included

Methods included from Simpleton

included

Instance Attribute Details

#active=(value) ⇒ Object (writeonly)

Sets the attribute active

Parameters:

  • value

    the value to set the attribute active to.



12
13
14
# File 'lib/radiant/extension.rb', line 12

def active=(value)
  @active = value
end

Class Method Details

.activate_extensionObject Also known as: activate



58
59
60
61
62
63
# File 'lib/radiant/extension.rb', line 58

def activate_extension
  return if instance.active?
  instance.activate if instance.respond_to? :activate
  ActionController::Routing::Routes.reload
  instance.active = true
end

.deactivate_extensionObject Also known as: deactivate



66
67
68
69
70
# File 'lib/radiant/extension.rb', line 66

def deactivate_extension
  return unless instance.active?
  instance.active = false
  instance.deactivate if instance.respond_to? :deactivate
end

.define_routes(&block) ⇒ Object



73
74
75
# File 'lib/radiant/extension.rb', line 73

def define_routes(&block)
  route_definitions << block
end

.extension_config {|Rails.configuration| ... } ⇒ Object

Expose the configuration object for depencencies, init hooks, &c class MyExtension < ActiveRecord::Base

extension_config do |config|
  config.gem 'gem_name'
  config.extension 'radiant-extension-name'
  config.after_initialize do
    run_something
  end
end

end

Yields:



95
96
97
# File 'lib/radiant/extension.rb', line 95

def extension_config(&block)
  yield Rails.configuration
end

.inherited(subclass) ⇒ Object



77
78
79
# File 'lib/radiant/extension.rb', line 77

def inherited(subclass)
  subclass.extension_name = subclass.name.to_name('Extension')
end

.route_definitionsObject



81
82
83
# File 'lib/radiant/extension.rb', line 81

def route_definitions
  @route_definitions ||= []
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/radiant/extension.rb', line 14

def active?
  @active
end

#adminObject



38
39
40
# File 'lib/radiant/extension.rb', line 38

def admin
  AdminUI.instance
end

#enabled?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/radiant/extension.rb', line 22

def enabled?
  active? and migrated?
end

#extension_enabled?(extension) ⇒ Boolean

Determine if another extension is installed and up to date.

if MyExtension.extension_enabled?(:third_party)

ThirdPartyExtension.extend(MyExtension::IntegrationPoints)

end

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
# File 'lib/radiant/extension.rb', line 47

def extension_enabled?(extension)
  begin
    extension = (extension.to_s.camelcase + 'Extension').constantize
    extension.enabled?
  rescue NameError
    false
  end
end

#migrated?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/radiant/extension.rb', line 18

def migrated?
  migrator.new(:up, migrations_path).pending_migrations.empty?
end

#migrations_pathObject



26
27
28
# File 'lib/radiant/extension.rb', line 26

def migrations_path
  File.join(self.root, 'db', 'migrate')
end

#migratorObject



30
31
32
33
34
35
36
# File 'lib/radiant/extension.rb', line 30

def migrator
  unless @migrator
    extension = self
    @migrator = Class.new(ExtensionMigrator){ self.extension = extension }
  end
  @migrator
end