miasma 0.2.38 → 0.3.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
  SHA1:
3
- metadata.gz: b1b12443a87fc43d5ff3653d64880ad421faca11
4
- data.tar.gz: 87a193d3e253bee8e5d8f39d4fa9683b2a189faa
3
+ metadata.gz: a7c89af4200f0f9b301ab945ba9463907b2d5f15
4
+ data.tar.gz: 437d01b09762f3310318c5d62918296cd75b2c2c
5
5
  SHA512:
6
- metadata.gz: 7092f00cef8368c15141e3bb176d176e400ef08fe9f6e9212d3e4d835440f364897f770f4a57101dd22647306ea28535afcc4f263b2bc7c272c06610842bb4e0
7
- data.tar.gz: adb1fa35cd4f0a446b6efff296e1170bcaf73a0cfe7d1957aa87d471a22169df31293a3fa10bfc8984c0857990db39da7f88a22ddcb433651c2dcb4c886e7de9
6
+ metadata.gz: 7681c24d0285ba51ee49e4645ba8658e0b000f6ae8f42f24d7d42d705122dc96622fa2cdb87396b830e8dd92ba6f844b8b6eed440931dd9416a8a2aa84f93a64
7
+ data.tar.gz: 1f0e9c36d3015859f290e91c42a2823e0a4ae01175cca6fad2f2afd13b6b5041e22d85bc8de6c86451c17be88ff6c46eda425433bf683e4ef58029fdf1ab4a53
@@ -1,3 +1,10 @@
1
+ # v0.3.0
2
+ * Automatically check for API provided methods
3
+ * Remove provider specific dependencies
4
+
5
+ _NOTE: Provider specific libraries are not longer
6
+ automatically included and must be explicitly defined._
7
+
1
8
  # v0.2.38
2
9
  * Fix cassette naming within spec abstracts
3
10
 
@@ -14,6 +14,8 @@ module Miasma
14
14
  include Miasma::Utils::Lazy
15
15
  include Miasma::Utils::Memoization
16
16
 
17
+ always_clean!
18
+
17
19
  # Create new API connection
18
20
  #
19
21
  # @param creds [Smash] credentials
@@ -7,13 +7,13 @@ module Miasma
7
7
  class Collection
8
8
 
9
9
  include Utils::Memoization
10
+ include Utils::ApiMethoding
10
11
 
11
12
  # @return [Miasma::Api] underlying service API
12
13
  attr_reader :api
13
14
 
14
15
  def initialize(api)
15
16
  @api = api
16
- @collection = nil
17
17
  end
18
18
 
19
19
  # @return [Array<Model>]
@@ -102,25 +102,37 @@ module Miasma
102
102
  # @param ident [String, Symbol] model identifier
103
103
  # @return [Model, NilClass]
104
104
  def perform_get(ident)
105
- all.detect do |obj|
106
- obj.id == ident ||
107
- (obj.respond_to?(:name) && !obj.name.nil? && obj.name == ident)
105
+ if(m_name = api_method_for(:get))
106
+ api.send(m_name, ident)
107
+ else
108
+ all.detect do |obj|
109
+ obj.id == ident ||
110
+ (obj.respond_to?(:name) && !obj.name.nil? && obj.name == ident)
111
+ end
108
112
  end
109
113
  end
110
114
 
111
115
  # @return [Array<Model>]
112
116
  def perform_population
113
- raise NotImplementedError
117
+ if(m_name = api_method_for(:all))
118
+ api.send(m_name)
119
+ else
120
+ raise NotImplementedError
121
+ end
114
122
  end
115
123
 
116
124
  # @return [Array<Model>]
117
125
  def perform_filter(args)
118
- if(args[:prefix])
119
- all.find_all do |item|
120
- item.name.start_with?(args[:prefix])
121
- end
126
+ if(m_name = api_method_for(:filter))
127
+ api.send(m_name, args)
122
128
  else
123
- all
129
+ if(args[:prefix])
130
+ all.find_all do |item|
131
+ item.name.start_with?(args[:prefix])
132
+ end
133
+ else
134
+ all
135
+ end
124
136
  end
125
137
  end
126
138
 
@@ -7,6 +7,7 @@ module Miasma
7
7
  class Model < Data
8
8
 
9
9
  include Utils::Memoization
10
+ include Utils::ApiMethoding
10
11
 
11
12
  attribute :custom, Smash, :coerce => lambda{|v| v.to_smash}, :default => Smash.new
12
13
 
@@ -100,7 +101,11 @@ module Miasma
100
101
  # @return [TrueClass, FalseClass] performed remote action
101
102
  # @raises [Miasma::Error::Save]
102
103
  def perform_save
103
- raise NotImplementedError.new 'Remote API save has not been implemented'
104
+ if(m_name = api_method_for(:save))
105
+ api.send(m_name, self)
106
+ else
107
+ raise NotImplementedError.new 'Remote API save has not been implemented'
108
+ end
104
109
  end
105
110
 
106
111
  # Reload model state from remote API
@@ -108,7 +113,11 @@ module Miasma
108
113
  # @return [TrueClass, FalseClass] performed remote action
