Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 9d83dc2

Browse files
dvdgs88pablorc
authored andcommitted
Feature/refactor organization (#88)
* Organization refactor * Remove comments * More changes * More refactor * Fix ActiveAdmin ask class * Add dependable * Remove comments * Use tty-prompt * Recipes are auto loaded into pathfinder.rb * Naming changes * Changes * Remove bootsnap * Fix carrierwave * More fixes * More changes
1 parent 7f74a21 commit 9d83dc2

35 files changed

+478
-160
lines changed

concerns/askable.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module Askable
2+
def self.included(base)
3+
base.send(:extend, ClassMethods)
4+
base.send(:include, InstanceMethods)
5+
end
6+
7+
module ClassMethods
8+
attr_accessor :ask, :default
9+
10+
def askable(value)
11+
@ask = value
12+
end
13+
14+
def default_answer(value)
15+
@default = value
16+
end
17+
end
18+
19+
module InstanceMethods
20+
def ask?
21+
self.class.ask.present?
22+
end
23+
24+
def ask!
25+
return unless ask?
26+
27+
if self.class.options.any?
28+
@pathfinder.utils.ask_with_options(self.class.ask, self.class.options)
29+
elsif self.class.default
30+
@pathfinder.utils.ask_with_default(self.class.ask, self.class.default)
31+
elsif self.class.confirmable?
32+
@pathfinder.utils.ask_with_confirmation(self.class.ask)
33+
else
34+
@pathfinder.utils.ask(self.class.ask)
35+
end
36+
end
37+
end
38+
end

concerns/auto_runnable.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module AutoRunnable
2+
def self.included(base)
3+
base.send(:extend, ClassMethods)
4+
end
5+
6+
module ClassMethods
7+
attr_accessor :auto_runnable
8+
9+
def is_auto_runnable
10+
@auto_runnable = true
11+
end
12+
end
13+
14+
def self.auto_runnables_for_module(mod)
15+
mod.constants.reduce([]) do |acc, c|
16+
klass = mod.const_get(c)
17+
auto_runnable = klass.is_a?(Class) && klass.auto_runnable ? klass : nil
18+
(acc << auto_runnable).compact
19+
end
20+
end
21+
end

concerns/confirmable.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Confirmable
2+
def self.included(base)
3+
base.send(:extend, ClassMethods)
4+
end
5+
6+
module ClassMethods
7+
attr_accessor :confirmable
8+
9+
def is_confirmable
10+
@confirmable = true
11+
end
12+
13+
def confirmable?
14+
@confirmable || false
15+
end
16+
end
17+
end

concerns/dependable.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Dependable
2+
def self.included(base)
3+
base.send(:extend, ClassMethods)
4+
base.send(:include, InstanceMethods)
5+
end
6+
7+
module ClassMethods
8+
attr_accessor :dependent
9+
10+
def dependable(value)
11+
@dependent = value
12+
end
13+
end
14+
15+
module InstanceMethods
16+
def dependent?
17+
self.class.dependent || false
18+
end
19+
20+
def perform?
21+
@pathfinder.recipes_list.map(&:class).include?(self.class.dependent.constantize)
22+
end
23+
end
24+
end

concerns/optionable.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Optionable
2+
def self.included(base)
3+
base.send(:extend, ClassMethods)
4+
end
5+
6+
module ClassMethods
7+
attr_accessor :options
8+
9+
def optionable(options)
10+
@options = options
11+
end
12+
13+
def options
14+
@options || []
15+
end
16+
end
17+
end

configurators.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require_relative 'configurators/base'
2+
require_relative 'configurators/active_admin'
3+
require_relative 'configurators/form_framework'
4+
require_relative 'configurators/image_magick'
5+
require_relative 'configurators/monitoring'

configurators/active_admin.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Configurators
2+
class ActiveAdmin < Base
3+
4+
askable 'What will be the main user class for Devise and ActiveAdmin?'
5+
default_answer 'AdminUser'
6+
dependable 'Recipes::ActiveAdmin'
7+
8+
def cook
9+
admin_class_name = ask!
10+
@template.run "rails g active_admin:install #{admin_class_name}"
11+
end
12+
13+
end
14+
end

configurators/base.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require_relative '../concerns/askable'
2+
require_relative '../concerns/optionable'
3+
require_relative '../concerns/confirmable'
4+
require_relative '../concerns/dependable'
5+
6+
module Configurators
7+
class Base
8+
9+
include ::Askable
10+
include ::Optionable
11+
include ::Confirmable
12+
include ::Dependable
13+
14+
def initialize(pathfinder)
15+
@pathfinder = pathfinder
16+
@template = pathfinder.template
17+
end
18+
19+
def cook
20+
end
21+
22+
def recipe
23+
end
24+
25+
end
26+
end

configurators/form_framework.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Configurators
2+
class FormFramework < Base
3+
4+
askable 'What framework do you want to use for your forms?'
5+
optionable %w(Default Marsman Bootstrap)
6+
7+
def cook
8+
case ask!
9+
when 'Marsman'
10+
@template.initializer('simple_form.rb', simple_form_template('marsman.rb'))
11+
when 'Bootstrap'
12+
@template.generate('simple_form:install --bootstrap')
13+
else
14+
@template.generate('simple_form:install')
15+
end
16+
end
17+
18+
private
19+
20+
def simple_form_template(filename)
21+
base_path = File.dirname(__FILE__).split('/')
22+
base_path.pop
23+
File.read(File.join(base_path, 'recipes', 'simple_form', filename))
24+
end
25+
26+
end
27+
end

configurators/image_magick.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Configurators
2+
class ImageMagick < Base
3+
4+
askable 'Are you going to handle images with CarrierWave?'
5+
dependable 'Recipes::CarrierWave'
6+
is_confirmable
7+
8+
def cook
9+
if ask!
10+
@template.gem 'mini_magick'
11+
end
12+
end
13+
14+
end
15+
end

0 commit comments

Comments
 (0)