Module: Barista::Extensions::ClassMethods

Defined in:
lib/barista/extensions.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) has_boolean_options(*names)



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/barista/extensions.rb', line 13

def has_boolean_options(*names)
  source = []
  names.each do |name|
    source << <<-EOM
      
      def #{name}!
        @#{name} = true
      end
      
      def #{name}?
        defined?(@#{name}) ? @#{name} : default_for_#{name}
      end
      
      def #{name}=(value)
        @#{name} = !!value
      end
      
      def default_for_#{name}
        false
      end
      
    EOM
  end
  class_eval source.join("\n"), __FILE__, __LINE__
end

- (Object) has_delegate_methods(delegate, *args)



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/barista/extensions.rb', line 51

def has_delegate_methods(delegate, *args)
  source = []
  args.each do |method|
    source << <<-EOM

      def #{method}(*args, &blk)
        #{delegate}.send(:#{method}, *args, &blk)
      end

    EOM
  end
  class_eval source.join("\n"), __FILE__, __LINE__
end

- (Object) has_deprecated_methods(*args)



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/barista/extensions.rb', line 65

def has_deprecated_methods(*args)
  source = []
  args.each do |method|
    source << <<-EOM

      def #{method}(*args, &blk)
        Barista.deprecate!(self, :#{method})
        nil
      end

    EOM
  end
  class_eval source.join("\n"), __FILE__, __LINE__
end

- (Object) has_hook_method(options)



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/barista/extensions.rb', line 39

def has_hook_method(options)
  source = []
  options.each_pair do |name, event|
    source << <<-EOM
      def #{name}(&blk)
        on_hook #{event.to_sym.inspect}, &blk
      end
    EOM
  end
  class_eval source.join("\n"), __FILE__, __LINE__
end