Class: Integrations::Field
- Inherits:
-
Object
- Object
- Integrations::Field
- Defined in:
- app/models/integrations/field.rb
Constant Summary collapse
- BOOLEAN_ATTRIBUTES =
%i[required api_only is_secret exposes_secrets].freeze
- ATTRIBUTES =
%i[ section type placeholder choices value checkbox_label title help if non_empty_password_help non_empty_password_title ].concat(BOOLEAN_ATTRIBUTES).freeze
- TYPES =
%i[text textarea password checkbox select].freeze
Instance Attribute Summary collapse
-
#integration_class ⇒ Object
readonly
Returns the value of attribute integration_class.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(name:, integration_class:, type: :text, is_secret: false, api_only: false, **attributes) ⇒ Field
constructor
A new instance of Field.
- #secret? ⇒ Boolean
Constructor Details
#initialize(name:, integration_class:, type: :text, is_secret: false, api_only: false, **attributes) ⇒ Field
Returns a new instance of Field.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/integrations/field.rb', line 20 def initialize(name:, integration_class:, type: :text, is_secret: false, api_only: false, **attributes) @name = name.to_s.freeze @integration_class = integration_class attributes[:type] = is_secret ? :password : type attributes[:api_only] = api_only attributes[:if] = attributes.fetch(:if, true) attributes[:is_secret] = is_secret @attributes = attributes.freeze invalid_attributes = attributes.keys - ATTRIBUTES if invalid_attributes.present? raise ArgumentError, "Invalid attributes #{invalid_attributes.inspect}" elsif !TYPES.include?(self[:type]) raise ArgumentError, "Invalid type #{self[:type].inspect}" end end |
Instance Attribute Details
#integration_class ⇒ Object (readonly)
Returns the value of attribute integration_class.
16 17 18 |
# File 'app/models/integrations/field.rb', line 16 def integration_class @integration_class end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'app/models/integrations/field.rb', line 16 def name @name end |
Instance Method Details
#[](key) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'app/models/integrations/field.rb', line 38 def [](key) return name if key == :name value = attributes[key] return integration_class.class_exec(&value) if value.respond_to?(:call) value end |
#secret? ⇒ Boolean
47 48 49 |
# File 'app/models/integrations/field.rb', line 47 def secret? self[:type] == :password end |