Class: Card

Inherits:
ApplicationRecord show all
Extended by:
CarrierWave::Mount
Defined in:
lib/card.rb,
lib/card/env.rb,
lib/card/mod.rb,
lib/card/set.rb,
lib/card/auth.rb,
lib/card/name.rb,
lib/card/view.rb,
lib/card/cache.rb,
lib/card/dirty.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/query/run.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/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/subcards/add.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/set/i18n_scope.rb,
lib/card/cache/temporary.rb,
lib/card/set/inheritance.rb,
lib/card/subcards/relate.rb,
lib/card/subcards/remove.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/mode.rb,
lib/card/migration/import.rb,
lib/card/query/attributes.rb,
lib/card/set/advanced_api.rb,
lib/card/set/i18n_scanner.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/mod/load_strategy.rb,
lib/card/model/save_helper.rb,
lib/card/view/cache_action.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/mod/module_template.rb,
lib/card/query/sql_statement.rb,
lib/card/env/location_history.rb,
lib/card/format/context_names.rb,
lib/card/query/interpretation.rb,
lib/card/format/nest/subformat.rb,
lib/card/mod/loader/set_loader.rb,
lib/card/set/format/haml_views.rb,
lib/card/content/diff/processor.rb,
lib/card/mod/load_strategy/eval.rb,
lib/card/name/fields_and_traits.rb,
lib/card/migration/import/merger.rb,
lib/card/set/event/delayed_event.rb,
lib/card/format/method_delegation.rb,
lib/card/act_manager/stage_director.rb,
lib/card/mod/load_strategy/tmp_files.rb,
lib/card/query/relational_attributes.rb,
lib/card/migration/import/import_data.rb,
lib/card/tasks/card/file_card_creator.rb,
lib/generators/card/set/set_generator.rb,
lib/card/act_manager/subdirector_array.rb,
lib/card/mod/loader/set_pattern_loader.rb,
lib/card/mod/load_strategy/set_tmp_files.rb,
lib/card/act_manager/stage_director/phases.rb,
lib/generators/card/format/format_generator.rb,
lib/card/mod/load_strategy/pattern_tmp_files.rb,
lib/card/mod/load_strategy/set_binding_magic.rb,
lib/card/tasks/card/file_card_creator/haml_card.rb,
lib/generators/card/template/template_generator.rb,
lib/card/tasks/card/file_card_creator/style_card.rb,
lib/card/tasks/card/file_card_creator/script_card.rb,
lib/generators/card/migration/migration_generator.rb,
lib/card/migration/import/import_data/card_content.rb,
lib/card/tasks/card/file_card_creator/output_helper.rb,
lib/card/migration/import/import_data/card_attributes.rb,
lib/card/tasks/card/file_card_creator/abstract_file_card.rb,
lib/card/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb,
lib/card/tasks/card/file_card_creator/abstract_file_card/source_file.rb,
lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.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/machines/lib/card/machine.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,
tmpsets/set/mod002-core/all/erb.rb,
tmpsets/set/mod002-core/all/haml.rb,
tmpsets/set/mod002-core/all/name.rb,
tmpsets/set/mod002-core/all/type.rb,
tmpsets/set/mod002-core/all/debug.rb,
tmpsets/set/mod002-core/all/event.rb,
tmpsets/set/mod002-core/all/fetch.rb,
tmpsets/set/mod002-core/all/rules.rb,
tmpsets/set/mod002-core/all/trash.rb,
tmpsets/set/mod002-core/all/utils.rb,
tmpsets/set/mod013-email/right/cc.rb,
tmpsets/set/mod013-email/right/to.rb,
tmpsets/set/mod002-core/all/actify.rb,
tmpsets/set/mod002-core/all/export.rb,
tmpsets/set/mod002-core/all/phases.rb,
tmpsets/set/mod002-core/all/stages.rb,
tmpsets/set/mod002-core/all/states.rb,
tmpsets/set/mod013-email/right/bcc.rb,
tmpsets/set/mod001-admin/self/admin.rb,
tmpsets/set/mod002-core/all/content.rb,
tmpsets/set/mod002-core/all/pattern.rb,
tmpsets/set/mod013-email/all/follow.rb,
tmpsets/set/mod013-email/all/notify.rb,
tmpsets/set/mod013-email/right/from.rb,
tmpsets/set/mod013-email/self/never.rb,
tmpsets/set/mod002-core/all/subcards.rb,
tmpsets/set/mod011-machines/type/css.rb,
tmpsets/set/mod013-email/self/always.rb,
tmpsets/set/mod013-email/self/edited.rb,
tmpsets/set/mod013-email/self/follow.rb,
tmpsets/set/mod016-standard/self/now.rb,
tmpsets/set/mod016-standard/type/set.rb,
tmpsets/set/mod016-standard/type/uri.rb,
tmpsets/set/mod017-account/type/user.rb,
tmpsets/set/mod001-admin/self/version.rb,
tmpsets/set/mod011-machines/type/scss.rb,
tmpsets/set/mod011-machines/type/skin.rb,
tmpsets/set/mod012-settings/self/help.rb,
tmpsets/set/mod012-settings/self/read.rb,
tmpsets/set/mod013-email/all/observer.rb,
tmpsets/set/mod013-email/right/follow.rb,
tmpsets/set/mod013-email/self/created.rb,
tmpsets/set/mod016-standard/all/error.rb,
tmpsets/set/mod016-standard/all/links.rb,
tmpsets/set/mod016-standard/self/foot.rb,
tmpsets/set/mod016-standard/type/date.rb,
tmpsets/set/mod016-standard/type/list.rb,
tmpsets/set/mod017-account/right/salt.rb,
tmpsets/set/mod002-core/all/collection.rb,
tmpsets/set/mod002-core/all/initialize.rb,
tmpsets/set/mod002-core/all/references.rb,
tmpsets/set/mod002-core/all/templating.rb,
tmpsets/set/mod002-core/all/view_cache.rb,
tmpsets/set/mod003-history/all/actions.rb,
tmpsets/set/mod003-history/all/history.rb,
tmpsets/set/mod012-settings/right/help.rb,
tmpsets/set/mod012-settings/right/read.rb,
tmpsets/set/mod012-settings/self/input.rb,
tmpsets/set/mod012-settings/self/style.rb,
tmpsets/set/mod016-standard/type/basic.rb,
tmpsets/set/mod017-account/all/account.rb,
tmpsets/set/mod017-account/right/email.rb,
tmpsets/set/mod017-account/right/token.rb,
tmpsets/set/mod017-account/self/signin.rb,
tmpsets/set/mod017-account/type/signup.rb,
tmpsets/set/mod002-core/all/active_card.rb,
tmpsets/set/mod002-core/all/permissions.rb,
tmpsets/set/mod005-pointer/type/pointer.rb,
tmpsets/set/mod012-settings/right/style.rb,
tmpsets/set/mod012-settings/self/create.rb,
tmpsets/set/mod012-settings/self/delete.rb,
tmpsets/set/mod012-settings/self/layout.rb,
tmpsets/set/mod012-settings/self/script.rb,
tmpsets/set/mod012-settings/self/thanks.rb,
tmpsets/set/mod012-settings/self/update.rb,
tmpsets/set/mod013-email/all/email_html.rb,
tmpsets/set/mod013-email/all/email_text.rb,
tmpsets/set/mod016-standard/all/comment.rb,
tmpsets/set/mod016-standard/rstar/rules.rb,
tmpsets/set/mod016-standard/self/alerts.rb,
tmpsets/set/mod016-standard/self/navbox.rb,
tmpsets/set/mod016-standard/self/recent.rb,
tmpsets/set/mod016-standard/self/search.rb,
tmpsets/set/mod016-standard/type/number.rb,
tmpsets/set/mod016-standard/type/phrase.rb,
tmpsets/set/mod016-standard/type/toggle.rb,
tmpsets/set/mod017-account/right/status.rb,
tmpsets/set/mod001-admin/self/admin_info.rb,
tmpsets/set/mod004-basic_formats/all/rss.rb,
tmpsets/set/mod010-basic_types/type/html.rb,
tmpsets/set/mod012-settings/right/create.rb,
tmpsets/set/mod012-settings/right/delete.rb,
tmpsets/set/mod012-settings/right/script.rb,
tmpsets/set/mod012-settings/right/update.rb,
tmpsets/set/mod012-settings/self/captcha.rb,
tmpsets/set/mod012-settings/self/default.rb,
tmpsets/set/mod012-settings/self/options.rb,
tmpsets/set/mod012-settings/type/setting.rb,
tmpsets/set/mod013-email/right/followers.rb,
tmpsets/set/mod013-email/right/following.rb,
tmpsets/set/mod014-developer/right/debug.rb,
tmpsets/set/mod015-carrierwave/type/file.rb,
tmpsets/set/mod016-standard/type/session.rb,
tmpsets/set/mod017-account/right/account.rb,
tmpsets/set/mod004-basic_formats/all/base.rb,
tmpsets/set/mod004-basic_formats/all/file.rb,
tmpsets/set/mod004-basic_formats/all/json.rb,
tmpsets/set/mod004-basic_formats/all/text.rb,
tmpsets/set/mod012-settings/right/comment.rb,
tmpsets/set/mod012-settings/right/default.rb,
tmpsets/set/mod012-settings/self/add_help.rb,
tmpsets/set/mod012-settings/self/autoname.rb,
tmpsets/set/mod014-developer/all/view_viz.rb,
tmpsets/set/mod015-carrierwave/self/admin.rb,
tmpsets/set/mod015-carrierwave/type/image.rb,
tmpsets/set/mod016-standard/type/cardtype.rb,
tmpsets/set/mod017-account/right/password.rb,
tmpsets/set/mod002-core/abstract/code_file.rb,
tmpsets/set/mod004-basic_formats/self/head.rb,
tmpsets/set/mod012-settings/right/add_help.rb,
tmpsets/set/mod012-settings/self/on_create.rb,
tmpsets/set/mod012-settings/self/on_delete.rb,
tmpsets/set/mod012-settings/self/on_update.rb,
tmpsets/set/mod012-settings/self/structure.rb,
tmpsets/set/mod014-developer/all/event_viz.rb,
tmpsets/set/mod016-standard/self/codenames.rb,
tmpsets/set/mod016-standard/type/listed_by.rb,
tmpsets/set/mod004-basic_formats/all/all_js.rb,
tmpsets/set/mod005-pointer/self/script_mods.rb,
tmpsets/set/mod011-machines/abstract/script.rb,
tmpsets/set/mod012-settings/right/structure.rb,
tmpsets/set/mod013-email/right/html_message.rb,
tmpsets/set/mod002-core/all/location_history.rb,
tmpsets/set/mod002-core/all/name_validations.rb,
tmpsets/set/mod004-basic_formats/all/all_css.rb,
tmpsets/set/mod004-basic_formats/all/all_csv.rb,
tmpsets/set/mod011-machines/abstract/machine.rb,
tmpsets/set/mod011-machines/self/script_slot.rb,
tmpsets/set/mod011-machines/self/style_cards.rb,
tmpsets/set/mod011-machines/type/java_script.rb,
tmpsets/set/mod012-settings/self/accountable.rb,
tmpsets/set/mod013-email/right/follow_fields.rb,
tmpsets/set/mod013-email/type/email_template.rb,
tmpsets/set/mod016-standard/all/list_changes.rb,
tmpsets/set/mod016-standard/right/discussion.rb,
tmpsets/set/mod016-standard/type/layout_type.rb,
tmpsets/set/mod016-standard/type/search_type.rb,
tmpsets/set/mod002-core/all/update_read_rules.rb,
tmpsets/set/mod006-ace_editor/self/script_ace.rb,
tmpsets/set/mod013-email/self/follow_defaults.rb,
tmpsets/set/mod015-carrierwave/all/file_utils.rb,
tmpsets/set/mod017-account/self/account_links.rb,
tmpsets/set/mod018-bootstrap/self/script_mods.rb,
tmpsets/set/mod002-core/all/tracked_attributes.rb,
tmpsets/set/mod003-history/all/content_history.rb,
tmpsets/set/mod005-pointer/abstract/01_pointer.rb,
tmpsets/set/mod005-pointer/self/script_editors.rb,
tmpsets/set/mod009-solid_cache/all/solid_cache.rb,
tmpsets/set/mod010-basic_types/type/plain_text.rb,
tmpsets/set/mod011-machines/all/reset_machines.rb,
tmpsets/set/mod011-machines/self/script_jquery.rb,
tmpsets/set/mod011-machines/type/coffee_script.rb,
tmpsets/set/mod012-settings/self/follow_fields.rb,
tmpsets/set/mod012-settings/self/options_label.rb,
tmpsets/set/mod016-standard/all/rich_html/form.rb,
tmpsets/set/mod016-standard/all/rich_html/menu.rb,
tmpsets/set/mod016-standard/right/when_created.rb,
tmpsets/set/mod016-standard/rstar/rules_editor.rb,
tmpsets/set/mod018-bootstrap/self/bootstrap_js.rb,
tmpsets/set/mod018-bootstrap/self/smartmenu_js.rb,
tmpsets/set/mod011-machines/right/machine_cache.rb,
tmpsets/set/mod011-machines/right/machine_input.rb,
tmpsets/set/mod012-settings/abstract/permission.rb,
tmpsets/set/mod016-standard/all/rich_html/modal.rb,
tmpsets/set/mod018-bootstrap/all/bootstrap/form.rb,
tmpsets/set/mod018-bootstrap/all/bootstrap/tabs.rb,
tmpsets/set/mod018-bootstrap/all/rich_bootstrap.rb,
tmpsets/set/mod018-bootstrap/self/smartmenu_css.rb,
tmpsets/set/mod005-pointer/abstract/code_pointer.rb,
tmpsets/set/mod009-solid_cache/right/solid_cache.rb,
tmpsets/set/mod011-machines/right/machine_output.rb,
tmpsets/set/mod012-settings/self/recent_settings.rb,
tmpsets/set/mod016-standard/all/rich_html/header.rb,
tmpsets/set/mod018-bootstrap/all/bootstrap/table.rb,
tmpsets/set/mod006-ace_editor/abstract/ace_editor.rb,
tmpsets/set/mod011-machines/self/script_card_menu.rb,
tmpsets/set/mod016-standard/all/rich_html/content.rb,
tmpsets/set/mod016-standard/all/rich_html/editing.rb,
tmpsets/set/mod016-standard/all/rich_html/toolbar.rb,
tmpsets/set/mod016-standard/all/rich_html/wrapper.rb,
tmpsets/set/mod018-bootstrap/all/bootstrap/helper.rb,
tmpsets/set/mod018-bootstrap/self/bootstrap_cards.rb,
tmpsets/set/mod011-machines/abstract/machine_input.rb,
tmpsets/set/mod012-settings/self/default_html_view.rb,
tmpsets/set/mod012-settings/self/table_of_contents.rb,
tmpsets/set/mod015-carrierwave/abstract/attachment.rb,
tmpsets/set/mod016-standard/right/when_last_edited.rb,
tmpsets/set/mod018-bootstrap/all/bootstrap/wrapper.rb,
tmpsets/set/mod005-pointer/abstract/01_pointer/edit.rb,
tmpsets/set/mod009-solid_cache/abstract/solid_cache.rb,
tmpsets/set/mod018-bootstrap/self/bootswatch_shared.rb,
tmpsets/set/mod006-ace_editor/self/script_ace_config.rb,
tmpsets/set/mod013-email/type_plus_right/user/follow.rb,
tmpsets/set/mod005-pointer/self/script_pointer_config.rb,
tmpsets/set/mod011-machines/self/script_jquery_helper.rb,
tmpsets/set/mod004-basic_formats/self/01_head/javascript.rb,
tmpsets/set/mod015-carrierwave/abstract/attachment/paths.rb,
tmpsets/set/mod011-machines/self/script_html5shiv_printshiv.rb,
tmpsets/set/mod011-machines/self/style_bootstrap_compatible.rb,
tmpsets/set/mod011-machines/self/style_jquery_ui_smoothness.rb,
tmpsets/set/mod007-prosemirror_editor/self/script_prosemirror.rb,
tmpsets/set/mod015-carrierwave/abstract/attachment/storage_type.rb,
tmpsets/set/mod015-carrierwave/abstract/attachment/upload_cache.rb,
tmpsets/set/mod007-prosemirror_editor/abstract/prosemirror_editor.rb,
tmpsets/set/mod007-prosemirror_editor/self/script_prosemirror_config.rb

