dm-is-select 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/dm-is-select.gemspec +9 -12
- data/lib/dm-is-select/is/select.rb +11 -5
- data/lib/dm-is-select/is/version.rb +1 -1
- data/spec/integration/select_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -3
- metadata +20 -20
- data/spec/spec.opts +0 -1
data/Rakefile
CHANGED
@@ -12,8 +12,8 @@ begin
|
|
12
12
|
gem.homepage = "http://github.com/kematzy/dm-is-select"
|
13
13
|
gem.authors = ["kematzy"]
|
14
14
|
gem.extra_rdoc_files = %w[ README.rdoc LICENSE TODO History.rdoc ]
|
15
|
-
gem.add_dependency('dm-core', '>= 0.10.
|
16
|
-
gem.add_dependency('dm-more', '>= 0.10.0')
|
15
|
+
gem.add_dependency('dm-core', '>= 0.10.2')
|
16
|
+
# gem.add_dependency('dm-more', '>= 0.10.0')
|
17
17
|
# gem.add_dependency('dm-validations', '>= 0.10.0')
|
18
18
|
|
19
19
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
@@ -26,6 +26,7 @@ end
|
|
26
26
|
require 'spec/rake/spectask'
|
27
27
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
28
28
|
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.spec_opts = ["--color", "--format", "nested", "--require", "spec/spec_helper.rb"]
|
29
30
|
spec.spec_files = FileList['spec/**/*_spec.rb']
|
30
31
|
end
|
31
32
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/dm-is-select.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dm-is-select}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["kematzy"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-05-20}
|
13
13
|
s.description = %q{A DataMapper plugin that makes getting the <tt>select</tt> options from a Model easier.}
|
14
14
|
s.email = %q{kematzy@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,13 +31,12 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/dm-is-select/is/select.rb",
|
32
32
|
"lib/dm-is-select/is/version.rb",
|
33
33
|
"spec/integration/select_spec.rb",
|
34
|
-
"spec/spec.opts",
|
35
34
|
"spec/spec_helper.rb"
|
36
35
|
]
|
37
36
|
s.homepage = %q{http://github.com/kematzy/dm-is-select}
|
38
37
|
s.rdoc_options = ["--charset=UTF-8"]
|
39
38
|
s.require_paths = ["lib"]
|
40
|
-
s.rubygems_version = %q{1.3.
|
39
|
+
s.rubygems_version = %q{1.3.6}
|
41
40
|
s.summary = %q{A DataMapper plugin that makes getting the <tt>select</tt> options from a Model easier.}
|
42
41
|
s.test_files = [
|
43
42
|
"spec/integration/select_spec.rb",
|
@@ -49,14 +48,12 @@ Gem::Specification.new do |s|
|
|
49
48
|
s.specification_version = 3
|
50
49
|
|
51
50
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
|
-
s.add_runtime_dependency(%q<dm-core>, [">= 0.10.
|
53
|
-
s.add_runtime_dependency(%q<dm-more>, [">= 0.10.0"])
|
51
|
+
s.add_runtime_dependency(%q<dm-core>, [">= 0.10.2"])
|
54
52
|
else
|
55
|
-
s.add_dependency(%q<dm-core>, [">= 0.10.
|
56
|
-
s.add_dependency(%q<dm-more>, [">= 0.10.0"])
|
53
|
+
s.add_dependency(%q<dm-core>, [">= 0.10.2"])
|
57
54
|
end
|
58
55
|
else
|
59
|
-
s.add_dependency(%q<dm-core>, [">= 0.10.
|
60
|
-
s.add_dependency(%q<dm-more>, [">= 0.10.0"])
|
56
|
+
s.add_dependency(%q<dm-core>, [">= 0.10.2"])
|
61
57
|
end
|
62
58
|
end
|
59
|
+
|
@@ -29,17 +29,23 @@ module DataMapper
|
|
29
29
|
# => creates a <select> options array with the results ordered in hierarchical order
|
30
30
|
# parent > child > grandchild for each parent
|
31
31
|
#
|
32
|
+
# is :select, :name, :value_field => :code
|
33
|
+
# => creates a <select> options array with the results ordered in hierarchical order
|
34
|
+
# parent > child > grandchild for each parent
|
35
|
+
#
|
32
36
|
#
|
33
37
|
# @api public
|
34
38
|
def is_select(select_field = :name, options = {})
|
35
39
|
raise ArgumentError, "The :select_field, must be an existing attribute in the Model. Got [ #{select_field.inspect} ]" unless properties.any?{ |p| p.name == select_field.to_sym }
|
36
40
|
|
37
41
|
@select_options = {
|
42
|
+
:value_field => "id",
|
38
43
|
# add specical features if we are working with Tree Model
|
39
44
|
:is_tree => false
|
40
45
|
}.merge(options)
|
41
46
|
|
42
47
|
@select_field = select_field
|
48
|
+
@value_field = @select_options[:value_field]
|
43
49
|
|
44
50
|
|
45
51
|
# Add class & Instance methods
|
@@ -49,7 +55,7 @@ module DataMapper
|
|
49
55
|
end
|
50
56
|
|
51
57
|
module ClassMethods
|
52
|
-
attr_reader :select_field, :select_options
|
58
|
+
attr_reader :select_field, :select_options, :value_field
|
53
59
|
|
54
60
|
##
|
55
61
|
# Provides the Model content in a ready to use <tt><select></tt> options array
|
@@ -128,19 +134,19 @@ module DataMapper
|
|
128
134
|
|
129
135
|
if self.select_options[:is_tree]
|
130
136
|
mi.each do |x|
|
131
|
-
res << [x.
|
137
|
+
res << [x.send(self.value_field), x.send(self.select_field)]
|
132
138
|
unless x.children.blank?
|
133
139
|
x.children.each do |child|
|
134
|
-
res << [child.
|
140
|
+
res << [child.send(self.value_field), "-- #{child.send(self.select_field)}"]
|
135
141
|
child.children.each do |grand_child|
|
136
|
-
res << [ grand_child.
|
142
|
+
res << [ grand_child.send(self.value_field), "-- -- #{grand_child.send(self.select_field)}"]
|
137
143
|
end unless child.children.blank?
|
138
144
|
end
|
139
145
|
end
|
140
146
|
end
|
141
147
|
else
|
142
148
|
mi.each do |x|
|
143
|
-
res << [x.
|
149
|
+
res << [x.send(self.value_field), x.send(self.select_field)]
|
144
150
|
end
|
145
151
|
end
|
146
152
|
res
|
@@ -27,6 +27,16 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
27
27
|
auto_migrate!
|
28
28
|
end
|
29
29
|
|
30
|
+
|
31
|
+
class Country
|
32
|
+
include DataMapper::Resource
|
33
|
+
property :code, String, :key => true
|
34
|
+
property :name, String
|
35
|
+
is :select, :name, :value_field => :code
|
36
|
+
|
37
|
+
auto_migrate!
|
38
|
+
end #/ Country
|
39
|
+
|
30
40
|
5.times do |n|
|
31
41
|
Category.create(:name => "Category #{n+1}")
|
32
42
|
end
|
@@ -38,6 +48,9 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
38
48
|
grandchild = TreeCategory.create(:name => "TreeCategory-#{parent_id}-Child-GrandChild" , :parent_id => child.id )
|
39
49
|
end
|
40
50
|
|
51
|
+
3.times do |i|
|
52
|
+
Country.create(:code => "A#{i}", :name => "Country#{i}")
|
53
|
+
end
|
41
54
|
|
42
55
|
describe "Class Methods" do
|
43
56
|
|
@@ -272,6 +285,22 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
272
285
|
|
273
286
|
end #/ Tree Model
|
274
287
|
|
288
|
+
describe "A value_field model" do
|
289
|
+
|
290
|
+
it "should return the default select options when given no params" do
|
291
|
+
Country.items_for_select_menu.should == [
|
292
|
+
[nil, "Select Country"],
|
293
|
+
["nil", " ------ "],
|
294
|
+
['A0', "Country0"],
|
295
|
+
['A1', "Country1"],
|
296
|
+
['A2', "Country2"],
|
297
|
+
# [4, "Country3"],
|
298
|
+
# [5, "Country4"]
|
299
|
+
]
|
300
|
+
end
|
301
|
+
|
302
|
+
end #/ A value_field model
|
303
|
+
|
275
304
|
end #/ #item_for_select_menu
|
276
305
|
|
277
306
|
end #/ Class Methods
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-is-select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- kematzy
|
@@ -9,29 +14,23 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-05-20 00:00:00 +08:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: dm-core
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
25
|
-
-
|
26
|
-
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 10
|
30
|
+
- 2
|
31
|
+
version: 0.10.2
|
27
32
|
type: :runtime
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.10.0
|
34
|
-
version:
|
33
|
+
version_requirements: *id001
|
35
34
|
description: A DataMapper plugin that makes getting the <tt>select</tt> options from a Model easier.
|
36
35
|
email: kematzy@gmail.com
|
37
36
|
executables: []
|
@@ -56,7 +55,6 @@ files:
|
|
56
55
|
- lib/dm-is-select/is/select.rb
|
57
56
|
- lib/dm-is-select/is/version.rb
|
58
57
|
- spec/integration/select_spec.rb
|
59
|
-
- spec/spec.opts
|
60
58
|
- spec/spec_helper.rb
|
61
59
|
has_rdoc: true
|
62
60
|
homepage: http://github.com/kematzy/dm-is-select
|
@@ -71,18 +69,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
69
|
requirements:
|
72
70
|
- - ">="
|
73
71
|
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
74
|
version: "0"
|
75
|
-
version:
|
76
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
76
|
requirements:
|
78
77
|
- - ">="
|
79
78
|
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
80
81
|
version: "0"
|
81
|
-
version:
|
82
82
|
requirements: []
|
83
83
|
|
84
84
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.3.
|
85
|
+
rubygems_version: 1.3.6
|
86
86
|
signing_key:
|
87
87
|
specification_version: 3
|
88
88
|
summary: A DataMapper plugin that makes getting the <tt>select</tt> options from a Model easier.
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour
|