| Conditions | 11 |
| Total Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
Complex classes like Simple.initialize() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | module RingCentralSdk::REST::Request |
||
| 2 | class Simple < RingCentralSdk::REST::Request::Base |
||
| 3 | def initialize(opts = {}) |
||
| 4 | @method = opts[:method] |
||
| 5 | @url = opts[:url] |
||
| 6 | @params = opts[:params] |
||
| 7 | @headers = opts[:headers] |
||
| 8 | @body = body.nil? ? '' : body |
||
| 9 | if body.is_a? Hash |
||
| 10 | @headers = {} unless @headers.is_a? Hash |
||
| 11 | @headers['Content-Type'] = 'application/json' |
||
| 12 | end |
||
| 13 | |||
| 14 | def content_type |
||
| 15 | ct = @headers.is_a?(Hash) \ |
||
| 16 | ? @headers['Content-Type'] || '' : 'application/json' |
||
| 17 | end |
||
| 18 | |||
| 19 | def method |
||
| 20 | @method |
||
| 21 | end |
||
| 22 | |||
| 23 | def url |
||
| 24 | @url |
||
| 25 | end |
||
| 26 | |||
| 27 | def params |
||
| 28 | @params |
||
| 29 | end |
||
| 30 | |||
| 31 | def headers |
||
| 32 | @headers |
||
| 33 | end |
||
| 34 | |||
| 35 | def body |
||
| 36 | @body |
||
| 37 | end |
||
| 38 | end |
||
| 41 |