Module: SqlcachedClient::Attachments::ClassMethods

Defined in:
lib/sqlcached_client/attachments.rb

Instance Method Summary collapse

Instance Method Details

#build_attachments(name, conditions, size) ⇒ Object



27
28
29
# File 'lib/sqlcached_client/attachments.rb', line 27

def build_attachments(name, conditions, size)
  size.times.map { @attachment_classes[name].new(conditions, nil) }
end

#has_attachment(name, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sqlcached_client/attachments.rb', line 8

def has_attachment(name, &block)
  @attachment_classes ||= {}
  @attachment_classes[name] =
    Class.new(Attachment) do

      @attachment_name = name
      class << self
        attr_reader :attachment_name
      end

      def initialize(conditions, content)
        super(self.class.attachment_name, conditions, content)
      end

      instance_exec(&block)
    end
  attr_accessor(name)
end