ehon 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/ehon.rb +6 -2
- data/lib/ehon/version.rb +1 -1
- data/spec/ehon_spec.rb +44 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcd69fa42ac239571bb6f7baafaf8c55aa9e6772
|
4
|
+
data.tar.gz: 489e87a3f7a78fef9496c8e7f587eab0e4b99b21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f68deac97792f5c76523edc1b328af422698fdeb714ee87c076398b3100e4813c7d39e7ce6a3178b572cff7a63c7e7df84a0d23dfcda813bc84fdeb024274fa3
|
7
|
+
data.tar.gz: 852faeb8faf196d081cd9df96ce74ca9b6b9610e99d71a6f8e8aea186e595949f25d156c02750ce0eafe22fd127bafc6d4c6b57e24b3840ab3f909f7cfccd970
|
data/README.md
CHANGED
@@ -67,7 +67,7 @@ DeviceTypel::IOS.android? #=> false
|
|
67
67
|
|
68
68
|
## Contributing
|
69
69
|
|
70
|
-
1. Fork it ( http://github.com
|
70
|
+
1. Fork it ( http://github.com/hekk/ehon/fork )
|
71
71
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
72
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
73
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/ehon.rb
CHANGED
@@ -24,10 +24,14 @@ module Ehon
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def method_missing(symbol, *args)
|
27
|
-
return
|
27
|
+
return read_attribute(symbol) if respond_to?(symbol)
|
28
28
|
super
|
29
29
|
end
|
30
30
|
|
31
|
+
def read_attribute(symbol)
|
32
|
+
self.options[symbol]
|
33
|
+
end
|
34
|
+
|
31
35
|
module ClassMethods
|
32
36
|
attr_accessor :contents, :default_options
|
33
37
|
|
@@ -52,7 +56,7 @@ module Ehon
|
|
52
56
|
findeds = queries.map {|query|
|
53
57
|
next self.contents[query] unless query.is_a?(Hash)
|
54
58
|
self.contents.values.find {|instance|
|
55
|
-
query.all? {|key, value| instance.
|
59
|
+
query.all? {|key, value| instance.read_attribute(key) == value }
|
56
60
|
}
|
57
61
|
}.compact
|
58
62
|
queries.size == 1 ? findeds.first : findeds
|
data/lib/ehon/version.rb
CHANGED
data/spec/ehon_spec.rb
CHANGED
@@ -71,6 +71,22 @@ describe Ehon do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
75
|
+
context 'with string key hash' do
|
76
|
+
let(:name) { 'scroll' }
|
77
|
+
|
78
|
+
before do
|
79
|
+
@instance = subject.page(1, 'name' => name)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should not be able to respond to name' do
|
83
|
+
expect(@instance).to_not be_respond_to(:name)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should be able to fetch name through read_attribute' do
|
87
|
+
expect(@instance.read_attribute('name')).to eq(name)
|
88
|
+
end
|
89
|
+
end
|
74
90
|
end
|
75
91
|
|
76
92
|
context 'with default options' do
|
@@ -82,7 +98,7 @@ describe Ehon do
|
|
82
98
|
end
|
83
99
|
|
84
100
|
it "should has default option {key: 'value'}" do
|
85
|
-
expect(
|
101
|
+
expect(subject.default_options).to eq({key: 'value'})
|
86
102
|
end
|
87
103
|
|
88
104
|
it "instacne should respond to key and return 'value'" do
|
@@ -108,6 +124,29 @@ describe Ehon do
|
|
108
124
|
expect(@instance_without_block).to_not be_respond_to(:potion?)
|
109
125
|
end
|
110
126
|
end
|
127
|
+
|
128
|
+
context 'custom method' do
|
129
|
+
before do
|
130
|
+
class Item
|
131
|
+
def name
|
132
|
+
name = read_attribute(:name)
|
133
|
+
value = read_attribute(:value)
|
134
|
+
"%s(%d)" % [name, value]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
@instance = subject.page(1, name: 'potion', value: 5)
|
138
|
+
end
|
139
|
+
|
140
|
+
after do
|
141
|
+
class Item
|
142
|
+
remove_method :name
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should override name attribute' do
|
147
|
+
expect(@instance.name).to eq('potion(5)')
|
148
|
+
end
|
149
|
+
end
|
111
150
|
end
|
112
151
|
|
113
152
|
describe '#==(other)' do
|
@@ -274,10 +313,10 @@ describe Ehon do
|
|
274
313
|
end
|
275
314
|
|
276
315
|
context 'with id and query' do
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
316
|
+
it "find with `[1, {value: 10}]` should return item id `potion` and `high potion`" do
|
317
|
+
finded = subject.find([1, {value: 10}])
|
318
|
+
expect(finded.map(&:name)).to eq(['potion', 'high potion'])
|
319
|
+
end
|
281
320
|
end
|
282
321
|
end
|
283
322
|
end
|