Overview

Cards are wiki-inspired building blocks.

This documentation is intended for developers who want to understand:

  1. how ruby Card objects work, and
  2. how to extend them.

It assumes that you've already read the introductory text in README.

Throughout this document we will refer to @card as an instance of a Card object.

Names

There are four important card identifiers, sometimes called "marks". Every card has a unique name, key, and id. Some cards also have a codename.

  @card.name     # The name, a {Card::Name} object, is the most recognizable card mark.
  @card.key      # The key, a String, is a simple lower-case name variant.
  @card.id       # The id is an Integer.
  @card.codename # The codename, a Symbol, is the name by which a card can be referred to in code.

All names with the same key (including the key itself) are considered variants of each other. No two cards can have names with the same key. Card::Name objects inherit from Strings but add many other methods for common card name patterns, eg "A+B".to_name.right => "B".

Setting a card's name, eg @card.name = "New Name", will automatically update the key. More on names.

More on codenames.

Type

Every card has a type, and every type itself has an associated card. For example, Paula's type might be User, so there is also a User card.

The type may be accessed in several ways:

  @card.type_id      # returns id of type card [Integer]
  @card.type_name    # returns name of type card [Card::Name]
  @card.type_code    # returns codename of type card [Symbol]
  @card.type_card    # returns Cardtype card associated with @card's type [Card]

