Class: WpApiClient::Collection
- Inherits:
-
Object
- Object
- WpApiClient::Collection
- Includes:
- Enumerable
- Defined in:
- lib/wp_api_client/collection.rb
Instance Attribute Summary collapse
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#total_available ⇒ Object
Returns the value of attribute total_available.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(resources, headers = nil) ⇒ Collection
constructor
A new instance of Collection.
- #method_missing(method, *args) ⇒ Object
- #next_page ⇒ Object
- #previous_page ⇒ Object
Constructor Details
#initialize(resources, headers = nil) ⇒ Collection
Returns a new instance of Collection.
7 8 9 10 11 12 13 14 |
# File 'lib/wp_api_client/collection.rb', line 7 def initialize(resources, headers = nil) resources = [resources] unless resources.is_a? Array @resources = resources.map { |object| WpApiClient::Entities::Base.build(object) } if headers @links = parse_link_header(headers['Link']) @total_available = headers['X-WP-TOTAL'].to_i end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
28 29 30 |
# File 'lib/wp_api_client/collection.rb', line 28 def method_missing(method, *args) @resources.send(method, *args) end |
Instance Attribute Details
#resources ⇒ Object
Returns the value of attribute resources.
5 6 7 |
# File 'lib/wp_api_client/collection.rb', line 5 def resources @resources end |
#total_available ⇒ Object
Returns the value of attribute total_available.
5 6 7 |
# File 'lib/wp_api_client/collection.rb', line 5 def total_available @total_available end |
Instance Method Details
#each(&block) ⇒ Object
16 17 18 |
# File 'lib/wp_api_client/collection.rb', line 16 def each(&block) @resources.each{|p| block.call(p)} end |
#next_page ⇒ Object
20 21 22 |
# File 'lib/wp_api_client/collection.rb', line 20 def next_page @links[:next] && @links[:next] end |
#previous_page ⇒ Object
24 25 26 |
# File 'lib/wp_api_client/collection.rb', line 24 def previous_page @links[:prev] && @links[:prev] end |