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
| # User model | |
| class User < ActiveRecord::Base | |
| has_many :invitations | |
| end | |
| # Invitation Model | |
| class Invitation < ActiveRecord::Base | |
| belongs_to :inviter, class_name: 'User' | |
| def accept | |
| self.accepted = true | |
| 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
| def accept_invitation | |
| Wf.new | |
| .chain(user: :user) { AcceptInvitation.new(invitation).call } | |
| .chain {|outflow| render json: { user: outflow.user } } | |
| .on_dam do |error_pool| | |
| render json: { errors: error_pool.full_messages }, status: 422 | |
| 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
| # controller | |
| def accept_invitation | |
| if invitation.accepted? | |
| render json: { errors: ['Invitation already accepted'] }, status: 422 | |
| else | |
| user = User.build_from_invitation(invitation) | |
| user.save! | |
| invitation.accept | |
| invitation.save! | |
| UserMailer.notify_affiliate_payment(invitation).deliver_later |
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
| require 'rubygems' | |
| require 'monadic' | |
| class MonadicService | |
| def initialize(user_id) | |
| @user_id = user_id | |
| end | |
| def call | |
| response = HTTParty.get("https://jsonplaceholder.typicode.com/users/#{@user_id}") |
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 CreateInvoiceNumbers < ActiveRecord::Migration | |
| def up | |
| create_table :invoice_numbers do |t| | |
| t.integer :year, null: false, unique: true | |
| t.integer :next_number_within_year, null: false, default: 1 | |
| end | |
| add_index :invoice_numbers, :year, unique: true | |
| (2016..2045).each do |year| |
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
| require 'spec_helper' | |
| describe 'thread safe tenants' do | |
| let(:db_names) { [db1, db2] } | |
| before do | |
| Apartment.configure do |config| | |
| config.excluded_models = ["Company"] | |
| config.tenant_names = lambda{ Company.pluck(:database) } | |
| config.use_schemas = false |
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
| def trace_calls_on | |
| scope = {} | |
| trace = TracePoint.new(:call, :line) do |tp| | |
| case tp.event | |
| when :call then puts "#{tp.path}:#{tp.lineno} #{tp.defined_class}::#{tp.method_id} " \ | |
| "called from #{scope[:path]}:#{scope[:lineno]} #{scope[:class]}::#{scope[:method_id]}" | |
| when :line then scope = { | |
| event: :line, | |
| lineno: tp.lineno, | |
| path: tp.path, |
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 Author::Work < AR::Base | |
| scope :with_text, -> { where.not(text: nil) } | |
| scope :started, -> { where(status: 0) } | |
| scope :in_progress, -> { started.with_text } | |
| 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 FormObjectBase | |
| include ::ActiveModel::Validations | |
| attr_reader :object, :params | |
| def initialize(object) | |
| @object = object | |
| end | |
| def assign(params) |
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
| def accept_group_terms | |
| if current_entity.user? && notification.group_terms? | |
| if params[:terms_of_service][:checked] | |
| user_group = notification.entity.user_groups.with_user(current_entity).first | |
| if user_group | |
| user_group.terms_accepted_at = Time.now | |
| user_group.save | |
| notification.mark_as_read_by(current_entity).save! | |
| render_notif | |
| else |