Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

changed to store the instance variable in the parent of DataMagic

  • Loading branch information...
commit e587f9e2a6532b5abba53b13d88e1b442f0d76f9 1 parent a01cf7d
@cheezy authored
Showing with 21 additions and 3 deletions.
  1. +4 −0 ChangeLog
  2. +4 −1 lib/data_magic.rb
  3. +13 −2 lib/data_magic/translation.rb
View
4 ChangeLog
@@ -1,3 +1,7 @@
+=== Version 0.15
+* Enhancements
+ * Added sequential translator
+
=== Version 0.14 / 2013-2-14
* Enhancements
* Added months_abbr translator
View
5 lib/data_magic.rb
@@ -8,7 +8,10 @@
module DataMagic
extend YmlReader
+ attr_reader :parent
+
def self.included(cls)
+ @parent = cls
translators.each do |translator|
Translation.send :include, translator
end
@@ -37,7 +40,7 @@ def translate(value)
end
def translation
- @translation ||= Translation.new
+ @translation ||= Translation.new parent
end
class << self
View
15 lib/data_magic/translation.rb
@@ -4,6 +4,12 @@ module DataMagic
class Translation
include DateTranslation
+ attr_reader :parent
+
+ def initialize(parent)
+ @parent = parent
+ end
+
#
# return a random name (first and last)
#
@@ -227,6 +233,11 @@ def randomize(value)
end
alias_method :dm_randomize, :randomize
+ #
+ # return an element from the array. The first request will return
+ # the first element, the second request will return the second,
+ # and so forth.
+ #
def sequential(value)
index = index_variable_for(value)
index = (index ? index + 1 : 0)
@@ -259,11 +270,11 @@ def mask(value)
private
def set_index_variable(ary, value)
- instance_variable_set(index_name(ary), value)
+ parent.instance_variable_set(index_name(ary), value)
end
def index_variable_for(ary)
- instance_variable_get(index_name(ary))
+ parent.instance_variable_get(index_name(ary))
end
def index_name(ary)
Please sign in to comment.
Something went wrong with that request. Please try again.