Module: Card::Set
- Included in:
- Abstract::Attachment, Abstract::Permission, All::Account, All::Actions, All::ActiveCard, All::AllCss, All::AllCsv, All::AllJs, All::Base, All::Bootstrap::Form, All::Bootstrap::Helper, All::Bootstrap::Wrapper, All::Collection, All::Comment, All::Content, All::ContentHistory, All::EmailHtml, All::EmailText, All::Erb, All::Error, All::EventViz, All::Fetch, All::File, All::Follow, All::Haml, All::History, All::Initialize, All::Json, All::Links, All::Name, All::Notify, All::Observer, All::Pattern, All::Permissions, All::Phases, All::References, All::RichBootstrap, All::RichHtml::Content, All::RichHtml::Editing, All::RichHtml::Form, All::RichHtml::Header, All::RichHtml::Menu, All::RichHtml::Modal, All::RichHtml::Toolbar, All::RichHtml::Wrapper, All::Rss, All::Rules, All::States, All::Templating, All::Text, All::TrackedAttributes, All::Trash, All::Type, All::Utils, All::ViewCache, Right::Account, Right::AddHelp, Right::Bcc, Right::Cc, Right::Comment, Right::Create, Right::Default, Right::Delete, Right::Discussion, Right::Email, Right::Follow, Right::FollowFields, Right::Followers, Right::Following, Right::From, Right::Help, Right::HtmlMessage, Right::MachineInput, Right::MachineOutput, Right::Password, Right::Read, Right::Salt, Right::Script, Right::Stats, Right::Status, Right::Structure, Right::Style, Right::To, Right::Token, Right::Update, Right::WhenCreated, Right::WhenLastEdited, Rstar::Rules, Self::AccountLinks, Self::Accountable, Self::AddHelp, Self::Alerts, Self::All, Self::Always, Self::Autoname, Self::BootstrapCards, Self::BootstrapJs, Self::BootswatchShared, Self::Captcha, Self::Create, Self::Created, Self::Default, Self::Delete, Self::Edited, Self::Follow, Self::FollowDefaults, Self::Foot, Self::Head, Self::Help, Self::Input, Self::Layout, Self::Navbox, Self::Never, Self::Now, Self::OnCreate, Self::OnDelete, Self::OnUpdate, Self::Options, Self::OptionsLabel, Self::PerformanceLog, Self::Read, Self::Recent, Self::RecentSettings, Self::Script, Self::ScriptAce, Self::ScriptCardMenu, Self::ScriptHtml5shivPrintshiv, Self::ScriptJquery, Self::ScriptJqueryHelper, Self::ScriptSlot, Self::ScriptTinymce, Self::Search, Self::Signin, Self::SmartmenuCss, Self::SmartmenuJs, Self::Stats, Self::Structure, Self::Style, Self::StyleBootstrapCompatible, Self::StyleCards, Self::StyleJqueryUiSmoothness, Self::TableOfContents, Self::Thanks, Self::Update, Self::Version, Type::Basic, Type::Cardtype, Type::CoffeeScript, Type::Css, Type::Date, Type::EmailTemplate, Type::File, Type::Html, Type::Image, Type::JavaScript, Type::LayoutType, Type::Number, Type::Phrase, Type::PlainText, Type::Pointer, Type::Scss, Type::SearchType, Type::Session, Type::Set, Type::Setting, Type::Signup, Type::Skin, Type::Toggle, Type::Uri, Type::User, TypePlusRight::User::Follow
- Defined in:
- lib/card/set.rb,
tmpsets/set/mod001-01_core/all/erb.rb,
tmpsets/set/mod001-01_core/all/haml.rb,
tmpsets/set/mod001-01_core/all/name.rb,
tmpsets/set/mod001-01_core/all/type.rb,
tmpsets/set/mod001-01_core/all/fetch.rb,
tmpsets/set/mod001-01_core/all/rules.rb,
tmpsets/set/mod001-01_core/all/trash.rb,
tmpsets/set/mod001-01_core/all/utils.rb,
tmpsets/set/mod006-05_email/right/cc.rb,
tmpsets/set/mod006-05_email/right/to.rb,
tmpsets/set/mod001-01_core/all/phases.rb,
tmpsets/set/mod001-01_core/all/states.rb,
tmpsets/set/mod006-05_email/right/bcc.rb,
tmpsets/set/mod001-01_core/all/content.rb,
tmpsets/set/mod001-01_core/all/pattern.rb,
tmpsets/set/mod006-05_email/all/follow.rb,
tmpsets/set/mod006-05_email/all/notify.rb,
tmpsets/set/mod006-05_email/right/from.rb,
tmpsets/set/mod006-05_email/self/never.rb,
tmpsets/set/mod004-03_machines/type/css.rb,
tmpsets/set/mod006-05_email/self/always.rb,
tmpsets/set/mod006-05_email/self/edited.rb,
tmpsets/set/mod006-05_email/self/follow.rb,
tmpsets/set/mod007-05_standard/self/all.rb,
tmpsets/set/mod007-05_standard/self/now.rb,
tmpsets/set/mod007-05_standard/type/set.rb,
tmpsets/set/mod007-05_standard/type/uri.rb,
tmpsets/set/mod004-03_machines/type/scss.rb,
tmpsets/set/mod004-03_machines/type/skin.rb,
tmpsets/set/mod005-04_settings/self/help.rb,
tmpsets/set/mod005-04_settings/self/read.rb,
tmpsets/set/mod006-05_email/all/observer.rb,
tmpsets/set/mod006-05_email/right/follow.rb,
tmpsets/set/mod006-05_email/self/created.rb,
tmpsets/set/mod007-05_standard/all/error.rb,
tmpsets/set/mod007-05_standard/all/links.rb,
tmpsets/set/mod007-05_standard/self/foot.rb,
tmpsets/set/mod007-05_standard/self/head.rb,
tmpsets/set/mod007-05_standard/type/date.rb,
tmpsets/set/mod007-05_standard/type/file.rb,
tmpsets/set/mod007-05_standard/type/user.rb,
tmpsets/set/mod001-01_core/all/collection.rb,
tmpsets/set/mod001-01_core/all/initialize.rb,
tmpsets/set/mod001-01_core/all/references.rb,
tmpsets/set/mod001-01_core/all/templating.rb,
tmpsets/set/mod001-01_core/all/view_cache.rb,
tmpsets/set/mod002-01_history/all/actions.rb,
tmpsets/set/mod002-01_history/all/history.rb,
tmpsets/set/mod003-02_basic_types/all/rss.rb,
tmpsets/set/mod005-04_settings/right/help.rb,
tmpsets/set/mod005-04_settings/right/read.rb,
tmpsets/set/mod005-04_settings/self/input.rb,
tmpsets/set/mod005-04_settings/self/style.rb,
tmpsets/set/mod007-05_standard/right/salt.rb,
tmpsets/set/mod007-05_standard/self/stats.rb,
tmpsets/set/mod007-05_standard/type/basic.rb,
tmpsets/set/mod007-05_standard/type/image.rb,
tmpsets/set/mod001-01_core/all/active_card.rb,
tmpsets/set/mod001-01_core/all/permissions.rb,
tmpsets/set/mod003-02_basic_types/all/base.rb,
tmpsets/set/mod003-02_basic_types/all/file.rb,
tmpsets/set/mod003-02_basic_types/all/json.rb,
tmpsets/set/mod003-02_basic_types/all/text.rb,
tmpsets/set/mod005-04_settings/right/style.rb,
tmpsets/set/mod005-04_settings/self/create.rb,
tmpsets/set/mod005-04_settings/self/delete.rb,
tmpsets/set/mod005-04_settings/self/layout.rb,
tmpsets/set/mod005-04_settings/self/script.rb,
tmpsets/set/mod005-04_settings/self/thanks.rb,
tmpsets/set/mod005-04_settings/self/update.rb,
tmpsets/set/mod006-05_email/all/email_html.rb,
tmpsets/set/mod006-05_email/all/email_text.rb,
tmpsets/set/mod007-05_standard/all/account.rb,
tmpsets/set/mod007-05_standard/all/comment.rb,
tmpsets/set/mod007-05_standard/right/email.rb,
tmpsets/set/mod007-05_standard/right/stats.rb,
tmpsets/set/mod007-05_standard/right/token.rb,
tmpsets/set/mod007-05_standard/rstar/rules.rb,
tmpsets/set/mod007-05_standard/self/alerts.rb,
tmpsets/set/mod007-05_standard/self/navbox.rb,
tmpsets/set/mod007-05_standard/self/recent.rb,
tmpsets/set/mod007-05_standard/self/search.rb,
tmpsets/set/mod007-05_standard/self/signin.rb,
tmpsets/set/mod007-05_standard/type/number.rb,
tmpsets/set/mod007-05_standard/type/phrase.rb,
tmpsets/set/mod007-05_standard/type/signup.rb,
tmpsets/set/mod007-05_standard/type/toggle.rb,
tmpsets/set/mod003-02_basic_types/type/html.rb,
tmpsets/set/mod005-04_settings/right/create.rb,
tmpsets/set/mod005-04_settings/right/delete.rb,
tmpsets/set/mod005-04_settings/right/script.rb,
tmpsets/set/mod005-04_settings/right/update.rb,
tmpsets/set/mod005-04_settings/self/captcha.rb,
tmpsets/set/mod005-04_settings/self/default.rb,
tmpsets/set/mod005-04_settings/self/options.rb,
tmpsets/set/mod005-04_settings/type/setting.rb,
tmpsets/set/mod006-05_email/right/followers.rb,
tmpsets/set/mod006-05_email/right/following.rb,
tmpsets/set/mod007-05_standard/right/status.rb,
tmpsets/set/mod007-05_standard/self/version.rb,
tmpsets/set/mod007-05_standard/type/session.rb,
tmpsets/set/mod003-02_basic_types/all/all_js.rb,
tmpsets/set/mod005-04_settings/right/comment.rb,
tmpsets/set/mod005-04_settings/right/default.rb,
tmpsets/set/mod005-04_settings/self/add_help.rb,
tmpsets/set/mod005-04_settings/self/autoname.rb,
tmpsets/set/mod007-05_standard/all/event_viz.rb,
tmpsets/set/mod007-05_standard/right/account.rb,
tmpsets/set/mod007-05_standard/type/cardtype.rb,
tmpsets/set/mod003-02_basic_types/all/all_css.rb,
tmpsets/set/mod003-02_basic_types/all/all_csv.rb,
tmpsets/set/mod005-04_settings/right/add_help.rb,
tmpsets/set/mod005-04_settings/self/on_create.rb,
tmpsets/set/mod005-04_settings/self/on_delete.rb,
tmpsets/set/mod005-04_settings/self/on_update.rb,
tmpsets/set/mod005-04_settings/self/structure.rb,
tmpsets/set/mod007-05_standard/right/password.rb,
tmpsets/set/mod003-02_basic_types/type/pointer.rb,
tmpsets/set/mod004-03_machines/self/script_ace.rb,
tmpsets/set/mod005-04_settings/right/structure.rb,
tmpsets/set/mod006-05_email/right/html_message.rb,
tmpsets/set/mod004-03_machines/self/script_slot.rb,
tmpsets/set/mod004-03_machines/self/style_cards.rb,
tmpsets/set/mod004-03_machines/type/java_script.rb,
tmpsets/set/mod005-04_settings/self/accountable.rb,
tmpsets/set/mod006-05_email/right/follow_fields.rb,
tmpsets/set/mod006-05_email/type/email_template.rb,
tmpsets/set/mod007-05_standard/right/discussion.rb,
tmpsets/set/mod007-05_standard/type/layout_type.rb,
tmpsets/set/mod007-05_standard/type/search_type.rb,
tmpsets/set/mod006-05_email/self/follow_defaults.rb,
tmpsets/set/mod001-01_core/all/tracked_attributes.rb,
tmpsets/set/mod002-01_history/all/content_history.rb,
tmpsets/set/mod003-02_basic_types/type/plain_text.rb,
tmpsets/set/mod004-03_machines/self/script_jquery.rb,
tmpsets/set/mod004-03_machines/type/coffee_script.rb,
tmpsets/set/mod005-04_settings/self/options_label.rb,
tmpsets/set/mod007-05_standard/all/rich_html/form.rb,
tmpsets/set/mod007-05_standard/all/rich_html/menu.rb,
tmpsets/set/mod007-05_standard/right/when_created.rb,
tmpsets/set/mod007-05_standard/self/account_links.rb,
tmpsets/set/mod008-06_bootstrap/self/bootstrap_js.rb,
tmpsets/set/mod008-06_bootstrap/self/smartmenu_js.rb,
tmpsets/set/mod004-03_machines/right/machine_input.rb,
tmpsets/set/mod004-03_machines/self/script_tinymce.rb,
tmpsets/set/mod005-04_settings/abstract/permission.rb,
tmpsets/set/mod007-05_standard/abstract/attachment.rb,
tmpsets/set/mod007-05_standard/all/rich_html/modal.rb,
tmpsets/set/mod008-06_bootstrap/all/bootstrap/form.rb,
tmpsets/set/mod008-06_bootstrap/all/rich_bootstrap.rb,
tmpsets/set/mod008-06_bootstrap/self/smartmenu_css.rb,
tmpsets/set/mod004-03_machines/right/machine_output.rb,
tmpsets/set/mod005-04_settings/self/recent_settings.rb,
tmpsets/set/mod007-05_standard/all/rich_html/header.rb,
tmpsets/set/mod007-05_standard/self/performance_log.rb,
tmpsets/set/mod004-03_machines/self/script_card_menu.rb,
tmpsets/set/mod007-05_standard/all/rich_html/content.rb,
tmpsets/set/mod007-05_standard/all/rich_html/editing.rb,
tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb,
tmpsets/set/mod007-05_standard/all/rich_html/wrapper.rb,
tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb,
tmpsets/set/mod008-06_bootstrap/self/bootstrap_cards.rb,
tmpsets/set/mod005-04_settings/self/table_of_contents.rb,
tmpsets/set/mod007-05_standard/right/when_last_edited.rb,
tmpsets/set/mod008-06_bootstrap/all/bootstrap/wrapper.rb,
tmpsets/set/mod008-06_bootstrap/self/bootswatch_shared.rb,
tmpsets/set/mod006-05_email/type_plus_right/user/follow.rb,
tmpsets/set/mod004-03_machines/self/script_jquery_helper.rb,
tmpsets/set/mod004-03_machines/self/script_html5shiv_printshiv.rb,
tmpsets/set/mod004-03_machines/self/style_bootstrap_compatible.rb,
tmpsets/set/mod004-03_machines/self/style_jquery_ui_smoothness.rb
Overview
remove_const :Set if const_defined?(:Set, false)
Defined Under Namespace
Modules: Abstract, All, Format, Right, Rstar, Self, Type, TypePlusRight
Constant Summary
collapse
- @@modules =
{ :base=>[], :base_format=>{}, :nonbase=>{}, :nonbase_format=>{} }
Class Method Summary
collapse
Instance Method Summary
collapse
-
#abstract_set? ⇒ Boolean
-
#all_set? ⇒ Boolean
-
#card_accessor(*args) ⇒ Object
ActiveCard support: accessing plus cards as attributes.
-
#card_reader(*args) ⇒ Object
-
#card_writer(*args) ⇒ Object
-
#define_active_job(name, final_method, queue = :default) ⇒ Object
-
#define_event_method(event, call_method, opts) ⇒ Object
-
#define_event_perform_later_method(event, method_name) ⇒ Object
-
#define_on_format(format_name = :base, &block) ⇒ Object
-
#ensure_set(&block) ⇒ Object
-
#event(event, opts = {}, &final) ⇒ Object
-
#format(*format_names, &block) ⇒ Object
-
#register_set_format(format_class, mod) ⇒ Object
-
#shortname ⇒ Object
-
#view(*args, &block) ⇒ Object
Class Method Details
.clean_empty_module_from_hash(hash) ⇒ Object
336
337
338
339
340
341
|
# File 'lib/card/set.rb', line 336
def clean_empty_module_from_hash hash
hash.each do |mod_name, modlist|
modlist.delete_if { |x| x.instance_methods.empty? }
hash.delete mod_name if modlist.empty?
end
end
|
.clean_empty_modules ⇒ Object
329
330
331
332
333
334
|
# File 'lib/card/set.rb', line 329
def clean_empty_modules
clean_empty_module_from_hash modules[ :nonbase ]
modules[ :nonbase_format ].values.each do |hash|
clean_empty_module_from_hash hash
end
end
|
.extended(mod) ⇒ Object
each set file calls ‘extend Card::Set` when loaded
267
268
269
|
# File 'lib/card/set.rb', line 267
def extended mod
register_set mod
end
|
.process_base_module_list(list, klass) ⇒ Object
318
319
320
321
322
323
324
325
326
327
|
# File 'lib/card/set.rb', line 318
def process_base_module_list list, klass
list.each do |mod|
if mod.instance_methods.any?
klass.send :include, mod
end
if class_methods = mod.const_get_if_defined( :ClassMethods )
klass.send :extend, class_methods
end
end
end
|
.process_base_modules ⇒ Object
“base modules” are modules that are permanently included on the Card or Format class “nonbase modules” are included dynamically on singleton_classes
309
310
311
312
313
314
315
316
|
# File 'lib/card/set.rb', line 309
def process_base_modules
process_base_module_list modules[:base], Card
modules[:base_format].each do |format_class, modules_list|
process_base_module_list modules_list, format_class
end
modules.delete :base
modules.delete :base_format
end
|
.register_set(set_module) ⇒ Object
make the set available for use
273
274
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/card/set.rb', line 273
def register_set set_module
if set_module.abstract_set?
elsif set_module.all_set?
modules[ :base ] << set_module
else
modules[ :nonbase ][ set_module.shortname ] ||= []
modules[ :nonbase ][ set_module.shortname ] << set_module
end
end
|
.write_tmp_file(from_file, to_file, rel_path) ⇒ Object
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
# File 'lib/card/set.rb', line 286
def write_tmp_file from_file, to_file, rel_path
name_parts = rel_path.gsub(/\.rb/,'').split(File::SEPARATOR)
submodules = name_parts.map { |a| "module #{a.camelize};" } * ' '
file_content = <<EOF
# -*- encoding : utf-8 -*-
class Card; module Set; #{submodules} extend Card::Set # ~~~~~~~~~~~ above autogenerated; below pulled from #{from_file} ~~~~~~~~~~~
#{ File.read from_file }
# ~~~~~~~~~~~ below autogenerated; above pulled from #{from_file} ~~~~~~~~~~~
end;end;#{'end;'*name_parts.size}
EOF
FileUtils.mkdir_p to_file.gsub /[^\/]*$/, ''
File.write to_file, file_content
to_file
end
|
Instance Method Details
#abstract_set? ⇒ Boolean
370
371
372
|
# File 'lib/card/set.rb', line 370
def abstract_set?
name =~ /^Card::Set::Abstract::/
end
|
#all_set? ⇒ Boolean
374
375
376
|
# File 'lib/card/set.rb', line 374
def all_set?
name =~ /^Card::Set::All::/
end
|
#card_accessor(*args) ⇒ Object
ActiveCard support: accessing plus cards as attributes
221
222
223
224
|
# File 'lib/card/set.rb', line 221
def card_accessor *args
options = args.
add_traits args, options.merge( :reader=>true, :writer=>true )
end
|
#card_reader(*args) ⇒ Object
226
227
228
229
|
# File 'lib/card/set.rb', line 226
def card_reader *args
options = args.
add_traits args, options.merge( :reader=>true )
end
|
#card_writer(*args) ⇒ Object
231
232
233
234
|
# File 'lib/card/set.rb', line 231
def card_writer *args
options = args.
add_traits args, options.merge( :writer=>true )
end
|
#define_active_job(name, final_method, queue = :default) ⇒ Object
creates an Active Job. The scheduled job gets the card object as argument and all serializable attributes of the card. (when the job is executed ActiveJob fetches the card from the database so all attributes get lost)
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
# File 'lib/card/set.rb', line 198
def define_active_job name, final_method, queue = :default
class_name = name.to_s.camelize
eval %{
class ::#{class_name} < ActiveJob::Base
queue_as #{queue}
end
}
Object.const_get(class_name).class_eval do
define_method :perform, proc { |card, attributes|
attributes.each do |name, args|
value = args[:symbol] ? args[:value].to_sym : args[:value]
card.instance_variable_set("@#{name}", value )
end
card.send final_method
}
end
end
|
#define_event_method(event, call_method, opts) ⇒ Object
181
182
183
184
185
186
187
188
189
|
# File 'lib/card/set.rb', line 181
def define_event_method event, call_method, opts
class_eval do
define_method event do
run_callbacks event do
send call_method
end
end
end
end
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/card/set.rb', line 164
def define_event_perform_later_method event, method_name
class_eval do
define_method method_name, proc {
s_attr = self.serializable_attributes.each_with_object({}) do |name, hash|
value = self.instance_variable_get("@#{name}")
hash[name] =
if Symbol === value { :value => value.to_s, :symbol => true }
else
{ :value => value }
end
end
Object.const_get(event.to_s.camelize).perform_later(self, s_attr)
}
end
end
|
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/card/set.rb', line 124
def define_on_format format_name=:base, &block
klass = Card::Format.format_class_name format_name mod = const_get_or_set klass do m = Module.new register_set_format Card.const_get(klass), m
m.extend Card::Set::Format
m
end
mod.class_eval &block
end
|
#ensure_set(&block) ⇒ Object
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/card/set.rb', line 237
def ensure_set &block
begin
set_module = block.call
rescue NameError => e
if e.message.match /uninitialized constant (?:Card::Set::)?(.+)$/
$1.split('::').inject(Card::Set) do |set_module, module_name|
set_module.const_get_or_set module_name do
Module.new
end
end
end
ensure_set &block else
set_module.extend Card::Set
end
end
|
#event(event, opts = {}, &final) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/card/set.rb', line 142
def event event, opts={}, &final
perform_later = (opts[:before] == :subsequent) || (opts[:after] == :subsequent)
final_method = "#{event}_without_callbacks" opts[:on] = [:create, :update ] if opts[:on] == :save
Card.define_callbacks event
class_eval do
define_method final_method, &final
end
if perform_later
defer_method = "#{event}_perform_later"
define_event_perform_later_method event, defer_method
define_active_job event, final_method, opts[:queue_as]
define_event_method event, defer_method, opts
else
define_event_method event, final_method, opts
end
set_event_callbacks event, opts
end
|
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/card/set.rb', line 113
def format *format_names, &block
if format_names.empty?
format_names = [:base]
elsif format_names.first == :all
format_names = Card::Format.registered.reject {|f| Card::Format.aliases[f]}
end
format_names.each do |f|
define_on_format f, &block
end
end
|
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
# File 'lib/card/set.rb', line 346
def register_set_format format_class, mod
if self.abstract_set?
elsif self.all_set?
modules[ :base_format ][ format_class ] ||= []
modules[ :base_format ][ format_class ] << mod
else
format_hash = modules[ :nonbase_format ][ format_class ] ||= {}
format_hash[ shortname ] ||= []
format_hash[ shortname ] << mod
end
end
|
#shortname ⇒ Object
361
362
363
364
365
366
367
368
|
# File 'lib/card/set.rb', line 361
def shortname
parts = name.split '::'
first = 2 set_class = Card::SetPattern.find parts[first].underscore
last = first + set_class.anchor_parts_count
parts[first..last].join '::'
end
|
#view(*args, &block) ⇒ Object
135
136
137
138
139
|
# File 'lib/card/set.rb', line 135
def view *args, &block
format do
view *args, &block
end
end
|