Class: ApiMaker::DeepMergeParams
- Inherits:
-
ApplicationService
- Object
- ServicePattern::Service
- ApplicationService
- ApiMaker::DeepMergeParams
- Defined in:
- app/services/api_maker/deep_merge_params.rb
Instance Attribute Summary collapse
-
#hash1 ⇒ Object
readonly
Returns the value of attribute hash1.
-
#hash2 ⇒ Object
readonly
Returns the value of attribute hash2.
Instance Method Summary collapse
-
#initialize(hash1, hash2) ⇒ DeepMergeParams
constructor
A new instance of DeepMergeParams.
- #perform ⇒ Object
Methods inherited from ApplicationService
Constructor Details
#initialize(hash1, hash2) ⇒ DeepMergeParams
Returns a new instance of DeepMergeParams.
4 5 6 7 |
# File 'app/services/api_maker/deep_merge_params.rb', line 4 def initialize(hash1, hash2) @hash1 = hash1 @hash2 = hash2 end |
Instance Attribute Details
#hash1 ⇒ Object (readonly)
Returns the value of attribute hash1.
2 3 4 |
# File 'app/services/api_maker/deep_merge_params.rb', line 2 def hash1 @hash1 end |
#hash2 ⇒ Object (readonly)
Returns the value of attribute hash2.
2 3 4 |
# File 'app/services/api_maker/deep_merge_params.rb', line 2 def hash2 @hash2 end |
Instance Method Details
#perform ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/api_maker/deep_merge_params.rb', line 9 def perform merged_hash = hash1.deep_merge(hash2) do |_key, this_val, other_val| if this_val.is_a?(Array) && other_val.is_a?(Array) && this_val.length == other_val.length this_val.zip(other_val).collect do |a, b| if a.is_a?(Hash) && b.is_a?(Hash) a.deep_merge(b) else other_val end end else other_val end end succeed! merged_hash end |