Module: Sunrise::FileUpload::Callbacks

Included in:
Manager
Defined in:
lib/sunrise/file_upload/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#_after_createObject

Provides access to the callback array for after_create :api: private



46
47
48
# File 'lib/sunrise/file_upload/callbacks.rb', line 46

def _after_create
  @_after_create ||= []
end

#_before_createObject

Provides access to the callback array for before_create :api: private



30
31
32
# File 'lib/sunrise/file_upload/callbacks.rb', line 30

def _before_create
  @_before_create ||= []
end

#_run_callbacks(kind, *args) ⇒ Object

Hook to _run_callbacks asserting for conditions.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/sunrise/file_upload/callbacks.rb', line 6

def _run_callbacks(kind, *args) #:nodoc:
  options = args.last # Last callback arg MUST be a Hash

  send("_#{kind}").each do |callback, conditions|
    invalid = conditions.find do |key, value|
      value.is_a?(Array) ? !value.include?(options[key]) : (value != options[key])
    end

    callback.call(*args) unless invalid
  end
end

#after_create(options = {}, method = :push, &block) ⇒ Object

A callback that runs after asset created Example:

Sunrise::FileUpload::Manager.after_create do |env, opts|
end

Raises:

  • (BlockNotGiven)


39
40
41
42
# File 'lib/sunrise/file_upload/callbacks.rb', line 39

def after_create(options = {}, method = :push, &block)
  raise BlockNotGiven unless block_given?
  _after_create.send(method, [block, options])
end

#before_create(options = {}, method = :push, &block) ⇒ Object

A callback that runs before create asset Example:

Sunrise::FileUpload::Manager.before_create do |env, opts|
end

Raises:

  • (BlockNotGiven)


23
24
25
26
# File 'lib/sunrise/file_upload/callbacks.rb', line 23

def before_create(options = {}, method = :push, &block)
  raise BlockNotGiven unless block_given?
  _before_create.send(method, [block, options])
end