zendesk_api 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.yardopts +1 -1
  2. data/Gemfile.lock +3 -1
  3. data/Rakefile +1 -0
  4. data/Readme.md +38 -0
  5. data/lib/zendesk_api.rb +2 -3
  6. data/lib/zendesk_api/actions.rb +9 -2
  7. data/lib/zendesk_api/association.rb +28 -54
  8. data/lib/zendesk_api/client.rb +20 -5
  9. data/lib/zendesk_api/collection.rb +31 -16
  10. data/lib/zendesk_api/configuration.rb +1 -0
  11. data/lib/zendesk_api/helpers.rb +1 -0
  12. data/lib/zendesk_api/lru_cache.rb +1 -0
  13. data/lib/zendesk_api/middleware/request/etag_cache.rb +1 -0
  14. data/lib/zendesk_api/middleware/request/retry.rb +2 -0
  15. data/lib/zendesk_api/middleware/request/upload.rb +1 -0
  16. data/lib/zendesk_api/middleware/response/callback.rb +1 -0
  17. data/lib/zendesk_api/middleware/response/deflate.rb +1 -0
  18. data/lib/zendesk_api/middleware/response/gzip.rb +2 -0
  19. data/lib/zendesk_api/middleware/response/logger.rb +1 -0
  20. data/lib/zendesk_api/middleware/response/parse_iso_dates.rb +1 -0
  21. data/lib/zendesk_api/rescue.rb +2 -0
  22. data/lib/zendesk_api/resource.rb +11 -6
  23. data/lib/zendesk_api/resources.rb +319 -0
  24. data/lib/zendesk_api/sideloading.rb +1 -0
  25. data/lib/zendesk_api/track_changes.rb +3 -2
  26. data/lib/zendesk_api/trackie.rb +1 -0
  27. data/lib/zendesk_api/version.rb +1 -1
  28. data/spec/association_spec.rb +1 -1
  29. data/spec/client_spec.rb +13 -2
  30. data/spec/collection_spec.rb +7 -7
  31. data/spec/data_resource_spec.rb +53 -66
  32. data/spec/read_resource_spec.rb +1 -1
  33. data/spec/resource_spec.rb +6 -6
  34. data/spec/spec_helper.rb +1 -1
  35. data/util/resource_handler.rb +68 -0
  36. data/util/verb_handler.rb +16 -0
  37. data/zendesk_api.gemspec +3 -2
  38. metadata +27 -12
  39. data/lib/zendesk_api/resources/forum.rb +0 -51
  40. data/lib/zendesk_api/resources/misc.rb +0 -79
  41. data/lib/zendesk_api/resources/ticket.rb +0 -97
  42. data/lib/zendesk_api/resources/user.rb +0 -59
@@ -1,4 +1,5 @@
1
1
  module ZendeskAPI
2
+ # @private
2
3
  module Sideloading
3
4
  def self.included(klass)
4
5
  klass.send(:attr_reader, :included)
@@ -1,6 +1,6 @@
1
- # Shamelessly stolen and modified from https://github.com/archan937/dirty_hashy
2
-
3
1
  module ZendeskAPI
2
+ # Shamelessly stolen and modified from https://github.com/archan937/dirty_hashy
3
+ # @private
4
4
  module TrackChanges
5
5
  def self.included(base)
6
6
  base.method_defined?(:regular_writer).tap do |defined|
@@ -17,6 +17,7 @@ module ZendeskAPI
17
17
  end
18
18
  end
19
19
 
20
+ # @private
20
21
  module InstanceMethods
21
22
  def clear_changes
22
23
  each do |k, v|
@@ -2,6 +2,7 @@ require 'hashie'
2
2
  require 'zendesk_api/track_changes'
3
3
 
4
4
  module ZendeskAPI
5
+ # @private
5
6
  class Trackie < Hashie::Mash
6
7
  include ZendeskAPI::TrackChanges
7
8
  end
@@ -1,3 +1,3 @@
1
1
  module ZendeskAPI
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -8,7 +8,7 @@ describe ZendeskAPI::Association do
8
8
  context "has" do
9
9
  before do
10
10
  ZendeskAPI::TestResource.associations.clear
11
- ZendeskAPI::TestResource.has :child, :class => :test_child
11
+ ZendeskAPI::TestResource.has :child, :class => ZendeskAPI::TestResource::TestChild
12
12
  end
