Module: Card::Set::All::Account

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod011-card-mod-account/all/account.rb,
card/tmpsets/set/mod010-card-mod-account/all/account.rb

Overview

Set: All cards (Account)

Defined Under Namespace

Modules: ClassMethods

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card-mod-account/set/all/account.rb"; end

Instance Method Details

#accountObject



14
15
16
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 14

def 
  fetch :account
end

#all_enabled_rolesObject



64
65
66
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 64

def all_enabled_roles
  @all_active_roles ||= (id == AnonymousID ? [] : enabled_role_ids)
end

#all_rolesObject



68
69
70
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 68

def all_roles
  @all_roles ||= (id == AnonymousID ? [] : fetch_roles)
end

#among?(ok_ids) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 22

def among? ok_ids
  ok_ids.any? do |ok_id|
    ok_id == AnyoneID ||
      (ok_id == AnyoneWithRoleID && all_enabled_roles.size > 1) ||
      parties.member?(ok_id)
  end
end

#clear_rolesObject



53
54
55
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 53

def clear_roles
  @parties = @all_roles = @all_active_roles = @read_rules = nil
end

#enabled_role_idsObject



72
73
74
75
76
77
78
79
80
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 72

def enabled_role_ids
  Auth.as_bot do
    # workaround for broken migrations
    return fetch_roles unless Card::Codename.exists? :enabled_roles

    enabled = enabled_roles_card
    enabled.virtual? ? enabled.item_ids : fetch_roles
  end
end

#enabled_roles_cardObject



82
83
84
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 82

def enabled_roles_card
  fetch :enabled_roles, eager_cache: true, new: { type_id: SessionID }
end

#event: generate_tokenObject



97
98
99
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 97

event :generate_token do
  Digest::SHA1.hexdigest "--#{Time.zone.now.to_f}--#{rand 10}--"
end

#event: set_stamperObject



101
102
103
104
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 101

event :set_stamper, :prepare_to_validate do
  self.updater_id = Auth.current_id
  self.creator_id = updater_id if new_card?
end

#fetch_read_rulesObject



44
45
46
47
48
49
50
51
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 44

def fetch_read_rules
  return [] if id == WagnBotID # always_ok, so not needed

  ([AnyoneID] + parties).each_with_object([]) do |party_id, rule_ids|
    next unless (cache = Card::Rule.read_rule_cache[party_id])
    rule_ids.concat cache
  end
end

#fetch_rolesObject



86
87
88
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 86

def fetch_roles
  [AnyoneSignedInID] + role_ids_from_roles_trait
end

#own_account?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 30

def own_account?
  # card is +*account card of signed_in user.
  name.part_names[0].key == Auth.as_card.key &&
    name.part_names[1].key == Card[:account].key
end

#partiesObject



18
19
20
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 18

def parties
  @parties ||= (all_enabled_roles << id).flatten.reject(&:blank?)
end

#read_rulesObject



36
37
38
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 36

def read_rules
  @read_rules ||= fetch_read_rules
end

#read_rules_hashObject



40
41
42
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 40

def read_rules_hash
  @read_rules_hash ||= read_rules.each_with_object({}) { |id, h| h[id] = true }
end

#role_ids_from_roles_traitObject



90
91
92
93
94
95
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 90

def role_ids_from_roles_trait
  Auth.as_bot do
    role_trait = fetch :roles
    role_trait ? role_trait.item_ids : []
  end
end

#with_clear_rolesObject



57
58
59
60
61
62
# File 'card/tmpsets/set/mod011-card-mod-account/all/account.rb', line 57

def with_clear_roles
  a, b, c, d = @parties, @all_roles, @all_active_roles, @read_rules
  yield
ensure
  @parties, @all_roles, @all_active_roles, @read_rules = a, b, c, d
end

#with_enabled_rolesObject



85
86
87
88
89
# File 'card/tmpsets/set/mod010-card-mod-account/all/account.rb', line 85

def with_enabled_roles
  Auth.as_bot do
    Card::Codename.exists?(:enabled_roles) ? yield(enabled_roles_card) : fetch_roles
  end
end