engineyard-serverside-adapter 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -38,14 +38,10 @@ end
38
38
 
39
39
  def remove_pre
40
40
  require 'engineyard-serverside-adapter/version'
41
- version = EY::Serverside::Adapter::VERSION
42
- unless version =~ /\.pre$/
43
- raise "Version #{version.inspect} does not end with .pre, you should release manually if you want a custom version name."
44
- end
45
- new_version = version.gsub(/\.pre$/, '')
41
+ new_version = Gem::Version.create(EY::Serverside::Adapter::VERSION).release
46
42
  puts "New version is #{new_version}"
47
43
  bump(new_version, "Bump to version #{new_version}")
48
- new_version
44
+ new_version.to_s
49
45
  end
50
46
 
51
47
  def next_pre(version)
@@ -1,5 +1,7 @@
1
1
  require 'escape'
2
2
  require 'pathname'
3
+ require 'engineyard-serverside-adapter/option'
4
+ require 'engineyard-serverside-adapter/arguments'
3
5
 
4
6
  module EY
5
7
  module Serverside
@@ -8,11 +10,9 @@ module EY
8
10
 
9
11
  def initialize(options = {}, &block)
10
12
  @gem_bin_path = Pathname.new(options[:gem_bin_path] || "")
11
- arguments = options[:arguments] || Arguments.new
12
- block.call arguments if block
13
- @serverside_version = arguments.serverside_version
14
-
15
- extract_state_from_arguments(arguments)
13
+ @arguments = options[:arguments] || Arguments.new
14
+ block.call @arguments if block
15
+ @serverside_version = @arguments[:serverside_version]
16
16
  validate!
17
17
  end
18
18
 
@@ -22,24 +22,22 @@ module EY
22
22
  end
23
23
 
24
24
  def verbose
25
- @state[:verbose]
25
+ @arguments[:verbose]
26
26
  end
27
27
 
28
28
  class << self
29
29
  attr_accessor :options
30
30
 
31
- def option(name, type, extra={:required => false})
32
- self.options ||= {}
33
- options[name] = extra.merge({:type => type})
31
+ def option(*args)
32
+ self.options ||= []
33
+ options << Option.new(*args)
34
34
  end
35
35
  end
36
36
 
37
37
  private
38
38
 
39
- def extract_state_from_arguments(arguments)
40
- @state = self.class.options.inject({}) do |acc, (option_name, option_attrs)|
41
- acc.merge(option_name => arguments.send(option_name))
42
- end
39
+ def applicable_options
40
+ @applicable_options ||= self.class.options.select { |option| option.on_version?(engineyard_serverside_version) }
43
41
  end
44
42
 
45
43
  def check_and_install_command
@@ -77,18 +75,16 @@ module EY
77
75
 
78
76
  def action_command
79
77
  cmd = Command.new(@gem_bin_path, engineyard_serverside_version, *task)
80
- @state.each do |option_name, value|
81
- option_type = self.class.options[option_name][:type]
82
- switch = "--" + option_name.to_s.gsub(/_/, '-')
83
- cmd.send("#{option_type}_argument", switch, value)
78
+ applicable_options.each do |option|
79
+ cmd.send("#{option.type}_argument", option.to_switch, @arguments[option.name])
84
80
  end
85
81
  cmd
86
82
  end
87
83
 
88
84
  def validate!
89
- self.class.options.each do |option_name, option_attrs|
90
- if option_attrs[:required] && !@state[option_name]
91
- raise ArgumentError, "Required field '#{option_name}' not provided."
85
+ applicable_options.each do |option|
86
+ if option.required? && !@arguments[option.name]
87
+ raise ArgumentError, "Required field '#{option.name}' not provided."
92
88
  end
93
89
  end
94
90
  end
@@ -6,17 +6,44 @@ module EY
6
6
  def self.nonempty_writer(*names)
7
7
  names.each do |name|
8
8
  define_method(:"#{name}=") do |value|