13
13
 
14
14
  it "should cache an set object" do
@@ -117,7 +117,7 @@ describe ZendeskAPI::Client do
117
117
  context "with a logger" do
118
118
  let(:out){ StringIO.new }
119
119
  subject { Logger.new(out) }
120
-
120
+
121
121
  it "should log" do
122
122
  @client.connection.builder.handlers.should include(ZendeskAPI::Middleware::Response::Logger)
123
123
  end
@@ -154,8 +154,19 @@ describe ZendeskAPI::Client do
154
154
 
155
155
  context "resources" do
156
156
  it "should return an instance of ZendeskAPI::Collection if there is no method" do
157
+ subject.instance_variable_get(:@resource_cache)["tickets"].should be_nil
158
+
157
159
  subject.tickets.should be_instance_of(ZendeskAPI::Collection)
158
- subject.instance_variable_defined?(:@tickets).should be_true
160
+
161
+ subject.instance_variable_get(:@resource_cache)["tickets"].should_not be_empty
162
+ end
163
+
164
+ it "should not cache calls with different options" do
165
+ subject.search(:query => 'abc').should_not == subject.search(:query => '123')
166
+ end
167
+
168
+ it "should cache calls with the same options" do
169
+ subject.search(:query => 'abc').should == subject.search(:query => 'abc')
159
170
  end
160
171
  end
161
172
 
@@ -408,7 +408,7 @@ describe ZendeskAPI::Collection do
408
408
 
409
409
  context "singular id on resource" do
410
410
  before(:each) do
411
- ZendeskAPI::TestResource.has :nil_resource
411
+ ZendeskAPI::TestResource.has ZendeskAPI::NilResource
412
412
 
