Class: ZendeskRails::Testing::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/zendesk_rails/testing.rb

Direct Known Subclasses

Comment, Ticket

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Resource

Returns a new instance of Resource.



4
5
6
# File 'lib/zendesk_rails/testing.rb', line 4

def initialize(attributes)
  @attributes = attributes.with_indifferent_access
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/zendesk_rails/testing.rb', line 8

def method_missing(method, *args, &block)
  if attribute = @attributes[method]
    attribute.respond_to?(:keys) ? OpenStruct.new(attribute) : attribute
  else
    super
  end
end

Class Method Details

.allObject



17
18
19
# File 'lib/zendesk_rails/testing.rb', line 17

def all
  (@all ||= []).sort { |a, b| b.created_at <=> a.created_at }
end

.clear!Object



22
23
24
# File 'lib/zendesk_rails/testing.rb', line 22

def clear!
  @all = []
end