Class: Object

Inherits:
BasicObject
Defined in:
lib/vendor/puppet/util/zaml.rb,
lib/vendor/puppet/util/metaid.rb,
lib/vendor/puppet/module_tool/skeleton/templates/generator/spec/spec_helper.rb,
lib/vendor/puppet/util/monkey_patches.rb

Overview

We need this because the RAL uses ‘should’ as a method. This allows us the same behaviour but with a different method name.

Instance Method Summary collapse

Instance Method Details

#assert_that(message = nil) ⇒ Object



69
70
71
72
73
# File 'lib/vendor/puppet/util/monkey_patches.rb', line 69

def assert_that(message = nil)
  unless yield
    raise Exception.new("Assertion failure: #{message}")
  end
end

#class_def(name, &blk) ⇒ Object

Defines an instance method within a class



17
18
19
# File 'lib/vendor/puppet/util/metaid.rb', line 17

def class_def(name, &blk)
  class_eval { define_method name, &blk }
end

#daemonizeObject

ActiveSupport 2.3.x mixes in a dangerous method that can cause rspec to fork bomb and other strange things like that.

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/vendor/puppet/util/monkey_patches.rb', line 58

def daemonize
  raise NotImplementedError, "Kernel.daemonize is too dangerous, please don't try to use it."
end

#meta_def(name, &blk) ⇒ Object

Adds methods to a singleton_class



7
8
9
# File 'lib/vendor/puppet/util/metaid.rb', line 7

def meta_def(name, &blk)
  meta_eval { define_method name, &blk }
end

#meta_eval(&blk) ⇒ Object



4
# File 'lib/vendor/puppet/util/metaid.rb', line 4

def meta_eval(&blk); singleton_class.instance_eval(&blk); end

#meta_undef(name, &blk) ⇒ Object

Remove singleton_class methods.



12
13
14
# File 'lib/vendor/puppet/util/metaid.rb', line 12

def meta_undef(name, &blk)
  meta_eval { remove_method name }
end

#singleton_classObject

The hidden singleton lurks behind everyone



3
# File 'lib/vendor/puppet/util/metaid.rb', line 3

def singleton_class; class << self; self; end; end

#to_yaml_propertiesObject



174
175
176
# File 'lib/vendor/puppet/util/zaml.rb', line 174

def to_yaml_properties
  instance_variables          # default YAML behaviour.
end

#to_zaml(z) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/vendor/puppet/util/zaml.rb', line 184

def to_zaml(z)
  z.first_time_only(self) {
    z.emit(zamlized_class_name(Object))
    z.nested {
      instance_variables = to_yaml_properties
      if instance_variables.empty?
        z.emit(" {}")
      else
        instance_variables.each { |v|
          z.nl
          v[1..-1].to_zaml(z)       # Remove leading '@'
          z.emit(': ')
          yaml_property_munge(instance_variable_get(v)).to_zaml(z)
        }
      end
    }
  }
end

#yaml_property_munge(x) ⇒ Object



177
178
179
# File 'lib/vendor/puppet/util/zaml.rb', line 177

def yaml_property_munge(x)
  x
end

#zamlized_class_name(root) ⇒ Object



180
181
182
183
# File 'lib/vendor/puppet/util/zaml.rb', line 180

def zamlized_class_name(root)
  cls = self.class
  "!ruby/#{root.name.downcase}#{cls == root ? '' : ":#{cls.respond_to?(:name) ? cls.name : cls}"}"
end