9
- if value.to_s.empty?
9
+ if value.nil? || value.to_s.empty?
10
10
  raise ArgumentError, "Value for '#{name}' must be non-empty."
11
11
  end
12
- instance_variable_set("@#{name}", value)
12
+ self[name] = value
13
+ end
14
+ end
15
+ end
16
+
17
+ def self.writer(*names)
18
+ names.each do |name|
19
+ define_method(:"#{name}=") do |value|
20
+ self[name] = value
13
21
  end
14
22
  end
15
23
  end
16
24
 
17
- attr_reader :app, :environment_name, :account_name, :config, :framework_env, :instances, :migrate, :ref, :repo, :serverside_version, :stack, :verbose
18
25
  nonempty_writer :app, :environment_name, :account_name, :framework_env, :ref, :repo, :serverside_version, :stack
19
- attr_writer :config, :migrate, :verbose
26
+ writer :config, :migrate, :verbose
27
+
28
+ def initialize(data={})
29
+ @data = data
30
+ end
31
+
32
+ def dup
33
+ self.class.new(@data.dup)
34
+ end
35
+
36
+ def []=(key, val)
37
+ @data[key.to_sym] = val
38
+ end
39
+
40
+ def [](key)
41
+ @data[key.to_sym]
42
+ end
43
+
44
+ def key?(key)
45
+ @data.key?(key.to_sym)
46
+ end
20
47
 
21
48
  def instances=(instances)
22
49
  unless instances.respond_to?(:each)
@@ -33,11 +60,15 @@ module EY
33
60
  end
34
61
  end
35
62
 
36
- @instances = instances
63
+ self[:instances] = instances
37
64
  end
38
65
 
39
66
  def serverside_version=(value)
40
- @serverside_version = Gem::Version.new(value).to_s
67
+ self[:serverside_version] = Gem::Version.create(value).to_s
68
+ end
69
+
70
+ def method_missing(meth, *)
71
+ key?(meth) ? self[meth] : super
41
72
  end
42
73
 
43
74
  end
@@ -4,8 +4,8 @@ module EY
4
4
  class Deploy < Action
5
5
 
6
6
  option :app, :string, :required => true
7
- option :account_name, :string, :required => true
8
- option :environment_name, :string, :required => true
7
+ option :account_name, :string, :required => true, :version => '>=2.0.0'
8
+ option :environment_name, :string, :required => true, :version => '>=2.0.0'
9
9
  option :stack, :string, :required => true
10
10
  option :instances, :instances, :required => true
11
11
  option :config, :json
@@ -4,8 +4,8 @@ module EY
4
4
  class DisableMaintenance < Action
5
5
 
6
6
  option :app, :string, :required => true
7
- option :account_name, :string, :required => true
8
- option :environment_name, :string, :required => true
7
+ option :account_name, :string, :required => true, :version => '>=2.0.0'
8
+ option :environment_name, :string, :required => true, :version => '>=2.0.0'
9
9
  option :instances, :instances, :required => true
10
10
  option :verbose, :boolean
11
11
 
@@ -4,8 +4,8 @@ module EY
4
4
  class EnableMaintenance < Action
5
5
 
6
6
  option :app, :string, :required => true
7
- option :account_name, :string, :required => true
8
- option :environment_name, :string, :required => true
7
+ option :account_name, :string, :required => true, :version => '>=2.0.0'
8
+ option :environment_name, :string, :required => true, :version => '>=2.0.0'
9
9
  option :instances, :instances, :required => true
10
10
  option :verbose, :boolean
11
11
 
@@ -4,8 +4,8 @@ module EY
4
4
  class Integrate < Action
5
5
 
6
6
  option :app, :string, :required => true
7
- option :account_name, :string, :required => true
8
- option :environment_name, :string, :required => true
7
+ option :account_name, :string, :required => true, :version => '>=2.0.0'
8
+ option :environment_name, :string, :required => true, :version => '>=2.0.0'
9
9
  option :stack, :string, :required => true
10
10
  option :instances, :instances, :required => true
