Sha256: 25df6131b93a55242f1c5210e72a9fab6918f2039534cf548b7e229e89e1059e

Contents?: true

Size: 844 Bytes

Versions: 2

Compression:

Stored size: 844 Bytes

Contents

# frozen_string_literal: true
module AffairsOfState
  class Config
    attr_reader :statuses, :column, :allow_blank, :scopes, :if, :methods_for_statuses

    DISALLOWED_STATUSES = [ "new" ].freeze

    def initialize(statuses:, column:, allow_blank:, scopes:, if:, prefix:)
      @column = column
      @allow_blank = !!allow_blank
      @scopes = !!scopes
      @if = binding.local_variable_get(:if)
      @prefix = prefix.presence
      @statuses = statuses.flatten.map(&:to_s)
      @methods_for_statuses = @statuses.to_h do |s|
        if @prefix
          [s.to_s, "#{ prefix }_#{ s }"]
        else
          [s.to_s, s.to_s]
        end
      end
      @statuses.each do |status|
        raise ArgumentError.new("Affairs of State: '#{ status }' is not a valid status") if DISALLOWED_STATUSES.include?(status)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
affairs_of_state-0.7.2 lib/affairs_of_state/config.rb
affairs_of_state-0.7.1 lib/affairs_of_state/config.rb