deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [01/30] Client: Complete rewrite of deltacloud-client
Date Tue, 26 Mar 2013 17:57:47 GMT
Updated Branches:
  refs/heads/master 95e86624c -> e107d206e


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b6d3365c/client/lib/instance_state.rb
----------------------------------------------------------------------
diff --git a/client/lib/instance_state.rb b/client/lib/instance_state.rb
deleted file mode 100644
index 6a64f57..0000000
--- a/client/lib/instance_state.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF 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.
-
-module DeltaCloud
-  module InstanceState
-
-    class State
-      attr_reader :name
-      attr_reader :transitions
-
-      def initialize(name)
-        @name, @transitions = name, []
-      end
-    end
-
-    class Transition
-      attr_reader :to
-      attr_reader :action
-
-      def initialize(to, action)
-        @to = to
-        @action = action
-      end
-
-      def auto?
-        @action.nil?
-      end
-    end
-
-  end
-
-end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b6d3365c/client/lib/string.rb
----------------------------------------------------------------------
diff --git a/client/lib/string.rb b/client/lib/string.rb
deleted file mode 100644
index fb90564..0000000
--- a/client/lib/string.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF 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.
-
-class String
-
-  unless method_defined?(:classify)
-    # Create a class name from string
-    def classify
-      self.singularize.camelize
-    end
-  end
-
-  unless method_defined?(:camelize)
-    # Camelize converts strings to UpperCamelCase
-    def camelize
-      self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
-    end
-  end
-
-  unless method_defined?(:singularize)
-    # Strip 's' character from end of string
-    def singularize
-      self.gsub(/s$/, '')
-    end
-  end
-
-  unless method_defined?(:pluralize)
-    def pluralize
-      return self + 'es' if self =~ /ess$/
-      return self[0, self.length-1] + "ies" if self =~ /ty$/
-      return self if self =~ /data$/
-      self + "s"
-    end
-  end
-
-  # Convert string to float if string value seems like Float
-  def convert
-    return self.to_f if self.strip =~ /^([\d\.]+$)/
-    self
-  end
-
-  # Simply converts whitespaces and - symbols to '_' which is safe for Ruby
-  def sanitize
-    self.strip.gsub(/(\W+)/, '_')
-  end
-
-end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b6d3365c/client/support/method_test_template.erb
----------------------------------------------------------------------
diff --git a/client/support/method_test_template.erb b/client/support/method_test_template.erb
new file mode 100644
index 0000000..89831fb
--- /dev/null
+++ b/client/support/method_test_template.erb
@@ -0,0 +1,53 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF 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.
+
+require_relative '../test_helper'
+
+describe Deltacloud::Client::Methods::<%=name.to_s.camelize%> do
+
+  before do
+    VCR.insert_cassette(__name__)
+    @client = new_client
+  end
+
+  after do
+    VCR.eject_cassette
+  end
+
+  it 'supports #<%=name.to_s.pluralize%>' do
+    @client.must_respond_to :<%=name.to_s.pluralize%>
+    @client.<%=name.to_s.pluralize%>.must_be_kind_of Array
+    @client.<%=name.to_s.pluralize%>.each { |r| r.must_be_instance_of Deltacloud::Client::<%=name.to_s.camelize%>
}
+  end
+
+  it 'supports filtering #<%=name.to_s.pluralize%> by :id param' do
+    result = @client.<%=name.to_s.pluralize%>(:id => 'XXX')
+    result.must_be_kind_of Array
+    result.size.must_equal 1
+    result.first.must_be_instance_of Deltacloud::Client::<%=name.to_s.camelize%>
+    result = @client.<%=name.to_s.pluralize%>(:id => 'unknown')
+    result.must_be_kind_of Array
+    result.size.must_equal 0
+  end
+
+  it 'support #<%=name.to_s%>' do
+    @client.must_respond_to :<%=name%>
+    result = @client.<%=name%>('XXX')
+    result.must_be_instance_of Deltacloud::Client::<%=name.to_s.camelize%>
+    lambda { @client.<%=name%>(nil) }.must_raise Deltacloud::Client::NotFound
+    lambda { @client.<%=name%>('foo') }.must_raise Deltacloud::Client::NotFound
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b6d3365c/client/support/methods_template.erb
----------------------------------------------------------------------
diff --git a/client/support/methods_template.erb b/client/support/methods_template.erb
new file mode 100644
index 0000000..b64b1eb
--- /dev/null
+++ b/client/support/methods_template.erb
@@ -0,0 +1,54 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF 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.
+
+module Deltacloud::Client
+  module Methods
+    module <%=name.to_s.camelize%>
+
+      # Retrieve list of all <%=name%> entities
+      #
+      # Filter options:
+      #
+      # - :id -> Filter entities using 'id' attribute
+      #
+      def <%=name.to_s.pluralize%>(filter_opts={})
+        from_collection :<%=name.to_s.pluralize%>,
+        connection.get(api_uri('<%=name.to_s.pluralize%>'), filter_opts)
+      end
+
+      # Retrieve the single <%=name%> entity
+      #
+      # - <%=name%>_id -> <%=name.to_s.camelize%> entity to retrieve
+      #
+      def <%=name%>(<%=name%>_id)
+        from_resource :<%=name%>,
+          connection.get(api_uri("<%=name.to_s.pluralize%>/#{<%=name%>_id}"))
+      end
+
+      # Create a new <%=name%>
+      #
+      # - create_opts
+      #
+      # def create_<%=name%>(create_opts={})
+      #   must_support! :<%=name.to_s.pluralize%>
+      #    response = connection.post(api_uri('<%=name.to_s.pluralize%>')) do |request|
+      #     request.params = create_opts
+      #   end
+      #   model(:<%=name%>).convert(self, response.body)
+      # end
+
+    end
+  end
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b6d3365c/client/support/model_template.erb
----------------------------------------------------------------------
diff --git a/client/support/model_template.erb b/client/support/model_template.erb
new file mode 100644
index 0000000..0def783
--- /dev/null
+++ b/client/support/model_template.erb
@@ -0,0 +1,45 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF 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.
+
+module Deltacloud::Client
+  class <%=name.to_s.camelize%> < Base
+
+    include Deltacloud::Client::Methods::<%=name.to_s.camelize%>
+
+    # Inherited attributes: :_id, :name, :description
+
+    # Custom attributes:
+    #
+    # attr_reader :state
+    # attr_reader :realm_id
+
+    # <%=name.to_s.camelize%> model methods
+    #
+    # def reboot!
+    #   <%=name%>_reboot(_id)
+    # end
+
+    # Parse the <%=name.to_s.camelize %> entity from XML body
+    #
+    # - xml_body -> Deltacloud API XML representation of the <%=name%>
+    #
+    def self.parse(xml_body)
+      {
+        # :state => xml_body.text_at(:state),
+        # :realm_id => xml_body.attr_at('realm', :id)
+      }
+    end
+  end
+end


Mime
View raw message