11
11
  option :framework_env, :string, :required => true
@@ -0,0 +1,28 @@
1
+ module EY
2
+ module Serverside
3
+ class Adapter
4
+ class Option
5
+ attr_reader :name, :type
6
+
7
+ def initialize(name, type, options={:required => false})
8
+ @name, @type = name, type
9
+ @version_requirement = Gem::Requirement.create(options[:version]) if options[:version]
10
+ @options = options
11
+ end
12
+
13
+ def to_switch
14
+ "--#{@name}".gsub(/_/, '-')
15
+ end
16
+
17
+ def on_version?(version)
18
+ !@version_requirement or @version_requirement.satisfied_by?(Gem::Version.create(version))
19
+ end
20
+
21
+ def required?
22
+ @options[:required]
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -4,8 +4,8 @@ module EY
4
4
  class Restart < Action
5
5
 
6
6
  option :app, :string, :required => true
7
- option :account_name, :string, :required => true
8
- option :environment_name, :string, :required => true
7
+ option :account_name, :string, :required => true, :version => '>=2.0.0'
8
+ option :environment_name, :string, :required => true, :version => '>=2.0.0'
9
9
  option :instances, :instances, :required => true
10
10
  option :stack, :string, :required => true
11
11
  option :verbose, :boolean
@@ -4,8 +4,8 @@ module EY
4
4
  class Rollback < Action
5
5
 
6
6
  option :app, :string, :required => true
7
- option :account_name, :string, :required => true
8
- option :environment_name, :string, :required => true
7
+ option :account_name, :string, :required => true, :version => '>=2.0.0'
8
+ option :environment_name, :string, :required => true, :version => '>=2.0.0'
9
9
  option :config, :json
10
10
  option :framework_env, :string, :required => true
11
11
  option :instances, :instances, :required => true
@@ -1,7 +1,7 @@
1
1
  module EY
2
2
  module Serverside
3
3
  class Adapter
4
- VERSION = "2.0.2"
4
+ VERSION = "2.0.3"
5
5
  # For backwards compatibility, the serverside version default will be maintained until 2.1
6
6
  # It is recommended that you supply a serverside_version to engineyard-serverside-adapter
7
7
  # rather than relying on the default version here. This default will go away soon.
@@ -37,7 +37,7 @@ shared_examples_for "a serverside action" do
37
37
  end
38
38
 
39
39
  @adapter.send(@method) do |args|
40
- args.app.should == 'app-from-adapter-new'
40
+ args[:app].should == 'app-from-adapter-new'
41
41
  end
42
42
  end
43
43
 
@@ -86,6 +86,8 @@ shared_examples_for "a serverside action" do
86
86
  commands = all_commands(action)
87
87
  commands.first.should == "(gem list engineyard-serverside | grep 'engineyard-serverside ' | egrep -q '1\\.6\\.4[,)]') || (sudo sh -c 'cd `mktemp -d` && gem install engineyard-serverside --no-rdoc --no-ri -v 1.6.4')"
88
88
  commands.last.should =~ /engineyard-serverside _1\.6\.4_/
89
+ commands.last.should_not =~ /--environment-name/ # 2.0.0 and above only
90
+ commands.last.should_not =~ /--account-name/ # 2.0.0 and above only
89
91
  end
90
92
  end
91
93
  end
@@ -24,6 +24,9 @@ describe EY::Serverside::Adapter::Deploy do
24
24
  it_should_require :repo
25
25
  it_should_require :stack
26
26
 
27
+ it_should_ignore_requirement_for_version :environment_name, '1.6.4'
28
+ it_should_ignore_requirement_for_version :account_name, '1.6.4'
29
+
27
30
  it_should_behave_like "it treats config as optional"
28
31
  it_should_behave_like "it treats migrate as optional"
29
32
 
@@ -15,6 +15,9 @@ describe EY::Serverside::Adapter::DisableMaintenance do
15
15
  it_should_require :account_name
16
16
  it_should_require :instances
17
17
 
