Class: Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/generator/base.rb

Direct Known Subclasses

Bricks::Git

Constant Summary collapse

BRICKS =
%w(init git clean_assets errbit frontend database heroku active_admin active_admin_extras)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/active_admin/generator/base.rb', line 5

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/active_admin/generator/base.rb', line 3

def context
  @context
end

Instance Method Details

#bricksObject



16
17
18
19
20
21
22
# File 'lib/active_admin/generator/base.rb', line 16

def bricks
  @bricks ||= BRICKS.map do |brick_module|
    brick_class = "bricks/#{brick_module}".camelize.constantize
    brick = brick_class.new(context)
    brick.apply? ? brick : nil
  end.compact
end

#hook(name) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/active_admin/generator/base.rb', line 38

def hook(name)
  bricks.each do |brick|
    puts brick.class.name
    if brick.respond_to? name
      brick.send(name)
    end
  end
end

#require_bricksObject



9
10
11
12
13
14
# File 'lib/active_admin/generator/base.rb', line 9

def require_bricks
  context.apply "bricks/base.rb"
  BRICKS.each do |brick_module|
    context.apply "bricks/#{brick_module}.rb"
  end
end

#run!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/active_admin/generator/base.rb', line 24

def run!
  require_bricks

  hook :before_bundle
    context.run "bundle install"
  hook :after_bundle

  hook :before_migrate
    context.rake "db:migrate"
  hook :after_migrate

  hook :recap
end