Switch to string keys

The OpenStruct initializer accepts both symbols and strings, but any
nested hashes will only allow access via string keys, so let's always
construct the object with strings for consistency.
This commit is contained in:
Jack Nagel 2015-02-21 18:32:52 -05:00
parent bb5f7739c7
commit 35860ac60f
2 changed files with 45 additions and 45 deletions

View File

@ -12,18 +12,18 @@ class Tab < OpenStruct
def self.create(formula, compiler, stdlib, build) def self.create(formula, compiler, stdlib, build)
attributes = { attributes = {
:used_options => build.used_options.as_flags, "used_options" => build.used_options.as_flags,
:unused_options => build.unused_options.as_flags, "unused_options" => build.unused_options.as_flags,
:tabfile => formula.prefix.join(FILENAME), "tabfile" => formula.prefix.join(FILENAME),
:built_as_bottle => !!ARGV.build_bottle?, "built_as_bottle" => !!ARGV.build_bottle?,
:poured_from_bottle => false, "poured_from_bottle" => false,
:tapped_from => formula.tap, "tapped_from" => formula.tap,
:time => Time.now.to_i, "time" => Time.now.to_i,
:HEAD => Homebrew.git_head, "HEAD" => Homebrew.git_head,
:compiler => compiler, "compiler" => compiler,
:stdlib => stdlib, "stdlib" => stdlib,
:source => { "source" => {
:path => formula.path.to_s, "path" => formula.path.to_s,
}, },
} }
@ -32,7 +32,7 @@ class Tab < OpenStruct
def self.from_file path def self.from_file path
attributes = Utils::JSON.load(File.read(path)) attributes = Utils::JSON.load(File.read(path))
attributes[:tabfile] = path attributes["tabfile"] = path
new(attributes) new(attributes)
end end
@ -86,7 +86,7 @@ class Tab < OpenStruct
else else
tab = empty tab = empty
tab.unused_options = f.options.as_flags tab.unused_options = f.options.as_flags
tab.source = { :path => f.path.to_s } tab.source = { "path" => f.path.to_s }
end end
tab tab
@ -94,17 +94,17 @@ class Tab < OpenStruct
def self.empty def self.empty
attributes = { attributes = {
:used_options => [], "used_options" => [],
:unused_options => [], "unused_options" => [],
:built_as_bottle => false, "built_as_bottle" => false,
:poured_from_bottle => false, "poured_from_bottle" => false,
:tapped_from => "", "tapped_from" => "",
:time => nil, "time" => nil,
:HEAD => nil, "HEAD" => nil,
:stdlib => nil, "stdlib" => nil,
:compiler => "clang", "compiler" => "clang",
:source => { "source" => {
:path => nil, "path" => nil,
}, },
} }
@ -157,16 +157,16 @@ class Tab < OpenStruct
def to_json def to_json
attributes = { attributes = {
:used_options => used_options.as_flags, "used_options" => used_options.as_flags,
:unused_options => unused_options.as_flags, "unused_options" => unused_options.as_flags,
:built_as_bottle => built_as_bottle, "built_as_bottle" => built_as_bottle,
:poured_from_bottle => poured_from_bottle, "poured_from_bottle" => poured_from_bottle,
:tapped_from => tapped_from, "tapped_from" => tapped_from,
:time => time, "time" => time,
:HEAD => self.HEAD, "HEAD" => self.HEAD,
:stdlib => (stdlib.to_s if stdlib), "stdlib" => (stdlib.to_s if stdlib),
:compiler => (compiler.to_s if compiler), "compiler" => (compiler.to_s if compiler),
:source => source || {}, "source" => source || {},
} }
Utils::JSON.dump(attributes) Utils::JSON.dump(attributes)

View File

@ -8,16 +8,16 @@ class TabTests < Homebrew::TestCase
@unused = Options.create(%w(--with-baz --without-qux)) @unused = Options.create(%w(--with-baz --without-qux))
@tab = Tab.new({ @tab = Tab.new({
:used_options => @used.as_flags, "used_options" => @used.as_flags,
:unused_options => @unused.as_flags, "unused_options" => @unused.as_flags,
:built_as_bottle => false, "built_as_bottle" => false,
:poured_from_bottle => true, "poured_from_bottle" => true,
:tapped_from => "Homebrew/homebrew", "tapped_from" => "Homebrew/homebrew",
:time => nil, "time" => nil,
:HEAD => TEST_SHA1, "HEAD" => TEST_SHA1,
:compiler => "clang", "compiler" => "clang",
:stdlib => "libcxx", "stdlib" => "libcxx",
:source => { :path => nil }, "source" => { "path" => nil },
}) })
end end