Class: Attachs::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/attachs/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Builder

Returns a new instance of Builder.



6
7
8
9
10
11
12
# File 'lib/attachs/builder.rb', line 6

def initialize(model)
  @model = model
  @concern = Module.new do
    extend ActiveSupport::Concern
    include Concern
  end
end

Instance Attribute Details

#concernObject (readonly)

Returns the value of attribute concern.



4
5
6
# File 'lib/attachs/builder.rb', line 4

def concern
  @concern
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/attachs/builder.rb', line 4

def model
  @model
end

Instance Method Details

#define(attribute, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/attachs/builder.rb', line 14

def define(attribute, options={})
  unless options.has_key?(:path)
    raise 'Path required'
  end
  define_writer attribute
  define_reader attribute, options
  define_attributes_writer attribute, options
  model.include concern
  model.attachments[attribute] = options
end