Class: ProfilePageType

Inherits:
Object
  • Object
show all
Includes:
EnumField::DefineEnum
Defined in:
app/models/enums/profile_page_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, slug = nil, disabled = false) ⇒ ProfilePageType

Returns a new instance of ProfilePageType.



7
8
9
10
11
# File 'app/models/enums/profile_page_type.rb', line 7

def initialize(code, slug = nil, disabled = false)
  @code = code.to_sym
  @slug = (slug || code).to_s
  @disabled = disabled
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'app/models/enums/profile_page_type.rb', line 5

def code
  @code
end

#disabledObject (readonly)

Returns the value of attribute disabled.



5
6
7
# File 'app/models/enums/profile_page_type.rb', line 5

def disabled
  @disabled
end

#slugObject (readonly)

Returns the value of attribute slug.



5
6
7
# File 'app/models/enums/profile_page_type.rb', line 5

def slug
  @slug
end

Class Method Details

.enabledObject



66
67
68
# File 'app/models/enums/profile_page_type.rb', line 66

def enabled
  all.reject(&:disabled?)
end

.find_by_params(params = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'app/models/enums/profile_page_type.rb', line 56

def find_by_params(params = {})
  if params[:mailing].present?
    mailing
  elsif params[:billing].present?
    billing
  else
    default
  end
end

.find_by_slug(slug) ⇒ Object



50
51
52
53
54
# File 'app/models/enums/profile_page_type.rb', line 50

def find_by_slug(slug)
  return first if slug.nil?

  all.detect { |type| type.slug == slug }
end

Instance Method Details

#build_form(params = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/enums/profile_page_type.rb', line 27

def build_form(params = {})
  if mailing?
    Account::MailingForm.new(params[:mailing])
  elsif billing?
    Account::BillingForm.new(params[:billing])
  else
    if params[:personal].present?
      Account::ProfileForm.new(params[:personal])
    elsif params[:email].present?
      Account::ProfileEmailForm.new(params[:email])
    elsif params[:password].present?
      Account::ProfilePasswordForm.new(params[:password])
    end
  end
end

#disabled?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/models/enums/profile_page_type.rb', line 17

def disabled?
  @disabled
end

#titleObject



13
14
15
# File 'app/models/enums/profile_page_type.rb', line 13

def title
  I18n.t(code, scope: [:account, :profile, :form_type_title])
end