Common type methods

Content

There are two primary methods for accessing a card's content:

  @card.db_content   # the content as it appears in the database
  @card.content      # the "official" content, which may be different from db_content when db_content is overridden with a structure rule.

Processing card content

Common content methods

Fetch

The two main ways to retrieve cards are fetching (retrieving cards one at a time) and querying (retrieving lists of cards). More on querying below.

Any of the above marks (name, key, id, codename) can be used to fetch a card, eg:

 @card = Card.fetch "Garden" # returns the card with the name "Garden" (or, more precisely, with the key "garden")
 @card = Card.fetch 100      # returns the card with the id 100
 @card = Card.fetch :help    # returns the card with the codename help

The fetch API will first try to find the card in the cache and will only look in the database if necessary.

More on fetching.

Query

Card queries find and return lists of cards, eg:

  Card.search type_id: 4 # returns an Array of cards with the type_id of 4.

More on queries

Views and Events

Views and events are a Decker's primary tools for manipulating cards. Views customize card presentation, while events customize card transactions. Or, if you like, views and events respectively alter cards in space and time.

Both views and events are defined in mods, short for modules or modifications.

More on views

More on events

Accounts and Permissions

Card code is always executed in the context of a given user account. Permissions for that account are automatically checked when running a query, performing an action, or rendering a view. A typical query, for example, can only return cards that the current user has permission to read.