413
413
  stub_json_request(:get, %r{test_resources\?include=nil_resources}, json(
414
414
  :test_resources => [{ :id => 1, :nil_resource_id => 4 }],
@@ -431,7 +431,7 @@ describe ZendeskAPI::Collection do
431
431
 
432
432
  context "plural ids on resource" do
433
433
  before(:each) do
434
- ZendeskAPI::TestResource.has_many :nil_resources
434
+ ZendeskAPI::TestResource.has_many ZendeskAPI::NilResource
435
435
 
436
436
  stub_json_request(:get, %r{test_resources\?include=nil_resources}, json(
437
437
  :test_resources => [{ :id => 1, :nil_resource_ids => [1, 4] }],
@@ -454,7 +454,7 @@ describe ZendeskAPI::Collection do
454
454
 
455
455
  context "ids in side load" do
456
456
  before(:each) do
457
- ZendeskAPI::TestResource.has_many :nil_resources
457
+ ZendeskAPI::TestResource.has_many ZendeskAPI::NilResource
458
458
 
459
459
  stub_json_request(:get, %r{test_resources\?include=nil_resources}, json(
460
460
  :test_resources => [{ :id => 1 }],
@@ -476,7 +476,7 @@ describe ZendeskAPI::Collection do
476
476
 
477
477
  context "id in side load" do
478
478
  before(:each) do
479
- ZendeskAPI::TestResource.has :nil_resource
479
+ ZendeskAPI::TestResource.has ZendeskAPI::NilResource
480
480
 
481
481
  stub_json_request(:get, %r{test_resources\?include=nil_resources}, json(
482
482
  :test_resources => [{ :id => 1 }],
@@ -498,7 +498,7 @@ describe ZendeskAPI::Collection do
498
498
 
499
499
  context "with name as key" do
500
500
  before(:each) do
501
- ZendeskAPI::TestResource.has :nil_resource, :include_key => :name
501
+ ZendeskAPI::TestResource.has ZendeskAPI::NilResource, :include_key => :name
502
502
 
503
503
  stub_json_request(:get, %r{test_resources\?include=nil_resources}, json(
504
504
  :test_resources => [{ :id => 1, :nil_resource_id => 4 }],
@@ -521,8 +521,8 @@ describe ZendeskAPI::Collection do
521
521
 
522
522
  context "sub-loading" do
523
523
  before(:each) do
524
- ZendeskAPI::TestResource.has :test_child
525
- ZendeskAPI::TestResource::TestChild.has :nil_resource
524
+ ZendeskAPI::TestResource.has ZendeskAPI::TestResource::TestChild
525
+ ZendeskAPI::TestResource::TestChild.has ZendeskAPI::NilResource
526
526
 
527
527
  stub_json_request(:get, %r{test_resources\?include=nil_resources}, json(
528
528
  :test_resources => [{ :id => 1, :test_child => { :nil_resource_id => 4 } }],
@@ -1,21 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ZendeskAPI::DataResource do
4
- context "ZendeskAPI.get_class" do
5
- it "should create a new class if there is none" do
6
- ZendeskAPI.const_defined?("Blergh").should be_false
7
- ZendeskAPI.get_class(:blergh).should == ZendeskAPI::Blergh
8
- end
9
-
10
- it "should find the class if it exists" do
11
- ZendeskAPI.get_class(:tickets).should == ZendeskAPI::Tickets
12
- end
13
-
14
- it "should handle 'nil' be passed in" do
15
- ZendeskAPI.get_class(nil).should be_false
16
- end
17
- end
18
-
19
4
  specify "singular resource name" do
20
5
  ZendeskAPI::Ticket.singular_resource_name.should == "ticket"
21
6
  ZendeskAPI::TicketField.singular_resource_name.should == "ticket_field"
@@ -72,23 +57,20 @@ describe ZendeskAPI::DataResource do
72
57
  end
73
58
 
74
59
  context "has" do
75
- before(:each) { ZendeskAPI::TestResource.has :foo }
60
+ before(:each) { ZendeskAPI::TestResource.has ZendeskAPI::TestResource }
76
61
 
77
62
  context "class methods" do
78
63
  subject { ZendeskAPI::TestResource }
79
- it "should define a method with the same name" do
80
- subject.instance_methods.map(&:to_s).should include("foo")
81
- end
82
64
 
83
- it "should create a class if none exists" do
84
- ZendeskAPI.const_defined?("Foo").should be_true
65
+ it "should define a method with the same name" do
66
+ subject.instance_methods.map(&:to_s).should include("test_resource")
85
67
  end
86
68
 
87
69
  context "with explicit class name" do
88
- before(:all) { ZendeskAPI::TestResource.has :baz, :class => :foo }
70
+ before(:all) { ZendeskAPI::TestResource.has :baz, :class => ZendeskAPI::TestResource }
89
71
 
90
- it "should not create a baz class" do
91
- ZendeskAPI.const_defined?("Baz").should be_false
72
+ it "should define a method with the same name" do
73
+ subject.instance_methods.map(&:to_s).should include("baz")
92
74
  end
93
75
  end
94
76
  end
@@ -96,82 +78,83 @@ describe ZendeskAPI::DataResource do
96
78
  context "instance method" do
97
79
  context "with no side-loading" do
98
80
  subject { ZendeskAPI::TestResource.new(client, :id => 1) }
99
- before(:each) { stub_json_request(:get, %r{test_resources/\d+/foo}, json(:foo => {})) }
81
+ before(:each) { stub_json_request(:get, %r{test_resources/\d+/test_resource}, json(:test_resource => {})) }
100
82
 
101
83
  it "should attempt to grab the resource from the host" do
102
- subject.foo.should be_instance_of(ZendeskAPI::Foo)
84
+ subject.test_resource.should be_instance_of(ZendeskAPI::TestResource)
103
85
  end
104
86
 
105
87
  it "should pass the path on to the resource" do
106
- subject.foo.path.should == "foos"
88
+ subject.test_resource.path.should == "test_resources"
107
89
  end
108
90
 
109
91
  context "with a client error" do
110
- before(:each) { stub_request(:get, %r{test_resources/\d+/foo}).to_return(:status => 500) }
92
+ before(:each) { stub_request(:get, %r{test_resources/\d+/test_resource}).to_return(:status => 500) }
111
93
 
112
94
  it "should handle it properly" do
113
- expect { silence_logger{ subject.foo.should be_nil } }.to_not raise_error
95
+ expect { silence_logger{ subject.test_resource.should be_nil } }.to_not raise_error
114
96
  end
115
97
  end
116
-
98
+
117
99
  context "with an explicit path set" do
118
100
  before(:each) do
119
- ZendeskAPI::TestResource.has :foo, :path => "blergh"
120
- stub_json_request(:get, %r{test_resources/\d+/blergh}, json(:foo => {}))
101
+ ZendeskAPI::TestResource.has ZendeskAPI::TestResource, :path => "blergh"
102
+ stub_json_request(:get, %r{test_resources/\d+/blergh}, json(:test_resource => {}))
121
103
  end
122
104
 
123
105
  it "should call the right path" do
124
- subject.foo.should be_instance_of(ZendeskAPI::Foo)
106
+ subject.test_resource.should be_instance_of(ZendeskAPI::TestResource)
125
107
  end
126
108
  end
127
109
  end
128
110
 
129
111
  context "with side-loading of resource" do
130
- let(:foo) { { :message => "FOO_OBJ" } }
131
- subject { ZendeskAPI::TestResource.new(client, :foo => foo) }
112
+ let(:test_resource) { { :message => "FOO_OBJ" } }
113
+ subject { ZendeskAPI::TestResource.new(client, :test_resource => test_resource).test_resource }
114
+
115
+ it "should load the correct instance" do
116
+ subject.should be_instance_of(ZendeskAPI::TestResource)
117
+ end
132
118
 
133
119
  it "should load foo from the hash" do
134
- subject.foo.should be_instance_of(ZendeskAPI::Foo)
120
+ subject.message.should == "FOO_OBJ"
135
121
  end
136
122
  end
137
123
 
138
124
  context "with side-loading of id" do
139
- subject { ZendeskAPI::TestResource.new(client, :foo_id => 1) }
125
+ subject { ZendeskAPI::TestResource.new(client, :test_resource_id => 1) }
140
126
  before(:each) do
141
- stub_json_request(:get, %r{foos/1}, json("foo" => {}))
127
+ stub_json_request(:get, %r{test_resources/1}, json("test_resource" => {}))
142
128
  end
143
129
 
144
130
  it "should find foo_id and load it from the api" do
145
- subject.foo
131
+ subject.test_resource
146
132
  end
147
133
 
148
134
  it "should handle nil response from find api" do
149
- ZendeskAPI::Foo.should_receive(:find).twice.and_return(nil)
150
- subject.foo.should be_nil
151
- subject.foo
135
+ ZendeskAPI::TestResource.should_receive(:find).twice.and_return(nil)
136
+ subject.test_resource.should be_nil
137
+ subject.test_resource
152
138
  end
153
139
  end
154
140
  end
155
141
  end
156
142
 
157
143
  context "has_many" do
158
- before(:each) { ZendeskAPI::TestResource.has_many :bars }
144
+ before(:each) { ZendeskAPI::TestResource.has_many ZendeskAPI::TestResource }
159
145
 
160
146
  context "class methods" do
161
147
  subject { ZendeskAPI::TestResource }
162
- it "should define a method with the same name" do
163
- subject.instance_methods.map(&:to_s).should include("bars")
164
- end
165
148
 
166
- it "should create a class if none exists" do
167
- ZendeskAPI.const_defined?("Bar").should be_true
149
+ it "should define a method with the same name" do
150
+ subject.instance_methods.map(&:to_s).should include("test_resources")
168
151
  end
169
152
 
170
153
  context "with explicit class name" do
171
- before(:each) { ZendeskAPI::TestResource.has_many :cats, :class => :foo }
154
+ before(:each) { ZendeskAPI::TestResource.has_many :cats, :class => ZendeskAPI::TestResource }
172
155
 
173
- it "should not create a baz class" do
174
- ZendeskAPI.const_defined?("Cat").should be_false
156
+ it "should define a method with the same name" do
157
+ subject.instance_methods.map(&:to_s).should include("cats")
175
158
  end
176
159
  end
177
160
  end
@@ -181,46 +164,50 @@ describe ZendeskAPI::DataResource do
181
164
  subject { ZendeskAPI::TestResource.new(client, :id => 1) }
182
165
 
183
166
  it "should not attempt to grab the resource from the host" do
184
- subject.bars.should be_instance_of(ZendeskAPI::Collection)
167
+ subject.test_resources.should be_instance_of(ZendeskAPI::Collection)
185
168
  end
186
169
 
187
170
  it "should pass the path on to the resource" do
188
- subject.bars.path.should == "test_resources/1/bars"
171
+ subject.test_resources.path.should == "test_resources/1/test_resources"
189
172
  end
190
173
 
191
174
  context "with an explicit path set" do
192
175
  before(:each) do
193
- ZendeskAPI::TestResource.has_many :bars, :path => "blargh"
176
+ ZendeskAPI::TestResource.has_many ZendeskAPI::TestResource, :path => "blargh"
194
177
  end
195
178
 
196
179
  it "should call the right path" do
197
- subject.bars.path.should == "test_resources/1/blargh"
180
+ subject.test_resources.path.should == "test_resources/1/blargh"
198
181
  end
199
182
  end
200
183
  end
201
184
 
202
185
  context "with side-loading of resource" do
203
- let(:bars) { [{ :message => "FOO_OBJ" }] }
204
- subject { ZendeskAPI::TestResource.new(client, :bars => bars) }
186
+ let(:test_resources) { [{ :message => "FOO_OBJ" }] }
187
+ subject { ZendeskAPI::TestResource.new(client, :test_resources => test_resources).test_resources.first }
188
+
189
+ it "should properly create instance" do
190
+ subject.message.should == "FOO_OBJ"
191
+ end
205
192
 
206
- it "should map bars onto Bar class" do
207
- subject.bars.first.should be_instance_of(ZendeskAPI::Bar)
193
+ it "should map bars onto TestResource class" do
194
+ subject.should be_instance_of(ZendeskAPI::TestResource)
208
195
  end
209
196
  end
210
197
 
211
198
  context "with side-loading of id" do
212
- let(:bars) { [1, 2, 3] }
213
- subject { ZendeskAPI::TestResource.new(client, :bar_ids => bars) }
199
+ let(:test_resource_ids) { [1, 2, 3] }
200
+ subject { ZendeskAPI::TestResource.new(client, :test_resource_ids => test_resource_ids) }
214
201
 
215
202
  it "should find foo_id and load it from the api" do
216
- ZendeskAPI::Bar.should_receive(:find).with(client, kind_of(Hash)).exactly(bars.length).times
217
- subject.bars
203
+ ZendeskAPI::TestResource.should_receive(:find).with(client, kind_of(Hash)).exactly(test_resource_ids.length).times
204
+ subject.test_resources
218
205
  end
219
206
 
220
207
  it "should handle nil response from find api" do
221
- ZendeskAPI::Bar.should_receive(:find).with(client, kind_of(Hash)).exactly(bars.length).times.and_return(nil)
222
- subject.bars.should be_empty
223
- subject.bars # Test expectations
208
+ ZendeskAPI::TestResource.should_receive(:find).with(client, kind_of(Hash)).exactly(test_resource_ids.length).times.and_return(nil)
209
+ subject.test_resources.should be_empty
210
+ subject.test_resources # Test expectations
224
211
  end
225
212
  end
226
213
  end
@@ -28,7 +28,7 @@ describe ZendeskAPI::ReadResource do
28
28
  "nil_resources" => [{ :id => 1, :name => :bye }, { :id => 2, :name => :hi }]
29
29
  ))
30
30
 
31
- subject.has :nil_resource
31
+ subject.has ZendeskAPI::NilResource
32
32
  @resource = subject.find(client, :id => id, :include => :nil_resource)
33
33
  end
34
34
 
@@ -114,8 +114,8 @@ describe ZendeskAPI::Resource do
114
114
  context "with unused associations" do
115
115
  before do
116
116
  ZendeskAPI::TestResource.associations.clear
117
- ZendeskAPI::TestResource.has :child, :class => :test_child
118
- ZendeskAPI::TestResource.has_many :children, :class => :test_child
117
+ ZendeskAPI::TestResource.has :child, :class => ZendeskAPI::TestResource::TestChild
118
+ ZendeskAPI::TestResource.has_many :children, :class => ZendeskAPI::TestResource::TestChild
119
119
  end
120
120
 
121
121
  it "should not touch them" do
@@ -155,7 +155,7 @@ describe ZendeskAPI::Resource do
155
155
  context "has" do
156
156
  before(:each) do
157
157
  ZendeskAPI::TestResource.associations.clear
158
- ZendeskAPI::TestResource.has :child, :class => :test_child
158
+ ZendeskAPI::TestResource.has :child, :class => ZendeskAPI::TestResource::TestChild
159
159
  stub_json_request(:put, %r{test_resources})
160
160
  subject.child = { :id => 2 }
161
161
  end
@@ -181,7 +181,7 @@ describe ZendeskAPI::Resource do
181
181
  context "has_many" do
182
182
  before(:each) do
183
183
  ZendeskAPI::TestResource.associations.clear
184
- ZendeskAPI::TestResource.has_many :children, :class => :test_child
184
+ ZendeskAPI::TestResource.has_many :children, :class => ZendeskAPI::TestResource::TestChild
185
185
 
186
186
  stub_json_request(:put, %r{test_resources})
187
187
  stub_json_request(:get, %r{children}, json(:test_children => []))
@@ -236,7 +236,7 @@ describe ZendeskAPI::Resource do
236
236
 
237
237
  context "true" do
238
238
  before(:each) do
239
- ZendeskAPI::TestResource.has :nil, :class => :nil_resource, :inline => true
239
+ ZendeskAPI::TestResource.has :nil, :class => ZendeskAPI::NilResource, :inline => true
240
240
 
241
241
  subject.nil = { :abc => :def }
242
242
  subject.save_associations
@@ -249,7 +249,7 @@ describe ZendeskAPI::Resource do
249
249
 
250
250
  context "create" do
251
251
  before(:each) do
252
- ZendeskAPI::TestResource.has :nil, :class => :nil_resource, :inline => :create
252
+ ZendeskAPI::TestResource.has :nil, :class => ZendeskAPI::NilResource, :inline => :create
253
253
  subject.nil = { :abc => :def }
254
254
  end
255
255
 
@@ -85,7 +85,7 @@ RSpec.configure do |c|
85
85
 
86
86
  c.before(:each) do
87
87
  ZendeskAPI::TestResource.associations.clear
88
- ZendeskAPI::TestResource.has_many :children, :class => :test_child
88
+ ZendeskAPI::TestResource.has_many :children, :class => ZendeskAPI::TestResource::TestChild
89
89
  end
90
90
 
91
91
  c.before(:each) do
@@ -0,0 +1,68 @@
1
+ require 'zendesk_api'
2
+
3
+ class ResourceHandler < YARD::Handlers::Ruby::Base
4
+ handles method_call(:has), method_call(:has_many)
5
+
6
+ def process
7
+ many = statement.jump(:ident).source == "has_many"
8
+
9
+ klass = get_klass(statement)
10
+
11
+ if klass
12
+ begin
13
+ klass = klass.split("::").inject(ZendeskAPI) do |p,k|
14
+ p.const_get(k)
15
+ end
16
+ rescue NameError
17
+ parent = ZendeskAPI.const_get(namespace.to_s.split('::').last)
18
+ klass = parent.const_get(klass)
19
+ end
20
+
21
+ name = statement.parameters.first.jump(:ident).source
22
+ else
23
+ klass = statement.parameters.first.source
24
+
25
+ begin
26
+ klass = ZendeskAPI.const_get(klass)
27
+ rescue NameError
28
+ parent = ZendeskAPI.const_get(namespace.to_s.split('::').last)
29
+ klass = parent.const_get(klass)
30
+ end
31
+
32
+ name = many ? klass.resource_name : klass.singular_resource_name
33
+ end
34
+
35
+ reader = YARD::CodeObjects::MethodObject.new(namespace, name)
36
+ register(reader)
37
+ reader.dynamic = true
38
+ reader.docstring.add_tag(YARD::Tags::Tag.new(:return, "The associated object", klass.name))
39
+
40
+ if many
41
+ reader.signature = "def #{name}=(options = {})"
42
+ reader.parameters = [['options', {}]]
43
+ reader.docstring.add_tag(YARD::Tags::Tag.new(:param, "Options to pass to the collection object", "Hash", "options"))
44
+ end
45
+
46
+ writer = YARD::CodeObjects::MethodObject.new(namespace, "#{name}=")
47
+ register(writer)
48
+ writer.signature = "def #{name}=(value)"
49
+ writer.parameters = [['value', nil]]
50
+ writer.dynamic = true
51
+ writer.docstring.add_tag(YARD::Tags::Tag.new(:return, "The associated object", klass.name))
52
+ writer.docstring.add_tag(YARD::Tags::Tag.new(:param, "The associated object or its attributes", "Hash or #{klass.name}", "value"))
53
+ end
54
+
55
+ def get_klass(statement)
56
+ statement.traverse do |node|
57
+ if node.type == :assoc && node.jump(:kw).source == "class"
58
+ classes = node.traverse do |value|
59
+ if value.type == :const_path_ref || value.type == :var_ref
60
+ return value.source
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ nil
67
+ end
68
+ end