Class: Neutral::VotingBuilder::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/neutral/voting_builder/router.rb

Instance Method Summary collapse

Constructor Details

#initialize(vote) ⇒ Router

Returns a new instance of Router.



6
7
8
# File 'lib/neutral/voting_builder/router.rb', line 6

def initialize(vote)
  @vote = vote
end

Instance Method Details

#[](element) ⇒ Object



10
11
12
# File 'lib/neutral/voting_builder/router.rb', line 10

def [](element)
  send element
end

#negativeObject



22
23
24
25
26
27
28
# File 'lib/neutral/voting_builder/router.rb', line 22

def negative
  if persisted?
    { path: vote_path(vote, value: 0), method: 'patch' }
  else
    { path: votes_path(vote: vote.main_attributes.merge(value: 0)), method: 'post' }
  end
end

#positiveObject



14
15
16
17
18
19
20
# File 'lib/neutral/voting_builder/router.rb', line 14

def positive
  if persisted?
    { path: vote_path(vote, value: 1), method: 'patch' }
  else
    { path: votes_path(vote: vote.main_attributes.merge(value: 1)), method: 'post' }
  end
end

#removeObject



30
31
32
33
# File 'lib/neutral/voting_builder/router.rb', line 30

def remove
  raise "Remove path for non-existent vote cannot be obtained" unless persisted?
  { path: vote_path(vote), method: 'delete' }
end