diff options
author | danielsdeleo <dan@opscode.com> | 2013-06-07 09:43:39 -0700 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-06-07 09:43:39 -0700 |
commit | 288c55f91b6f4eb5a1bd474dbaa3fffeb644f9b9 (patch) | |
tree | c16a6afc87185a4d625a4b390ea63bd4f8b8bb0c /lib/chef/mixin/template.rb | |
parent | d6f6533a2fd674bde77d74c76c599b1457070a9a (diff) | |
download | chef-288c55f91b6f4eb5a1bd474dbaa3fffeb644f9b9.tar.gz |
Add ruby 1.8 fallbacks for IO.binread
Diffstat (limited to 'lib/chef/mixin/template.rb')
-rw-r--r-- | lib/chef/mixin/template.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/chef/mixin/template.rb b/lib/chef/mixin/template.rb index f92bbb4325..f515f5c00d 100644 --- a/lib/chef/mixin/template.rb +++ b/lib/chef/mixin/template.rb @@ -23,6 +23,18 @@ class Chef module Mixin module Template + # A compatibility wrapper around IO.binread so it works on Ruby 1.8.7. + # -- + # Used in the TemplateContext class, but that method namespace is shared + # with user code, so we want to avoid adding methods there when possible. + def self.binread(file) + if IO.respond_to?(:binread) + IO.binread(file) + else + IO.read(file) + end + end + # == ChefContext # ChefContext was previously used to mix behavior into Erubis::Context so # that it would be available to templates. This behavior has now moved to @@ -93,11 +105,11 @@ class Chef partial_context._extend_modules(@_extension_modules) template_location = @template_finder.find(partial_name, options) - _render_template(IO.binread(template_location), partial_context) + _render_template(Mixin::Template.binread(template_location), partial_context) end def render_template(template_location) - _render_template(IO.binread(template_location), self) + _render_template(Mixin::Template.binread(template_location), self) end def render_template_from_string(template) |