Class: PagesCore::Plugin
- Inherits:
-
Object
- Object
- PagesCore::Plugin
- Defined in:
- lib/pages_core/plugin.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.called_from ⇒ Object
Returns the value of attribute called_from.
-
.paths ⇒ Object
Returns the value of attribute paths.
Class Method Summary collapse
- .admin_menu_item(label, path, group = :custom, options = {}) ⇒ Object
- .existing_migrations ⇒ Object
- .existing_removed_migrations ⇒ Object
- .inherited(plugin) ⇒ Object
- .migrations ⇒ Object
- .plugins ⇒ Object
- .remove_old_migrations! ⇒ Object
- .removed_migrations ⇒ Object
Instance Method Summary collapse
- #migrations ⇒ Object
- #migrations? ⇒ Boolean
- #migrations_path ⇒ Object
- #paths ⇒ Object
- #removed_migrations ⇒ Object
- #removed_migrations_path ⇒ Object
- #root ⇒ Object
Class Attribute Details
.called_from ⇒ Object
Returns the value of attribute called_from.
10 11 12 |
# File 'lib/pages_core/plugin.rb', line 10 def called_from @called_from end |
.paths ⇒ Object
Returns the value of attribute paths.
10 11 12 |
# File 'lib/pages_core/plugin.rb', line 10 def paths @paths end |
Class Method Details
.admin_menu_item(label, path, group = :custom, options = {}) ⇒ Object
26 27 28 |
# File 'lib/pages_core/plugin.rb', line 26 def (label, path, group = :custom, = {}) PagesCore::AdminMenuItem.register(label, path, group, ) end |
.existing_migrations ⇒ Object
51 52 53 54 55 |
# File 'lib/pages_core/plugin.rb', line 51 def existing_migrations migrations .map { |m| Rails.root.join("db", "migrate", m.basename) } .select { |m| File.exist?(m) } end |
.existing_removed_migrations ⇒ Object
46 47 48 49 |
# File 'lib/pages_core/plugin.rb', line 46 def existing_removed_migrations removed_migrations .select { |m| File.exist?(Rails.root.join("db", "migrate", m)) } end |
.inherited(plugin) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pages_core/plugin.rb', line 12 def inherited(plugin) plugin.paths ||= default_paths plugin.called_from = begin # Remove the line number from backtraces making sure we # don't leave anything behind call_stack = caller.map { |p| p.sub(/:\d+.*/, "") } File.dirname( call_stack.detect do |p| p !~ %r{railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack} end ) end end |
.migrations ⇒ Object
38 39 40 |
# File 'lib/pages_core/plugin.rb', line 38 def migrations plugins.map { |p| p.new.migrations }.flatten.compact end |
.plugins ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/pages_core/plugin.rb', line 30 def plugins @plugins ||= ::PagesCore::Plugin.subclasses.map do |class_name| class_name.to_s.split("::").inject(Object) do |klass, m| klass.const_get(m) end end end |
.remove_old_migrations! ⇒ Object
57 58 59 60 61 |
# File 'lib/pages_core/plugin.rb', line 57 def remove_old_migrations! (existing_removed_migrations + existing_migrations).each do |migration| File.unlink Rails.root.join("db", "migrate", migration) end end |
.removed_migrations ⇒ Object
42 43 44 |
# File 'lib/pages_core/plugin.rb', line 42 def removed_migrations plugins.map { |p| p.new.removed_migrations }.flatten.compact end |
Instance Method Details
#migrations ⇒ Object
93 94 95 96 97 |
# File 'lib/pages_core/plugin.rb', line 93 def migrations Dir.entries(migrations_path) .select { |f| f =~ /\.rb$/ } .map { |f| migrations_path.join(f) } end |
#migrations? ⇒ Boolean
89 90 91 |
# File 'lib/pages_core/plugin.rb', line 89 def migrations? File.exist?(migrations_path) && File.directory?(migrations_path) end |
#migrations_path ⇒ Object
81 82 83 |
# File 'lib/pages_core/plugin.rb', line 81 def migrations_path root.join(paths["db/migrate"]) end |
#paths ⇒ Object
77 78 79 |
# File 'lib/pages_core/plugin.rb', line 77 def paths self.class.paths end |
#removed_migrations ⇒ Object
99 100 101 102 |
# File 'lib/pages_core/plugin.rb', line 99 def removed_migrations return unless File.exist?(removed_migrations_path) YAML.load_file(removed_migrations_path) end |
#removed_migrations_path ⇒ Object
85 86 87 |
# File 'lib/pages_core/plugin.rb', line 85 def removed_migrations_path root.join(paths["config/removed_migrations.yml"]) end |
#root ⇒ Object
73 74 75 |
# File 'lib/pages_core/plugin.rb', line 73 def root @root ||= find_root_with_subfolder("app") end |