18
+ it_should_ignore_requirement_for_version :environment_name, '1.6.4'
19
+ it_should_ignore_requirement_for_version :account_name, '1.6.4'
20
+
18
21
  context "with valid arguments" do
19
22
  let(:command) do
20
23
  adapter = described_class.new do |arguments|
@@ -15,6 +15,9 @@ describe EY::Serverside::Adapter::EnableMaintenance do
15
15
  it_should_require :account_name
16
16
  it_should_require :instances
17
17
 
18
+ it_should_ignore_requirement_for_version :environment_name, '1.6.4'
19
+ it_should_ignore_requirement_for_version :account_name, '1.6.4'
20
+
18
21
  context "with valid arguments" do
19
22
 
20
23
  let(:command) do
@@ -19,6 +19,9 @@ describe EY::Serverside::Adapter::Integrate do
19
19
  it_should_require :instances
20
20
  it_should_require :framework_env
21
21
 
22
+ it_should_ignore_requirement_for_version :environment_name, '1.6.4'
23
+ it_should_ignore_requirement_for_version :account_name, '1.6.4'
24
+
22
25
  context "with valid arguments" do
23
26
  let(:command) do
24
27
  adapter = described_class.new do |arguments|
@@ -17,6 +17,9 @@ describe EY::Serverside::Adapter::Restart do
17
17
  it_should_require :instances
18
18
  it_should_require :stack
19
19
 
20
+ it_should_ignore_requirement_for_version :environment_name, '1.6.4'
21
+ it_should_ignore_requirement_for_version :account_name, '1.6.4'
22
+
20
23
  context "with valid arguments" do
21
24
  let(:command) do
22
25
  adapter = described_class.new do |arguments|
@@ -19,6 +19,9 @@ describe EY::Serverside::Adapter::Rollback do
19
19
  it_should_require :instances
20
20
  it_should_require :stack
21
21
 
22
+ it_should_ignore_requirement_for_version :environment_name, '1.6.4'
23
+ it_should_ignore_requirement_for_version :account_name, '1.6.4'
24
+
22
25
  context "with valid arguments" do
23
26
  let(:command) do
24
27
  adapter = described_class.new do |arguments|
@@ -59,6 +59,24 @@ module RequiredFieldHelpers
59
59
  end
60
60
  end
61
61
  end
62
+
63
+ def it_should_ignore_requirement_for_version(field, version)
64
+ context "field #{field} on version #{version}" do
65
+ it "is does not require #{field}" do
66
+ arguments = arguments_without(field)
67
+ arguments.serverside_version = version
68
+ lambda { described_class.new(:arguments => arguments) }.should_not raise_error
69
+ end
70
+
71
+ it "it does not include #{field} in the command, even if it is set" do
72
+ arguments = valid_arguments
73
+ arguments.serverside_version = version
74
+ action = described_class.new(:arguments => arguments)
75
+ commands = all_commands(action)
76
+ commands.last.should_not include(EY::Serverside::Adapter::Option.new(field, :string).to_switch)
77
+ end
78
+ end
79
+ end
62
80
  end
63
81
 
64
82
  RSpec.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engineyard-serverside-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-29 00:00:00.000000000 Z
13
+ date: 2012-08-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: escape
@@ -99,6 +99,7 @@ files:
99
99
  - lib/engineyard-serverside-adapter/disable_maintenance.rb
100
100
  - lib/engineyard-serverside-adapter/enable_maintenance.rb
101
101
  - lib/engineyard-serverside-adapter/integrate.rb
102
+ - lib/engineyard-serverside-adapter/option.rb
102
103
  - lib/engineyard-serverside-adapter/restart.rb
103
104
  - lib/engineyard-serverside-adapter/rollback.rb
104
105
  - lib/engineyard-serverside-adapter/version.rb
@@ -125,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
126
  version: '0'
126
127
  segments:
127
128
  - 0
128
- hash: 3765689580942820898
129
+ hash: -3663156867639779323
129
130
  required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  none: false
131
132
  requirements: