card 1.16.15 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/config/initializers/recaptcha.rb +21 -4
- data/db/migrate_core_cards/20130823192433_add_style_cards.rb +1 -1
- data/db/migrate_core_cards/20140512155840_add_script_cards.rb +1 -1
- data/db/migrate_core_cards/20140629222005_add_email_cards.rb +2 -2
- data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +1 -1
- data/db/migrate_core_cards/20150528084659_add_session_cardtype.rb +1 -1
- data/db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb +63 -0
- data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
- data/db/migrate_core_cards/20150903130006_attachment_upload_cards.rb +1 -1
- data/db/schema.rb +1 -1
- data/db/seed/new/card_actions.yml +602 -394
- data/db/seed/new/card_acts.yml +595 -1
- data/db/seed/new/card_changes.yml +26282 -10262
- data/db/seed/new/card_references.yml +1252 -1084
- data/db/seed/new/cards.yml +1899 -1423
- data/db/seed/test/fixtures/card_actions.yml +1653 -1413
- data/db/seed/test/fixtures/card_acts.yml +1063 -445
- data/db/seed/test/fixtures/card_changes.yml +29674 -13637
- data/db/seed/test/fixtures/card_references.yml +1976 -1815
- data/db/seed/test/fixtures/cards.yml +3194 -2719
- data/lib/card.rb +14 -13
- data/lib/card/auth.rb +10 -6
- data/lib/card/cache.rb +58 -120
- data/lib/card/cache/persistent.rb +50 -0
- data/lib/card/cache/temporary.rb +38 -0
- data/lib/card/chunk.rb +34 -25
- data/lib/card/content.rb +3 -3
- data/lib/card/env.rb +3 -0
- data/lib/card/format.rb +56 -53
- data/lib/card/migration.rb +6 -2
- data/lib/card/name.rb +9 -1
- data/lib/card/query.rb +1 -1
- data/lib/card/reference.rb +17 -11
- data/lib/card/set.rb +1 -1
- data/lib/card/subcards.rb +6 -6
- data/lib/card/view_cache.rb +45 -28
- data/lib/generators/card/migration/templates/card_migration.erb +1 -2
- data/mod/01_core/chunk/include.rb +71 -48
- data/mod/01_core/chunk/link.rb +6 -3
- data/mod/01_core/chunk/query_reference.rb +38 -29
- data/mod/01_core/chunk/reference.rb +23 -24
- data/mod/01_core/set/all/collection.rb +1 -1
- data/mod/01_core/set/all/fetch.rb +39 -12
- data/mod/01_core/set/all/permissions.rb +2 -4
- data/mod/01_core/set/all/references.rb +50 -75
- data/mod/01_core/set/all/rules.rb +19 -18
- data/mod/01_core/set/all/subcards.rb +1 -1
- data/mod/01_core/set/all/templating.rb +31 -88
- data/mod/01_core/set/all/tracked_attributes.rb +7 -14
- data/mod/01_core/set/all/utils.rb +77 -66
- data/mod/01_core/set_pattern/07_type_plus_right.rb +6 -3
- data/mod/01_core/spec/set/all/fetch_spec.rb +148 -96
- data/mod/01_core/spec/set/all/templating_spec.rb +49 -40
- data/mod/01_core/spec/set/all/trash_spec.rb +1 -1
- data/mod/01_history/set/all/actions.rb +1 -1
- data/mod/02_basic_types/set/all/base.rb +13 -7
- data/mod/02_basic_types/set/all/rss.rb +17 -22
- data/mod/02_basic_types/set/type/plain_text.rb +5 -2
- data/mod/02_basic_types/spec/set/all/base_spec.rb +1 -0
- data/mod/02_basic_types/spec/set/all/rss_spec.rb +7 -6
- data/mod/03_machines/lib/javascript/wagn.js.coffee +22 -9
- data/mod/03_machines/set/right/machine_output.rb +1 -1
- data/mod/04_settings/lib/card/setting.rb +45 -31
- data/mod/04_settings/set/right/structure.rb +47 -1
- data/mod/04_settings/set/self/default_html_view.rb +2 -0
- data/mod/04_settings/set/self/follow_fields.rb +2 -0
- data/mod/04_settings/set/self/recent_settings.rb +1 -1
- data/mod/05_standard/file/favicon/image-icon.png +0 -0
- data/mod/05_standard/file/favicon/image-large.png +0 -0
- data/mod/05_standard/file/favicon/image-medium.png +0 -0
- data/mod/05_standard/file/favicon/image-original.png +0 -0
- data/mod/05_standard/file/favicon/image-small.png +0 -0
- data/mod/05_standard/set/all/links.rb +27 -26
- data/mod/05_standard/set/all/rich_html/editing.rb +1 -1
- data/mod/05_standard/set/all/rich_html/toolbar.rb +1 -1
- data/mod/05_standard/set/rstar/rules.rb +20 -325
- data/mod/05_standard/set/rstar/rules_editor.rb +362 -0
- data/mod/05_standard/set/self/admin_info.rb +82 -0
- data/mod/05_standard/set/self/all.rb +16 -10
- data/mod/05_standard/set/self/head.rb +20 -19
- data/mod/05_standard/set/type/signup.rb +0 -1
- data/mod/05_standard/spec/set/all/account_spec.rb +44 -43
- data/mod/05_standard/spec/set/right/account_spec.rb +4 -2
- data/mod/05_standard/spec/set/type/search_type_spec.rb +8 -0
- data/mod/05_standard/spec/set/type/signup_spec.rb +24 -17
- data/mod/06_bootstrap/set/all/bootstrap/helper.rb +1 -1
- data/spec/lib/card/cache_spec.rb +64 -70
- data/spec/lib/card/content_spec.rb +236 -150
- data/spec/lib/card/reference_spec.rb +22 -38
- data/spec/lib/card/subcards_spec.rb +38 -0
- data/spec/lib/card/view_cache_spec.rb +8 -0
- data/spec/spec_helper.rb +1 -1
- data/tmpsets/set/mod001-01_core/all/collection.rb +77 -74
- data/tmpsets/set/mod001-01_core/all/content.rb +14 -16
- data/tmpsets/set/mod001-01_core/all/fetch.rb +137 -110
- data/tmpsets/set/mod001-01_core/all/name.rb +58 -40
- data/tmpsets/set/mod001-01_core/all/pattern.rb +12 -11
- data/tmpsets/set/mod001-01_core/all/permissions.rb +125 -117
- data/tmpsets/set/mod001-01_core/all/phases.rb +2 -1
- data/tmpsets/set/mod001-01_core/all/references.rb +52 -77
- data/tmpsets/set/mod001-01_core/all/rules.rb +47 -53
- data/tmpsets/set/mod001-01_core/all/templating.rb +31 -87
- data/tmpsets/set/mod001-01_core/all/tracked_attributes.rb +12 -21
- data/tmpsets/set/mod001-01_core/all/trash.rb +4 -1
- data/tmpsets/set/mod001-01_core/all/type.rb +23 -21
- data/tmpsets/set/mod001-01_core/all/utils.rb +80 -64
- data/tmpsets/set/mod002-01_history/all/actions.rb +20 -16
- data/tmpsets/set/mod002-01_history/all/history.rb +18 -13
- data/tmpsets/set/mod003-02_basic_types/all/base.rb +37 -10
- data/tmpsets/set/mod003-02_basic_types/all/rss.rb +17 -22
- data/tmpsets/set/mod003-02_basic_types/type/plain_text.rb +5 -2
- data/tmpsets/set/mod003-02_basic_types/type/pointer.rb +51 -39
- data/tmpsets/set/mod004-03_machines/right/machine_output.rb +10 -6
- data/tmpsets/set/mod005-04_settings/abstract/permission.rb +10 -5
- data/tmpsets/set/mod005-04_settings/right/structure.rb +47 -1
- data/tmpsets/set/mod005-04_settings/self/recent_settings.rb +1 -0
- data/tmpsets/set/mod005-04_settings/type/setting.rb +4 -1
- data/tmpsets/set/mod006-05_email/all/follow.rb +45 -54
- data/tmpsets/set/mod006-05_email/all/notify.rb +88 -73
- data/tmpsets/set/mod006-05_email/right/followers.rb +17 -14
- data/tmpsets/set/mod006-05_email/self/follow_defaults.rb +22 -18
- data/tmpsets/set/mod006-05_email/type/email_template.rb +1 -1
- data/tmpsets/set/mod007-05_standard/abstract/attachment.rb +94 -67
- data/tmpsets/set/mod007-05_standard/all/account.rb +18 -20
- data/tmpsets/set/mod007-05_standard/all/comment.rb +51 -29
- data/tmpsets/set/mod007-05_standard/all/error.rb +129 -99
- data/tmpsets/set/mod007-05_standard/all/links.rb +27 -26
- data/tmpsets/set/mod007-05_standard/all/rich_html/content.rb +115 -103
- data/tmpsets/set/mod007-05_standard/all/rich_html/editing.rb +112 -78
- data/tmpsets/set/mod007-05_standard/all/rich_html/form.rb +123 -81
- data/tmpsets/set/mod007-05_standard/all/rich_html/modal.rb +15 -58
- data/tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb +2 -2
- data/tmpsets/set/mod007-05_standard/right/account.rb +71 -75
- data/tmpsets/set/mod007-05_standard/right/email.rb +16 -13
- data/tmpsets/set/mod007-05_standard/right/password.rb +20 -12
- data/tmpsets/set/mod007-05_standard/right/status.rb +2 -2
- data/tmpsets/set/mod007-05_standard/right/token.rb +49 -2
- data/tmpsets/set/mod007-05_standard/rstar/rules.rb +20 -325
- data/tmpsets/set/mod007-05_standard/self/all.rb +16 -10
- data/tmpsets/set/mod007-05_standard/self/head.rb +76 -62
- data/tmpsets/set/mod007-05_standard/self/search.rb +45 -22
- data/tmpsets/set/mod007-05_standard/self/signin.rb +14 -12
- data/tmpsets/set/mod007-05_standard/type/cardtype.rb +13 -11
- data/tmpsets/set/mod007-05_standard/type/file.rb +1 -1
- data/tmpsets/set/mod007-05_standard/type/search_type.rb +3 -2
- data/tmpsets/set/mod007-05_standard/type/set.rb +20 -16
- data/tmpsets/set/mod007-05_standard/type/signup.rb +19 -25
- data/tmpsets/set/mod007-05_standard/type/user.rb +1 -1
- data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb +1 -1
- data/tmpsets/set_pattern/106-type_plus_right.rb +6 -3
- metadata +11 -2
data/lib/card.rb
CHANGED
@@ -8,10 +8,10 @@ Object.send :remove_const, :Card if Object.send(:const_defined?, :Card)
|
|
8
8
|
# a. how ruby Card objects work, and
|
9
9
|
# b. how to extend them.
|
10
10
|
#
|
11
|
-
# It assumes that you've already read the introductory text
|
11
|
+
# It assumes that you've already read the introductory text
|
12
|
+
# in {file:README_Developers.rdoc}.
|
12
13
|
#
|
13
14
|
class Card < ActiveRecord::Base
|
14
|
-
|
15
15
|
# attributes that ActiveJob can handle
|
16
16
|
def self.serializable_attr_accessor *args
|
17
17
|
self.serializable_attributes = args
|
@@ -36,24 +36,29 @@ class Card < ActiveRecord::Base
|
|
36
36
|
has_many :references_from, class_name: :Reference, foreign_key: :referee_id
|
37
37
|
has_many :references_to, class_name: :Reference, foreign_key: :referer_id
|
38
38
|
has_many :acts, -> { order :id }
|
39
|
-
has_many :actions, -> { where(
|
40
|
-
has_many :drafts, -> { where(
|
39
|
+
has_many :actions, -> { where(draft: [nil, false]).order :id }
|
40
|
+
has_many :drafts, -> { where(draft: true).order :id }, class_name: :Action
|
41
41
|
|
42
|
-
cattr_accessor :set_patterns, :
|
43
|
-
|
42
|
+
cattr_accessor :set_patterns, :serializable_attributes, :error_codes,
|
43
|
+
:set_specific_attributes
|
44
|
+
@@set_patterns = []
|
45
|
+
@@error_codes = {}
|
44
46
|
|
45
|
-
serializable_attr_accessor
|
47
|
+
serializable_attr_accessor(
|
48
|
+
:action, :supercard, :superleft,
|
49
|
+
:current_act, :current_action,
|
46
50
|
:comment, :comment_author, # obviated soon
|
47
51
|
:update_referencers, # wrong mechanism for this
|
48
52
|
:update_all_users, # if the above is wrong then this one too
|
49
53
|
:silent_change, # and this probably too
|
50
54
|
:remove_rule_stash,
|
51
55
|
:last_action_id_before_edit
|
56
|
+
)
|
52
57
|
|
53
58
|
attr_accessor :follower_stash
|
54
59
|
|
55
|
-
|
56
|
-
|
60
|
+
define_callbacks :prepare, :approve, :store, :stored, :extend, :subsequent,
|
61
|
+
:select_action, :show, :handle
|
57
62
|
|
58
63
|
before_validation :prepare
|
59
64
|
before_validation :approve
|
@@ -63,8 +68,4 @@ class Card < ActiveRecord::Base
|
|
63
68
|
TRACKED_FIELDS = %w(name type_id db_content trash)
|
64
69
|
extend CarrierWave::Mount
|
65
70
|
ActiveSupport.run_load_hooks(:card, self)
|
66
|
-
|
67
|
-
|
68
71
|
end
|
69
|
-
|
70
|
-
|
data/lib/card/auth.rb
CHANGED
@@ -6,6 +6,10 @@ class Card
|
|
6
6
|
@@simulating_setup_need = nil
|
7
7
|
|
8
8
|
SETUP_COMPLETED_KEY = 'SETUP_COMPLETED'
|
9
|
+
DEFAULT_RECAPTCHA_SETTINGS = {
|
10
|
+
recaptcha_public_key: '6LeoHfESAAAAAN1NdQeYHREq4jTSQhu1foEzv6KC',
|
11
|
+
recaptcha_private_key: '6LeoHfESAAAAAHLZpn7ijrO4_KGLEr2nGL4qjjis'
|
12
|
+
}
|
9
13
|
|
10
14
|
# after_save :reset_instance_cache
|
11
15
|
|
@@ -136,12 +140,12 @@ class Card
|
|
136
140
|
@@current_id = @@as_id if @@current_id.nil?
|
137
141
|
|
138
142
|
return unless block_given?
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
143
|
+
yield
|
144
|
+
ensure
|
145
|
+
if block_given?
|
146
|
+
@@as_id = tmp_id
|
147
|
+
@@as_card = tmp_card
|
148
|
+
end
|
145
149
|
end
|
146
150
|
|
147
151
|
def as_bot &block
|
data/lib/card/cache.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
3
|
class Card
|
4
|
-
|
5
4
|
ActiveSupport::Cache::FileStore.class_eval do
|
6
5
|
# escape special symbols \*"<>| additionaly to :?.
|
7
6
|
# All of them not allowed to use in ms windows file system
|
8
|
-
def real_file_path
|
9
|
-
name = name.gsub('%','%25').gsub('?','%3F').gsub(':','%3A')
|
10
|
-
name = name.gsub('\\','%5C').gsub('*','%2A').gsub('"','%22')
|
11
|
-
name = name.gsub('<','%3C').gsub('>','%3E').gsub('|','%7C')
|
12
|
-
'%s/%s.cache' % [@cache_path, name
|
7
|
+
def real_file_path name
|
8
|
+
name = name.gsub('%', '%25').gsub('?', '%3F').gsub(':', '%3A')
|
9
|
+
name = name.gsub('\\', '%5C').gsub('*', '%2A').gsub('"', '%22')
|
10
|
+
name = name.gsub('<', '%3C').gsub('>', '%3E').gsub('|', '%7C')
|
11
|
+
'%s/%s.cache' % [@cache_path, name]
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
15
|
class Cache
|
17
|
-
|
18
16
|
TEST_ENVS = %w{test cucumber}
|
19
17
|
@@prepopulating = TEST_ENVS.include? Rails.env
|
20
18
|
@@no_rails_cache = TEST_ENVS.include?(Rails.env) || ENV['NO_RAILS_CACHE']
|
@@ -24,8 +22,10 @@ class Card
|
|
24
22
|
|
25
23
|
class << self
|
26
24
|
def [] klass
|
27
|
-
raise
|
28
|
-
|
25
|
+
raise 'nil klass' if klass.nil?
|
26
|
+
cache_type = (@@no_rails_cache ? nil : Cardio.cache)
|
27
|
+
cache_by_class[klass] ||= new class: klass,
|
28
|
+
store: cache_type
|
29
29
|
end
|
30
30
|
|
31
31
|
def renew
|
@@ -36,44 +36,39 @@ class Card
|
|
36
36
|
raise "renewing nil cache: #{klass}"
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
def prefix_root
|
43
|
-
@@prefix_root ||= ( cfg = Cardio.config and cfg = cfg.database_configuration and
|
44
|
-
cfg[Rails.env]['database'] )
|
39
|
+
reset_soft
|
45
40
|
end
|
46
41
|
|
47
42
|
def system_prefix klass
|
48
|
-
"#{
|
43
|
+
"#{Rails.env}/#{klass}"
|
49
44
|
end
|
50
45
|
|
51
|
-
def restore
|
52
|
-
|
46
|
+
def restore
|
47
|
+
reset_soft
|
53
48
|
prepopulate
|
54
49
|
end
|
55
50
|
|
56
|
-
def
|
57
|
-
|
58
|
-
('a'..'z').to_a[rand(26)] +
|
59
|
-
('a'..'z').to_a[rand(26)]
|
51
|
+
def reset_global # deprecated
|
52
|
+
reset_all
|
60
53
|
end
|
61
54
|
|
62
|
-
def
|
63
|
-
|
64
|
-
|
65
|
-
|
55
|
+
def reset_all
|
56
|
+
reset_hard
|
57
|
+
reset_soft
|
58
|
+
|
66
59
|
Card::Codename.reset_cache
|
67
60
|
Cardio.delete_tmp_files
|
68
61
|
end
|
69
62
|
|
70
|
-
def
|
71
|
-
cache_by_class.each do |
|
72
|
-
if
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
63
|
+
def reset_hard
|
64
|
+
cache_by_class.each do |_klass, cache|
|
65
|
+
cache.hard.reset if cache.hard
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def reset_soft
|
70
|
+
cache_by_class.each do |_klass, cache|
|
71
|
+
cache.soft.reset
|
77
72
|
end
|
78
73
|
end
|
79
74
|
|
@@ -82,11 +77,11 @@ class Card
|
|
82
77
|
when Hash
|
83
78
|
obj.sort.map do |key, value|
|
84
79
|
"#{key}=>(#{obj_to_key(value)})"
|
85
|
-
end.join
|
80
|
+
end.join ','
|
86
81
|
when Array
|
87
82
|
obj.map do |value|
|
88
83
|
obj_to_key(value)
|
89
|
-
end.join
|
84
|
+
end.join ','
|
90
85
|
else
|
91
86
|
obj.to_s
|
92
87
|
end
|
@@ -96,127 +91,70 @@ class Card
|
|
96
91
|
|
97
92
|
def prepopulate
|
98
93
|
return unless @@prepopulating
|
94
|
+
soft = Card.cache.soft
|
99
95
|
@@rule_cache ||= Card.rule_cache
|
100
96
|
@@user_ids_cache ||= Card.user_ids_cache
|
101
97
|
@@read_rule_cache ||= Card.read_rule_cache
|
102
98
|
@@rule_keys_cache ||= Card.rule_keys_cache
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
99
|
+
soft.write 'RULES', @@rule_cache
|
100
|
+
soft.write 'READRULES', @@read_rule_cache
|
101
|
+
soft.write 'USER_IDS', @@user_ids_cache
|
102
|
+
soft.write 'RULE_KEYS', @@rule_keys_cache
|
107
103
|
end
|
108
104
|
end
|
109
105
|
|
110
|
-
attr_reader :
|
111
|
-
attr_accessor :local
|
106
|
+
attr_reader :hard, :soft
|
112
107
|
|
113
108
|
def initialize opts={}
|
114
|
-
#warn "new cache #{opts.inspect}"
|
115
109
|
@klass = opts[:class]
|
116
|
-
@
|
117
|
-
@local = Hash.new
|
118
|
-
self.system_prefix = opts[:prefix] || self.class.system_prefix(opts[:class])
|
119
|
-
cache_by_class[klass] = self
|
120
|
-
end
|
110
|
+
cache_by_class[@klass] = self
|
121
111
|
|
112
|
+
# hard cache mirrors the db
|
113
|
+
# only difference to db: it caches virtual cards
|
114
|
+
@hard = Persistent.new opts if opts[:store]
|
122
115
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
@prefix = system_prefix + self.class.generate_cache_id + "/"
|
127
|
-
else
|
128
|
-
@system_prefix += '/' unless @system_prefix[-1] == '/'
|
129
|
-
@cache_id = @store.fetch(@system_prefix + "cache_id") do
|
130
|
-
self.class.generate_cache_id
|
131
|
-
end
|
132
|
-
@prefix = @system_prefix + @cache_id + "/"
|
133
|
-
end
|
116
|
+
# soft cache is temporary
|
117
|
+
# lasts only one request/script execution/console session
|
118
|
+
@soft = Temporary.new
|
134
119
|
end
|
135
120
|
|
136
121
|
def read key
|
137
|
-
|
138
|
-
|
139
|
-
elsif @store
|
140
|
-
write_local key, @store.read(@prefix + key)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def read_local key
|
145
|
-
@local[key]
|
146
|
-
end
|
147
|
-
|
148
|
-
def write_variable key, variable, value
|
149
|
-
key = @prefix + key
|
150
|
-
if @store && (object = @store.read key)
|
151
|
-
object.instance_variable_set "@#{ variable }", value
|
152
|
-
@store.write key, object
|
153
|
-
end
|
154
|
-
value
|
122
|
+
@soft.read(key) ||
|
123
|
+
(@hard && (ret = @hard.read(key)) && @soft.write(key, ret))
|
155
124
|
end
|
156
125
|
|
157
126
|
def write key, value
|
158
|
-
@
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
def write_local key, value
|
163
|
-
@local[key] = value
|
127
|
+
@hard.write key, value if @hard
|
128
|
+
@soft.write key, value
|
164
129
|
end
|
165
130
|
|
166
131
|
def fetch key, &block
|
167
|
-
|
168
|
-
if @
|
169
|
-
@
|
132
|
+
@soft.fetch(key) do
|
133
|
+
if @hard
|
134
|
+
@hard.fetch(key, &block)
|
170
135
|
else
|
171
136
|
block.call
|
172
137
|
end
|
173
138
|
end
|
174
139
|
end
|
175
140
|
|
176
|
-
def fetch_local key
|
177
|
-
read_local(key) || write_local(key, yield)
|
178
|
-
end
|
179
|
-
|
180
141
|
def delete key
|
181
|
-
@
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
def delete_local key
|
186
|
-
@local.delete key
|
142
|
+
@hard.delete key if @hard
|
143
|
+
@soft.delete key
|
187
144
|
end
|
188
145
|
|
189
146
|
def dump
|
190
|
-
p
|
191
|
-
@
|
192
|
-
p "#{k} --> #{v.inspect[0..30]}"
|
193
|
-
end
|
147
|
+
p 'dumping temporary request cache....'
|
148
|
+
@soft.dump
|
194
149
|
end
|
195
150
|
|
196
|
-
def reset
|
197
|
-
|
198
|
-
@
|
199
|
-
if @store
|
200
|
-
if hard
|
201
|
-
begin
|
202
|
-
@store.clear
|
203
|
-
rescue => e
|
204
|
-
Rails.logger.debug "Problem clearing cache: #{e.message}"
|
205
|
-
end
|
206
|
-
else
|
207
|
-
@store.write @system_prefix + "cache_id", @cache_id
|
208
|
-
end
|
209
|
-
end
|
210
|
-
@prefix = @system_prefix + @cache_id + "/"
|
211
|
-
end
|
212
|
-
|
213
|
-
def reset_local
|
214
|
-
@local = {}
|
151
|
+
def reset
|
152
|
+
@hard.reset if @hard
|
153
|
+
@soft.reset
|
215
154
|
end
|
216
155
|
|
217
156
|
def exist? key
|
218
|
-
@
|
157
|
+
@soft.exist?(key) || (@hard && @hard.exist?(key))
|
219
158
|
end
|
220
159
|
end
|
221
160
|
end
|
222
|
-
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
class Card::Cache::Persistent
|
4
|
+
attr_reader :prefix
|
5
|
+
|
6
|
+
def initialize opts
|
7
|
+
@store = opts[:store]
|
8
|
+
self.system_prefix =
|
9
|
+
opts[:prefix] || Card::Cache.system_prefix(opts[:class])
|
10
|
+
end
|
11
|
+
|
12
|
+
def system_prefix= system_prefix
|
13
|
+
@system_prefix = system_prefix
|
14
|
+
@prefix = "#{system_prefix}/"
|
15
|
+
end
|
16
|
+
|
17
|
+
def read key
|
18
|
+
@store.read(@prefix + key)
|
19
|
+
end
|
20
|
+
|
21
|
+
def write_variable key, variable, value
|
22
|
+
if @store && (object = @store.read key)
|
23
|
+
object.instance_variable_set "@#{variable}", value
|
24
|
+
@store.write key, object
|
25
|
+
end
|
26
|
+
value
|
27
|
+
end
|
28
|
+
|
29
|
+
def write key, value
|
30
|
+
@store.write(@prefix + key, value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def fetch key, &block
|
34
|
+
@store.fetch @prefix + key, &block
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete key
|
38
|
+
@store.delete @prefix + key
|
39
|
+
end
|
40
|
+
|
41
|
+
def reset
|
42
|
+
@store.clear
|
43
|
+
rescue => e
|
44
|
+
Rails.logger.debug "Problem clearing cache: #{e.message}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def exist? key
|
48
|
+
@store.exist? @prefix + key
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Card::Cache::Temporary
|
2
|
+
attr_reader :store
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@store = Hash.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def read key
|
9
|
+
return unless @store.has_key? key
|
10
|
+
@store[key]
|
11
|
+
end
|
12
|
+
|
13
|
+
def write key, value
|
14
|
+
@store[key] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch key, &block
|
18
|
+
read(key) || write(key, block.call)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete key
|
22
|
+
@store.delete key
|
23
|
+
end
|
24
|
+
|
25
|
+
def dump
|
26
|
+
@store.each do |k, v|
|
27
|
+
p "#{k} --> #{v.inspect[0..30]}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset
|
32
|
+
@store = {}
|
33
|
+
end
|
34
|
+
|
35
|
+
def exist? key
|
36
|
+
@store.has_key? key
|
37
|
+
end
|
38
|
+
end
|
data/lib/card/chunk.rb
CHANGED
@@ -7,9 +7,7 @@ require 'uri/common'
|
|
7
7
|
# +pattern+ that states what sort of text it matches.
|
8
8
|
# Chunks are initalized by passing in the result of a
|
9
9
|
|
10
|
-
|
11
10
|
class Card
|
12
|
-
|
13
11
|
# A chunk is a pattern of text that can be protected
|
14
12
|
# and interrogated by a format. Each Chunk class has a
|
15
13
|
# +pattern+ that states what sort of text it matches.
|
@@ -17,12 +15,15 @@ class Card
|
|
17
15
|
# match by its pattern.
|
18
16
|
module Chunk
|
19
17
|
mattr_accessor :raw_list, :prefix_regexp_by_list, :prefix_map
|
20
|
-
@@raw_list
|
18
|
+
@@raw_list = {}
|
19
|
+
@@prefix_regexp_by_list = {}
|
20
|
+
@@prefix_map = {}
|
21
21
|
|
22
22
|
class << self
|
23
23
|
def register_class klass, hash
|
24
24
|
klass.config = hash.merge class: klass
|
25
|
-
prefix_index = hash[:idx_char] || :default
|
25
|
+
prefix_index = hash[:idx_char] || :default
|
26
|
+
# ^ this is gross and needs to be moved out.
|
26
27
|
prefix_map[prefix_index] = klass.config
|
27
28
|
end
|
28
29
|
|
@@ -31,51 +32,57 @@ class Card
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def find_class_by_prefix prefix
|
34
|
-
config = prefix_map[
|
35
|
-
|
35
|
+
config = prefix_map[prefix[0, 1]] ||
|
36
|
+
prefix_map[prefix[-1, 1]] ||
|
37
|
+
prefix_map[:default]
|
38
|
+
# prefix identified by first character, last character, or default.
|
39
|
+
# a little ugly...
|
36
40
|
config[:class]
|
37
41
|
end
|
38
42
|
|
39
43
|
def get_prefix_regexp chunk_list_key
|
40
44
|
prefix_regexp_by_list[chunk_list_key] ||= begin
|
41
|
-
|
42
|
-
|
45
|
+
prefix_res = raw_list[chunk_list_key].map do |chunkname|
|
46
|
+
chunk_class = const_get chunkname
|
43
47
|
chunk_class.config[:prefix_re]
|
44
48
|
end
|
45
49
|
/(?:#{ prefix_res * '|' })/m
|
46
50
|
end
|
47
51
|
end
|
48
|
-
|
49
52
|
end
|
50
53
|
|
51
|
-
|
52
|
-
#
|
53
|
-
register_list :default, [
|
54
|
-
|
55
|
-
|
56
|
-
register_list :
|
54
|
+
# not sure whether this is best place. Could really happen almost anywhere
|
55
|
+
# (even before chunk classes are loaded).
|
56
|
+
register_list :default, [
|
57
|
+
:URI, :HostURI, :EmailURI, :EscapedLiteral, :Include, :Link
|
58
|
+
]
|
59
|
+
register_list :references, [:EscapedLiteral, :Include, :Link]
|
60
|
+
register_list :inclusion_only, [:Include]
|
61
|
+
register_list :query, [:QueryReference]
|
57
62
|
|
58
63
|
class Abstract
|
59
64
|
class_attribute :config
|
60
65
|
attr_reader :text, :process_chunk
|
61
66
|
|
62
67
|
class << self
|
63
|
-
|
64
68
|
# if the prefix regex matched check that chunk against the full regex
|
65
69
|
def full_match content, prefix=nil
|
66
|
-
|
67
|
-
content.match full_re( prefix )
|
70
|
+
content.match full_re(prefix)
|
68
71
|
end
|
69
72
|
|
70
|
-
def full_re
|
73
|
+
def full_re _prefix
|
71
74
|
config[:full_re]
|
72
75
|
end
|
73
76
|
|
74
|
-
def context_ok?
|
77
|
+
def context_ok? _content, _chunk_start
|
75
78
|
true
|
76
79
|
end
|
77
80
|
end
|
78
81
|
|
82
|
+
def reference_code
|
83
|
+
'I'
|
84
|
+
end
|
85
|
+
|
79
86
|
def initialize match, content
|
80
87
|
@text = match[0]
|
81
88
|
@processed = nil
|
@@ -84,8 +91,9 @@ class Card
|
|
84
91
|
self
|
85
92
|
end
|
86
93
|
|
87
|
-
def interpret
|
88
|
-
Rails.logger.info
|
94
|
+
def interpret _match_string, _content, _params
|
95
|
+
Rails.logger.info 'no #interpret method found for chunk class: ' \
|
96
|
+
"#{self.class}"
|
89
97
|
end
|
90
98
|
|
91
99
|
def format
|
@@ -101,11 +109,12 @@ class Card
|
|
101
109
|
end
|
102
110
|
|
103
111
|
def inspect
|
104
|
-
"<##{self.class}##{
|
112
|
+
"<##{self.class}##{self}>"
|
105
113
|
end
|
106
114
|
|
107
|
-
def as_json
|
108
|
-
@process_chunk || @processed||
|
115
|
+
def as_json _options={}
|
116
|
+
@process_chunk || @processed ||
|
117
|
+
"not rendered #{self.class}, #{card && card.name}"
|
109
118
|
end
|
110
119
|
end
|
111
120
|
end
|