droplet_kit 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23066062e13119e43659c08818ac400f8f059b7ab4fba6fd6ad932cf92424cc3
4
- data.tar.gz: 429825725ffa50893fd84bedca6cdbbe22c52863d03fd19b3661334caab392a3
3
+ metadata.gz: 2a482f4679dd8fe42fad27bbf85151777108bc2ac4d361c64c2a02480b988bfc
4
+ data.tar.gz: ac6c62a63eabbb5cf077fae7578bda59dab98fbb1c086b6b50bbf17dae50e1cc
5
5
  SHA512:
6
- metadata.gz: 6ac8efdcb36b8f2c6bd9022b7b28146a147d116b035857ecc1151aaf071ee203b2699331fe7ae04152cf1ae97cd3dadd2426e063b473d5f44d0e5ac9c32b6f52
7
- data.tar.gz: cff9d0911da3b859df5f4b3b720ae7c345728c74bf7ec9e1f42d00fe7d47c1a0b3499bf886e0788e6b01c4c5c8143bef4db222aa0cdb8e9de02f9a3fcafe25ba
6
+ metadata.gz: b830d7461f8fb8edcc430aef1e80f0893f6df649402f25489da8221eb484b0028f38feb6b925c15c9da8e339edb638cc58fa0ffd375915d9d2a80497969700c8
7
+ data.tar.gz: 73a313dc86a7eb1247ce335abc59bbd394dba2e2b27decda42d247e17c525cc11de7acbd501fe6b6dfd9ef4e7181bee6b59d2e3499f8bd698c65445764d9cdf4
@@ -1,5 +1,4 @@
1
1
  require 'droplet_kit/version'
2
- require 'active_support/all'
3
2
  require 'resource_kit'
4
3
  require 'kartograph'
5
4
 
@@ -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
- @access_token = options.with_indifferent_access[:access_token]
13
- @api_url = options.with_indifferent_access[:api_url] || DIGITALOCEAN_API
14
- @open_timeout = options.with_indifferent_access[:open_timeout] || DEFAULT_OPEN_TIMEOUT
15
- @timeout = options.with_indifferent_access[:timeout] || DEFAULT_TIMEOUT
16
- @user_agent = options.with_indifferent_access[:user_agent]
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.underscore
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::#{collection.camelize}".constantize
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::#{collection.camelize}".constantize
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].each do |key|
5
+ :region, :image, :networks, :kernel, :size_slug, :tags,
6
+ :volume_ids].each do |key|
6
7
  attribute(key)
7
8
  end
8
9
 
@@ -5,7 +5,9 @@ module DropletKit
5
5
  attribute :links
6
6
 
7
7
  def self_link
8
- links.try(:myself)
8
+ return unless links
9
+
10
+ links.myself
9
11
  end
10
12
 
11
13
  def to_model
@@ -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
@@ -1,3 +1,3 @@
1
1
  module DropletKit
2
- VERSION = "3.1.0"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -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 klass.name.in?((ENV['SKIP_CLASSES'] || '').split(','))
9
+ if (ENV['SKIP_CLASSES'] || '').split(',').include?(klass.name)
9
10
  next
10
11
  end
11
12
 
12
- puts "## #{klass.name.demodulize.underscore.humanize}"
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
- params << klass.name.demodulize.underscore.downcase.gsub('_resource', '')
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.1.0
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