Class: Neutral::VotingBuilder::Router
- Inherits:
-
Object
- Object
- Neutral::VotingBuilder::Router
- Defined in:
- lib/neutral/voting_builder/router.rb
Instance Method Summary collapse
- #[](element) ⇒ Object
-
#initialize(vote) ⇒ Router
constructor
A new instance of Router.
- #negative ⇒ Object
- #positive ⇒ Object
- #remove ⇒ Object
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 |
#negative ⇒ Object
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 |
#positive ⇒ Object
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 |
#remove ⇒ Object
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 |