Module: Attach::ModelExtension::ClassMethods

Defined in:
lib/attach/model_extension/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#attachment(name, **options, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/attach/model_extension/class_methods.rb', line 25

def attachment(name, **options, &block)
  setup_model
  parse_dsl(name, &block)

  define_method name do
    get_attachment(name)
  end

  define_method "#{name}=" do |file|
    set_attachment(name, file, **options)
  end

  define_method "#{name}_delete" do
    instance_variable_get("@#{name}_delete")
  end

  define_method "#{name}_delete=" do |delete|
    delete = delete.to_i
    instance_variable_set("@#{name}_delete", delete)
    if delete == 1
      @pending_attachment_deletions ||= []
      @pending_attachment_deletions << name
    end
  end
end

#attachment_processorsObject



21
22
23
# File 'lib/attach/model_extension/class_methods.rb', line 21

def attachment_processors
  @attachment_processors ||= {}
end

#attachment_validatorsObject



17
18
19
# File 'lib/attach/model_extension/class_methods.rb', line 17

def attachment_validators
  @attachment_validators ||= {}
end

#includes_attachment(*args, **options) ⇒ Object



51
52
53
54
55
56
# File 'lib/attach/model_extension/class_methods.rb', line 51

def includes_attachment(*args, **options)
  manipulate do |scope|
    inclusion = Inclusion.new(scope, *args, **options)
    inclusion.prepare
  end
end