Class: TrustyCms::Extension
- Inherits:
-
Object
- Object
- TrustyCms::Extension
- Includes:
- Annotatable, Simpleton
- Defined in:
- lib/trusty_cms/extension.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
writeonly
Sets the attribute active.
Class Method Summary collapse
- .activate_extension ⇒ Object
- .deactivate_extension ⇒ Object (also: deactivate)
- .extension_config {|Rails.configuration| ... } ⇒ Object
- .inherited(subclass) ⇒ Object
- .migrate_from(extension_name, until_migration = nil) ⇒ Object
Instance Method Summary collapse
- #active? ⇒ Boolean
- #add_item(*args) ⇒ Object
- #admin ⇒ Object
- #enabled? ⇒ Boolean
-
#extension_enabled?(extension) ⇒ Boolean
Determine if another extension is installed and up to date.
- #load_initializers ⇒ Object
- #migrated? ⇒ Boolean
- #migrates_from ⇒ Object
- #migrations_path ⇒ Object
- #migrator ⇒ Object
- #root ⇒ Object
-
#routed? ⇒ Boolean
Conventional plugin-like routing.
- #routing_file ⇒ Object
- #tab(name, options = {}, &block) ⇒ Object (also: #add_tab)
Methods included from Annotatable
Methods included from Simpleton
Instance Attribute Details
#active=(value) ⇒ Object (writeonly)
Sets the attribute active
12 13 14 |
# File 'lib/trusty_cms/extension.rb', line 12 def active=(value) @active = value end |
Class Method Details
.activate_extension ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/trusty_cms/extension.rb', line 105 def activate_extension return if instance.active? instance.activate_extension if instance.respond_to? :activate Dir["#{Rails.root}/config/routes/**/*.rb"].each do |route_file| end instance.active = true end |
.deactivate_extension ⇒ Object Also known as: deactivate
114 115 116 117 118 119 |
# File 'lib/trusty_cms/extension.rb', line 114 def deactivate_extension return unless instance.active? instance.active = false instance.deactivate if instance.respond_to? :deactivate end |
.extension_config {|Rails.configuration| ... } ⇒ Object
130 131 132 |
# File 'lib/trusty_cms/extension.rb', line 130 def extension_config yield Rails.configuration end |
.inherited(subclass) ⇒ Object
122 123 124 |
# File 'lib/trusty_cms/extension.rb', line 122 def inherited(subclass) subclass.extension_name = subclass.name.to_name('Extension') end |
.migrate_from(extension_name, until_migration = nil) ⇒ Object
126 127 128 |
# File 'lib/trusty_cms/extension.rb', line 126 def migrate_from(extension_name, until_migration = nil) instance.migrates_from[extension_name] = until_migration end |
Instance Method Details
#active? ⇒ Boolean
14 15 16 |
# File 'lib/trusty_cms/extension.rb', line 14 def active? @active end |
#add_item(*args) ⇒ Object
88 89 90 |
# File 'lib/trusty_cms/extension.rb', line 88 def add_item(*args) @the_tab.add_item(*args) end |
#admin ⇒ Object
61 62 63 |
# File 'lib/trusty_cms/extension.rb', line 61 def admin AdminUI.instance end |
#enabled? ⇒ Boolean
26 27 28 |
# File 'lib/trusty_cms/extension.rb', line 26 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
97 98 99 100 101 102 |
# File 'lib/trusty_cms/extension.rb', line 97 def extension_enabled?(extension) extension = (extension.to_s.camelcase + 'Extension').constantize extension.enabled? rescue NameError false end |
#load_initializers ⇒ Object
47 48 49 50 51 |
# File 'lib/trusty_cms/extension.rb', line 47 def load_initializers Dir["#{root}/config/initializers/**/*.rb"].sort.each do |initializer| require initializer end end |
#migrated? ⇒ Boolean
22 23 24 |
# File 'lib/trusty_cms/extension.rb', line 22 def migrated? migrator.new(:up, migrations_path).pending_migrations.empty? end |
#migrates_from ⇒ Object
39 40 41 |
# File 'lib/trusty_cms/extension.rb', line 39 def migrates_from @migrates_from ||= {} end |
#migrations_path ⇒ Object
35 36 37 |
# File 'lib/trusty_cms/extension.rb', line 35 def migrations_path File.join(root, 'db', 'migrate') end |
#migrator ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/trusty_cms/extension.rb', line 53 def migrator unless @migrator extension = self @migrator = Class.new(ExtensionMigrator) { self.extension = extension } end @migrator end |
#root ⇒ Object
18 19 20 |
# File 'lib/trusty_cms/extension.rb', line 18 def root path.to_s end |
#routed? ⇒ Boolean
Conventional plugin-like routing
31 32 33 |
# File 'lib/trusty_cms/extension.rb', line 31 def routed? File.exist?(routing_file) end |
#routing_file ⇒ Object
43 44 45 |
# File 'lib/trusty_cms/extension.rb', line 43 def routing_file File.join(root, 'config', 'routes.rb') end |
#tab(name, options = {}, &block) ⇒ Object Also known as: add_tab
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/trusty_cms/extension.rb', line 65 def tab(name, = {}, &block) @the_tab = admin.nav[name] unless @the_tab @the_tab = TrustyCms::AdminUI::NavTab.new(name) before = .delete(:before) after = .delete(:after) tab_name = before || after tab_object = admin.nav[tab_name] if tab_object index = admin.nav.index(tab_object) index += 1 unless before admin.nav.insert(index, @the_tab) else admin.nav << @the_tab end end if block_given? block.call(@the_tab) end @the_tab end |