Class: Card

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
CarrierWave::Mount
Defined in:
lib/card.rb,
lib/card/env.rb,
lib/card/set.rb,
lib/card/auth.rb,
lib/card/name.rb,
lib/card/view.rb,
lib/card/cache.rb,
lib/card/error.rb,
lib/card/query.rb,
lib/card/format.rb,
lib/card/mailer.rb,
lib/card/content.rb,
lib/card/codename.rb,
lib/card/mod/dirs.rb,
lib/card/subcards.rb,
lib/card/reference.rb,
lib/card/set/event.rb,
lib/card/set/trait.rb,
lib/card/view/stub.rb,
lib/card/auth/proxy.rb,
lib/card/auth/setup.rb,
lib/card/mod/loader.rb,
lib/card/query/join.rb,
lib/card/set/basket.rb,
lib/card/set/format.rb,
lib/card/set/loader.rb,
lib/card/view/cache.rb,
lib/card/view/fetch.rb,
lib/generators/card.rb,
lib/card/act_manager.rb,
lib/card/env/success.rb,
lib/card/format/nest.rb,
lib/card/query/value.rb,
lib/card/set/helpers.rb,
lib/card/set_pattern.rb,
lib/card/auth/current.rb,
lib/card/content/diff.rb,
lib/card/env/location.rb,
lib/card/format/error.rb,
lib/card/format/names.rb,
lib/card/view/options.rb,
lib/card/content/chunk.rb,
lib/card/content/clean.rb,
lib/card/format/render.rb,
lib/card/query/helpers.rb,
lib/card/query/sorting.rb,
lib/card/content/parser.rb,
lib/card/format/content.rb,
lib/card/migration/core.rb,
lib/card/name/view_name.rb,
lib/card/set/i18n_scope.rb,
lib/card/cache/temporary.rb,
lib/card/set/inheritance.rb,
lib/card/view/visibility.rb,
lib/card/auth/permissions.rb,
lib/card/cache/persistent.rb,
lib/card/content/diff/lcs.rb,
lib/card/content/truncate.rb,
lib/card/format/nest/main.rb,
lib/card/format/nest/view.rb,
lib/card/migration/import.rb,
lib/card/query/attributes.rb,
lib/card/set/advanced_api.rb,
lib/card/act_manager/stage.rb,
lib/card/cache/prepopulate.rb,
lib/card/format/nest/fetch.rb,
lib/card/format/permission.rb,
lib/card/model/save_helper.rb,
lib/card/name/name_variants.rb,
lib/card/query/conjunctions.rb,
lib/card/content/diff/result.rb,
lib/card/format/registration.rb,
lib/card/query/sql_statement.rb,
lib/card/env/location_history.rb,
lib/card/query/interpretation.rb,
lib/card/format/nest/subformat.rb,
lib/card/set/format/haml_views.rb,
lib/card/content/diff/processor.rb,
lib/card/name/fields_and_traits.rb,
lib/card/migration/import/merger.rb,
lib/card/act_manager/stage_director.rb,
lib/card/query/relational_attributes.rb,
lib/card/migration/import/import_data.rb,
lib/generators/card/set/set_generator.rb,
lib/card/act_manager/subdirector_array.rb,
lib/generators/card/format/format_generator.rb,
lib/generators/card/template/template_generator.rb,
lib/generators/card/migration/migration_generator.rb,
lib/card/migration/import/import_data/card_content.rb,
lib/card/migration/import/import_data/card_attributes.rb,
mod/core/format/data_format.rb,
mod/core/format/html_format.rb,
mod/core/format/text_format.rb,
mod/basic_formats/format/js_format.rb,
mod/basic_formats/format/css_format.rb,
mod/basic_formats/format/csv_format.rb,
mod/basic_formats/format/rss_format.rb,
mod/basic_formats/format/xml_format.rb,
mod/basic_formats/format/file_format.rb,
mod/basic_formats/format/json_format.rb,
mod/notifications/format/email_html_format.rb,
mod/notifications/format/email_text_format.rb,
mod/core/chunk/nest.rb,
mod/core/chunk/literal.rb,
mod/core/chunk/reference.rb,
mod/core/chunk/view_stub.rb,
mod/history/lib/card/act.rb,
mod/history/lib/card/action.rb,
mod/history/lib/card/change.rb,
mod/settings/lib/card/setting.rb,
mod/history/lib/card/action/admin.rb,
mod/history/lib/card/action/differ.rb,
mod/history/lib/card/act/act_renderer.rb,
mod/notifications/lib/card/follow_option.rb,
mod/history/lib/card/action/action_renderer.rb,
mod/history/lib/card/act/act_renderer/absolute_act_renderer.rb,
mod/history/lib/card/act/act_renderer/relative_act_renderer.rb

Overview

require_dependency File.expand_path("../../action/action_renderer", FILE)

Defined Under Namespace

Modules: Auth, Env, FollowOption, Generators, Mod, Model, Set, Setting, Version Classes: Act, ActManager, Action, Cache, Change, Codename, Content, Error, Format, Mailer, Migration, Name, Query, Reference, Subcards, View

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#follower_stashObject

Returns the value of attribute follower_stash.



66
67
68
# File 'lib/card.rb', line 66

def follower_stash
  @follower_stash
end

Class Method Details

.cacheObject



5
6
7
# File 'lib/card/cache.rb', line 5

def cache
  Card::Cache[Card]
end

.configObject



8
9
10
# File 'lib/card/mod/loader.rb', line 8

def config
  Cardio.config
end

.const_missing(const) ⇒ Integer

If a card has the codename example, then Card::ExampleID should return the id for that card. This method makes that help.

