-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yunlei
committed
Sep 23, 2014
1 parent
0ed0c32
commit 565bb4a
Showing
16 changed files
with
159 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,42 @@ | ||
module AePageObjects | ||
class DocumentProxy | ||
|
||
# Remove all instance methods so even things like class() | ||
# get handled by method_missing(). <lifted from activerecord> | ||
instance_methods.each do |m| | ||
unless m.to_s =~ /^(?:nil\?|send|object_id|to_a|tap)$|^__|^respond_to|is_a?|instance_variable_get/ | ||
undef_method m | ||
end | ||
undef_method(m) if m.to_s !~ /(?:^__|^nil?$|^send$|^object_id$|instance_variable_get)/ | ||
end | ||
|
||
def initialize(loaded_page, document_loader) | ||
@loaded_page = loaded_page | ||
@document_loader = document_loader | ||
def initialize(loaded_page, query) | ||
@loaded_page = loaded_page | ||
@query = query | ||
end | ||
|
||
def is_a?(document_class) | ||
super || @loaded_page.is_a?(document_class) | ||
super || @loaded_page.is_a?(document_class) | ||
end | ||
|
||
def as_a(document_class) | ||
if @loaded_page.is_a?(document_class) | ||
return @loaded_page | ||
end | ||
|
||
raise DocumentLoadError, "#{document_class.name} not expected. Allowed types: #{@document_loader.permitted_types_dump}" | ||
raise CastError, "Loaded page is not a #{document_class.name}. Allowed pages: #{@query.permitted_types_dump}" | ||
end | ||
|
||
private | ||
|
||
def implicit_document | ||
@implicit_document ||= as_a(implicit_document_class) | ||
end | ||
|
||
def implicit_document_class | ||
@implicit_document_class ||= @document_loader.default_document_class | ||
if @loaded_page.is_a? @query.default_document_class | ||
@loaded_page | ||
else | ||
raise CastError, "#{@query.default_document_class} expected, but #{@loaded_page.class} loaded" | ||
end | ||
end | ||
|
||
def method_missing(name, *args, &block) | ||
implicit_document.__send__(name, *args, &block) | ||
end | ||
|
||
def respond_to?(*args) | ||
super || implicit_document_class.allocate.respond_to?(*args) | ||
def respond_to_missing?(*args) | ||
super || implicit_document.respond_to?(*args) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,6 @@ class PathNotResolvable < Error | |
|
||
class DocumentLoadError < Error | ||
end | ||
class CastError < Error | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# encoding: UTF-8 | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended to check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(:version => 1) do | ||
|
||
create_table "authors", :force => true do |t| | ||
t.integer "lock_version" | ||
t.string "first_name" | ||
t.string "last_name" | ||
t.datetime "created_at", :null => false | ||
t.datetime "updated_at", :null => false | ||
end | ||
|
||
create_table "books", :force => true do |t| | ||
t.integer "lock_version" | ||
t.integer "author_id" | ||
t.string "title" | ||
t.datetime "created_at", :null => false | ||
t.datetime "updated_at", :null => false | ||
end | ||
|
||
create_table "indices", :force => true do |t| | ||
t.integer "lock_version" | ||
t.integer "pages" | ||
t.integer "book_id" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.