Module: Card::Set::AdvancedApi
- Included in:
- Card::Set
- Defined in:
- lib/card/set/advanced_api.rb
Overview
advanced set module API
Instance Method Summary collapse
- #assign_type(type, module_key = nil) ⇒ Object
- #attachment(name, args) ⇒ Object
- #define_set_from_error(error) ⇒ Object
- #ensure_set(&block) ⇒ Object
- #setting_opts(opts) ⇒ Object
- #stage_method(method, opts = {}, &block) ⇒ Object
Instance Method Details
#assign_type(type, module_key = nil) ⇒ Object
5 6 7 8 |
# File 'lib/card/set/advanced_api.rb', line 5 def assign_type type, module_key=nil module_key ||= shortname Type.assignment[module_key] = type end |
#attachment(name, args) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/card/set/advanced_api.rb', line 33 def name, args include_set Abstract::Attachment add_attributes name, "remote_#{name}_url".to_sym, :action_id_of_cached_upload, :empty_ok, :storage_type, :bucket, :mod mount_uploader name, (args[:uploader] || ::CarrierWave::FileCardUploader) Card.define_dirty_methods name end |
#define_set_from_error(error) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/card/set/advanced_api.rb', line 26 def define_set_from_error error match = error..match(/uninitialized constant (?:Card::Set::)?(.+)$/) return unless match define_set match[1] end |
#ensure_set(&block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/card/set/advanced_api.rb', line 15 def ensure_set &block set_module = yield set_module = card_set_module_const_get(set_module) unless set_module.is_a?(Module) rescue NameError => e define_set_from_error e # try again - there might be another submodule that doesn't exist ensure_set(&block) else set_module.extend Card::Set end |
#setting_opts(opts) ⇒ Object
10 11 12 13 |
# File 'lib/card/set/advanced_api.rb', line 10 def setting_opts opts extend Card::Setting register_setting opts end |
#stage_method(method, opts = {}, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/card/set/advanced_api.rb', line 42 def stage_method method, opts={}, &block class_eval do define_method "_#{method}", &block define_method method do |*args| if (error = wrong_stage(opts) || wrong_action(opts[:on])) raise Card::Error, error end send "_#{method}", *args end end end |