Sha256: 393ac8a7fc0d07d740ae20c053a08210f0c2d350df9aaef4f58b605ab46969f1
Contents?: true
Size: 1.2 KB
Versions: 17
Compression:
Stored size: 1.2 KB
Contents
module Shamu module Attributes # 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( '...' ) module FluidAssignment extend ActiveSupport::Concern included do |base| raise "Must include Shamu::Attributes first." unless base < Shamu::Attributes raise "Must include Shamu::Attributes::Assignment first." unless base < Shamu::Attributes::Assignment end # DSL for declaring fluid assignment. class_methods do private 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 end end end end
Version data entries
17 entries across 17 versions & 1 rubygems