This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TenantCreator | |
def initialize(user_name, email, company_name) | |
@tenant = Tenant.new(name: company_name) | |
@user = @tenant.users.new(name: user_name, email: email) | |
end | |
def call | |
if persist! | |
SignupMailer.welcome(user).deliver_now | |
AnalyticsTracker.new(tenant).call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessageCreator | |
# ... | |
def call | |
process! | |
return result | |
end | |
private | |
def process! | |
if message.save |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WidgetCreator | |
# ... | |
attr_reader :widget, :success, :errors | |
def result | |
OpenStruct.new(success?: !errors, errors: errors.try(:flatten), widget: widget) | |
end | |
end | |
widget_creator = WidgetCreator.new(params).call | |
widget_creator.success? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserCreator | |
# ... | |
# UserCreator.new(params).call | |
def call | |
do_the_work(args) | |
end | |
# Alternatively some people think this reads nicer: | |
# UserCreateor.call(params) | |
def self.call(*args) | |
new(*args).call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserCreator | |
def initialize(params) | |
@user = User.new(params) | |
end | |
private | |
attr_reader :user | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LeadMagnetsController < FormsController | |
private | |
def skope | |
current_user.lead_magnets | |
end | |
def form_params | |
params[:form] = params[:lead_magnet] | |
params.require(:form).permit(permitted_params) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FormsController < ApplicationController | |
before_action :set_form, only: [:show, :edit, :update, :destroy, :embed, :customize] | |
# GET /forms | |
# GET /forms.json | |
def index | |
@forms = skope.newest_first | |
respond_to do |format| | |
format.html | |
format.json { render json: @forms } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OptInsController < FormsController | |
private | |
def skope | |
current_user.opt_ins | |
end | |
def form_params | |
params[:form] = params[:opt_in] | |
params.require(:form).permit(permitted_params) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PronounceablePassword | |
WORDS = (IO.readlines(File.join File.dirname(__FILE__), 'words.txt')).each { |w| w.chop! } | |
class << self | |
def random_pronouncable_password(options={}) | |
options={ | |
:rand_seed => 999 | |
}.update(options) | |
words = WORDS.dup | |
[words.delete_at(rand(words.length)), rand(options[:rand_seed]), words[rand(words.length)]].join("-") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# numbers.rb | |
def numbers(*ary) | |
ary.all?{|a| a.is_a?(Numeric)} | |
end | |
numbers(1,2,3.0) | |
# => true | |
numbers(1,2,'foo') | |
# => false |