jp_bank 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/jp_bank/version.rb +1 -1
- data/lib/jp_bank.rb +16 -0
- data/spec/jp_bank_spec.rb +36 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c9d299e32204c592ebf144288483d7590f20c9d
|
4
|
+
data.tar.gz: af8542fd960144452bf6367324381002dfa389d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5bb34c534e48af4d5b09ed335eded606b5a0a8a10969e85596da7297c1dc08f96b628acef25f4bdc98f46a5c42c29352f6cd94e09ec824d823e879f8141f65d
|
7
|
+
data.tar.gz: 19906a9e19b390047680e2d1bd8d6f8422470b499ced14e0ed36069ea14825c6e91d68365a74f41c654f98785c1653da366e7d85bcc2a41a70567b194ba2bdf7
|
data/README.md
CHANGED
@@ -28,6 +28,24 @@ bank.code #=> "0036"
|
|
28
28
|
```
|
29
29
|
|
30
30
|
|
31
|
+
`JpBank` module provides `jp_bank` class method:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class Account
|
35
|
+
attr_reader :bank_code
|
36
|
+
jp_bank :bank
|
37
|
+
|
38
|
+
def initialize(args)
|
39
|
+
...
|
40
|
+
@bank_code = args[:bank_code]
|
41
|
+
...
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
account = Account.new(bank_code: '0036')
|
46
|
+
account.bank.name #=> '楽天銀行'
|
47
|
+
```
|
48
|
+
|
31
49
|
## Contributing
|
32
50
|
|
33
51
|
1. Fork it ( http://github.com/<my-github-username>/jp_bank/fork )
|
data/lib/jp_bank/version.rb
CHANGED
data/lib/jp_bank.rb
CHANGED
@@ -2,4 +2,20 @@ require "jp_bank/version"
|
|
2
2
|
|
3
3
|
module JpBank
|
4
4
|
autoload :Bank, File.expand_path('../jp_bank/bank', __FILE__)
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend JpBank::ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def jp_bank(attr_name, options={})
|
12
|
+
bank_code_method = options[:bank_code] || :bank_code
|
13
|
+
|
14
|
+
self.class_eval do
|
15
|
+
define_method attr_name do
|
16
|
+
JpBank::Bank.find(self.send(bank_code_method))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
5
21
|
end
|
data/spec/jp_bank_spec.rb
CHANGED
@@ -1,5 +1,41 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe JpBank do
|
4
|
+
describe '.jp_bank' do
|
5
|
+
context 'Without any options' do
|
6
|
+
let(:klass) do
|
7
|
+
klass = Class.new do
|
8
|
+
include JpBank
|
9
|
+
jp_bank :bank
|
4
10
|
|
11
|
+
def bank_code
|
12
|
+
'0036'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
klass
|
16
|
+
end
|
17
|
+
|
18
|
+
specify 'generates bank method' do
|
19
|
+
expect(klass.new.bank.code).to eq('0036')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'When specified method name by option' do
|
24
|
+
let(:klass) do
|
25
|
+
klass = Class.new do
|
26
|
+
include JpBank
|
27
|
+
jp_bank :bank, bank_code: :b_code
|
28
|
+
|
29
|
+
def b_code
|
30
|
+
'0036'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
klass
|
34
|
+
end
|
35
|
+
|
36
|
+
specify 'generates bank method' do
|
37
|
+
expect(klass.new.bank.code).to eq('0036')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
5
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jp_bank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tatsuya Sato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|