.attribute(name, options = {}) ⇒ Object

Links the specification of values in the scaffold file to the assignment of
instance variables.

Examples:

Simple specification

classMyRegion<Scaffolder::Regionattribute:value# "value" usable as a keyword in the scaffold file
end

Specification with a default value

attribute:value,:default=>1

Specification with where proc is evaluated for the default

attribute:value,:default=>lamdba{Time.now.to_s}

Specification with proc where the region instance is avaiable

attribute:value,:default=>lamdba{|s|s.other_variable+1}

Parameters:

Define(Symbol)
—

attributes for this type of scaffold region. Attributes are read from the
scaffold file and stored as instance variables.

options(Hash)(defaults to: {})
—

Attribute options.

Options Hash (options):

Default(Object, Proc)
—

Specify a default value for this attribute if a value is not defined in the
scaffold file.

34
35
36
37
38
39
40
41
42
43
44
45

# File 'lib/scaffolder/region.rb', line 34defattribute(name,options={})define_method(name)do|*arg|var="@#{name}"default=options[:default]unlessarg.first# Is an argument is passed to the method?
value=instance_variable_get(var)returnvalueifvaluereturndefault.respond_to?(:call)?default.call(self):defaultendinstance_variable_set(var,arg.first)endend