maiha-dm-ys 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/dm-ys.rb +1 -0
- data/lib/dm-ys/base.rb +1 -0
- data/lib/dm-ys/indexed_property.rb +31 -0
- data/lib/dm-ys/proxy.rb +3 -1
- data/spec/indexed_property_spec.rb +37 -0
- metadata +4 -3
data/Rakefile
CHANGED
@@ -33,7 +33,7 @@ AUTHOR = "maiha"
|
|
33
33
|
EMAIL = "maiha@wota.jp"
|
34
34
|
HOMEPAGE = "http://github.com/maiha/dm-ys"
|
35
35
|
SUMMARY = "a DataMapper extension that uses html table as its schema and data powerfully like YunkerStar"
|
36
|
-
GEM_VERSION = "0.2.
|
36
|
+
GEM_VERSION = "0.2.2"
|
37
37
|
|
38
38
|
spec = Gem::Specification.new do |s|
|
39
39
|
# s.rubyforge_project = 'merb'
|
data/lib/dm-ys.rb
CHANGED
data/lib/dm-ys/base.rb
CHANGED
@@ -15,6 +15,7 @@ module DataMapper
|
|
15
15
|
name = 'YunkelStar'
|
16
16
|
model.send :include, DataMapper::Resource
|
17
17
|
model.send :include, Proxy
|
18
|
+
model.send :include, IndexedProperty
|
18
19
|
# model.send :include, MemoryRepository
|
19
20
|
model.const_set(name, self) unless model.const_defined?(name)
|
20
21
|
extra_inclusions.each { |inclusion| model.send(:include, inclusion) }
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module YunkerStar
|
3
|
+
|
4
|
+
# ==== Example
|
5
|
+
#
|
6
|
+
# Class Foo
|
7
|
+
# include DataMapper::YunkerStar
|
8
|
+
# property :id, Serial
|
9
|
+
#
|
10
|
+
# foo = Foo.new
|
11
|
+
# foo[0] == foo[:id] == foo["id"] == foo.attributes[:id]
|
12
|
+
|
13
|
+
class InvalidIndex < RuntimeError; end
|
14
|
+
|
15
|
+
module IndexedProperty
|
16
|
+
def [](key)
|
17
|
+
case key
|
18
|
+
when Integer
|
19
|
+
self[properties.map(&:name)[key]]
|
20
|
+
when String
|
21
|
+
attributes[key.intern]
|
22
|
+
when Symbol
|
23
|
+
attributes[key]
|
24
|
+
else
|
25
|
+
raise InvalidIndex, "expected Integer/String/Symbol, but got #{key.class}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/dm-ys/proxy.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "spec_helper" )
|
2
|
+
|
3
|
+
describe DataMapper::YunkerStar do
|
4
|
+
class ::Cute1
|
5
|
+
include DataMapper::YunkerStar
|
6
|
+
uri spec_data_path("cute1.html")
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@cute = Cute1.first
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should provide #[]" do
|
14
|
+
@cute.should respond_to(:[])
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#[]" do
|
18
|
+
it "should accept symbol as a key" do
|
19
|
+
@cute[:id].should == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should accept string as a key" do
|
23
|
+
@cute["id"].should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should accept integer as a key" do
|
27
|
+
@cute[0].should == 1
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should raise InvalidIndex for unknown key" do
|
31
|
+
lambda {
|
32
|
+
@cute[Object]
|
33
|
+
}.should raise_error(DataMapper::YunkerStar::InvalidIndex)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maiha-dm-ys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maiha
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-02 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/dm-ys.rb
|
59
59
|
- lib/dm-ys
|
60
60
|
- lib/dm-ys/base.rb
|
61
|
+
- lib/dm-ys/indexed_property.rb
|
61
62
|
- lib/dm-ys/memory_repository.rb
|
62
63
|
- lib/dm-ys/scraper.rb
|
63
64
|
- lib/dm-ys/cached_accessor.rb
|
@@ -67,7 +68,7 @@ files:
|
|
67
68
|
- spec/data/cute1.html
|
68
69
|
- spec/data/ki.html
|
69
70
|
- spec/data/blank.html
|
70
|
-
- spec/
|
71
|
+
- spec/indexed_property_spec.rb
|
71
72
|
- spec/spec_helper.rb
|
72
73
|
- spec/pagination_spec.rb
|
73
74
|
has_rdoc: true
|