You can see the current user with Card::Auth.current. The permissions of a proxy user can be temporarily assumed using Card::Auth#as.

More on accounts

Defined Under Namespace

Modules: Auth, Env, FollowOption, Generators, Machine, Mod, Model, Set, Setting, Version Classes: Act, ActManager, Action, Cache, Change, Codename, Content, Error, FileCardCreator, 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.



149
150
151
# File 'lib/card.rb', line 149

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



4
5
6
# File 'lib/card/mod/dirs.rb', line 4

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



139
140
141
142
143
144
# File 'lib/card/codename.rb', line 139

def self.const_missing const
  return super unless const.to_s =~ /^([A-Z]\S*)ID$/
  code = Regexp.last_match(1).underscore
  code_id = Card::Codename.id!(code)
  const_set const, code_id
end

.define_dirty_methods(field) ⇒ Object



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

def self.define_dirty_methods field
  define_method "#{field}_before_act" do
    attribute_before_act field
  end

  define_method "#{field}_is_changing?" do
    attribute_is_changing? field
  end
end

.pathsObject



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

def paths
  Cardio.paths
end

.serializable_attr_accessor(*args) ⇒ Object

attributes that ActiveJob can handle



127
128
129
130
# File 'lib/card.rb', line 127

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

Instance Method Details

