Skip to content

Commit

Permalink
Shuffle around some internal variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
Empact committed Mar 3, 2009
1 parent 226c36d commit a7021fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/roxml.rb
Expand Up @@ -414,14 +414,14 @@ def xml_reader(*syms, &block)
def xml_accessor(*syms, &block)
xml_attr(*syms, &block).each do |attr|
add_reader(attr)
attr_writer(attr.variable_name)
attr_writer(attr.attr_name)
end
end

private
def add_reader(attr)
define_method(attr.accessor) do
instance_variable_get("@#{attr.variable_name}")
instance_variable_get(attr.instance_variable_name)
end
end
end
Expand Down Expand Up @@ -487,7 +487,7 @@ def from_xml(data, *initialization_args)
value = attr.to_ref(inst).value_in(xml)
inst.respond_to?(attr.setter) \
? inst.send(attr.setter, value) \
: inst.instance_variable_set("@#{attr.variable_name}", value)
: inst.instance_variable_set(attr.instance_variable_name, value)
end
inst.try(:after_parse)
end
Expand Down
11 changes: 6 additions & 5 deletions lib/roxml/definition.rb
Expand Up @@ -12,7 +12,7 @@ def bool_attr_reader(*attrs)

module ROXML
class Definition # :nodoc:
attr_reader :name, :type, :wrapper, :hash, :blocks, :accessor, :to_xml
attr_reader :name, :type, :wrapper, :hash, :blocks, :accessor, :to_xml, :attr_name
bool_attr_reader :name_explicit, :array, :cdata, :required, :frozen

def initialize(sym, opts = {}, &block)
Expand Down Expand Up @@ -65,7 +65,8 @@ def initialize(sym, opts = {}, &block)
opts[:from].sub!('@', '')
end

@name = (opts[:from] || variable_name).to_s
@attr_name = accessor.to_s.chomp('?')
@name = (opts[:from] || @attr_name).to_s
@name = @name.singularize if hash? || array?
if hash? && (hash.key.name? || hash.value.name?)
@name = '*'
Expand All @@ -74,12 +75,12 @@ def initialize(sym, opts = {}, &block)
raise ArgumentError, "Can't specify both :else default and :required" if required? && @default
end

def variable_name
accessor.to_s.chomp('?')
def instance_variable_name
:"@#{attr_name}"
end

def setter
:"#{variable_name}="
:"#{attr_name}="
end

def hash
Expand Down
2 changes: 1 addition & 1 deletion lib/roxml/xml/references.rb
Expand Up @@ -6,7 +6,7 @@ class RequiredElementMissing < Exception # :nodoc:
# Internal base class that represents an XML - Class binding.
#
class XMLRef # :nodoc:
delegate :required?, :array?, :blocks, :accessor, :variable_name, :default, :to => :opts
delegate :required?, :array?, :blocks, :accessor, :default, :to => :opts

def initialize(opts, instance)
@opts = opts
Expand Down

0 comments on commit a7021fd

Please sign in to comment.