Skip to content

Commit

Permalink
Merge 268a01f into 8ba4f0e
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaradclimber committed Oct 13, 2014
2 parents 8ba4f0e + 268a01f commit 8c586a2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
19 changes: 12 additions & 7 deletions lib/health_inspector/checklists/roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def load_item(name)
Role.new(@context,
name: name,
server: load_item_from_server(name),
local: load_item_from_local(name)
local: local_items(name)
)
end

Expand All @@ -24,8 +24,17 @@ def server_items
end

def local_items
Dir["#{@context.repo_path}/roles/**/*.{rb,json,js}"].map do |e|
File.basename(e, '.*')
@local_items ||= Dir["#{@context.repo_path}/roles/**/*.{rb,json,js}"].inject({}) do |h, filename|
case filename
when /\.json$/
role = Chef::JSONCompat.from_json(IO.read(filename))
when /\.rb$/
role = Chef::Role.new
role.from_file(filename)
role = role.to_hash
end
h[role['name']] = role
h
end
end

Expand All @@ -35,10 +44,6 @@ def load_item_from_server(name)
rescue
nil
end

def load_item_from_local(name)
load_ruby_or_json_from_local(Chef::Role, 'roles', name)
end
end
end
end
3 changes: 3 additions & 0 deletions spec/chef-repo/roles/role_one.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "role_one"
}
Empty file removed spec/chef-repo/roles/role_two.json
Empty file.
1 change: 1 addition & 0 deletions spec/chef-repo/roles/role_two.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name 'role_two'
3 changes: 3 additions & 0 deletions spec/chef-repo/roles/subdir/role_from_subdir.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "role_from_subdir"
}
2 changes: 1 addition & 1 deletion spec/health_inspector/checklists/roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

describe '#local_items' do
it 'returns a list of roles from the chef repo' do
expect(checklist.local_items.sort)
expect(checklist.local_items.keys.sort)
.to eq %w(role_from_subdir role_one role_two)
end
end
Expand Down

0 comments on commit 8c586a2

Please sign in to comment.