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
| # Illustrate the usage of service objects named in the verb-first form. | |
| # a test user | |
| user = User.where(name: 'Oleg').first | |
| SubscribeUserToList.call(user) | |
| # => "Oleg was added to the mailing list." | |
| UnsubscribeUserFromList.call(user) | |
| # => "Oleg was removed from the mailing list." |
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
| # Illustrate the usage of service objects named in the noun-first form. | |
| # a test user | |
| user = User.where(name: 'Oleg').first | |
| UserListSubscription.subscribe(oleg, list) | |
| # => "Oleg was added to the mailing list." | |
| UserListSubscription.unsubscribe(oleg, list) | |
| # => "Oleg was removed from the mailing list." |
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
| namespace :archive do | |
| task :users do | |
| users.each do |user| | |
| UnsubscribeUserFromList.call(user) | |
| ArchiveUserComments.call(user) | |
| end | |
| end | |
| 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 ArchiveUserWorker | |
| include Sidekiq::Worker | |
| def perform(user) | |
| UnsubscribeUserFromList.call(user) | |
| end | |
| 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
| [1] pry(main)> user = User.find(99) | |
| [2] pry(main)> RemoveUserComments.call(user) | |
| => "User #99 was removed." |
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 ArchiveInactiveUsers | |
| def self.call(users) | |
| users.each do |user| | |
| UnsubscribeUserFromList.call(user) | |
| SendGoodbyeEmail.call(user) | |
| RemoveUserComment.call(user) | |
| end | |
| end | |
| 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
| #!/usr/bin/env ruby | |
| $:.unshift 'spec' | |
| require 'rspec' | |
| require 'rails_helper' | |
| spec = ARGV[0] | |
| # ----------------------------------------------------------------------------- |
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
| #!/usr/bin/env ruby | |
| $:.unshift 'spec' | |
| require 'rspec' | |
| require 'rails_helper' | |
| require 'benchmark/ips' | |
| spec = ARGV[0] |
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
| module YourNamespace | |
| class Item < ActiveRecord::Base | |
| end | |
| end | |
| YourNamespace.require_sti_dependencies(:item) |
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
| # admin/user.rb | |
| ActiveAdmin.register User do | |
| filter :role_in_all, as: :select, | |
| multiple: true, | |
| collection: -> { Role.order(name: :asc).all } | |
| end |