cassiomarques-booleanize 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 0.2.1 (06 May 2009)
2
+ * Ruby 1.9 Support
3
+ * Booleanize::Config class as Singleton
4
+ * Fixes on the tests to run on Ruby 1.9
5
+
1
6
  0.2.0 (02 Dec 2008)
2
7
  * Now booleanize will receive symbols, arrays or hashes as parameters.
3
8
 
data/lib/booleanize.rb CHANGED
@@ -49,27 +49,33 @@
49
49
  # active_users = User.active #=> same as named_scope :active, :conditions => {:active => true}
50
50
  # disabled_users = User.not_active #=> same as named_scope :not_active, :conditions => {:active => false}
51
51
  #
52
+ require 'singleton'
53
+
52
54
  module Booleanize
53
55
 
54
56
  class Config
57
+ include Singleton
58
+
59
+ attr_accessor :default_for_true, :default_for_false
60
+
55
61
  def self.default_strings(options = {})
56
62
  error = "Wrong configuration parameters for booleanize: You should pass something like {:true => \"Yes\", :false => \"No\" }"
57
63
  raise error unless options.is_a?(Hash) and [:true, :false].all? { |k| options.has_key? k }
58
- @@default_for_true = options[:true]
59
- @@default_for_false = options[:false]
64
+ instance.default_for_true = options[:true]
65
+ instance.default_for_false = options[:false]
60
66
  end
61
67
 
62
68
  protected
63
- def self.default_for_true; @@default_for_true rescue nil; end
64
- def self.default_for_false; @@default_for_false rescue nil; end
69
+ def self.default_for_true; instance.default_for_true rescue nil; end
70
+ def self.default_for_false; instance.default_for_false rescue nil; end
65
71
  end
66
72
 
67
73
  def booleanize(*params)
68
74
  params.each do |param|
69
75
  case param
70
- when Symbol: create_methods_for_symbol(param)
71
- when Array: create_methods_for_array(param)
72
- when Hash: create_methods_for_hash(param)
76
+ when Symbol; create_methods_for_symbol(param)
77
+ when Array; create_methods_for_array(param)
78
+ when Hash; create_methods_for_hash(param)
73
79
  else raise_error
74
80
  end
75
81
  end
@@ -89,6 +95,7 @@ module Booleanize
89
95
  true_str = (true_str.nil? ? (Config.default_for_true.nil? ? "True" : Config.default_for_true) : true_str.to_s)
90
96
  false_str = (false_str.nil? ? (Config.default_for_false.nil? ? "False" : Config.default_for_false) : false_str.to_s)
91
97
  class_eval("def #{attr_name}_humanize; #{attr_name} ? #{true_str.inspect} : #{false_str.inspect}; end")
98
+
92
99
  end
93
100
 
94
101
  def create_methods(attr_name, true_str = nil, false_str = nil)
@@ -126,4 +133,4 @@ module Booleanize
126
133
 
127
134
  end
128
135
 
129
- ActiveRecord::Base.extend Booleanize
136
+ ActiveRecord::Base.send(:extend, Booleanize)
@@ -202,7 +202,8 @@ describe "booleanize" do
202
202
  describe "with global configuration" do
203
203
  before do
204
204
  Booleanize::Config.default_strings :true => "Oh yes!", :false => "Nooo"
205
- class User
205
+
206
+ User.class_eval do
206
207
  booleanize :active
207
208
  booleanize :smart => ["Too smart", "Duh!"]
208
209
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassiomarques-booleanize
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - "C\xC3\xA1ssio Marques"