module Shamu::Attributes::FluidAssignment

Add methods to a class to make it easy to build out an object using fluid assignment.

@example

# Without fluid
obj = AttributeObject.new
obj.name = '...'
obj.email = '...'

# With fluid
obj = FluidObject.new
obj.name( '...' )
   .email( '...' )

Public Instance Methods

define_attribute_reader( name, ** ) click to toggle source
# File lib/shamu/attributes/fluid_assignment.rb, line 31
          def define_attribute_reader( name, ** )
            class_eval <<-RUBY, __FILE__, __LINE__ + 1
              def #{ name }( *args )
                if args.length > 0
                  assign_#{ name }( *args )
                  self
                else
                  return @#{ name } if defined? @#{ name }
                  @#{ name } = fetch_#{ name }
                end
              end
            RUBY
          end