Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.
38 changes: 38 additions & 0 deletions concerns/askable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Askable
def self.included(base)
base.send(:extend, ClassMethods)
base.send(:include, InstanceMethods)
end

module ClassMethods
attr_accessor :ask, :default

def askable(value)
@ask = value
end

def default_answer(value)
@default = value
end
end

module InstanceMethods
def ask?
self.class.ask.present?
end

def ask!
return unless ask?

if self.class.options.any?
@pathfinder.utils.ask_with_options(self.class.ask, self.class.options)
elsif self.class.default
@pathfinder.utils.ask_with_default(self.class.ask, self.class.default)
elsif self.class.confirmable?
@pathfinder.utils.ask_with_confirmation(self.class.ask)
else
@pathfinder.utils.ask(self.class.ask)
end
end
end
end
21 changes: 21 additions & 0 deletions concerns/auto_runnable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module AutoRunnable
def self.included(base)
base.send(:extend, ClassMethods)
end

module ClassMethods
attr_accessor :auto_runnable

def is_auto_runnable
@auto_runnable = true
end
end

def self.auto_runnables_for_module(mod)
mod.constants.reduce([]) do |acc, c|
klass = mod.const_get(c)
auto_runnable = klass.is_a?(Class) && klass.auto_runnable ? klass : nil
(acc << auto_runnable).compact
end
end
end
17 changes: 17 additions & 0 deletions concerns/confirmable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Confirmable
def self.included(base)
base.send(:extend, ClassMethods)
end

module ClassMethods
attr_accessor :confirmable

def is_confirmable
@confirmable = true
end

def confirmable?
@confirmable || false
end
end
end
24 changes: 24 additions & 0 deletions concerns/dependable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Dependable
def self.included(base)
base.send(:extend, ClassMethods)
base.send(:include, InstanceMethods)
end

module ClassMethods
attr_accessor :dependent

def dependable(value)
@dependent = value
end
end

module InstanceMethods
def dependent?
self.class.dependent || false
end

def perform?
@pathfinder.recipes_list.map(&:class).include?(self.class.dependent.constantize)
end
end
end
17 changes: 17 additions & 0 deletions concerns/optionable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Optionable
def self.included(base)
base.send(:extend, ClassMethods)
end

module ClassMethods
attr_accessor :options

def optionable(options)
@options = options
end

def options
@options || []
end
end
end
5 changes: 5 additions & 0 deletions configurators.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative 'configurators/base'
require_relative 'configurators/active_admin'
require_relative 'configurators/form_framework'
require_relative 'configurators/image_magick'
require_relative 'configurators/monitoring'
14 changes: 14 additions & 0 deletions configurators/active_admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Configurators
class ActiveAdmin < Base

askable 'What will be the main user class for Devise and ActiveAdmin?'
default_answer 'AdminUser'
dependable 'Recipes::ActiveAdmin'

def cook
admin_class_name = ask!
@template.run "rails g active_admin:install #{admin_class_name}"
end

end
end
26 changes: 26 additions & 0 deletions configurators/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require_relative '../concerns/askable'
require_relative '../concerns/optionable'
require_relative '../concerns/confirmable'
require_relative '../concerns/dependable'

module Configurators
class Base

include ::Askable
include ::Optionable
include ::Confirmable
include ::Dependable

def initialize(pathfinder)
@pathfinder = pathfinder
@template = pathfinder.template
end

def cook
end

def recipe
end

end
end
27 changes: 27 additions & 0 deletions configurators/form_framework.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Configurators
class FormFramework < Base

askable 'What framework do you want to use for your forms?'
optionable %w(Default Marsman Bootstrap)

def cook
case ask!
when 'Marsman'
@template.initializer('simple_form.rb', simple_form_template('marsman.rb'))
when 'Bootstrap'
@template.generate('simple_form:install --bootstrap')
else
@template.generate('simple_form:install')
end
end

private

def simple_form_template(filename)
base_path = File.dirname(__FILE__).split('/')
base_path.pop
File.read(File.join(base_path, 'recipes', 'simple_form', filename))
end

end
end
15 changes: 15 additions & 0 deletions configurators/image_magick.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Configurators
class ImageMagick < Base

askable 'Are you going to handle images with CarrierWave?'
dependable 'Recipes::CarrierWave'
is_confirmable

def cook
if ask!
@template.gem 'mini_magick'
end
end

end
end
17 changes: 17 additions & 0 deletions configurators/monitoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Configurators
class Monitoring < Base

askable 'Choose Monitoring Engine:'
optionable %w(None Rollbar Airbrake)

def recipe
case ask!
when 'Rollbar'
@pathfinder.add_recipe(Recipes::Rollbar.new(@pathfinder))
when 'Airbrake'
@pathfinder.add_recipe(Recipes::Airbrake.new(@pathfinder))
end
end

end
end
Loading