109
114
  # @raises [Miasma::Error::Save]
110
115
  def perform_reload
111
- raise NotImplementedError.new 'Remote API reload has not been implemented'
116
+ if(m_name = api_method_for(:reload))
117
+ api.send(m_name, self)
118
+ else
119
+ raise NotImplementedError.new 'Remote API reload has not been implemented'
120
+ end
112
121
  end
113
122
 
114
123
  # Destroy model from remote API
@@ -116,7 +125,11 @@ module Miasma
116
125
  # @return [TrueClass, FalseClass] performed remote action
117
126
  # @raises [Miasma::Error::Save]
118
127
  def perform_destroy
119
- raise NotImplementedError.new 'Remote API destroy has not been implemented'
128
+ if(m_name = api_method_for(:destroy))
129
+ api.send(m_name, self)
130
+ else
131
+ raise NotImplementedError.new 'Remote API destroy has not been implemented'
132
+ end
120
133
  end
121
134
 
122
135
  end
@@ -2,6 +2,7 @@ require 'miasma'
2
2
 
3
3
  module Miasma
4
4
  module Utils
5
+ autoload :ApiMethoding, 'miasma/utils/api_methoding'
5
6
  autoload :Lazy, 'miasma/utils/lazy'
6
7
  autoload :Memoization, 'miasma/utils/memoization'
7
8
  autoload :Immutable, 'miasma/utils/immutable'
@@ -0,0 +1,19 @@
1
+ require 'miasma'
2
+
3
+ module Miasma
4
+ module Utils
5
+
6
+ module ApiMethoding
7
+
8
+ # Generate the supported API method for
9
+ # a given action
10
+ def api_method_for(action)
11
+ klass = self.respond_to?(:model) ? model : self.class
12
+ m_name = "#{Bogo::Utility.snake(klass.name.split('::').last)}_#{action}"
13
+ self.api.respond_to?(m_name) ? m_name : nil
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -1,4 +1,4 @@
1
1
  module Miasma
2
2
  # current library version
3
- VERSION = Gem::Version.new('0.2.38')
3
+ VERSION = Gem::Version.new('0.3.0')
4
4
  end
@@ -15,11 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.add_runtime_dependency 'multi_xml'
16
16
  s.add_runtime_dependency 'xml-simple'
17
17
  s.add_runtime_dependency 'bogo', '>= 0.1.30', '< 1.0'
18
- # Include provider libs that do not have outside deps
19
- s.add_runtime_dependency 'miasma-aws'
20
- s.add_runtime_dependency 'miasma-open-stack'
21
- s.add_runtime_dependency 'miasma-rackspace'
22
- # Include development dependencies for running tests
23
18
  s.add_development_dependency 'pry'
19
+ s.add_development_dependency 'rake'
20
+ s.add_development_dependency 'minitest'
24
21
  s.files = Dir['{bin,lib}/**/*'] + %w(miasma.gemspec README.md CHANGELOG.md LICENSE)
25
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miasma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.38
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -93,27 +93,13 @@ dependencies:
93
93
  - !ruby/object:Gem::Version
94
94
  version: '1.0'
95
95
  - !ruby/object:Gem::Dependency
96
- name: miasma-aws
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :runtime
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: '0'
109
- - !ruby/object:Gem::Dependency
110
- name: miasma-open-stack
96
+ name: pry
111
97
  requirement: !ruby/object:Gem::Requirement
112
98
  requirements:
113
99
  - - ">="
114
100
  - !ruby/object:Gem::Version
115
101
  version: '0'
116
- type: :runtime
102
+ type: :development
117
103
  prerelease: false
118
104
  version_requirements: !ruby/object:Gem::Requirement
119
105
  requirements:
@@ -121,13 +107,13 @@ dependencies:
121
107
  - !ruby/object:Gem::Version
122
108
  version: '0'
123
109
  - !ruby/object:Gem::Dependency
124
- name: miasma-rackspace
110
+ name: rake
125
111
  requirement: !ruby/object:Gem::Requirement
126
112
  requirements:
127
113
  - - ">="
128
114
  - !ruby/object:Gem::Version
129
115
  version: '0'
130
- type: :runtime
116
+ type: :development
131
117
  prerelease: false
132
118
  version_requirements: !ruby/object:Gem::Requirement
133
119
  requirements:
@@ -135,7 +121,7 @@ dependencies:
135
121
  - !ruby/object:Gem::Version
136
122
  version: '0'
137
123
  - !ruby/object:Gem::Dependency
138
- name: pry
124
+ name: minitest
139
125
  requirement: !ruby/object:Gem::Requirement
140
126
  requirements:
141
127
  - - ">="
@@ -198,6 +184,7 @@ files:
198
184
  - lib/miasma/types/thin_model.rb
199
185
  - lib/miasma/utils.rb
200
186
  - lib/miasma/utils/animal_strings.rb
187
+ - lib/miasma/utils/api_methoding.rb
201
188
  - lib/miasma/utils/immutable.rb
202
189
  - lib/miasma/utils/lazy.rb
203
190
  - lib/miasma/utils/memoization.rb