Module: Saxomattic::ClassMethods

Defined in:
lib/saxomattic.rb

Instance Method Summary collapse

Instance Method Details

#_active_attr_attributes(options_hash = {}) ⇒ Object



76
77
78
# File 'lib/saxomattic.rb', line 76

def _active_attr_attributes(options_hash = {})
  options_hash.slice!(::Saxomattic::ACTIVE_ATTR_ATTRIBUTES)
end

#_sax_machine_attributes(options_hash = {}) ⇒ Object



80
81
82
# File 'lib/saxomattic.rb', line 80

def _sax_machine_attributes(options_hash = {})
  options_hash.slice!(::Saxomattic::SAX_MACHINE_ATTRIBUTES)
end

#attribute(*args) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/saxomattic.rb', line 50

def attribute(*args)
  options = args.extract_options!
  field = args.first

  # If you want to setup a default set of elements, you can!
  # :default => [ true, false, false, true ]
  if options[:elements] && !options[:elements].kind_of?(Array)
    options.merge!(:default => [])
  end

  _active_attr_attribute(field, _active_attr_attributes(options.dup))

  case
  when options[:ancestor] then
    _sax_machine_ancestor(field, _sax_machine_attributes(options.dup))
  when options[:attribute] then
    _sax_machine_attribute(field, _sax_machine_attributes(options.dup))
  when options[:elements] then
    _sax_machine_elements(field, _sax_machine_attributes(options.dup))
  when options[:value] then
    _sax_machine_value(field, _sax_machine_attributes(options.dup))
  else # Default state is an element
    _sax_machine_element(field, _sax_machine_attributes(options.dup))
  end
end