Class: Radiant::Extension
- Inherits:
-
Rails::Engine
- Object
- Rails::Engine
- Radiant::Extension
- Defined in:
- lib/radiant/extension.rb,
lib/radiant/extension/script.rb
Defined Under Namespace
Modules: Configurable, Script Classes: Configuration
Instance Attribute Summary collapse
-
#active ⇒ Object
writeonly
Sets the attribute active.
Class Method Summary collapse
- .enabled? ⇒ Boolean
-
.extension_config {|config| ... } ⇒ Object
Expose the configuration object for init hooks class MyExtension < ActiveRecord::Base extension_config do |config| config.after_initialize do run_something end end end.
-
.find_root_with_flag(flag, default = nil) ⇒ Object
override the original method to compensate for some extensions not having a “lib” directory.
-
.inherited(subclass) ⇒ Object
def activate_extension return if instance.active? instance.activate if instance.respond_to? :activate instance.active = true end alias :activate :activate_extension.
- .migrated? ⇒ Boolean
- .migrations_path ⇒ Object
- .migrator ⇒ Object
- .subclasses ⇒ Object
Instance Method Summary collapse
- #active? ⇒ Boolean
- #add_item(*args) ⇒ Object
- #admin ⇒ Object
-
#extension_enabled?(extension) ⇒ Boolean
Determine if another extension is installed and up to date.
- #tab(name, &block) ⇒ Object (also: #add_tab)
Instance Attribute Details
#active=(value) ⇒ Object (writeonly)
Sets the attribute active
62 63 64 |
# File 'lib/radiant/extension.rb', line 62 def active=(value) @active = value end |
Class Method Details
.enabled? ⇒ Boolean
141 142 143 |
# File 'lib/radiant/extension.rb', line 141 def enabled? active? and migrated? end |
.extension_config {|config| ... } ⇒ Object
Expose the configuration object for init hooks class MyExtension < ActiveRecord::Base
extension_config do |config|
config.after_initialize do
run_something
end
end
end
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/radiant/extension.rb', line 184 def extension_config(&block) ActiveSupport::Deprecation.warn(<<-MSG, caller) extension_config is deprecated. Use `config` or `initializer` methods instead: # example config: add a load path for this specific Extension config.autoload_paths << File.expand_path("../lib/some/path", __FILE__) # example initializer block initializer "my_extension.add_middleware" do |app| app.middleware.use MyExtension::Middleware end MSG yield config end |
.find_root_with_flag(flag, default = nil) ⇒ Object
override the original method to compensate for some extensions not having a “lib” directory. also, don’t traverse upwards beyond the “vendor/extensions” directory
136 137 138 139 |
# File 'lib/radiant/extension.rb', line 136 def find_root_with_flag(flag, default = nil) path = File.dirname(self.called_from) default ||= path end |
.inherited(subclass) ⇒ Object
def activate_extension
return if instance.active?
instance.activate if instance.respond_to? :activate
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
119 120 121 122 123 |
# File 'lib/radiant/extension.rb', line 119 def inherited(subclass) super subclass.called_from = caller.first.sub(/:\d+$/, '') subclass.extension_name(subclass.name.to_name('Extension')) end |
.migrated? ⇒ Boolean
129 130 131 |
# File 'lib/radiant/extension.rb', line 129 def migrated? migrator.new(:up, migrations_path).pending_migrations.empty? end |
.migrations_path ⇒ Object
145 146 147 |
# File 'lib/radiant/extension.rb', line 145 def migrations_path File.join(self.root, 'db', 'migrate') end |
.migrator ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/radiant/extension.rb', line 149 def migrator unless @migrator extension = self @migrator = Class.new(ExtensionMigrator){ self.extension = extension } end @migrator end |
.subclasses ⇒ Object
125 126 127 |
# File 'lib/radiant/extension.rb', line 125 def subclasses superclass.subclasses end |
Instance Method Details
#active? ⇒ Boolean
64 65 66 |
# File 'lib/radiant/extension.rb', line 64 def active? @active end |
#add_item(*args) ⇒ Object
85 86 87 |
# File 'lib/radiant/extension.rb', line 85 def add_item(*args) @the_tab.add_item(*args) end |
#admin ⇒ Object
68 69 70 |
# File 'lib/radiant/extension.rb', line 68 def admin AdminUI.instance 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
94 95 96 97 98 99 100 101 |
# File 'lib/radiant/extension.rb', line 94 def extension_enabled?(extension) begin extension = (extension.to_s.camelcase + 'Extension').constantize extension.enabled? rescue NameError false end end |
#tab(name, &block) ⇒ Object Also known as: add_tab
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/radiant/extension.rb', line 72 def tab(name,&block) @the_tab = admin.nav[name] unless @the_tab @the_tab = Radiant::AdminUI::NavTab.new(name) admin.nav << @the_tab end if block_given? block.call(@the_tab) end return @the_tab end |