163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/magnetic/field.rb', line 163
def field *argv, &block
name = argv.delete_first{|arg| String === arg or Symbol === arg }
base = argv.delete_first{|arg| Field::Base.class === arg}
configuring = argv.delete_first{|arg| ['configure', :configure, 'configuring', :configuring].include? arg}
options = argv.delete_first{|arg| Hash === arg}
name ||= base.name
raise ArgumentError, 'nameless field!' unless name
name = name.to_s
if options.nil? and base.nil? and block.nil?
field = field_for name
field.clone unless field.nil?
else
options ||= {}
options.to_options!
field =
if configuring
field_for name
else
base ||= Field::Base
field = base.clone
field.name = name
field.owner = self
field
end
field.configure options, &block
unless configuring
raise ArgumentError, "duplicate field '#{ name }' in #{ fieldset[name].inspect }" if fieldset.has_key?(field.name)
fieldset[field.name] = field
end
field
end
end
|