Class: AccountSerializer

Inherits:
AbstractSerializer show all
Defined in:
app/serializers/account_serializer.rb

Class Method Summary collapse

Methods inherited from AbstractSerializer

opts, serialize

Class Method Details

.abilities(account) ⇒ Object

список возможностей с учётом запретов



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/serializers/account_serializer.rb', line 44

def abilities()
       = ::Dictionaries::AccountType::CLASS_BY_TYPE[.type_id]
  default_abilities = ::Dicts::Accounts::Ability.()
  prohibited        = .user.permissions

  # отнимаем запрещённые действия из дефолтных
  not_prohibited = ->(ability) { prohibited.none? { |a| a.action.to_s == ability.index.to_s } }
  abilities      = default_abilities.map do |a|
    {
      action: a.index,
      can:    not_prohibited[a]
    }
  end

  { abilities: abilities }
end

.active(account) ⇒ Object



14
15
16
# File 'app/serializers/account_serializer.rb', line 14

def active()
  { active: .active }
end

.available_attributesObject



3
4
5
6
7
8
9
10
11
12
# File 'app/serializers/account_serializer.rb', line 3

def available_attributes
  %i[
    active
    created_at
    id
    type_index
    props
    abilities
  ]
end

.created_at(account) ⇒ Object



18
19
20
# File 'app/serializers/account_serializer.rb', line 18

def created_at()
  { created_at: .created_at }
end

.id(account) ⇒ Object



22
23
24
# File 'app/serializers/account_serializer.rb', line 22

def id()
  { id: .id }
end

.props(account) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/serializers/account_serializer.rb', line 30

def props()
  props = case .type_id
            when ::Dicts::AccountType::MANAGER_GUEST.id
              mg = .manager_guest
              {
                  radius: mg.radius.to_i
              }
            else
              {}
          end
  { props: props }
end

.type_index(account) ⇒ Object



26
27
28
# File 'app/serializers/account_serializer.rb', line 26

def type_index()
  { type_index: ::Dicts::AccountType.find(.type_id).index }
end