Sha256: 397fdebba297df9b3293251b9eeb0c57d0254f8fc86e310c271bc6ec08eab9d8

Contents?: true

Size: 950 Bytes

Versions: 4

Compression:

Stored size: 950 Bytes

Contents

module Jobshop
  class Registration < VirtualRecord
    memo_attr(:user) { team.users.build(user_params) }
    memo_attr(:team) {
      record = Jobshop::Team.find(params[:team_id])
      record.assign_attributes(team_params)
      record
    }

    def save
      return false unless valid?

      result = ActiveRecord::Base.transaction do
        user.save!
        team.update!(owner: user,
                     registration_token: nil,
                     registration_token_sent_at: nil)
      end

      result != false
    end

    private

    def registration_params
      params.fetch(:registration, ActionController::Parameters.new)
    end

    def team_params
      registration_params.fetch(
        :team, ActionController::Parameters.new).permit(:name)
    end

    def user_params
      registration_params.fetch(:user, ActionController::Parameters.new).
        permit(:email, :password, :password_confirmation)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jobshop-0.0.9 app/models/jobshop/registration.rb
jobshop-0.0.7 app/models/jobshop/registration.rb
jobshop-0.0.6 app/models/jobshop/registration.rb
jobshop-0.0.5 app/models/jobshop/registration.rb