#attribute_before_act(attr) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/card/dirty.rb', line 16

def attribute_before_act attr
  if saved_change_to_attribute? attr
    attribute_before_last_save attr
  elsif will_save_change_to_attribute? attr
    mutations_from_database.changed_values[attr]
  elsif not_in_callback?
    attribute_was attr
  else
    _read_attribute attr
  end
end

#attribute_is_changing?(attr) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/card/dirty.rb', line 32

def attribute_is_changing? attr
  if not_in_callback?
    attribute_changed? attr
  else
    saved_change_to_attribute?(attr) || will_save_change_to_attribute?(attr)
  end
end

#clean_after_stage_failObject



8
9
10
11
12
# File 'lib/card/act_manager/stage_director.rb', line 8

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

#deserialize_for_active_job!(attr) ⇒ Object



53
54
55
56
57
58
# File 'lib/card/set/event/delayed_event.rb', line 53

def deserialize_for_active_job! attr
  attr.each do |attname, val|
    instance_variable_set("@#{attname}", val)
  end
  include_set_modules
end

#deserialize_hash_value(value) ⇒ Object



99
100
101
102
103
# File 'lib/card/set/event/delayed_event.rb', line 99

def deserialize_hash_value value
  value.each_with_object({}) do |(k, v), h|
    h[k] = deserialize_value v[:value], v[:type]
  end
