Class: ROXML::Opts
Overview
:nodoc:
Instance Attribute Summary collapse
-
#accessor ⇒ Object
readonly
Returns the value of attribute accessor.
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #array? ⇒ Boolean
- #cdata? ⇒ Boolean
- #content? ⇒ Boolean
- #hash? ⇒ Boolean
-
#initialize(sym, *args, &block) ⇒ Opts
constructor
A new instance of Opts.
- #required? ⇒ Boolean
- #variable_name ⇒ Object
- #wrapper ⇒ Object
Constructor Details
#initialize(sym, *args, &block) ⇒ Opts
Returns a new instance of Opts.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/roxml/options.rb', line 94 def initialize(sym, *args, &block) @accessor = sym @opts = (args) @default = @opts.delete(:else) @opts.reverse_merge!(:as => [], :in => nil) @opts[:as] = [*@opts[:as]] @type = extract_type(args) @opts[:as] << :bool if @accessor.to_s.ends_with?('?') if @type.respond_to?(:xml_name?) && @type.xml_name? unless self.class.silence_xml_name_warning? warn "WARNING: As of 2.3, a breaking change has been in the naming of sub-objects. " + "ROXML now considers the xml_name of the sub-object before falling back to the accessor name of the parent. " + "Use :from on the parent declaration to override this behavior. Set ROXML::SILENCE_XML_NAME_WARNING to avoid this message." self.class.silence_xml_name_warning! end @opts[:from] ||= @type.tag_name else @opts[:from] ||= variable_name end @blocks = collect_blocks(block, @opts[:as]) @name = @opts[:from].to_s @name = @name.singularize if hash? || array? if hash? && (hash.key.name? || hash.value.name?) @name = '*' end raise ArgumentError, "Can't specify both :else default and :required" if required? && default end |
Instance Attribute Details
#accessor ⇒ Object (readonly)
Returns the value of attribute accessor.
82 83 84 |
# File 'lib/roxml/options.rb', line 82 def accessor @accessor end |
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
82 83 84 |
# File 'lib/roxml/options.rb', line 82 def blocks @blocks end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
82 83 84 |
# File 'lib/roxml/options.rb', line 82 def default @default end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
82 83 84 |
# File 'lib/roxml/options.rb', line 82 def hash @hash end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
82 83 84 |
# File 'lib/roxml/options.rb', line 82 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
82 83 84 |
# File 'lib/roxml/options.rb', line 82 def type @type end |
Class Method Details
.silence_xml_name_warning! ⇒ Object
89 90 91 |
# File 'lib/roxml/options.rb', line 89 def silence_xml_name_warning! @silence_xml_name_warning = true end |
Instance Method Details
#array? ⇒ Boolean
144 145 146 |
# File 'lib/roxml/options.rb', line 144 def array? @opts[:as].include? :array end |
#cdata? ⇒ Boolean
148 149 150 |
# File 'lib/roxml/options.rb', line 148 def cdata? @opts[:as].include? :cdata end |
#content? ⇒ Boolean
140 141 142 |
# File 'lib/roxml/options.rb', line 140 def content? @type == :content end |
#hash? ⇒ Boolean
136 137 138 |
# File 'lib/roxml/options.rb', line 136 def hash? @type == :hash end |
#required? ⇒ Boolean
156 157 158 |
# File 'lib/roxml/options.rb', line 156 def required? @opts[:required] end |
#variable_name ⇒ Object
128 129 130 |
# File 'lib/roxml/options.rb', line 128 def variable_name accessor.to_s.ends_with?('?') ? accessor.to_s.chomp('?') : accessor.to_s end |
#wrapper ⇒ Object
152 153 154 |
# File 'lib/roxml/options.rb', line 152 def wrapper @opts[:in] end |