Class: RubyLokaliseApi::Resources::Base

Inherits:
Object
  • Object
show all
Extended by:
Concerns::AttrsLoadable, Concerns::Unsupportable, Utils::Attributes
Includes:
Concerns::HashAccessible, Utils::Keys
Defined in:
lib/ruby_lokalise_api/resources/base.rb

Constant Summary collapse

ATTRS_FILENAME =
'resource_attributes.yml'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Unsupportable

no_support_for

Methods included from Concerns::AttrsLoadable

extended, inherited

Methods included from Utils::Keys

#collection_key_for, #data_key_for

Methods included from Concerns::HashAccessible

#[]

Constructor Details

#initialize(response) ⇒ Base

Returns a new instance of Base.



16
17
18
19
20
# File 'lib/ruby_lokalise_api/resources/base.rb', line 16

def initialize(response)
  @self_endpoint = response.endpoint

  populate_attrs_from response.content
end

Class Method Details

.delegate_call(from, to = nil) ⇒ Object

Delegates instance method calls to the client methods



41
42
43
44
45
# File 'lib/ruby_lokalise_api/resources/base.rb', line 41

def delegate_call(from, to = nil)
  define_method(from) do |*args|
    @self_endpoint.client.send((to || from), *read_main_params.push(*args))
  end
end

Instance Method Details

#destroyObject

Deletes the current resource



28
29
30
31
32
# File 'lib/ruby_lokalise_api/resources/base.rb', line 28

def destroy
  RubyLokaliseApi::Generics::DeletedResource.new(
    reinit_endpoint.do_delete.content
  )
end

#reload_dataObject

Reloads the current resource with new values from the API



35
36
37
# File 'lib/ruby_lokalise_api/resources/base.rb', line 35

def reload_data
  self.class.new reinit_endpoint.do_get
end

#update(params) ⇒ Object

Updates the current resource



23
24
25
# File 'lib/ruby_lokalise_api/resources/base.rb', line 23

def update(params)
  self.class.new reinit_endpoint(params).do_put
end