soror 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42d441c4bd3902be3e288411d4cc568e9e8a1988
4
- data.tar.gz: 31f9696ef46faf3d88dc5dcd3e8a73300c62ee25
3
+ metadata.gz: 034997ba85838ff60db49c955ea8b4f4405f5c33
4
+ data.tar.gz: 56411d4aa19bb9b7b8ee338f3ad7d2c986b39998
5
5
  SHA512:
6
- metadata.gz: eeee8b20d3f49371f18cbc1b6231181138b9d6b0a0a1cd3fdeed4ee44a24c48e669d2a734431c1c865b74ce400049285250ef01a2d9e14ab13b949fc9285371c
7
- data.tar.gz: 323ee560c02571ffdc90c8cae872fdcdf8c0e1f6f99e02ad8121ac9b63300e36151790aedf0ffd2828f5f2c3ccb889872571412dad04a65a7fd3a5437e6d2157
6
+ metadata.gz: 668a7efefa9faaed4c4382d1f832f84ac7bc3f83ff8052f9a2660fa8119399c3cfcf4980b6acc7afa07036f800f5d781a8da146072e9ad549fb4bd785bbc0902
7
+ data.tar.gz: 500a4bc5dfabb60a656e30773c3a2c4449899c4dc5b134ae57f0ad3c920f868745b9ff7547b082aed2002f152f586fa2000743c1e47bf0f0125d8d2f8d2d3047
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Soror
2
2
 
3
- Soror is EC2 instances searcher, EC2 instances are searched by tags
3
+ Search for EC2 instances by tags :mag_right:
4
4
 
5
5
  ## Installation
6
6
 
@@ -22,15 +22,15 @@ Or install it yourself as:
22
22
 
23
23
  ```ruby
24
24
  # Search for EC2 instances which have the tag `{ "Key": "name", "Value": "soror" }`
25
- # You can use methods of AWS::EC2::Instance to an element of return value
26
- # See http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Instance.html
27
- Soror::EC2::Instance.search_by(name: 'soror') #=> [<AWS::EC2::Instance>, ...]
25
+ # You can use methods of Aws::EC2::Instance to an element of return value
26
+ # See http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Instance.html
27
+ Soror::EC2::Instance.search_by(name: 'soror') #=> [<Aws::EC2::Instance>, ...]
28
28
  ```
29
29
 
30
30
  ### Configuration
31
31
 
32
32
  ```ruby
33
- Soror.config(access_key_id: 'xxxxx', secret_access_key: 'xxxxx', region: 'ap-northeast-1')
33
+ Soror.config = { access_key_id: 'xxxxx', secret_access_key: 'xxxxx', region: 'ap-northeast-1' }
34
34
  ```
35
35
 
36
36
  Or put the configuration file on your home directory as:
@@ -43,12 +43,6 @@ region: 'ap-northeast-1'
43
43
  EOS
44
44
  ```
45
45
 
46
- ### Memoization
47
-
48
- ```ruby
49
- Soror.start_memoizing
50
- ```
51
-
52
46
  ## CLI
53
47
 
54
48
  ```
data/bin/soror CHANGED
@@ -22,7 +22,6 @@ fail OptionParser::MissingArgument, '--attributes' if options[:attributes].nil?
22
22
  fail OptionParser::InvalidArgument, '--attributes' if options[:attributes].empty?
23
23
 
24
24
  Soror.config(options[:config])
25
- Soror.start_memoizing
26
25
 
27
26
  instances = Soror::EC2::Instance.search_by(options[:tag])
28
27
  exit! if instances.empty?
@@ -1,14 +1,17 @@
1
1
  module Soror
2
2
  module EC2
3
3
  class Instance
4
- extend Soror::EC2
4
+ class << self
5
+ include Soror::EC2
5
6
 
