Class: Steroids::Support::NoticableMethods::NoticableRuntime

Inherits:
Object
  • Object
show all
Defined in:
lib/steroids/support/noticable_methods.rb

Overview


Noticable runtime class (attached to instance)


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(concern = [], success_notice: nil) ⇒ NoticableRuntime

Returns a new instance of NoticableRuntime.



71
72
73
74
75
76
# File 'lib/steroids/support/noticable_methods.rb', line 71

def initialize(concern = [], success_notice: nil)
  @concern = concern
  @success_notice = success_notice.presence || success_notice_placeholder
  @errors = NoticableCollection.new(:errors)
  @notices = NoticableCollection.new(:notices)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



69
70
71
# File 'lib/steroids/support/noticable_methods.rb', line 69

def errors
  @errors
end

#noticesObject (readonly)

Returns the value of attribute notices.



68
69
70
# File 'lib/steroids/support/noticable_methods.rb', line 68

def notices
  @notices
end

Instance Method Details

#errors?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/steroids/support/noticable_methods.rb', line 89

def errors?
  @errors.any?
end

#full_messagesObject Also known as: notice, message



78
79
80
81
82
83
84
# File 'lib/steroids/support/noticable_methods.rb', line 78

def full_messages
  if self.errors?
    @errors.full_messages
  else
    @notices.full_messages.presence || @success_notice
  end
end

#merge(noticable) ⇒ Object



97
98
99
100
# File 'lib/steroids/support/noticable_methods.rb', line 97

def merge(noticable)
  @notices.merge(noticable.notices)
  @errors.merge(noticable.errors)
end

#success?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/steroids/support/noticable_methods.rb', line 93

def success?
  !errors?
end