Module: HasHelpers::Cards::Roles

Defined in:
lib/has_helpers/cards/roles.rb

Class Method Summary collapse

Class Method Details

.all(organization_id: nil, **opts) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/has_helpers/cards/roles.rb', line 19

def all(organization_id: nil, **opts)
  case HasHelpers::Cards.config.mode
  when :server
    scope = ::HasHelpers::Role.all
    scope = scope.where(organization_id: organization_id) if organization_id.present?
    scope.to_a
  when :client
    remote.all(organization_id: organization_id, **opts)
  end
end

.find(id, **opts) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/has_helpers/cards/roles.rb', line 8

def find(id, **opts)
  return nil if id.blank?

  case HasHelpers::Cards.config.mode
  when :server
    ::HasHelpers::Role.find_by(id: id)
  when :client
    remote.find(id, **opts)
  end
end

.remoteObject



42
43
44
# File 'lib/has_helpers/cards/roles.rb', line 42

def remote
  @remote ||= RemoteRoles.new
end

.remote=(remote) ⇒ Object



46
47
48
# File 'lib/has_helpers/cards/roles.rb', line 46

def remote=(remote)
  @remote = remote
end

.reset!Object



50
51
52
# File 'lib/has_helpers/cards/roles.rb', line 50

def reset!
  @remote = nil
end

.where(ids: nil, organization_id: nil, **opts) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/has_helpers/cards/roles.rb', line 30

def where(ids: nil, organization_id: nil, **opts)
  case HasHelpers::Cards.config.mode
  when :server
    scope = ::HasHelpers::Role.all
    scope = scope.where(id: ids) if ids
    scope = scope.where(organization_id: organization_id) if organization_id.present?
    scope.to_a
  when :client
    remote.where(ids: ids, organization_id: organization_id, **opts)
  end
end