Class: AttachmentMagick::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/attachment_magick/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(set, default_grids) ⇒ DSL

Returns a new instance of DSL.



6
7
8
9
10
# File 'lib/attachment_magick/dsl.rb', line 6

def initialize(set, default_grids)
  @set    = set
  @styles = {}
  @default_grids = default_grids
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *params, &blk) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/attachment_magick/dsl.rb', line 12

def method_missing(name, *params, &blk)
  options = params.first

  if options.nil?
    options = @default_grids[name.to_sym]
  elsif options.is_a?(String)
    values = options.split('x')

    options = {}
    options.merge!(:width   => values.first.to_i) if values.first
    options.merge!(:height  => values.last.to_i)  if values.second
    options.merge!(:ajust   => values.second.match(/\W/).to_s) unless values.second.match(/\W/).to_s.blank? if values.second

    options = @default_grids[name.to_sym].merge(options)
  elsif options.is_a?(Hash)
    options = @default_grids[name.to_sym].merge(options)
  end

  @styles.merge!(name.to_sym => options)
end

Instance Attribute Details

#default_optionsObject (readonly)

Returns the value of attribute default_options.



4
5
6
# File 'lib/attachment_magick/dsl.rb', line 4

def default_options
  @default_options
end

#stylesObject (readonly)

Returns the value of attribute styles.



3
4
5
# File 'lib/attachment_magick/dsl.rb', line 3

def styles
  @styles
end