Parameters:

  • const (Const)

Returns:

  • (Integer)

Raises:

  • error if codename is missing



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/card/codename.rb', line 83

def self.const_missing const
  if const.to_s =~ /^([A-Z]\S*)ID$/ &&
     (code = Regexp.last_match(1).underscore.to_sym)
    if (card_id = Codename[code])
      const_set const, card_id
    else
      raise "Missing codename #{code} (#{const})"
    end
  else
    super
  end
end

.expire(name) ⇒ Object



24
25
26
27
28
# File 'lib/card/cache.rb', line 24

def expire name
  key = name.to_name.key
  return unless (card = Card.cache.read key)
  card.expire
end

.pathsObject



12
13
14
# File 'lib/card/mod/loader.rb', line 12

def paths
  Cardio.paths
end

.serializable_attr_accessor(*args) ⇒ Object

attributes that ActiveJob can handle



17
18
19
20
# File 'lib/card.rb', line 17

def self.serializable_attr_accessor *args
  self.serializable_attributes = args
  attr_accessor(*args)
end

.write_to_cache(card, opts) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/card/cache.rb', line 9

def write_to_cache card, opts
  if opts[:local_only]
    write_to_soft_cache card
  elsif Card.cache
    Card.cache.write card.key, card
    Card.cache.write "~#{card.id}", card.key if card.id.to_i.nonzero?
  end
end

.write_to_soft_cache(card) ⇒ Object



18
19
20
21
22
# File 'lib/card/cache.rb', line 18

def write_to_soft_cache card
  return unless Card.cache
  Card.cache.soft.write card.key, card
  Card.cache.soft.write "~#{card.id}", card.key if card.id.to_i.nonzero?
end

Instance Method Details

#clean_after_stage_failObject



11
12
13
14
15
# File 'lib/card/act_manager/stage_director.rb', line 11

def clean_after_stage_fail
  @action = nil
  expire_pieces
  subcards.each(&:expire_pieces)
end

#deserialize_for_active_job!(attr) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/card/set/event.rb', line 2

def deserialize_for_active_job! attr
  attr.each do |attname, args|
    # symbols are not allowed so all symbols arrive here as strings
    # convert strings that were symbols before back to symbols
    value = args[:symbol] ? args[:value].to_sym : args[:value]
    instance_variable_set("@#{attname}", value)
  end
  include_set_modules
end

#expire_subcardsObject



17
18
19
# File 'lib/card/subcards.rb', line 17

def expire_subcards
  subcards.clear
end

#left_id=(card_or_id) ⇒ Object



293
294
295
# File 'lib/card/subcards.rb', line 293

def left_id= card_or_id
  write_card_or_id :left_id, card_or_id
end

#log_event_call(event) ⇒ Object



40
41
42
43
44
# File 'lib/card/set/event.rb', line 40

def log_event_call event
  Rails.logger.debug "#{name}: #{event}"
  # puts "#{name}: #{event}"
  # puts "#{Card::ActManager.to_s}".green
end

#restore_changes_informationObject



3
4
5
6
7
8
9
# File 'lib/card/act_manager/stage_director.rb', line 3

def restore_changes_information
  return unless @previously_changed
  @changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
  @previously_changed.each do |k, (old, _new)|
    @changed_attributes[k] = old
  end
end

#right_id=(card_or_id) ⇒ Object



289
290
291
# File 'lib/card/subcards.rb', line 289

def right_id= card_or_id
  write_card_or_id :right_id, card_or_id
end

#serializable_attributesObject



62
63
64
# File 'lib/card.rb', line 62

def serializable_attributes
  self.class.serializable_attributes + set_specific.keys
end

#serialize_for_active_jobObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/card/set/event.rb', line 27

def serialize_for_active_job
  serializable_attributes.each_with_object({}) do |name, hash|
    value = instance_variable_get("@#{name}")
    hash[name] =
      # ActiveJob doesn't accept symbols as arguments
      if value.is_a? Symbol
        { value: value.to_s, symbol: true }
      else
        { value: value }
      end
  end
end

#subcardsObject



13
14
15
# File 'lib/card/subcards.rb', line 13

def subcards
  @subcards ||= Subcards.new(self)
end

#type_id=(card_or_id) ⇒ Object



297
298
299
# File 'lib/card/subcards.rb', line 297

def type_id= card_or_id
  write_card_or_id :type_id, card_or_id
end

#with_env_and_auth(env, auth) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/card/set/event.rb', line 12

def with_env_and_auth env, auth
  # If active jobs (and hence the integrate_with_delay events) don't run
  # in a background process then Card::Env.deserialize! decouples the
  # controller's params hash and the Card::Env's params hash with the
  # effect that params changes in the CardController get lost
  # (a crucial example are success params that are processed in
  # CardController#update_params_for_success)
  return yield if Decko.config.active_job.queue_adapter == :inline
  Card::Auth.with auth do
    Card::Env.with env do
      yield
    end
  end
end

#with_id_when_exists(card, &block) ⇒ Object



318
319
320
# File 'lib/card/subcards.rb', line 318

def with_id_when_exists card, &block
  card.director.call_after_store(&block)
end

#write_card_or_id(attribute, card_or_id) ⇒ Object



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/card/subcards.rb', line 301

def write_card_or_id attribute, card_or_id
  if card_or_id.is_a? Card
    card = card_or_id
    if card.id
      write_attribute attribute, card.id
    else
      add_subcard card
      card.director.prior_store = true
      with_id_when_exists(card) do |id|
        write_attribute attribute, id
      end
    end
  else
    write_attribute attribute, card_or_id
  end
end