booleanize 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/Rakefile +2 -2
- data/lib/booleanize.rb +7 -11
- metadata +28 -43
data/README.rdoc
CHANGED
@@ -97,7 +97,7 @@ Just clone the plugin inside <tt>RAILS_ROOT/vendor/plugins</tt>
|
|
97
97
|
|
98
98
|
=== Rails 3
|
99
99
|
|
100
|
-
The 0.
|
100
|
+
The 0.5 version and above is suited for use with Rails 3. For previous versions, it will work but you'll get lots of warnings.
|
101
101
|
|
102
102
|
== Running the tests
|
103
103
|
|
data/Rakefile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
-
require '
|
3
|
+
require 'rdoc/task'
|
4
4
|
|
5
5
|
desc 'Default: run unit tests.'
|
6
6
|
task :default => :spec
|
7
7
|
|
8
8
|
RSpec::Core::RakeTask.new do |t|
|
9
9
|
t.spec_opts = ["--color", "--format", "specdoc"]
|
10
|
-
end
|
10
|
+
end
|
11
11
|
|
12
12
|
desc 'Generate documentation for the booleanize plugin.'
|
13
13
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
data/lib/booleanize.rb
CHANGED
@@ -6,9 +6,9 @@
|
|
6
6
|
# = Description
|
7
7
|
#
|
8
8
|
# Creates two instance methods and two scopes for each of the received boolean attributes.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# == Instance methods
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Creates a attr_name_humanize for each boolean attribute, which returns a specific string for each boolean true or false.
|
13
13
|
# Creates a attr_name? method for each boolean attribute.
|
14
14
|
#
|
@@ -55,9 +55,9 @@ module Booleanize
|
|
55
55
|
|
56
56
|
class Config
|
57
57
|
include Singleton
|
58
|
-
|
58
|
+
|
59
59
|
attr_accessor :default_for_true, :default_for_false
|
60
|
-
|
60
|
+
|
61
61
|
def self.default_strings(options = {})
|
62
62
|
error = "Wrong configuration parameters for booleanize: You should pass something like {:true => \"Yes\", :false => \"No\" }"
|
63
63
|
raise error unless options.is_a?(Hash) and [:true, :false].all? { |k| options.has_key? k }
|
@@ -83,22 +83,18 @@ module Booleanize
|
|
83
83
|
|
84
84
|
private
|
85
85
|
def create_true_scope(attr_name)
|
86
|
-
|
86
|
+
scope attr_name, lambda { where attr_name => true }
|
87
87
|
end
|
88
88
|
|
89
89
|
def create_false_scope(attr_name)
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
def create_scope(params)
|
94
|
-
Rails.version > "2.3.8" ? scope(*params) : named_scope(*params)
|
90
|
+
scope :"not_#{attr_name}", lambda { where attr_name => false }
|
95
91
|
end
|
96
92
|
|
97
93
|
def create_humanize_method(attr_name, true_str, false_str)
|
98
94
|
true_str = (true_str.nil? ? (Config.default_for_true.nil? ? "True" : Config.default_for_true) : true_str.to_s)
|
99
95
|
false_str = (false_str.nil? ? (Config.default_for_false.nil? ? "False" : Config.default_for_false) : false_str.to_s)
|
100
96
|
class_eval("def #{attr_name}_humanize; #{attr_name} ? #{true_str.inspect} : #{false_str.inspect}; end")
|
101
|
-
|
97
|
+
|
102
98
|
end
|
103
99
|
|
104
100
|
def create_methods(attr_name, true_str = nil, false_str = nil)
|
metadata
CHANGED
@@ -1,32 +1,24 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: booleanize
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
version: "0.5"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.6'
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
12
|
-
-
|
7
|
+
authors:
|
8
|
+
- Cássio Marques
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2010-09-03 00:00:00 -03:00
|
18
|
-
default_executable:
|
12
|
+
date: 2015-05-10 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
|
-
|
14
|
+
description: A Rails plugin that adds some new methods for boolean attributes in Active
|
15
|
+
Record models.
|
22
16
|
email: cassiommc@gmail.com
|
23
17
|
executables: []
|
24
|
-
|
25
18
|
extensions: []
|
26
|
-
|
27
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
28
20
|
- README.rdoc
|
29
|
-
files:
|
21
|
+
files:
|
30
22
|
- CHANGELOG
|
31
23
|
- MIT-LICENSE
|
32
24
|
- README.rdoc
|
@@ -35,41 +27,34 @@ files:
|
|
35
27
|
- lib/booleanize.rb
|
36
28
|
- spec/booleanize_spec.rb
|
37
29
|
- spec/db/create_testing_structure.rb
|
38
|
-
has_rdoc: true
|
39
30
|
homepage: http://github.com/cassiomarques/booleanize
|
40
31
|
licenses: []
|
41
|
-
|
42
32
|
post_install_message:
|
43
|
-
rdoc_options:
|
33
|
+
rdoc_options:
|
44
34
|
- --main
|
45
35
|
- README.rdoc
|
46
|
-
require_paths:
|
36
|
+
require_paths:
|
47
37
|
- lib
|
48
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
49
43
|
none: false
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
- 0
|
56
|
-
version: "0"
|
57
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
58
49
|
none: false
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
hash: 3
|
63
|
-
segments:
|
64
|
-
- 0
|
65
|
-
version: "0"
|
66
50
|
requirements: []
|
67
|
-
|
68
51
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.
|
52
|
+
rubygems_version: 1.8.24
|
70
53
|
signing_key:
|
71
54
|
specification_version: 3
|
72
|
-
summary: A Rails plugin that adds some new methods for boolean attributes in Active
|
73
|
-
|
55
|
+
summary: A Rails plugin that adds some new methods for boolean attributes in Active
|
56
|
+
Record models.
|
57
|
+
test_files:
|
74
58
|
- spec/booleanize_spec.rb
|
75
59
|
- spec/db/create_testing_structure.rb
|
60
|
+
has_rdoc: true
|