Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jphager2 committed Jan 7, 2020
1 parent 9b3a612 commit 322f0bb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
# 0.1.3

* Improve error message a bit

# 0.1.2

* Error in mapped attribute raises `Scrapework::MappingError`
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
scrapework (0.1.2)
scrapework (0.1.3)
active_attr
activesupport
nokogiri
Expand All @@ -27,7 +27,7 @@ GEM
jaro_winkler (1.5.2)
mini_portile2 (2.4.0)
minitest (5.11.3)
nokogiri (1.10.3)
nokogiri (1.10.2)
mini_portile2 (~> 2.4.0)
parallel (1.17.0)
parser (2.6.2.1)
Expand Down
10 changes: 9 additions & 1 deletion lib/scrapework/object.rb
Expand Up @@ -7,6 +7,7 @@

module Scrapework
# Base class for web data type
# rubocop:disable Metrics/ClassLength
class Object
include ActiveAttr::Model

Expand All @@ -17,6 +18,7 @@ def self.reflections
end

# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def self.belongs_to(object, options = {})
ivar = "@#{object}"
mapped_method = "_mapped_#{object}"
Expand All @@ -36,6 +38,7 @@ def self.belongs_to(object, options = {})

reflections[object] = { type: 'belongs_to', class: reflection_class }
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength

# rubocop:disable Naming/PredicateName
Expand Down Expand Up @@ -101,6 +104,8 @@ def self.has_one(object, options = {})
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
def self.paginate(&block)
mapped_method = :_pagination

Expand All @@ -118,6 +123,8 @@ def self.paginate(&block)
self.class.new(pages[1]) if pages[1]
end
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize

def self.map(name, &block)
mapped_method = :"_mapped_#{name}"
Expand All @@ -126,7 +133,7 @@ def self.map(name, &block)
value = begin
instance_exec(_document, &block)
rescue StandardError => e
raise MappingError, e.message
raise MappingError, "failed to scrape `#{name}`: #{e.message}"
end

public_send("#{name}=", value)
Expand Down Expand Up @@ -156,3 +163,4 @@ def load
end
end
end
# rubocop:enable Metrics/ClassLength
2 changes: 1 addition & 1 deletion lib/scrapework/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Scrapework
VERSION = '0.1.2'
VERSION = '0.1.3'
end

0 comments on commit 322f0bb

Please sign in to comment.