card 1.101.3 → 1.101.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/config/initializers/02_patches/active_record.rb +1 -1
- data/config/locales/en.yml +155 -378
- data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +1 -1
- data/lib/card.rb +15 -2
- data/lib/card/auth.rb +5 -2
- data/lib/card/auth/current.rb +39 -100
- data/lib/card/auth/proxy.rb +36 -16
- data/lib/card/auth/token.rb +6 -0
- data/lib/card/cache/all.rb +83 -0
- data/lib/card/cache/card_class.rb +41 -0
- data/lib/card/cache/persistent.rb +3 -34
- data/lib/card/cache/persistent_class.rb +28 -0
- data/lib/card/codename.rb +1 -1
- data/lib/card/content.rb +16 -2
- data/lib/card/content/all.rb +59 -0
- data/lib/card/director/act_direction.rb +4 -0
- data/lib/card/director/all.rb +61 -0
- data/lib/card/director/card_class.rb +18 -0
- data/lib/card/director/phases.rb +0 -1
- data/lib/card/dirty.rb +13 -3
- data/lib/card/env/success.rb +14 -14
- data/lib/card/env/success/target.rb +9 -11
- data/lib/card/error.rb +1 -1
- data/lib/card/fetch/all.rb +32 -0
- data/lib/card/fetch/card_class.rb +147 -0
- data/lib/card/format.rb +1 -1
- data/lib/card/format/error.rb +3 -3
- data/lib/card/format/nest.rb +1 -1
- data/lib/card/format/nest/fetch.rb +1 -1
- data/lib/card/lexicon.rb +2 -2
- data/lib/card/name/all.rb +8 -0
- data/lib/card/name/all/descendants.rb +6 -3
- data/lib/card/name/card_class.rb +26 -0
- data/lib/card/reference/all.rb +131 -0
- data/lib/card/rule/all.rb +75 -0
- data/lib/card/set/event/all.rb +95 -0
- data/lib/card/set/event/skip_and_trigger.rb +89 -0
- data/lib/card/set/pattern/all.rb +63 -0
- data/lib/card/subcards/all.rb +103 -0
- data/lib/cardio/migration/import.rb +1 -1
- data/lib/cardio/utils.rb +5 -3
- data/mod/admin/set/self/admin_info.rb +3 -5
- data/mod/admin/set/self/trash.rb +2 -2
- data/mod/core/set/all/autoname.rb +17 -0
- data/mod/core/set/all/codename.rb +2 -2
- data/mod/core/set/all/content.rb +52 -97
- data/mod/core/set/all/name_events.rb +69 -58
- data/mod/core/set/all/reference_events.rb +67 -0
- data/mod/core/set/all/states.rb +2 -2
- data/mod/core/set/all/subcards.rb +0 -100
- data/mod/core/set/all/trash.rb +11 -13
- data/mod/core/set/all/type.rb +7 -9
- data/mod/core/set/all/utils.rb +3 -0
- data/mod/core/set/type/cardtype.rb +3 -3
- data/mod/core/set_pattern/06_rule.rb +1 -1
- data/mod/core/spec/set/all/{rules2_spec.rb → clean_me_spec.rb} +0 -0
- data/mod/core/spec/set/all/name_events_spec.rb +204 -0
- metadata +30 -37
- data/lib/card/mod_inflector.rb +0 -16
- data/lib/card/name/all/class_methods.rb +0 -28
- data/mod/core/set/all/actify.rb +0 -68
- data/mod/core/set/all/cache.rb +0 -109
- data/mod/core/set/all/event_conditions.rb +0 -172
- data/mod/core/set/all/fetch.rb +0 -122
- data/mod/core/set/all/fetch_helper.rb +0 -35
- data/mod/core/set/all/i18n.rb +0 -9
- data/mod/core/set/all/pattern.rb +0 -54
- data/mod/core/set/all/references.rb +0 -191
- data/mod/core/set/all/rename.rb +0 -33
- data/mod/core/set/all/rules.rb +0 -81
- data/mod/core/spec/set/all/actify_spec.rb +0 -58
- data/mod/core/spec/set/all/content_spec.rb +0 -15
- data/mod/core/spec/set/all/event_conditions_spec.rb +0 -217
- data/mod/core/spec/set/all/fetch_helper_spec.rb +0 -65
- data/mod/core/spec/set/all/fetch_spec.rb +0 -338
- data/mod/core/spec/set/all/i18n_spec.rb +0 -17
- data/mod/core/spec/set/all/pattern_spec.rb +0 -101
- data/mod/core/spec/set/all/permissions/reader_rules_spec.rb +0 -166
- data/mod/core/spec/set/all/references_spec.rb +0 -62
- data/mod/core/spec/set/all/rename_spec.rb +0 -189
- data/mod/core/spec/set/all/rules_spec.rb +0 -100
- data/mod/core/spec/set/all/subcards_spec.rb +0 -102
@@ -15,40 +15,9 @@ class Card
|
|
15
15
|
# re-included after retrieval from the persistent cache.
|
16
16
|
#
|
17
17
|
class Persistent
|
18
|
-
|
19
|
-
|
20
|
-
class << self
|
21
|
-
# name of current database; used here to insure that different databases
|
22
|
-
# are cached separately
|
23
|
-
# TODO: find better home for this method
|
24
|
-
def database_name
|
25
|
-
@database_name ||= (cfg = Cardio.config) &&
|
26
|
-
(dbcfg = cfg.database_configuration) &&
|
27
|
-
dbcfg[Rails.env]["database"]
|
28
|
-
end
|
29
|
-
|
30
|
-
def stamp
|
31
|
-
@stamp ||= Cardio.cache.fetch(stamp_key) { new_stamp }
|
32
|
-
end
|
33
|
-
|
34
|
-
# stamp generator
|
35
|
-
def new_stamp
|
36
|
-
Time.now.to_i.to_s(36) + rand(999).to_s(36)
|
37
|
-
end
|
18
|
+
extend PersistentClass
|
38
19
|
|
39
|
-
|
40
|
-
"#{database_name}-stamp"
|
41
|
-
end
|
42
|
-
|
43
|
-
def renew
|
44
|
-
@stamp = nil
|
45
|
-
end
|
46
|
-
|
47
|
-
def reset
|
48
|
-
@stamp = new_stamp
|
49
|
-
Cardio.cache.write stamp_key, @stamp
|
50
|
-
end
|
51
|
-
end
|
20
|
+
attr_accessor :prefix
|
52
21
|
|
53
22
|
# @param opts [Hash]
|
54
23
|
# @option opts [Rails::Cache] :store
|
@@ -58,7 +27,7 @@ class Card
|
|
58
27
|
@store = opts[:store]
|
59
28
|
@klass = opts[:class]
|
60
29
|
@class_key = @klass.to_s.to_name.key
|
61
|
-
@database = opts[:database] ||
|
30
|
+
@database = opts[:database] || Cardio.database_name
|
62
31
|
end
|
63
32
|
|
64
33
|
# renew insures you're using the most current cache version by
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Card
|
2
|
+
class Cache
|
3
|
+
# class methods for Card::Cache::Persistent
|
4
|
+
module PersistentClass
|
5
|
+
def stamp
|
6
|
+
@stamp ||= Cardio.cache.fetch(stamp_key) { new_stamp }
|
7
|
+
end
|
8
|
+
|
9
|
+
# stamp generator
|
10
|
+
def new_stamp
|
11
|
+
Time.now.to_i.to_s(36) + rand(999).to_s(36)
|
12
|
+
end
|
13
|
+
|
14
|
+
def stamp_key
|
15
|
+
"#{Cardio.database_name}-stamp"
|
16
|
+
end
|
17
|
+
|
18
|
+
def renew
|
19
|
+
@stamp = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def reset
|
23
|
+
@stamp = new_stamp
|
24
|
+
Cardio.cache.write stamp_key, @stamp
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/card/codename.rb
CHANGED
@@ -138,7 +138,7 @@ class Card
|
|
138
138
|
|
139
139
|
def unknown_codename! mark
|
140
140
|
raise Card::Error::CodenameNotFound,
|
141
|
-
Cardio.
|
141
|
+
Cardio.t(:lib_exception_unknown_codename, codename: mark)
|
142
142
|
end
|
143
143
|
|
144
144
|
def id_constant codename, id=nil
|
data/lib/card/content.rb
CHANGED
@@ -36,9 +36,10 @@ class Card
|
|
36
36
|
end
|
37
37
|
|
38
38
|
# Find all chunks of a given type
|
39
|
-
# @param chunk_type [Chunk Class]
|
39
|
+
# @param chunk_type [Chunk Class or Symbol]
|
40
40
|
# @return [Array of Chunk instances]
|
41
|
-
def find_chunks chunk_type
|
41
|
+
def find_chunks chunk_type=nil
|
42
|
+
chunk_type = interpret_chunk_type chunk_type
|
42
43
|
each_chunk.select { |chunk| chunk.is_a?(chunk_type) }
|
43
44
|
end
|
44
45
|
|
@@ -119,6 +120,19 @@ class Card
|
|
119
120
|
|
120
121
|
private
|
121
122
|
|
123
|
+
def interpret_chunk_type chunk_type
|
124
|
+
case chunk_type
|
125
|
+
when nil
|
126
|
+
Chunk
|
127
|
+
when Symbol, String
|
128
|
+
Chunk.const_get chunk_type
|
129
|
+
when Class
|
130
|
+
chunk_type
|
131
|
+
else
|
132
|
+
raise ArgumentError, "unknown chunk type: #{chunk_type}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
122
136
|
def stash_chunks chunk_classes
|
123
137
|
chunks = []
|
124
138
|
each_chunk do |chunk|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class Card
|
2
|
+
class Content
|
3
|
+
# content-related methods for cards
|
4
|
+
module All
|
5
|
+
def content
|
6
|
+
structured_content || standard_content
|
7
|
+
end
|
8
|
+
alias_method :raw_content, :content # DEPRECATED!
|
9
|
+
|
10
|
+
def content= value
|
11
|
+
self.db_content = standardize_content(value)
|
12
|
+
end
|
13
|
+
|
14
|
+
def content?
|
15
|
+
content.present?
|
16
|
+
end
|
17
|
+
|
18
|
+
def standard_content
|
19
|
+
db_content || (new_card? && template.db_content)
|
20
|
+
end
|
21
|
+
|
22
|
+
def standardize_content value
|
23
|
+
value.is_a?(Array) ? value.join("\n") : value
|
24
|
+
end
|
25
|
+
|
26
|
+
def structured_content
|
27
|
+
structure && template.db_content
|
28
|
+
end
|
29
|
+
|
30
|
+
def refresh_content
|
31
|
+
self.content = Card.find(id)&.db_content
|
32
|
+
end
|
33
|
+
|
34
|
+
def save_content_draft _content
|
35
|
+
clear_drafts
|
36
|
+
end
|
37
|
+
|
38
|
+
def clear_drafts
|
39
|
+
drafts.created_by(Card::Auth.current_id).each(&:delete)
|
40
|
+
end
|
41
|
+
|
42
|
+
def last_draft_content
|
43
|
+
drafts.last.card_changes.last.value
|
44
|
+
end
|
45
|
+
|
46
|
+
def blank_content?
|
47
|
+
content.blank? || content.strip.blank?
|
48
|
+
end
|
49
|
+
|
50
|
+
def nests?
|
51
|
+
content_object.has_chunk? Content::Chunk::Nest
|
52
|
+
end
|
53
|
+
|
54
|
+
def content_object
|
55
|
+
Card::Content.new content, self
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -60,6 +60,10 @@ class Card
|
|
60
60
|
directors.keys.any? { |card| card.key == name.to_name.key }
|
61
61
|
end
|
62
62
|
|
63
|
+
def include_id? id
|
64
|
+
directors.keys.any? { |card| card.id == id }
|
65
|
+
end
|
66
|
+
|
63
67
|
def new_director card, parent
|
64
68
|
if !parent && act_card && act_card != card && running_act?
|
65
69
|
act_card.director.subdirectors.add card
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class Card
|
2
|
+
class Director
|
3
|
+
# director-related Card instance methods
|
4
|
+
module All
|
5
|
+
def act options={}, &block
|
6
|
+
if act_card
|
7
|
+
add_to_act options, &block
|
8
|
+
else
|
9
|
+
start_new_act(&block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def act_card
|
14
|
+
Card::Director.act_card
|
15
|
+
end
|
16
|
+
|
17
|
+
def act_card?
|
18
|
+
self == act_card
|
19
|
+
end
|
20
|
+
|
21
|
+
def save! *args
|
22
|
+
as_subcard = args.first&.delete :as_subcard
|
23
|
+
act(as_subcard: as_subcard) { super }
|
24
|
+
end
|
25
|
+
|
26
|
+
def save *args
|
27
|
+
act { super }
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid? *args
|
31
|
+
act(validating: true) { super }
|
32
|
+
end
|
33
|
+
|
34
|
+
def update *args
|
35
|
+
act { super }
|
36
|
+
end
|
37
|
+
|
38
|
+
def update! *args
|
39
|
+
act { super }
|
40
|
+
end
|
41
|
+
|
42
|
+
alias_method :update_attributes, :update
|
43
|
+
alias_method :update_attributes!, :update!
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def start_new_act
|
48
|
+
self.director = nil
|
49
|
+
Director.run_act(self) do
|
50
|
+
run_callbacks(:act) { yield }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_to_act options={}
|
55
|
+
director.appoint self unless @director
|
56
|
+
director.head = true unless options[:validating] || options[:as_subcard]
|
57
|
+
yield
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Card
|
2
|
+
class Director
|
3
|
+
# director-related Card class methods
|
4
|
+
module CardClass
|
5
|
+
def create! opts
|
6
|
+
card = Card.new opts
|
7
|
+
card.save!
|
8
|
+
card
|
9
|
+
end
|
10
|
+
|
11
|
+
def create opts
|
12
|
+
card = Card.new opts
|
13
|
+
card.save
|
14
|
+
card
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/card/director/phases.rb
CHANGED
data/lib/card/dirty.rb
CHANGED
@@ -61,10 +61,20 @@ class Card
|
|
61
61
|
super || dirty_name(left_id_before_act, right_id_before_act)
|
62
62
|
end
|
63
63
|
|
64
|
-
def dirty_name
|
65
|
-
return unless
|
64
|
+
def dirty_name left_id, right_id
|
65
|
+
return unless left_id.present? && right_id.present?
|
66
66
|
|
67
|
-
|
67
|
+
parts = [left_id, right_id].map { |id| Card.quick_fetch(id)&.name_before_act }
|
68
|
+
|
69
|
+
Card::Name[*parts]
|
70
|
+
end
|
71
|
+
|
72
|
+
def lex_before_act
|
73
|
+
if (old_left_id = left_id_before_act)
|
74
|
+
[old_left_id, right_id_before_act]
|
75
|
+
else
|
76
|
+
name_before_act
|
77
|
+
end
|
68
78
|
end
|
69
79
|
end
|
70
80
|
end
|
data/lib/card/env/success.rb
CHANGED
@@ -5,8 +5,8 @@ class Card
|
|
5
5
|
include Location
|
6
6
|
include Target
|
7
7
|
|
8
|
-
attr_accessor :
|
9
|
-
attr_writer :params, :card
|
8
|
+
attr_accessor :name, :name_context, :reload
|
9
|
+
attr_writer :params, :redirect, :card
|
10
10
|
attr_reader :id
|
11
11
|
|
12
12
|
def initialize name_context=nil, success_args=nil
|
@@ -17,12 +17,8 @@ class Card
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_url name_context=@name_context
|
20
|
-
|
21
|
-
|
22
|
-
target.format.path params
|
23
|
-
else
|
24
|
-
target
|
25
|
-
end
|
20
|
+
target = target name_context
|
21
|
+
target.is_a?(Card) ? target.format.path(params) : target
|
26
22
|
end
|
27
23
|
|
28
24
|
def in_context name_context
|
@@ -34,10 +30,14 @@ class Card
|
|
34
30
|
if value.is_a? Hash
|
35
31
|
apply value
|
36
32
|
else
|
37
|
-
self.
|
33
|
+
self.mark = value
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
37
|
+
def redirect
|
38
|
+
@redirect.present? ? @redirect : false
|
39
|
+
end
|
40
|
+
|
41
41
|
def reload?
|
42
42
|
@reload.to_s == "true"
|
43
43
|
end
|
@@ -79,11 +79,9 @@ class Card
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def method_missing method, *args
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
super
|
86
|
-
end
|
82
|
+
return super unless (m = method.match(/^(\w+(=)?)/))
|
83
|
+
|
84
|
+
infer_bracket m[1].to_sym, m[2], args[0]
|
87
85
|
end
|
88
86
|
|
89
87
|
def infer_bracket method, assign, val
|
@@ -94,6 +92,8 @@ class Card
|
|
94
92
|
|
95
93
|
def apply hash
|
96
94
|
hash.each_pair do |key, value|
|
95
|
+
next unless value.present?
|
96
|
+
|
97
97
|
self[key] = value
|
98
98
|
end
|
99
99
|
end
|
@@ -11,16 +11,13 @@ class Card
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def target name_context=@name_context
|
14
|
-
card(name_context) ||
|
15
|
-
(@target == :previous ? Card::Env.previous_location : @target) ||
|
16
|
-
Card.fetch(name_context)
|
14
|
+
card(name_context) || @target || Card.fetch(name_context)
|
17
15
|
end
|
18
16
|
|
19
17
|
# TODO: refactor to use cardish
|
20
18
|
def mark= value
|
21
19
|
case value
|
22
20
|
when Integer then @id = value
|
23
|
-
when String then @name = value
|
24
21
|
when Card then @card = value
|
25
22
|
else
|
26
23
|
self.target = value
|
@@ -60,13 +57,14 @@ class Card
|
|
60
57
|
|
61
58
|
def process_target value
|
62
59
|
case value
|
63
|
-
when ""
|
64
|
-
|
65
|
-
when
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
else
|
60
|
+
when ""
|
61
|
+
""
|
62
|
+
when "*previous", ":previous", :previous
|
63
|
+
Card::Env.previous_location
|
64
|
+
when %r{^(http|/)}
|
65
|
+
value
|
66
|
+
else
|
67
|
+
@name = Name[value]
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|
data/lib/card/error.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
class Card
|
2
|
+
class Fetch
|
3
|
+
# fetch-related Card instance methods
|
4
|
+
module All
|
5
|
+
# fetching from the context of a card
|
6
|
+
def fetch traits, opts={}
|
7
|
+
opts[:new][:supercard] = self if opts[:new]
|
8
|
+
Array.wrap(traits).inject(self) do |card, trait|
|
9
|
+
Card.fetch card.name.trait(trait), opts
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def newish opts
|
14
|
+
reset_patterns
|
15
|
+
Card.with_normalized_new_args opts do |norm_opts|
|
16
|
+
handle_type norm_opts do
|
17
|
+
assign_attributes norm_opts
|
18
|
+
self.name = name # trigger superize_name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def refresh force=false
|
24
|
+
return self unless force || frozen? || readonly?
|
25
|
+
return unless id
|
26
|
+
fresh_card = self.class.find id
|
27
|
+
fresh_card.include_set_modules
|
28
|
+
fresh_card
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|