Class: AffairsOfState::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/affairs_of_state/config.rb

Constant Summary collapse

DISALLOWED_STATUSES =
[ "new" ].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statuses:, column:, allow_blank:, scopes:, if:, prefix:) ⇒ Config

Returns a new instance of Config.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/affairs_of_state/config.rb', line 8

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

Instance Attribute Details

#allow_blankObject (readonly)

Returns the value of attribute allow_blank.



4
5
6
# File 'lib/affairs_of_state/config.rb', line 4

def allow_blank
  @allow_blank
end

#columnObject (readonly)

Returns the value of attribute column.



4
5
6
# File 'lib/affairs_of_state/config.rb', line 4

def column
  @column
end

#ifObject (readonly)

Returns the value of attribute if.



4
5
6
# File 'lib/affairs_of_state/config.rb', line 4

def if
  @if
end

#methods_for_statusesObject (readonly)

Returns the value of attribute methods_for_statuses.



4
5
6
# File 'lib/affairs_of_state/config.rb', line 4

def methods_for_statuses
  @methods_for_statuses
end

#scopesObject (readonly)

Returns the value of attribute scopes.



4
5
6
# File 'lib/affairs_of_state/config.rb', line 4

def scopes
  @scopes
end

#statusesObject (readonly)

Returns the value of attribute statuses.



4
5
6
# File 'lib/affairs_of_state/config.rb', line 4

def statuses
  @statuses
end