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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6f679d3a6c580601953c3594238d548c064dfea
4
- data.tar.gz: 53efc2c7afd11d34d047bc9535706c5c8b63c18e
3
+ metadata.gz: 7c9d299e32204c592ebf144288483d7590f20c9d
4
+ data.tar.gz: af8542fd960144452bf6367324381002dfa389d8
5
5
  SHA512:
6
- metadata.gz: e7003c834e2ce35d0e832f092676d5bb84a79812abd091af3ba30a96a30069ea1590080df2517025b79bd28d663bd93452241593a3890357bdd1382913a8bf08
7
- data.tar.gz: 33a84a31f230d92d3aa75155842972e6c5457fd2371b32a6613f6e45ae052c30f1948c60303e3bd22a4632f18eceba8d8b674aeeac95a6435e22485c27f3007b
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 )
@@ -1,3 +1,3 @@
1
1
  module JpBank
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.1
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-27 00:00:00.000000000 Z
11
+ date: 2014-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler