Class: Condo::Configuration
- Inherits:
-
Object
- Object
- Condo::Configuration
- Includes:
- Singleton
- Defined in:
- lib/condo/configuration.rb
Constant Summary collapse
- @@callbacks =
{ # #:resident_id # Must be defined by the including class # :bucket_name => proc {"#{Rails.application.class.parent_name}#{instance_eval @@callbacks[:resident_id]}"}, :object_key => proc { |upload| if upload[:file_path] upload[:file_path] + upload[:file_name] else upload[:file_name] end }, :object_options => proc { |upload| {:permissions => :private} }, :pre_validation => proc { |upload| true }, # To respond with errors use: lambda {return false, {:errors => {:param_name => 'wtf are you doing?'}}} :sanitize_filename => proc { |filename| filename = filename.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') filename.gsub!(/^.*(\\|\/)/, '') # get only the filename (just in case) filename.gsub!(/[^\w\.\-]/, '_') # replace all non alphanumeric or periods with underscore filename }, :sanitize_filepath => proc { |filepath| filepath = filepath.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') filepath.gsub!(/[^\w\.\-\/]/, '_') # replace all non alphanumeric or periods with underscore filepath }, :select_residence => proc { |config, resident_id, upload| # Where config === ::Condo::Configuration # and resident_id is the result of the resident_id callback # upload will only be present if it already exists config.residencies[0] } #:upload_complete # Must be defined by the including class #:destroy_upload # the actual delete should be done by the application }
Class Method Summary collapse
-
.add_residence(name, options = {}) ⇒ Object
Allows for predefined storage providers (maybe you only use Amazon?).
- .callbacks ⇒ Object
- .dynamic_residence(name, options = {}) ⇒ Object
- .get_residence(name, options = {}) ⇒ Object
- .residencies ⇒ Object
-
.set_callback(name, callback = nil, &block) ⇒ Object
Allows you to override default callback behaviour.
Class Method Details
.add_residence(name, options = {}) ⇒ Object
Allows for predefined storage providers (maybe you only use Amazon?)
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/condo/configuration.rb', line 64 def self.add_residence(name, = {}) @@residencies ||= [] @@residencies << ("Condo::Strata::#{name.to_s.camelize}".constantize.new()).tap do |res| name = name.to_sym namespace = ([:namespace] || :global).to_sym @@locations ||= {} @@locations[namespace] ||= {} @@locations[namespace][name] ||= {} if [:location].present? @@locations[namespace][name][[:location].to_sym] = res else @@locations[namespace][name][:default] = res @@locations[namespace][name][res.location.to_sym] = res end end end |
.callbacks ⇒ Object
49 50 51 |
# File 'lib/condo/configuration.rb', line 49 def self.callbacks @@callbacks end |
.dynamic_residence(name, options = {}) ⇒ Object
95 96 97 |
# File 'lib/condo/configuration.rb', line 95 def self.dynamic_residence(name, = {}) return "Condo::Strata::#{name.to_s.camelize}".constantize.new() end |
.get_residence(name, options = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/condo/configuration.rb', line 83 def self.get_residence(name, = {}) name = name.to_sym namespace = ([:namespace] || :global).to_sym location = ([:location] || :default).to_sym if @@locations && @@locations[namespace] && @@locations[namespace][name] && @@locations[namespace][name][location] return @@locations[namespace][name][location] end nil end |
.residencies ⇒ Object
99 100 101 |
# File 'lib/condo/configuration.rb', line 99 def self.residencies @@residencies end |
.set_callback(name, callback = nil, &block) ⇒ Object
Allows you to override default callback behaviour
54 55 56 57 58 59 60 61 |
# File 'lib/condo/configuration.rb', line 54 def self.set_callback(name, callback = nil, &block) callback ||= block if callback.respond_to?(:call) @@callbacks[name.to_sym] = callback else raise ArgumentError, 'No callback provided' end end |