end

#deserialize_value(val, type) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/card/set/event/delayed_event.rb', line 86

def deserialize_value val, type
  case type
  when "symbol"
    val.to_sym
  when "time"
    DateTime.parse val
  when "hash"
    deserialize_hash_value val
  else
    val
  end
end

#log_event_call(event) ⇒ Object



83
84
85
86
87
# File 'lib/card/set/event.rb', line 83

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

#not_in_callback?Boolean

or in integrate_with_delay stage

Returns:

  • (Boolean)


28
29
30
# File 'lib/card/dirty.rb', line 28

def not_in_callback? # or in integrate_with_delay stage
  mutation_tracker.equal?(mutations_from_database)
end

#restore_changes_informationObject



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

def restore_changes_information
  return unless saved_changes.present?
  @changed_attributes = previous_mutation_tracker.changed_values
end

#serializable_attributesObject



145
146
147
# File 'lib/card.rb', line 145

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

#serialize_for_active_jobObject



60
61
62
63
64
# File 'lib/card/set/event/delayed_event.rb', line 60

def serialize_for_active_job
  serializable_attributes.each_with_object({}) do |name, hash|
    hash[name] = instance_variable_get("@#{name}")
  end
end

#serialize_hash_valueObject



82
83
84
# File 'lib/card/set/event/delayed_event.rb', line 82

def serialize_hash_value
  value.each_with_object({}) { |(k, v), h| h[k] = serialize_value(v) }
end

#serialize_value(value) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/card/set/event/delayed_event.rb', line 66

def serialize_value value
  # ActiveJob doesn't accept symbols and Time as arguments
  case value
  when Symbol
    { value: value.to_s, type: "symbol" }
  when Time
    { value: value.to_s, type: "time" }
  when Hash
    { value: serialize_hash_value(value), type: "hash"}
  when ActionController::Parameters
    serialize_value value.to_unsafe_h
  else
    { value: value }
  end
end