Class: LMC::Principal
- Inherits:
-
Object
- Object
- LMC::Principal
- Defined in:
- lib/lmc/principal.rb
Constant Summary collapse
- PRINCIPAL_URL_BASE =
%w[cloud-service-auth users].freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.get_self(cloud) ⇒ Object
this is actually a bad hack because the lmc api treats users different from principals.
Instance Method Summary collapse
-
#initialize(data) ⇒ Principal
constructor
A new instance of Principal.
-
#save ⇒ Object
returns itself, allows chaining.
- #to_json(*a) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ Principal
Returns a new instance of Principal.
14 15 16 |
# File 'lib/lmc/principal.rb', line 14 def initialize(data) apply_data(data) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/lmc/principal.rb', line 6 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/lmc/principal.rb', line 6 def name @name end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
6 7 8 |
# File 'lib/lmc/principal.rb', line 6 def password @password end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/lmc/principal.rb', line 6 def type @type end |
Class Method Details
.get_self(cloud) ⇒ Object
this is actually a bad hack because the lmc api treats users different from principals.
10 11 12 |
# File 'lib/lmc/principal.rb', line 10 def self.get_self(cloud) new(cloud.get([PRINCIPAL_URL_BASE, 'self'])) end |
Instance Method Details
#save ⇒ Object
returns itself, allows chaining
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lmc/principal.rb', line 19 def save response = if @id.nil? Cloud.instance.post ['cloud-service-auth', 'principals'], self else raise 'editing principals not supported' # @cloud.put ["cloud-service-auth", "principals", @id], self end apply_data(response) self end |
#to_json(*a) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/lmc/principal.rb', line 34 def to_json(*a) { 'name' => @name, 'type' => @type, 'password' => @password }.to_json(*a) end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/lmc/principal.rb', line 30 def to_s "#{@name} - #{@id}" end |