Module: EasyDecorator::ClassMethods

Defined in:
lib/easy_decorator.rb

Instance Method Summary collapse

Instance Method Details

#decorate(decorator) ⇒ Object



13
14
15
16
17
# File 'lib/easy_decorator.rb', line 13

def decorate(decorator)
  # get line number of decorator statement and add decorator method to the buffer
  line_num = caller.first.split(':')[1]
  @decorators[:method_buffer].prepend({ decorator: decorator, line: line_num })
end

#decoratorsObject



19
20
21
# File 'lib/easy_decorator.rb', line 19

def decorators
  @decorators
end

#method_added(method_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/easy_decorator.rb', line 23

def method_added(method_name)
  return if bypass_method_added(method_name)

  # validate correct syntax
  method_line = caller.first.split(':')[1]
  validate_syntax(method_line)

  source_method_name = "easy_decorator_#{method_name}".to_sym
  alias_method source_method_name, method_name
  method_chain = build_method_chain(method_name)
  setup_decorated_method(method_name, method_chain)
end