Class: Gapic::Presenters::SamplePresenter
- Inherits:
-
Object
- Object
- Gapic::Presenters::SamplePresenter
- Defined in:
- lib/gapic/presenters/sample_presenter.rb
Overview
A presenter for samples.
Defined Under Namespace
Classes: RequestField
Instance Method Summary collapse
- #description ⇒ Object
- #fields ⇒ Object
-
#initialize(api, sample_config) ⇒ SamplePresenter
constructor
A new instance of SamplePresenter.
- #input_parameters ⇒ Object
- #kwargs ⇒ Object
- #response_raw ⇒ Object
Constructor Details
#initialize(api, sample_config) ⇒ SamplePresenter
Returns a new instance of SamplePresenter.
25 26 27 28 |
# File 'lib/gapic/presenters/sample_presenter.rb', line 25 def initialize api, sample_config @api = api @sample_config = sample_config end |
Instance Method Details
#description ⇒ Object
30 31 32 |
# File 'lib/gapic/presenters/sample_presenter.rb', line 30 def description @sample_config["description"] end |
#fields ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gapic/presenters/sample_presenter.rb', line 38 def fields dotted_hash = @sample_config["request"].each_with_object({}) do |f, memo| memo[f["field"]] = f end dotted_hash.each_with_object({}) do |(path, f), memo| parts = path.split "." leaf_hash = parts[0...-1].inject(memo) { |h, k| h[k] ||= {} } leaf_hash[parts.last] = RequestField.new f end end |
#input_parameters ⇒ Object
34 35 36 |
# File 'lib/gapic/presenters/sample_presenter.rb', line 34 def input_parameters @sample_config["request"].select { |f| f.key? "input_parameter" }.map { |f| RequestField.new f } end |
#kwargs ⇒ Object
49 50 51 |
# File 'lib/gapic/presenters/sample_presenter.rb', line 49 def kwargs fields.keys.map { |k| "#{k}: #{k}" }.join ", " end |
#response_raw ⇒ Object
53 54 55 |
# File 'lib/gapic/presenters/sample_presenter.rb', line 53 def response_raw @sample_config["response"] end |