Skip to content

Commit

Permalink
Convert to_map to to_hash, #94.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaines-r7 committed Dec 30, 2014
1 parent 042c2a3 commit d4a6b48
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/nexpose/dag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def self.load(nsc, id)
end

def _to_entity_details
obj = { 'searchCriteria' => @criteria.to_map,
obj = { 'searchCriteria' => @criteria.to_hash,
'name' => @name,
'tag' => @description.nil? ? '' : @description,
'dynamic' => true,
Expand Down
10 changes: 6 additions & 4 deletions lib/nexpose/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,12 @@ def initialize(field, operator, value = '')

# Convert this object into the map format expected by Nexpose.
#
def to_map
def to_hash
{ 'metadata' => { 'fieldName' => field },
'operator' => operator,
'values' => Array(value) }
end
alias_method :to_map, :to_hash

def self.parse(json)
Criterion.new(json['metadata']['fieldName'],
Expand All @@ -310,15 +311,16 @@ def initialize(criteria = [], match = 'AND')
@match = match.upcase
end

def to_map
def to_hash
{ 'operator' => @match,
'criteria' => @criteria.map { |c| c.to_map } }
'criteria' => @criteria.map { |c| c.to_hash } }
end
alias_method :to_map, :to_hash

# Convert this object into the format expected by Nexpose.
#
def to_json
JSON.generate(to_map)
JSON.generate(to_hash)
end

# Generate the payload needed for a POST request for Asset Filter.
Expand Down
2 changes: 1 addition & 1 deletion lib/nexpose/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def save_dynamic_criteria(nsc)
'tag' => @description.nil? ? '' : @description,
'riskFactor' => @risk_factor,
# 'vCenter' => @discovery_connection_id,
'searchCriteria' => @criteria.nil? ? { 'operator' => 'AND' } : @criteria.to_map }
'searchCriteria' => @criteria.nil? ? { 'operator' => 'AND' } : @criteria.to_hash }
json = JSON.generate(details)

response = AJAX.post(nsc, uri, json, AJAX::CONTENT_TYPE::JSON)
Expand Down
2 changes: 1 addition & 1 deletion lib/nexpose/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def to_json
'tag_config' => { 'site_ids' => @site_ids,
'tag_associated_asset_ids' => @associated_asset_ids,
'asset_group_ids' => @asset_group_ids,
'search_criteria' => @search_criteria ? @search_criteria.to_map : nil
'search_criteria' => @search_criteria ? @search_criteria.to_hash : nil
}
}
if @type == Type::Generic::CUSTOM
Expand Down

0 comments on commit d4a6b48

Please sign in to comment.