DEFRA / ruby-services-team

Guides, info and issue management for the Ruby Services team
Other
1 stars 3 forks source link

Refactor form object attribute assignments #72

Closed Cruikshanks closed 4 years ago

Cruikshanks commented 5 years ago

Originated from https://eaflood.atlassian.net/browse/RUBY-309

We have a lot of form objects that look like this:

attr_accessor :foo, :bar, :baz

def initialize(registration)
  self.foo = @transient_registration.foo
  self.bar = @transient_registration.bar
  self.baz = @transient_registration.baz
end

This seems like a prime candidate for refactoring. Then we could set the variables once as a constant, rather than having the current repetitive situation.

This came out of a code review here: https://github.com/DEFRA/waste-exemptions-engine/pull/139#discussion_r279315668

cintamani commented 4 years ago

This has been addressed using delegate