Class: NewStoreApi::Role

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/role.rb

Overview

Needed for granting permissions per group not individually.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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,
               permissions = 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 = permissions unless permissions == SKIP
  @updated_at = updated_at unless updated_at == SKIP
end

Instance Attribute Details

#created_atDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


15
16
17
# File 'lib/new_store_api/models/role.rb', line 15

def created_at
  @created_at
end

#idString

Identifier of the role.

Returns:

  • (String)


19
20
21
# File 'lib/new_store_api/models/role.rb', line 19

def id
  @id
end

#is_readonlyTrueClass | FalseClass

The role is read-only and not editable.

Returns:

  • (TrueClass | FalseClass)


23
24
25
# File 'lib/new_store_api/models/role.rb', line 23

def is_readonly
  @is_readonly
end

#nameString

Name of the role.

Returns:

  • (String)


27
28
29
# File 'lib/new_store_api/models/role.rb', line 27

def name
  @name
end

#permissionsArray[Permission]

List of permissions which are assigned to the role.

Returns:



31
32
33
# File 'lib/new_store_api/models/role.rb', line 31

def permissions
  @permissions
end

#updated_atDateTime

List of permissions which are assigned to the role.

Returns:

  • (DateTime)


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
  permissions = nil
  unless hash['permissions'].nil?
    permissions = []
    hash['permissions'].each do |structure|
      permissions << (Permission.from_hash(structure) if structure)
    end
  end

  permissions = 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,
           permissions,
           updated_at)
end

.namesObject

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

.nullablesObject

An array for nullable fields



60
61
62
# File 'lib/new_store_api/models/role.rb', line 60

def self.nullables
  []
end

.optionalsObject

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

#inspectObject

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_atObject



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_atObject



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_sObject

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