Class: Sipity::Forms::CreateSipForm

Inherits:
BaseForm
  • Object
show all
Defined in:
app/forms/sipity/forms/create_sip_form.rb

Overview

Responsible for creating a new sip. What goes into this is more complicated that the entity might allow.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseForm

#persisted?, #submit, #to_key, #to_param

Constructor Details

#initialize(attributes = {}) ⇒ CreateSipForm



12
13
14
15
16
17
# File 'app/forms/sipity/forms/create_sip_form.rb', line 12

def initialize(attributes = {})
  @title = attributes[:title]
  @work_publication_strategy = attributes[:work_publication_strategy]
  @publication_date = attributes[:publication_date]
  self.collaborators_attributes = attributes[:collaborators_attributes]
end

Instance Attribute Details

#collaborators_attributesObject

Returns the value of attribute collaborators_attributes



32
33
34
# File 'app/forms/sipity/forms/create_sip_form.rb', line 32

def collaborators_attributes
  @collaborators_attributes
end

#publication_dateObject

Returns the value of attribute publication_date



21
22
23
# File 'app/forms/sipity/forms/create_sip_form.rb', line 21

def publication_date
  @publication_date
end

#titleObject

Returns the value of attribute title



19
20
21
# File 'app/forms/sipity/forms/create_sip_form.rb', line 19

def title
  @title
end

#work_publication_strategyObject

Returns the value of attribute work_publication_strategy



20
21
22
# File 'app/forms/sipity/forms/create_sip_form.rb', line 20

def work_publication_strategy
  @work_publication_strategy
end

Class Method Details

.model_nameObject



8
9
10
# File 'app/forms/sipity/forms/create_sip_form.rb', line 8

def self.model_name
  Models::Sip.model_name
end

Instance Method Details

#collaboratorsObject



28
29
30
# File 'app/forms/sipity/forms/create_sip_form.rb', line 28

def collaborators
  @collaborators || [Models::Collaborator.build_default]
end

#each_collaborator_must_be_validObject (private)



54
55
56
57
# File 'app/forms/sipity/forms/create_sip_form.rb', line 54

def each_collaborator_must_be_valid
  return true if Array.wrap(@collaborators).all?(&:valid?)
  errors.add(:collaborators_attributes, 'are incomplete')
end

#possible_work_publication_strategiesObject



48
49
50
# File 'app/forms/sipity/forms/create_sip_form.rb', line 48

def possible_work_publication_strategies
  Models::Sip.work_publication_strategies
end

#publication_date_required?Boolean (private)



59
60
61
# File 'app/forms/sipity/forms/create_sip_form.rb', line 59

def publication_date_required?
  work_publication_strategy == Models::Sip::ALREADY_PUBLISHED
end