6
- def self.search_by(tags)
7
- warn %q{[DEPRECATION] `Soror::EC2::Instance.search_by` won't be memoized. If you want to memoize, use `Soror.start_memoizing`.}
8
- AWS.memoize do
9
- ec2.instances.
10
- filter('instance-state-name', 'running').
11
- select{ |i| tags.all?{ |k, v| i.tags[k.to_s] == v.to_s } }
7
+ def search_by(tags)
8
+ filters = [].tap do |array|
9
+ array << { name: 'instance-state-name', values: ['running'] }
10
+ tags.each do |k, v|
11
+ array << { name: "tag:#{k}", values: [v] }
12
+ end
13
+ end
14
+ resource.instances(filters: filters).to_a
12
15
  end
13
16
  end
14
17
  end
data/lib/soror/ec2.rb CHANGED
@@ -2,8 +2,12 @@ require 'soror/ec2/instance'
2
2
 
3
3
  module Soror
4
4
  module EC2
5
- def ec2
6
- @@ec2 ||= AWS::EC2.new
5
+ def client
6
+ @@client ||= Aws::EC2::Client.new
7
+ end
8
+
9
+ def resource
10
+ @@resource ||= Aws::EC2::Resource.new(client: client)
7
11
  end
8
12
  end
9
13
  end
data/lib/soror/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Soror
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/soror.rb CHANGED
@@ -1,16 +1,38 @@
1
- require 'aws-sdk-v1'
1
+ require 'aws-sdk'
2
2
  require 'forwardable'
3
3
  require 'soror/ec2'
4
4
  require 'soror/version'
5
5
  require 'yaml'
6
6
 
7
+ unless {}.respond_to?(:symbolize_keys)
8
+ class Hash
9
+ def symbolize_keys
10
+ dup.symbolize_keys!
11
+ end
12
+
13
+ def symbolize_keys!
14
+ keys.each do |key|
15
+ self[(key.to_sym rescue key) || key] = delete(key)
16
+ end
17
+ self
18
+ end
19
+ end
20
+ end
21
+
7
22
  module Soror
8
23
  class << self
9
24
  extend Forwardable
10
- def_delegators AWS, :config, :start_memoizing, :stop_memoizing
25
+ def_delegators Aws, :config=
26
+
27
+ def config(hash)
28
+ warn '[DEPRECATION] `Soror.config` will be removed. Please use `Soror.config=` instead.'
29
+ hash.symbolize_keys.each{ |k, v| Aws.config[k] = v }
30
+ end
11
31
  end
12
32
  end
13
33
 
14
34
  File.expand_path('~/.soror').tap do |path|
15
- File.exists?(path) && Soror.config(YAML.load_file(path))
35
+ if File.exists?(path)
36
+ Soror.config = YAML.load_file(path).symbolize_keys
37
+ end
16
38
  end
data/soror.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Soror::VERSION
9
9
  spec.authors = ["kirikiriyamama"]
10
10
  spec.email = ["kirikiriyamama@icloud.com"]
11
- spec.summary = %q{Soror is EC2 instances seacher}
11
+ spec.summary = %q{Search for EC2 instances by tags}
12
12
  spec.description = spec.summary
13
13
  spec.homepage = "https://github.com/kirikiriyamama/soror"
14
14
  spec.license = "MIT"
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
 
24
- spec.add_runtime_dependency "aws-sdk-v1"
24
+ spec.add_runtime_dependency "aws-sdk", '~> 2'
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soror
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kirikiriyamama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,20 +39,20 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: aws-sdk-v1
42
+ name: aws-sdk
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
55
- description: Soror is EC2 instances seacher
54
+ version: '2'
55
+ description: Search for EC2 instances by tags
56
56
  email:
57
57
  - kirikiriyamama@icloud.com
58
58
  executables:
@@ -94,5 +94,5 @@ rubyforge_project:
94
94
  rubygems_version: 2.2.2
95
95
  signing_key:
96
96
  specification_version: 4
97
- summary: Soror is EC2 instances seacher
97
+ summary: Search for EC2 instances by tags
98
98
  test_files: []