Class: PriceHubble::Dossier

Inherits:
BaseEntity show all
Defined in:
lib/price_hubble/entity/dossier.rb

Overview

The PriceHubble dossier for a single property.

Instance Attribute Summary

Attributes inherited from BaseEntity

#_unmapped

Instance Method Summary collapse

Methods inherited from BaseEntity

inherited, #initialize

Methods included from Utils::Bangers

bangers

Methods included from EntityConcern::Persistence

#destroyed?, #mark_as_destroyed, #new_record?, #persisted?

Methods included from EntityConcern::Client

#client, client

Methods included from EntityConcern::Associations

has_many, has_one, inherited_setup_associations

Methods included from EntityConcern::Attributes

#assign_attributes, #attributes, inherited_setup_attributes, tracked_attr, typed_attr

Methods included from EntityConcern::Attributes::StringInquirer

typed_attr_string_inquirer

Methods included from EntityConcern::Attributes::Range

typed_attr_range

Methods included from EntityConcern::Attributes::Enum

typed_attr_enum

Methods included from EntityConcern::Attributes::DateArray

typed_attr_date_array

Constructor Details

This class inherits a constructor from PriceHubble::BaseEntity

Instance Method Details

#delete(**args) ⇒ PriceHubble::Dossier, false Also known as: destroy

Deletes the instance at the remote application and freezes this instance to reflect that no changes should be made (since they can’t be persisted).

Parameters:

  • args (Hash{Symbol => Mixed})

    addition settings

Returns:



56
57
58
# File 'lib/price_hubble/entity/dossier.rb', line 56

def delete(**args)
  client.delete_dossier(self, **args) || false
end

Create a new dossier share link.

Parameters:

  • ttl (ActiveSupport::Duration) (defaults to: 365.days)

    the time to live for the new link

  • locale (String) (defaults to: 'de_CH')

    the user frontend locale

  • args (Hash{Symbol => Mixed})

    additional options

Returns:

  • (String)

    the new dossier frontend link



67
68
69
70
71
72
73
74
75
# File 'lib/price_hubble/entity/dossier.rb', line 67

def link(ttl: 365.days, locale: 'de_CH', lang: 'de', **args)
  # Make sure the current dossier is saved before we try to generate a link
  return unless save(**args)

  # Send a "share dossier" request to the service
  url = client.share_dossier(self, ttl: ttl, locale: locale, **args)
  url += "?lang=#{lang}" if url
  url
end

#save(**args) ⇒ Boolean

Save the dossier.

Parameters:

  • args (Hash{Symbol => Mixed})

    additional options

Returns:

  • (Boolean)

    the result state



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/price_hubble/entity/dossier.rb', line 35

def save(**args)
  # When the current entity is already persisted, we send an update
  if id.present?
    # Skip making requests when the current entity is not dirty
    return true unless changed?

    # The current entity is dirty, so send an update request
    return client.update_dossier(self, **args)
  end

  # Otherwise we send a new creation request
  client.create_dossier(self, **args) && true
end