Class: PagesCore::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/pages_core/plugin.rb

Direct Known Subclasses

PagesPlugin

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.called_fromObject

Returns the value of attribute called_from.



10
11
12
# File 'lib/pages_core/plugin.rb', line 10

def called_from
  @called_from
end

.pathsObject

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 admin_menu_item(label, path, group = :custom, options = {})
  PagesCore::AdminMenuItem.register(label, path, group, options)
end

.existing_migrationsObject



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_migrationsObject



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

.migrationsObject



38
39
40
# File 'lib/pages_core/plugin.rb', line 38

def migrations
  plugins.map { |p| p.new.migrations }.flatten.compact
end

.pluginsObject



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_migrationsObject



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

#migrationsObject



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

Returns:

  • (Boolean)


89
90
91
# File 'lib/pages_core/plugin.rb', line 89

def migrations?
  File.exist?(migrations_path) && File.directory?(migrations_path)
end

#migrations_pathObject



81
82
83
# File 'lib/pages_core/plugin.rb', line 81

def migrations_path
  root.join(paths["db/migrate"])
end

#pathsObject



77
78
79
# File 'lib/pages_core/plugin.rb', line 77

def paths
  self.class.paths
end

#removed_migrationsObject



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_pathObject



85
86
87
# File 'lib/pages_core/plugin.rb', line 85

def removed_migrations_path
  root.join(paths["config/removed_migrations.yml"])
end

#rootObject



73
74
75
# File 'lib/pages_core/plugin.rb', line 73

def root
  @root ||= find_root_with_subfolder("app")
end