Class: NewStoreApi::Role
- Defined in:
- lib/new_store_api/models/role.rb
Overview
Needed for granting permissions per group not individually.
Instance Attribute Summary collapse
-
#created_at ⇒ DateTime
TODO: Write general description for this method.
-
#id ⇒ String
Identifier of the role.
-
#is_readonly ⇒ TrueClass | FalseClass
The role is read-only and not editable.
-
#name ⇒ String
Name of the role.
-
#permissions ⇒ Array[Permission]
List of permissions which are assigned to the role.
-
#updated_at ⇒ DateTime
List of permissions which are assigned to the role.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#initialize(id = nil, name = nil, created_at = SKIP, is_readonly = SKIP, permissions = SKIP, updated_at = SKIP) ⇒ Role
constructor
A new instance of Role.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
- #to_custom_created_at ⇒ Object
- #to_custom_updated_at ⇒ Object
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(id = nil, name = nil, created_at = SKIP, is_readonly = SKIP, permissions = SKIP, updated_at = SKIP) ⇒ Role
Returns a new instance of Role.
64 65 66 67 68 69 70 71 72 |
# File 'lib/new_store_api/models/role.rb', line 64 def initialize(id = nil, name = nil, created_at = SKIP, is_readonly = SKIP, = SKIP, updated_at = SKIP) @created_at = created_at unless created_at == SKIP @id = id @is_readonly = is_readonly unless is_readonly == SKIP @name = name @permissions = unless == SKIP @updated_at = updated_at unless updated_at == SKIP end |
Instance Attribute Details
#created_at ⇒ DateTime
TODO: Write general description for this method
15 16 17 |
# File 'lib/new_store_api/models/role.rb', line 15 def created_at @created_at end |
#id ⇒ String
Identifier of the role.
19 20 21 |
# File 'lib/new_store_api/models/role.rb', line 19 def id @id end |
#is_readonly ⇒ TrueClass | FalseClass
The role is read-only and not editable.
23 24 25 |
# File 'lib/new_store_api/models/role.rb', line 23 def is_readonly @is_readonly end |
#name ⇒ String
Name of the role.
27 28 29 |
# File 'lib/new_store_api/models/role.rb', line 27 def name @name end |
#permissions ⇒ Array[Permission]
List of permissions which are assigned to the role.
31 32 33 |
# File 'lib/new_store_api/models/role.rb', line 31 def @permissions end |
#updated_at ⇒ DateTime
List of permissions which are assigned to the role.
35 36 37 |
# File 'lib/new_store_api/models/role.rb', line 35 def updated_at @updated_at end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/new_store_api/models/role.rb', line 75 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. id = hash.key?('id') ? hash['id'] : nil name = hash.key?('name') ? hash['name'] : nil created_at = if hash.key?('created_at') (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at']) else SKIP end is_readonly = hash.key?('is_readonly') ? hash['is_readonly'] : SKIP # Parameter is an array, so we need to iterate through it = nil unless hash['permissions'].nil? = [] hash['permissions'].each do |structure| << (Permission.from_hash(structure) if structure) end end = SKIP unless hash.key?('permissions') updated_at = if hash.key?('updated_at') (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at']) else SKIP end # Create object from extracted values. Role.new(id, name, created_at, is_readonly, , updated_at) end |
.names ⇒ Object
A mapping from model property names to API property names.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/new_store_api/models/role.rb', line 38 def self.names @_hash = {} if @_hash.nil? @_hash['created_at'] = 'created_at' @_hash['id'] = 'id' @_hash['is_readonly'] = 'is_readonly' @_hash['name'] = 'name' @_hash['permissions'] = 'permissions' @_hash['updated_at'] = 'updated_at' @_hash end |
.nullables ⇒ Object
An array for nullable fields
60 61 62 |
# File 'lib/new_store_api/models/role.rb', line 60 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
50 51 52 53 54 55 56 57 |
# File 'lib/new_store_api/models/role.rb', line 50 def self.optionals %w[ created_at is_readonly permissions updated_at ] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
128 129 130 131 132 133 |
# File 'lib/new_store_api/models/role.rb', line 128 def inspect class_name = self.class.name.split('::').last "<#{class_name} created_at: #{@created_at.inspect}, id: #{@id.inspect}, is_readonly:"\ " #{@is_readonly.inspect}, name: #{@name.inspect}, permissions: #{@permissions.inspect},"\ " updated_at: #{@updated_at.inspect}>" end |
#to_custom_created_at ⇒ Object
112 113 114 |
# File 'lib/new_store_api/models/role.rb', line 112 def to_custom_created_at DateTimeHelper.to_rfc3339(created_at) end |
#to_custom_updated_at ⇒ Object
116 117 118 |
# File 'lib/new_store_api/models/role.rb', line 116 def to_custom_updated_at DateTimeHelper.to_rfc3339(updated_at) end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
121 122 123 124 125 |
# File 'lib/new_store_api/models/role.rb', line 121 def to_s class_name = self.class.name.split('::').last "<#{class_name} created_at: #{@created_at}, id: #{@id}, is_readonly: #{@is_readonly}, name:"\ " #{@name}, permissions: #{@permissions}, updated_at: #{@updated_at}>" end |