lib/immoscout/models/actions/real_estate.rb in immoscout-1.3.2 vs lib/immoscout/models/actions/real_estate.rb in immoscout-1.4.0
- old
+ new
@@ -6,10 +6,11 @@
# rubocop:disable Metrics/BlockLength because this is how an ActiveSupport
# concern looks like
module Immoscout
module Models
module Actions
+ # Actions to work with real estate objects.
module RealEstate
extend ActiveSupport::Concern
included do
include Immoscout::Models::Concerns::Modelable
@@ -19,12 +20,10 @@
.fetch('realestates.realEstates', {})
.fetch('realEstateList', {})
.fetch('realEstateElement', nil)
end
- # rubocop:disable Metrics/AbcSize because this is the
- # bare minimum logic
def save
response = \
if id
api.put("user/#{api.user_name}/realestate/#{id}", as_json)
else
@@ -33,11 +32,10 @@
handle_response(response)
self.id = id_from_response(response) unless id
self
end
- # rubocop:enable Metrics/AbcSize
def destroy
response = api.delete("user/#{api.user_name}/realestate/#{id}")
handle_response(response)
self
@@ -77,11 +75,11 @@
)
handle_response(response)
self
end
- private
+ protected
def check_placement_type(type)
raise ArgumentError, "Unknown placement type '#{type}'" unless %w[
topplacement premiumplacement showcaseplacement
].include?(type.to_s)
@@ -98,27 +96,19 @@
def find_by(hash)
external_id = hash.symbolize_keys.fetch(:external_id)
find("ext-#{external_id}")
end
- # rubocop:disable Metrics/AbcSize because of the mapping logic
def all
response = api.get("user/#{api.user_name}/realestate")
handle_response(response)
objects = unpack_collection.call(response.body)
objects
.map { |object| new(object) }
.select { |object| object.type =~ /#{name.demodulize}/i }
end
- # rubocop:enable Metrics/AbcSize
-
- def first
- all.first
- end
-
- def last
- all.last
- end
+ delegate :first, to: :all
+ delegate :last, to: :all
def create(hash)
instance = new(hash)
instance.save
instance