File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,19 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
2828### Deprecated
2929- None
3030
31+ ## v0.3.5
32+
33+ ### Added
34+ - ` Response ` instance now delegates to params via ` method_missing ` .
35+ ```
36+ params = { foo: { bar: :baz }}
37+ response = Viberroo::Response.new(params)
38+ # Previously, those could only be accessed through params:
39+ puts response.params.foo.bar
40+ # Now those can be accessed directly:
41+ puts response.foo.bar
42+ ```
43+
3144## v0.3.4
3245Start a changelog.
3346
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ source 'https://rubygems.org'
33gemspec
44
55group :development , :test do
6- gem 'byebug'
6+ gem 'pry- byebug'
77 gem 'rake' , '~> 12.0'
88 gem 'rspec' , '~> 3.0'
99 gem 'webmock'
Original file line number Diff line number Diff line change 11PATH
22 remote: .
33 specs:
4- viberroo (0.3.4 )
4+ viberroo (0.3.5 )
55 recursive-open-struct (~> 1.1.1 )
66
77GEM
1010 addressable (2.8.0 )
1111 public_suffix (>= 2.0.2 , < 5.0 )
1212 byebug (11.1.3 )
13+ coderay (1.1.3 )
1314 crack (0.4.5 )
1415 rexml
1516 diff-lcs (1.4.4 )
1617 hashdiff (1.0.1 )
18+ method_source (1.0.0 )
19+ pry (0.13.1 )
20+ coderay (~> 1.1 )
21+ method_source (~> 1.0 )
22+ pry-byebug (3.9.0 )
23+ byebug (~> 11.0 )
24+ pry (~> 0.13.0 )
1725 public_suffix (4.0.6 )
1826 rake (12.3.3 )
1927 recursive-open-struct (1.1.3 )
@@ -42,7 +50,7 @@ PLATFORMS
4250 ruby
4351
4452DEPENDENCIES
45- byebug
53+ pry- byebug
4654 rake (~> 12.0 )
4755 redcarpet
4856 rspec (~> 3.0 )
Original file line number Diff line number Diff line change @@ -16,7 +16,15 @@ class Response
1616 # skip_before_action :verify_authenticity_token
1717 #
1818 # def callback
19+ # # For example, params contain the following:
20+ # # { foo: { bar: { baz: :boo }}}
1921 # @response = Viberroo::Response.new(params.permit!)
22+ # # Those can be accessed through params:
23+ # puts @response.params.foo
24+ # # Or directly:
25+ # puts @response.foo
26+ # puts @response.foo.bar
27+ # puts @response.foo.bar.baz
2028 # @bot = Viberroo::Bot.new(response: @response)
2129 #
2230 # head :ok
@@ -47,5 +55,9 @@ def user_id
4755 @params . dig ( :user , :id )
4856 end
4957 end
58+
59+ def method_missing ( method )
60+ params . public_send ( method )
61+ end
5062 end
5163end
Original file line number Diff line number Diff line change 11module Viberroo
2- VERSION = '0.3.4 ' . freeze
2+ VERSION = '0.3.5 ' . freeze
33end
Original file line number Diff line number Diff line change 112112 it { is_expected . to eq ( params [ :sender ] [ :id ] ) }
113113 end
114114 end
115+
116+ describe 'method_missing' do
117+ let ( :params ) { { foo : { bar : :baz } } }
118+
119+ subject { Viberroo ::Response . new ( params ) }
120+
121+ it 'self delegated methods to params' do
122+ expect ( subject . foo . to_h ) . to eq ( bar : :baz )
123+ expect ( subject . foo . bar ) . to eq ( :baz )
124+ end
125+ end
115126end
You can’t perform that action at this time.
0 commit comments