Class: Shark::SurveyParticipant

Inherits:
Base
  • Object
show all
Extended by:
Shark::SurveyService::Resource
Defined in:
lib/shark/survey_participant.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

add_datetime_accessors

Class Method Details

.create(attributes) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/shark/survey_participant.rb', line 17

def self.create(attributes)
  attributes_copy = attributes.symbolize_keys
  survey_id = attributes_copy.delete(:survey_id)
  raise ArgumentError, 'Missing attribute :survey_id' unless survey_id

  participant = new(attributes_copy)
  participant.relationships.survey = { data: { id: survey_id } }
  participant.save

  participant
end

.find(*args) ⇒ Object



13
14
15
# File 'lib/shark/survey_participant.rb', line 13

def self.find(*args)
  super.first
end

.table_nameObject



9
10
11
# File 'lib/shark/survey_participant.rb', line 9

def self.table_name
  'participants'
end

Instance Method Details

#participateObject



33
34
35
# File 'lib/shark/survey_participant.rb', line 33

def participate
  update(state: 'participated')
end

#participated?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/shark/survey_participant.rb', line 29

def participated?
  state == 'participated'
end