Class: Parameter

Inherits:
ApplicationRecord show all
Extended by:
FriendlyId
Includes:
Authorizable, HiddenValue, KeyType, KeyValueValidation, Parameterizable::ByIdName
Defined in:
app/models/parameter.rb

Constant Summary collapse

PRIORITY =
{ :common_parameter => 0,
  :organization_parameter => 10,
  :location_parameter => 20,
  :domain_parameter => 30,
  :subnet_parameter => 40,
  :os_parameter => 50,
  :group_parameter => 60,
  :host_parameter => 70,
}

Constants included from KeyType

KeyType::KEY_TYPES

Constants included from HiddenValue

HiddenValue::HIDDEN_VALUE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Authorizable

#authorized?, #check_permissions_after_save

Methods included from PermissionName

#permission_name

Methods included from KeyValueValidation

#validate_and_cast_value

Methods included from HiddenValue

#hidden_value, #safe_value

Methods inherited from ApplicationRecord

graphql_type, #logger, logger

Methods included from AuditAssociations::AssociationsDefinitions

#audit_associations, #audited, #configure_dirty_associations, #normalize_associations

Class Method Details

.type_priority(type) ⇒ Object


58
59
60
# File 'app/models/parameter.rb', line 58

def self.type_priority(type)
  PRIORITY.fetch(type.to_s.underscore.to_sym, nil) unless type.nil?
end

Instance Method Details

#editable_by_user?Boolean

Returns:

  • (Boolean)

54
55
56
# File 'app/models/parameter.rb', line 54

def editable_by_user?
  Parameter.authorized(:edit_params).where(:id => id).exists?
end

#hash_for_include_source(source, source_name = nil) ⇒ Object


67
68
69
70
71
72
73
74
75
76
# File 'app/models/parameter.rb', line 67

def hash_for_include_source(source, source_name = nil)
  options = {
    :value => value, :source => source, :key_type => key_type,
    :safe_value => safe_value, :parameter_type => parameter_type,
    :hidden_value? => hidden_value?,
    :searchable_value => searchable_value
  }
  options[:source_name] = source_name if source_name
  options
end

#value_before_type_castObject


62
63
64
65
# File 'app/models/parameter.rb', line 62

def value_before_type_cast
  return self[:value] if errors[:value].present?
  self.class.format_value_before_type_cast(value, key_type)
end