Skip to content

Commit

Permalink
use psych
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Jul 17, 2013
1 parent e066d89 commit 2b4c63c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/aspects.rb
Expand Up @@ -53,7 +53,7 @@
#
################################################################################

interwiki_map = YAML.load_file(File.join(Config['config_path'], 'interwiki.yml'))
interwiki_map = yaml_load_file(File.join(Config['config_path'], 'interwiki.yml'))

################################################################################
# Creole aspects configuration
Expand Down
2 changes: 1 addition & 1 deletion lib/olelo.rb
Expand Up @@ -4,7 +4,7 @@
require 'digest/sha2'
require 'open3'
require 'set'
require 'yaml'
require 'psych'
require 'mimemagic'
require 'socket'
require 'multi_json'
Expand Down
2 changes: 1 addition & 1 deletion lib/olelo/config.rb
Expand Up @@ -42,7 +42,7 @@ def load(file)
end

def load!(file)
update(YAML.load_file(file))
update(Util.yaml_load_file(file))
end

def each(&block)
Expand Down
4 changes: 2 additions & 2 deletions lib/olelo/initializer.rb
Expand Up @@ -23,7 +23,7 @@ def initialize(logger)

def init_locale
Locale.locale = Config['locale']
Locale.add(YAML.load_file(File.join(File.dirname(__FILE__), 'locale.yml')))
Locale.add(yaml_load_file(File.join(File.dirname(__FILE__), 'locale.yml')))
end

def init_templates
Expand All @@ -38,7 +38,7 @@ def init_plugins
# Load locale provided by plugin
Plugin.after(:load) do
virtual_fs.glob('locale.yml') do |fs, name|
Locale.add(YAML.load(fs.read(name)))
Locale.add(yaml_load(fs.read(name)))
end
end

Expand Down
12 changes: 12 additions & 0 deletions lib/olelo/util.rb
Expand Up @@ -50,6 +50,18 @@ def check
raise MultiError, errors if !errors.empty?
end

def yaml_load_file(file)
yaml_load(File.read(file))
end

def yaml_load(content)
Psych.safe_load(content)
end

def yaml_dump(object)
Psych.dump(object)
end

# Like CGI.escape but escapes space not as +
def escape(s)
s = s.to_s
Expand Down
4 changes: 2 additions & 2 deletions plugins/repositories/gitrb_repository.rb
Expand Up @@ -92,7 +92,7 @@ def get_content(path, version)
def get_attributes(path, version)
check_path(path)
object = get_object(path + ATTRIBUTE_EXT, version)
object && object.type == :blob ? YAML.load(object.data) : {}
object && object.type == :blob ? yaml_load(object.data) : {}
end

# @override
Expand All @@ -115,7 +115,7 @@ def set_content(path, content)
# @override
def set_attributes(path, attributes)
check_path(path)
attributes = attributes.blank? ? nil : YAML.dump(attributes).sub(/\A\-\-\-\s*\n/s, '')
attributes = attributes.blank? ? nil : yaml_dump(attributes).sub(/\A\-\-\-\s*\n/s, '')
expand_tree(path)
if attributes
@git.root[path + ATTRIBUTE_EXT] = Gitrb::Blob.new(data: attributes)
Expand Down
4 changes: 2 additions & 2 deletions plugins/repositories/rugged_repository.rb
Expand Up @@ -203,7 +203,7 @@ def set_content(path, content)

def set_attributes(path, attributes)
check_path(path)
attributes = attributes.blank? ? nil : YAML.dump(attributes).sub(/\A\-\-\-\s*\n/s, '')
attributes = attributes.blank? ? nil : yaml_dump(attributes).sub(/\A\-\-\-\s*\n/s, '')
expand_tree(path)
if attributes
work_tree[path + ATTRIBUTE_EXT] = Blob.new(@git, attributes)
Expand Down Expand Up @@ -337,7 +337,7 @@ def get_attributes(path, version)
raise 'Not a commit' unless Rugged::Commit === commit
path += ATTRIBUTE_EXT
object = object_by_path(commit, path)
object ? YAML.load(object.content) : {}
object ? yaml_load(object.content) : {}
end

def diff(path, from, to)
Expand Down

0 comments on commit 2b4c63c

Please sign in to comment.