Module: ChefWorkflow::AttrSupport

Included in:
EC2Support, GeneralSupport, IPSupport, KnifeSupport, Scheduler, VagrantSupport
Defined in:
lib/chef-workflow/support/attr.rb

Overview

Mixin to make exposing attr modification via ‘instance_eval` easier.

Instance Method Summary collapse

Instance Method Details

#fancy_attr(name) ⇒ Object

Defines an attribute that is both a standard writer, but with an overloaded reader that accepts an optional argument. Equivalent to this code for ‘foo`:

attr_writer :foo

def foo(*args)
  if args.count > 0
    @foo = arg
  end

  @foo
end


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/chef-workflow/support/attr.rb', line 20

def fancy_attr(name)
  class_eval "    attr_writer :\#{name}\n    def \#{name}(*args)\n      if args.count > 0\n        @\#{name} = args.first\n      end\n\n      @\#{name}\n    end\n  EOF\nend\n"