benhamill / assembler

Block-based initializers for your Ruby objects.
https://github.com/benhamill/assembler#readme
MIT License
1 stars 0 forks source link

Extend Builder with attribute accessors #16

Closed kerinin closed 10 years ago

kerinin commented 10 years ago

Allows values to be read from the builder during construction and after being coerced. For example:

class Foo
   extend Assembler
   assemble_from_options :number, coerce: :to_i
   assemble_from name: nil, name_prefix: 'prefix', bignumber: false
end
Foo.new(number: '10') do |foo|
  foo.bignumber = true if foo.bar > 5
  foo.name ||= "#{foo.name_prefix}_suffix"
end

This should allow us to do some really neat stuff around conditional assignment and input munging

kerinin commented 10 years ago

@benhamill OK, I remember what this was about now - see what you think

benhamill commented 10 years ago

:+1:

benhamill commented 10 years ago

Oh wait. Edit CHANGES.md and maybe the README first?

kerinin commented 10 years ago

@benhamill Good call on docs - does that explanation & example work for you?

benhamill commented 10 years ago

That's great! Merge this and I'll rebase my branch again and do my edits.

benhamill commented 10 years ago

@kerinin Clean up your old branches. Were you raised in a barn? :wink: