Module: Styler::Style::ClassMethods

Defined in:
lib/styler/style.rb

Instance Method Summary collapse

Instance Method Details

#association(*methods) ⇒ Object

Add all the methods that will call other model instances here. As there are no collection-styles, set up complicated stuff in :prepare



6
7
8
9
10
11
12
13
# File 'lib/styler/style.rb', line 6

def association(*methods)
  methods.each do |m|
    define_method(m) {|*args, &block|
      assoc = @model.send(m, *args, &block)
      ::Styler.new_style_for(assoc,serialize_to_hash.merge({@model.class.to_s.downcase.split('::').last => self}))
    }
  end
end

#delegate(*methods) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/styler/style.rb', line 15

def delegate(*methods)
  methods.each do |m|
    define_method(m) { |*args|
      @model.send(m, *args)
    }
  end
end

#delegate_to_controller(*methods) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/styler/style.rb', line 23

def delegate_to_controller(*methods)
  methods.each do |m|
    define_method(m) { |*args|
      @__controller.send(m, *args)
    }
  end
end

#style_for(model) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/styler/style.rb', line 31

def style_for(model)
  model.instance_methods.each do |method|
    unless method_defined? method
      define_method(method) {|*args| @model.send(method, *args)}
    end
  end
  Styler::STYLES.merge!({model => self})
end