Skip to content
Browse files

mmm, fancy accessor magic

  • Loading branch information...
1 parent d1d9469 commit 9375382f115a9588c2a248087d0f12c818010abc @jnicklas committed Jun 4, 2008
Showing with 11 additions and 2 deletions.
  1. +2 −2 lib/gibberish_attributes.rb
  2. +9 −0 spec/gibberish_attributes_spec.rb
View
4 lib/gibberish_attributes.rb
@@ -19,8 +19,8 @@ module ClassMethods
def translate(*attrs)
attrs.each do |attr|
self.class_eval <<-CLASS
- def #{attr}
- get_value_for_translation(:#{attr}, Gibberish.current_language)
+ def #{attr}(lang = nil)
+ get_value_for_translation(:#{attr}, lang || Gibberish.current_language)
end
def #{attr}=(value)
View
9 spec/gibberish_attributes_spec.rb
@@ -16,6 +16,15 @@
@instance.title.should == 'monkey'
end
+ it "should create a reader, which accesses a specific language with an argument" do
+ Gibberish.should_not_receive(:current_language)
+ @class.translate :title
+
+ @instance.should_receive(:title_de).and_return('affe')
+
+ @instance.title(:de).should == 'affe'
+ end
+
it "should create a writer, which accesses the default language (en)" do
Gibberish.should_receive(:current_language).and_return(:en)
@class.translate :title

0 comments on commit 9375382

Please sign in to comment.
Something went wrong with that request. Please try again.