Class: Hotwire::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hotwire/base.rb

Direct Known Subclasses

Request, Response::Base

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

Instance Method Summary collapse

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

#errorsObject (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, message, detailed_message=nil)
  unless @@error_reasons.include?(reason)
    raise ArgumentError.new("Invalid error reason: #{reason}")
  end
  error = {:reason => reason.to_s, :message => message}
  error[:detailed_message] = detailed_message if detailed_message
  @errors << error
  return self
end

#valid?Boolean

Checks whether this instance is valid (in terms of configuration parameters) or not.

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/hotwire/base.rb', line 20

def valid?
  validate
  @errors.size == 0
end

#validateObject

Placeholder to be overwritten by subclasses



26
27
# File 'lib/hotwire/base.rb', line 26

def validate
end