Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6714 from bgeuken/update_arch_controller
Refactor architecture controller service
- Loading branch information
Showing
3 changed files
with
9 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
src/api/app/services/architectures_controller_service/architecture_updater.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
module ArchitecturesControllerService | ||
class ArchitectureUpdater | ||
def initialize(archs) | ||
@archs = archs | ||
@all_valid = true | ||
def initialize(params) | ||
@archs = params.require(:archs).permit! | ||
@all_valid = false | ||
end | ||
|
||
def call | ||
@archs.each do |name, value| | ||
@all_valid = @archs.to_h.map do |name, value| | ||
arch = Architecture.find_by(name: name) | ||
arch.available = value | ||
@all_valid &&= arch.save | ||
arch.save | ||
end | ||
|
||
self | ||
end | ||
|
||
def valid? | ||
@all_valid | ||
@all_valid.all? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters