class DTK::Client::Violation::Attribute
represents a component, node, or assembly attribute
Constants
- LegalValueIdent
Public Class Methods
new(attribute_hash)
click to toggle source
# File lib/violation/attribute.rb, line 22 def initialize(attribute_hash) # ref is the only key that is guarenteed to be present @ref = attribute_hash['ref'] @datatype = attribute_hash['datatype'] @hidden = attribute_hash['hidden'] @legal_values = attribute_hash['legal_values'] @fix_text = attribute_hash['fix_text'] end
Public Instance Methods
illegal_value?(value)
click to toggle source
Returns error message if an error
# File lib/violation/attribute.rb, line 36 def illegal_value?(value) value_does_not_match_datatype?(value) or value_not_legal_type?(value) end
prompt_user_for_value()
click to toggle source
# File lib/violation/attribute.rb, line 31 def prompt_user_for_value Shell::InteractiveWizard.prompt_user_for_value(fix_text) end
set_attribute(service_id, value)
click to toggle source
# File lib/violation/attribute.rb, line 40 def set_attribute(service_id, value) post_body = { :assembly_id => service_id, :pattern => @ref, :value => value } response = Session.post('assembly/set_attributes', post_body) response.ok? ? Fix::Result.ok : Fix::Result.error end
Private Instance Methods
fix_text()
click to toggle source
# File lib/violation/attribute.rb, line 52 def fix_text @fix_text ||= "Enter value for attribute '#{@ref}'" end
value_does_not_match_datatype?(value)
click to toggle source
# File lib/violation/attribute.rb, line 56 def value_does_not_match_datatype?(value) if @datatype # TODO: put in datatype test end end
value_not_legal_type?(value)
click to toggle source
# File lib/violation/attribute.rb, line 63 def value_not_legal_type?(value) return nil unless @legal_values and ! @legal_values.include?(value) error_msg = "Illegal value; value must be one of:" @legal_values.each do |legal_value| error_msg << "\n#{' ' * LegalValueIdent}#{legal_value}" end error_msg end