Module: RoHelpers::RoHelper::ClassMethods

Included in:
BashBuilderHelper::ClsMeths
Defined in:
lib/ro_helpers/ro_helper.rb

Instance Method Summary collapse

Instance Method Details

#def_meth(meth, meth_type = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ro_helpers/ro_helper.rb', line 50

def def_meth(meth, meth_type=nil)
  meth = meth.to_s
  if defined?(meth_feature) and meth.match(meth_feature)
    if meth.match(%r{_})
      new_method = meth.to_s.sub(%r{_}, "")

      if meth_type == 'singleton'
        define_singleton_method new_method.to_sym do |*args|
          before_each if defined? before_each
          send(meth.to_sym, *args)
          after_each if defined? after_each
        end
      else
        define_method new_method.to_sym do |*args|
          before_each if defined? before_each
          send(meth.to_sym, *args)
          after_each if defined? after_each
        end
      end
    end
  end
end

#meth_featureObject



28
29
30
# File 'lib/ro_helpers/ro_helper.rb', line 28

def meth_feature
  %r{^_}
end

#method_added(meth) ⇒ Object



37
38
39
40
41
# File 'lib/ro_helpers/ro_helper.rb', line 37

def method_added(meth)
  super
  #puts "method:#{meth}"
  def_meth(meth)
end

#methsObject



32
33
34
35
# File 'lib/ro_helpers/ro_helper.rb', line 32

def meths
  @meths.uniq! if @meths.respond_to?(:uniq!)
  @meths ||= []
end

#singleton_method_added(meth) ⇒ Object



44
45
46
47
48
# File 'lib/ro_helpers/ro_helper.rb', line 44

def singleton_method_added(meth)
  super
  #puts "singleton_method:#{meth}"
  def_meth(meth, 'singleton')
end