-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Azure Storage Table/CosmosDB support (#999)
- Loading branch information
Mikkel Malmberg
authored
Jul 6, 2021
1 parent
6a11c0f
commit a96aea3
Showing
34 changed files
with
839 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Licensed to Elasticsearch B.V. under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Elasticsearch B.V. licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
# frozen_string_literal: true | ||
|
||
module ElasticAPM | ||
# An interface for creating simple, value holding objects that correspond to | ||
# object fields in the API. | ||
# | ||
# Example: | ||
# class MyThing | ||
# include Fields | ||
# field :name | ||
# field :address, optional: true | ||
# end | ||
# | ||
# MyThing.new(name: 'AJ').to_h | ||
# # => { name: 'AJ' } | ||
# MyThing.new().empty? | ||
# # => true | ||
module Fields | ||
module InstanceMethods | ||
def initialize(**attrs) | ||
attrs.each do |key, value| | ||
self.send(:"#{key}=", value) | ||
end | ||
|
||
super() | ||
end | ||
|
||
def empty? | ||
self.class.fields.each do |key| | ||
next if send(key) | ||
next if optionals.include?(key) | ||
|
||
return true | ||
end | ||
|
||
false | ||
end | ||
|
||
def to_h | ||
self.class.fields.each_with_object({}) do |key, fields| | ||
fields[key] = send(key) | ||
end | ||
end | ||
|
||
private | ||
|
||
def optionals | ||
self.class.optionals | ||
end | ||
end | ||
|
||
module ClassMethods | ||
def field(key, optional: false) | ||
attr_accessor(key) | ||
|
||
fields.push(key) | ||
optionals.push(key) if optional | ||
end | ||
|
||
attr_reader :fields, :optionals | ||
end | ||
|
||
def self.included(cls) | ||
cls.extend(ClassMethods) | ||
cls.include(InstanceMethods) | ||
|
||
cls.instance_variable_set(:@fields, []) | ||
cls.instance_variable_set(:@optionals, []) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.