Module: Sencha::Model::Util

Defined in:
lib/sencha-model/model.rb

Class Method Summary collapse

Class Method Details

.extract_fieldset_and_options(arguments) ⇒ {Symbol}, {Hash}

returns the fieldset from the arguments and normalizes the options.

Returns:

  • ({Symbol}, {Hash})


344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/sencha-model/model.rb', line 344

def self.extract_fieldset_and_options arguments
  orig_args = arguments
  fieldset = :default
  options = { # default options
    :visited_classes => [],
    :fields => []
  }
  if arguments.size > 2 || (arguments.size == 2 && !arguments[0].is_a?(Symbol))
    raise ArgumentError, "Don't know how to handle #{arguments.inspect}"
  elsif arguments.size == 2 && arguments[0].is_a?(Symbol)
    fieldset = arguments.shift
    if arguments[0].is_a?(Array)
      options.update({
        :fields => arguments[0]
      })
    elsif arguments[0].is_a?(Hash)
      options.update(arguments[0])
    end
  elsif arguments.size == 1 && (arguments[0].is_a?(Symbol) || arguments[0].is_a?(String))
    fieldset = arguments.shift.to_sym
  elsif arguments.size == 1 && arguments[0].is_a?(Hash)
    fieldset = arguments[0].delete(:fieldset) || :default
    options.update(arguments[0])
  end
  [fieldset, options]
end