Class: Apiwork::Introspection::Dump::Contract
- Inherits:
-
Object
- Object
- Apiwork::Introspection::Dump::Contract
- Defined in:
- lib/apiwork/introspection/dump/contract.rb
Instance Method Summary collapse
-
#initialize(contract_class, expand: false) ⇒ Contract
constructor
A new instance of Contract.
- #to_h ⇒ Object
Constructor Details
#initialize(contract_class, expand: false) ⇒ Contract
Returns a new instance of Contract.
7 8 9 10 11 |
# File 'lib/apiwork/introspection/dump/contract.rb', line 7 def initialize(contract_class, expand: false) @contract_class = contract_class @expand = @type_dump = Type.new(contract_class.api_class) end |
Instance Method Details
#to_h ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/apiwork/introspection/dump/contract.rb', line 13 def to_h @contract_class.api_class.ensure_all_contracts_built! result = { actions: {} } action_names = available_actions action_names = @contract_class.actions.keys if action_names.empty? action_names.each do |action_name| contract_action = @contract_class.action_for(action_name) result[:actions][action_name] = Action.new(contract_action).to_h if contract_action end if @expand types, enums = build_referenced_types_and_enums(result[:actions]) else types = build_local_types enums = build_local_enums end result[:types] = types result[:enums] = enums result end |