Module: FlyIO::OperationRegistry
- Defined in:
- lib/fly_io/operation_registry.rb
Defined Under Namespace
Classes: Operation
Constant Summary collapse
- MANIFEST_PATHS =
%w[operations.json additional_operations.json prometheus_operations.json].map do |name| File.("generated/#{name}", __dir__) end.freeze
Class Method Summary collapse
- .fetch(identity_or_operation_id, method: nil, path: nil) ⇒ Object
- .operations ⇒ Object
- .resources ⇒ Object
Class Method Details
.fetch(identity_or_operation_id, method: nil, path: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fly_io/operation_registry.rb', line 23 def fetch(identity_or_operation_id, method: nil, path: nil) key = identity_or_operation_id.to_s matches = operations.select do |operation| (operation.identity == key || operation.operation_id == key) && (!method || operation.http_method == method.to_s.downcase) && (!path || operation.path == path) end raise FlyIO::ArgumentError, "unknown operation: #{key}" if matches.empty? if matches.length > 1 raise FlyIO::ArgumentError, "ambiguous operation ID #{key}; specify method: and path:" end matches.first end |
.operations ⇒ Object
13 14 15 16 17 |
# File 'lib/fly_io/operation_registry.rb', line 13 def operations @operations ||= MANIFEST_PATHS.flat_map do |path| JSON.parse(File.read(path)).fetch("operations") end.map { |data| Operation.new(data) }.freeze end |
.resources ⇒ Object
19 20 21 |
# File 'lib/fly_io/operation_registry.rb', line 19 def resources @resources ||= operations.group_by(&:ruby_resource).transform_values(&:freeze).freeze end |