Class: Radiant::Extension
- Includes:
- Annotatable, Simpleton
- Defined in:
- lib/radiant/extension.rb,
lib/radiant/extension/script.rb
Defined Under Namespace
Modules: Script
Instance Attribute Summary collapse
-
#active ⇒ Object
writeonly
Sets the attribute active.
Class Method Summary collapse
- .activate_extension ⇒ Object (also: activate)
- .deactivate_extension ⇒ Object (also: deactivate)
- .define_routes(&block) ⇒ Object
-
.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.
- .inherited(subclass) ⇒ Object
- .route_definitions ⇒ Object
Instance Method Summary collapse
- #active? ⇒ Boolean
- #admin ⇒ Object
- #enabled? ⇒ Boolean
-
#extension_enabled?(extension) ⇒ Boolean
Determine if another extension is installed and up to date.
- #migrated? ⇒ Boolean
- #migrations_path ⇒ Object
- #migrator ⇒ Object
Methods included from Annotatable
Methods included from Simpleton
Instance Attribute Details
#active=(value) ⇒ Object (writeonly)
Sets the attribute active
12 13 14 |
# File 'lib/radiant/extension.rb', line 12 def active=(value) @active = value end |
Class Method Details
.activate_extension ⇒ Object 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_extension ⇒ Object 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
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_definitions ⇒ Object
81 82 83 |
# File 'lib/radiant/extension.rb', line 81 def route_definitions @route_definitions ||= [] end |
Instance Method Details
#active? ⇒ Boolean
14 15 16 |
# File 'lib/radiant/extension.rb', line 14 def active? @active end |
#enabled? ⇒ 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
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
18 19 20 |
# File 'lib/radiant/extension.rb', line 18 def migrated? migrator.new(:up, migrations_path).pending_migrations.empty? end |
#migrations_path ⇒ Object
26 27 28 |
# File 'lib/radiant/extension.rb', line 26 def migrations_path File.join(self.root, 'db', 'migrate') end |
#migrator ⇒ Object
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 |