Module: Rib::Plugin

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#disabledObject

Returns the value of attribute disabled.



4
5
6
# File 'lib/rib/plugin.rb', line 4

def disabled
  @disabled
end

Class Method Details

.extended(mod) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rib/plugin.rb', line 28

def self.extended mod
  mod.send(:include, Rib)

  snake_name = mod.name.sub(/(\w+::)+?(\w+)$/, '\2').
    gsub(/([A-Z][a-z]*)/, '\\1_').downcase[0..-2]

  code = (%w[enable disable].map{ |meth|
    <<-RUBY
      def #{meth}_#{snake_name} &block
        #{mod.name}.#{meth}(&block)
      end
    RUBY
  } + %w[enabled? disabled?].map{ |meth|
    <<-RUBY
      def #{snake_name}_#{meth} &block
        #{mod.name}.#{meth}(&block)
      end
    RUBY
  }).join("\n")

  Rib.singleton_class.module_eval(code, __FILE__, __LINE__)
end

Instance Method Details

#disableObject



13
14
15
16
17
18
# File 'lib/rib/plugin.rb', line 13

def disable
  self.disabled = true
  if block_given? then yield else enabled? end
ensure
  self.disabled = false if block_given?
end

#disabled?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rib/plugin.rb', line 24

def disabled?
  !!disabled
end

#enableObject



6
7
8
9
10
11
# File 'lib/rib/plugin.rb', line 6

def enable
  self.disabled = false
  if block_given? then yield else enabled? end
ensure
  self.disabled = true if block_given?
end

#enabled?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rib/plugin.rb', line 20

def enabled?
  !disabled
end