Class: Lokalise::Collections::Base
- Inherits:
-
Object
- Object
- Lokalise::Collections::Base
- Extended by:
- Request, Utils::AttributeHelpers, Utils::EndpointHelpers
- Includes:
- Utils::AttributeHelpers
- Defined in:
- lib/ruby-lokalise-api/collections/base.rb
Direct Known Subclasses
Contributor, CustomTranslationStatus, File, Key, KeyComment, Order, PaymentCard, Project, ProjectComment, ProjectLanguage, Screenshot, Snapshot, SystemLanguage, Task, Team, TeamUser, TeamUserGroup, Translation, TranslationProvider
Constant Summary
Constants included from Request
Constants included from Lokalise::Connection
Lokalise::Connection::BASE_URL
Constants included from Utils::AttributeHelpers
Utils::AttributeHelpers::UNIFIED_RESOURCES
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
-
#request_params ⇒ Object
readonly
Returns the value of attribute request_params.
-
#results_per_page ⇒ Object
readonly
Returns the value of attribute results_per_page.
-
#team_id ⇒ Object
readonly
Returns the value of attribute team_id.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
-
#total_results ⇒ Object
readonly
Returns the value of attribute total_results.
Class Method Summary collapse
-
.all(client, path, params = {}) ⇒ Object
Performs a batch query fetching multiple records.
Instance Method Summary collapse
- #first_page? ⇒ Boolean
-
#initialize(response, params = {}) ⇒ Lokalise::Collections::Base
constructor
Initializes a new collection based on the response.
- #last_page? ⇒ Boolean
- #next_page ⇒ Object
- #next_page? ⇒ Boolean
- #prev_page ⇒ Object
- #prev_page? ⇒ Boolean
Methods included from Request
Methods included from JsonHandler
Methods included from Lokalise::Connection
Methods included from Utils::AttributeHelpers
attributes_for, data_key_for, id_key_for
Methods included from Utils::EndpointHelpers
Constructor Details
#initialize(response, params = {}) ⇒ Lokalise::Collections::Base
Initializes a new collection based on the response
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 17 def initialize(response, params = {}) produce_collection_for response populate_pagination_data_for response # Project and team id may not be present in some cases @project_id = response['content']['project_id'] @team_id = response['content']['team_id'] @request_params = params @client = response['client'] @path = response['path'] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 9 def client @client end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
9 10 11 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 9 def collection @collection end |
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
9 10 11 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 9 def current_page @current_page end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 9 def path @path end |
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
9 10 11 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 9 def project_id @project_id end |
#request_params ⇒ Object (readonly)
Returns the value of attribute request_params.
9 10 11 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 9 def request_params @request_params end |
#results_per_page ⇒ Object (readonly)
Returns the value of attribute results_per_page.
9 10 11 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 9 def results_per_page @results_per_page end |
#team_id ⇒ Object (readonly)
Returns the value of attribute team_id.
9 10 11 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 9 def team_id @team_id end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
9 10 11 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 9 def total_pages @total_pages end |
#total_results ⇒ Object (readonly)
Returns the value of attribute total_results.
9 10 11 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 9 def total_results @total_results end |
Class Method Details
.all(client, path, params = {}) ⇒ Object
Performs a batch query fetching multiple records
30 31 32 33 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 30 def all(client, path, params = {}) new get(path, client, params), params end |
Instance Method Details
#first_page? ⇒ Boolean
52 53 54 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 52 def first_page? !prev_page? end |
#last_page? ⇒ Boolean
42 43 44 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 42 def last_page? !next_page? end |
#next_page ⇒ Object
56 57 58 59 60 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 56 def next_page return nil if last_page? fetch_page @current_page + 1 end |
#next_page? ⇒ Boolean
37 38 39 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 37 def next_page? @current_page.positive? && @current_page < @total_pages end |
#prev_page ⇒ Object
62 63 64 65 66 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 62 def prev_page return nil if first_page? fetch_page @current_page - 1 end |
#prev_page? ⇒ Boolean
47 48 49 |
# File 'lib/ruby-lokalise-api/collections/base.rb', line 47 def prev_page? @current_page > 1 end |