Class: CpOraclecloud::Image
- Inherits:
-
Object
- Object
- CpOraclecloud::Image
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- app/models/cp_oraclecloud/image.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#description ⇒ Object
Returns the value of attribute description.
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
- .all ⇒ Object
- .connection ⇒ Object
- .create(params) ⇒ Object
- .delete(id) ⇒ Object
- .find_by_id(id) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Image
constructor
A new instance of Image.
- #persisted? ⇒ Boolean
- #to_model ⇒ Object
- #to_s ⇒ Object
- #update(params) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Image
Returns a new instance of Image.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/cp_oraclecloud/image.rb', line 11 def initialize(attributes = {}) if !attributes[:name].blank? regex = attributes[:name].match(/\/.*\/(.*)/) if regex && regex.length > 1 clean_name = regex[1] attributes[:id] = clean_name attributes[:name] = clean_name end end attributes.each do |field, value| send("#{field}=", value) end end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
7 8 9 |
# File 'app/models/cp_oraclecloud/image.rb', line 7 def default @default end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'app/models/cp_oraclecloud/image.rb', line 7 def description @description end |
#entries ⇒ Object
Returns the value of attribute entries.
7 8 9 |
# File 'app/models/cp_oraclecloud/image.rb', line 7 def entries @entries end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'app/models/cp_oraclecloud/image.rb', line 7 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'app/models/cp_oraclecloud/image.rb', line 7 def name @name end |
#uri ⇒ Object
Returns the value of attribute uri.
7 8 9 |
# File 'app/models/cp_oraclecloud/image.rb', line 7 def uri @uri end |
Class Method Details
.all ⇒ Object
37 38 39 40 41 |
# File 'app/models/cp_oraclecloud/image.rb', line 37 def self.all result = [] connection.image_lists.each { |k| result.push(CpOraclecloud::Image.new(k.attributes))} result end |
.connection ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'app/models/cp_oraclecloud/image.rb', line 67 def self.connection @connection ||= Fog::Compute.new( :provider => 'OracleCloud', :oracle_username => CpOraclecloud.username, :oracle_password => CpOraclecloud.password, :oracle_domain => CpOraclecloud.domain, :oracle_compute_api => CpOraclecloud.compute_api ) end |
.create(params) ⇒ Object
48 49 50 51 52 |
# File 'app/models/cp_oraclecloud/image.rb', line 48 def self.create(params) connection.image_lists.create(:name => params[:name], :default => params[:default], :description => params[:description]) end |
.delete(id) ⇒ Object
63 64 65 |
# File 'app/models/cp_oraclecloud/image.rb', line 63 def self.delete(id) connection.image_lists.get(id).destroy end |
.find_by_id(id) ⇒ Object
43 44 45 46 |
# File 'app/models/cp_oraclecloud/image.rb', line 43 def self.find_by_id(id) data = connection.image_lists.get(id) CpOraclecloud::Image.new(data.attributes) end |
Instance Method Details
#persisted? ⇒ Boolean
33 34 35 |
# File 'app/models/cp_oraclecloud/image.rb', line 33 def persisted? !id.blank? end |
#to_model ⇒ Object
29 30 31 |
# File 'app/models/cp_oraclecloud/image.rb', line 29 def to_model self end |
#to_s ⇒ Object
25 26 27 |
# File 'app/models/cp_oraclecloud/image.rb', line 25 def to_s name end |
#update(params) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/models/cp_oraclecloud/image.rb', line 54 def update(params) fog = self.class.connection.image_lists.get(id) [:name, :default, :description].each do |field| fog.attributes[field.to_sym] = params[field.to_sym] end fog.update end |