Class: Hotwire::Base
- Inherits:
-
Object
- Object
- Hotwire::Base
- Defined in:
- lib/hotwire/base.rb
Direct Known Subclasses
Constant Summary collapse
- @@error_reasons =
Set.new([ :not_modified, :user_not_authenticated, :unknown_data_source_id, :access_denied, :unsupported_query_operation, :invalid_query, :invalid_request, :internal_error, :not_supported, :illegal_formatting_patterns, :other ])
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#add_error(reason, message, detailed_message = nil) ⇒ Object
Manually adds a new validation error.
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
-
#valid? ⇒ Boolean
Checks whether this instance is valid (in terms of configuration parameters) or not.
-
#validate ⇒ Object
Placeholder to be overwritten by subclasses.
Constructor Details
#initialize(*args) ⇒ Base
Returns a new instance of Base.
14 15 16 |
# File 'lib/hotwire/base.rb', line 14 def initialize *args @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
12 13 14 |
# File 'lib/hotwire/base.rb', line 12 def errors @errors end |
Instance Method Details
#add_error(reason, message, detailed_message = nil) ⇒ Object
Manually adds a new validation error. reason
should be a symbol detailing the cause of the errors and should be one of the ERROR_REASONS
. message
is a short descriptive message, while detailed_message
, if provided, can be a longer message that can include minimal html formatting (anchor tags with a single href attribute).
34 35 36 37 38 39 40 41 42 |
# File 'lib/hotwire/base.rb', line 34 def add_error(reason, , =nil) unless @@error_reasons.include?(reason) raise ArgumentError.new("Invalid error reason: #{reason}") end error = {:reason => reason.to_s, :message => } error[:detailed_message] = if @errors << error return self end |
#valid? ⇒ Boolean
Checks whether this instance is valid (in terms of configuration parameters) or not.
20 21 22 23 |
# File 'lib/hotwire/base.rb', line 20 def valid? validate @errors.size == 0 end |
#validate ⇒ Object
Placeholder to be overwritten by subclasses
26 27 |
# File 'lib/hotwire/base.rb', line 26 def validate end |