droplet_kit 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/droplet_kit.rb +0 -1
- data/lib/droplet_kit/client.rb +7 -5
- data/lib/droplet_kit/mappings/droplet_mapping.rb +1 -0
- data/lib/droplet_kit/models/base_model.rb +5 -4
- data/lib/droplet_kit/models/droplet.rb +2 -1
- data/lib/droplet_kit/models/project_assignment.rb +3 -1
- data/lib/droplet_kit/utils.rb +33 -0
- data/lib/droplet_kit/version.rb +1 -1
- data/lib/tasks/resource_doc.rake +14 -4
- metadata +2 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a482f4679dd8fe42fad27bbf85151777108bc2ac4d361c64c2a02480b988bfc
|
4
|
+
data.tar.gz: ac6c62a63eabbb5cf077fae7578bda59dab98fbb1c086b6b50bbf17dae50e1cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b830d7461f8fb8edcc430aef1e80f0893f6df649402f25489da8221eb484b0028f38feb6b925c15c9da8e339edb638cc58fa0ffd375915d9d2a80497969700c8
|
7
|
+
data.tar.gz: 73a313dc86a7eb1247ce335abc59bbd394dba2e2b27decda42d247e17c525cc11de7acbd501fe6b6dfd9ef4e7181bee6b59d2e3499f8bd698c65445764d9cdf4
|
data/lib/droplet_kit.rb
CHANGED
data/lib/droplet_kit/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'droplet_kit/utils'
|
2
3
|
|
3
4
|
module DropletKit
|
4
5
|
class Client
|
@@ -9,11 +10,12 @@ module DropletKit
|
|
9
10
|
attr_reader :access_token, :api_url, :open_timeout, :timeout, :user_agent
|
10
11
|
|
11
12
|
def initialize(options = {})
|
12
|
-
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
13
|
+
options = DropletKit::Utils.transform_keys(options, &:to_sym)
|
14
|
+
@access_token = options[:access_token]
|
15
|
+
@api_url = options[:api_url] || DIGITALOCEAN_API
|
16
|
+
@open_timeout = options[:open_timeout] || DEFAULT_OPEN_TIMEOUT
|
17
|
+
@timeout = options[:timeout] || DEFAULT_TIMEOUT
|
18
|
+
@user_agent = options[:user_agent]
|
17
19
|
end
|
18
20
|
|
19
21
|
def connection
|
@@ -21,6 +21,7 @@ module DropletKit
|
|
21
21
|
property :size_slug, scopes: [:read]
|
22
22
|
property :tags, scopes: [:read]
|
23
23
|
property :vpc_uuid, scopes: [:read]
|
24
|
+
property :volume_ids, scopes: [:read]
|
24
25
|
|
25
26
|
property :region, scopes: [:read], include: RegionMapping
|
26
27
|
property :image, scopes: [:read], include: ImageMapping
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'virtus'
|
2
|
+
require 'droplet_kit/utils'
|
2
3
|
|
3
4
|
module DropletKit
|
4
5
|
class BaseModel
|
@@ -18,7 +19,7 @@ module DropletKit
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def collection_name
|
21
|
-
self.class.name.split('::').last
|
22
|
+
DropletKit::Utils.underscore self.class.name.split('::').last
|
22
23
|
end
|
23
24
|
|
24
25
|
def identifier
|
@@ -36,7 +37,7 @@ module DropletKit
|
|
36
37
|
return true if UNSUPPORTED_COLLECTIONS.include?(collection)
|
37
38
|
|
38
39
|
begin
|
39
|
-
"DropletKit::#{
|
40
|
+
const_get "DropletKit::#{DropletKit::Utils.camelize(collection)}"
|
40
41
|
rescue NameError
|
41
42
|
return false
|
42
43
|
end
|
@@ -53,7 +54,7 @@ module DropletKit
|
|
53
54
|
|
54
55
|
return nil if UNSUPPORTED_COLLECTIONS.include?(collection)
|
55
56
|
|
56
|
-
klass = "DropletKit::#{
|
57
|
+
klass = const_get("DropletKit::#{DropletKit::Utils.camelize(collection)}")
|
57
58
|
klass.from_identifier(identifier)
|
58
59
|
end
|
59
60
|
|
@@ -61,4 +62,4 @@ module DropletKit
|
|
61
62
|
new(id: identifier)
|
62
63
|
end
|
63
64
|
end
|
64
|
-
end
|
65
|
+
end
|
@@ -2,7 +2,8 @@ module DropletKit
|
|
2
2
|
class Droplet < BaseModel
|
3
3
|
[:id, :name, :memory, :vcpus, :disk, :locked, :created_at,
|
4
4
|
:status, :backup_ids, :snapshot_ids, :action_ids, :features,
|
5
|
-
:region, :image, :networks, :kernel, :size_slug, :tags
|
5
|
+
:region, :image, :networks, :kernel, :size_slug, :tags,
|
6
|
+
:volume_ids].each do |key|
|
6
7
|
attribute(key)
|
7
8
|
end
|
8
9
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module DropletKit
|
2
|
+
module Utils
|
3
|
+
def self.camelize(term)
|
4
|
+
string = term.to_s
|
5
|
+
string.sub!(/^[a-z\d]*/, &:capitalize)
|
6
|
+
string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) { $2.capitalize }
|
7
|
+
string.gsub!('/'.freeze, '::'.freeze)
|
8
|
+
string
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.underscore(term)
|
12
|
+
return term unless /[A-Z-]|::/ =~ term
|
13
|
+
|
14
|
+
word = term.to_s.gsub('::'.freeze, '/'.freeze)
|
15
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
|
16
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
|
17
|
+
word.tr!('-'.freeze, '_'.freeze)
|
18
|
+
word.downcase!
|
19
|
+
word
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.transform_keys(hash, &block)
|
23
|
+
return hash.transform_keys(&block) if hash.respond_to?(:transform_keys)
|
24
|
+
return to_enum(__caller__) unless block_given?
|
25
|
+
|
26
|
+
{}.tap do |result|
|
27
|
+
hash.each do |key, value|
|
28
|
+
result[block.call(key)] = value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/droplet_kit/version.rb
CHANGED
data/lib/tasks/resource_doc.rake
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
require 'droplet_kit'
|
2
|
+
require 'droplet_kit/utils'
|
2
3
|
|
3
4
|
namespace :doc do
|
4
5
|
task :resources do
|
5
6
|
resources = DropletKit::Client.resources
|
6
7
|
|
7
8
|
resources.each do |key, klass|
|
8
|
-
if
|
9
|
+
if (ENV['SKIP_CLASSES'] || '').split(',').include?(klass.name)
|
9
10
|
next
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
+
class_name = DropletKit::Utils.underscore klass.name.split('::'.freeze).last
|
14
|
+
human_name = class_name.dup
|
15
|
+
human_name.tr!('_'.freeze, ' '.freeze)
|
16
|
+
human_name.gsub!(/([a-z\d]*)/i) { |match| match.downcase }
|
17
|
+
human_name.gsub!(/\A\w/) { |match| match.upcase }
|
18
|
+
|
19
|
+
puts "## #{human_name}"
|
13
20
|
puts
|
14
21
|
puts " client = DropletKit::Client.new(access_token: 'TOKEN')"
|
15
22
|
puts " client.#{key} #=> #{klass.name}"
|
@@ -21,7 +28,10 @@ namespace :doc do
|
|
21
28
|
params = []
|
22
29
|
|
23
30
|
if action.body && action.body.arity > 0
|
24
|
-
|
31
|
+
resource = class_name.dup
|
32
|
+
resource.gsub!('_resource', '')
|
33
|
+
resource.downcase!
|
34
|
+
params << resource
|
25
35
|
end
|
26
36
|
|
27
37
|
if action_options.any?
|
@@ -39,4 +49,4 @@ namespace :doc do
|
|
39
49
|
puts
|
40
50
|
end
|
41
51
|
end
|
42
|
-
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: droplet_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Ross
|
@@ -52,26 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.2.3
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: activesupport
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.0'
|
62
|
-
- - "<"
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: '6'
|
65
|
-
type: :runtime
|
66
|
-
prerelease: false
|
67
|
-
version_requirements: !ruby/object:Gem::Requirement
|
68
|
-
requirements:
|
69
|
-
- - ">"
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '3.0'
|
72
|
-
- - "<"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '6'
|
75
55
|
- !ruby/object:Gem::Dependency
|
76
56
|
name: faraday
|
77
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -295,6 +275,7 @@ files:
|
|
295
275
|
- lib/droplet_kit/resources/volume_action_resource.rb
|
296
276
|
- lib/droplet_kit/resources/volume_resource.rb
|
297
277
|
- lib/droplet_kit/resources/vpc_resource.rb
|
278
|
+
- lib/droplet_kit/utils.rb
|
298
279
|
- lib/droplet_kit/version.rb
|
299
280
|
- lib/tasks/resource_doc.rake
|
300
281
|
homepage: https://github.com/digitalocean/droplet_kit
|