ehon 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26332159b5ba10a4e88371c85265c39a3a088f8a
4
- data.tar.gz: a7a7588f7a1b3fd8fea85c18464eec0f750957cc
3
+ metadata.gz: bcd69fa42ac239571bb6f7baafaf8c55aa9e6772
4
+ data.tar.gz: 489e87a3f7a78fef9496c8e7f587eab0e4b99b21
5
5
  SHA512:
6
- metadata.gz: da617d040c65e82e0b3e6c569a27855baa70509b35cd2bf91bf173e07ba7336b6c61664a04f4efc1538af2dc419094f96408366f59913b2a88471dff2a24929d
7
- data.tar.gz: 77abcc82ffabafec73fb62fb2181df3a31d65a25465d46c9d420a5207cc669b882b01d1149328c2ebe6ea9de960a21025183ca8dd7cb263f59a93054760a2aa2
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/<my-github-username>/ehon/fork )
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 self.options[symbol] if respond_to?(symbol)
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.options[key] == value }
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
@@ -1,3 +1,3 @@
1
1
  module Ehon
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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(Item.default_options).to eq({key: 'value'})
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
- it "find with `[1, {value: 10}]` should return item id `potion` and `high potion`" do
278
- finded = subject.find([1, {value: 10}])
279
- expect(finded.map(&:name)).to eq(['potion', 'high potion'])
280
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomohiro Nishimura