Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load taken urls from db instead of complete objects #182

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/stringex/acts_as_url/adapter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def create_callbacks!(klass)
end

def ensure_unique_url!(instance)
@url_owners = nil
@taken_urls = nil
self.instance = instance

handle_url!
Expand Down Expand Up @@ -131,7 +131,7 @@ def url_taken?(url)
if settings.url_taken_method
instance.send(settings.url_taken_method, url)
else
url_owners.any?{|owner| url_attribute_for(owner) == url}
taken_urls.include?(url)
end
end

Expand Down Expand Up @@ -196,8 +196,8 @@ def url_owner_conditions
@url_owner_conditions
end

def url_owners
@url_owners ||= url_owners_class.unscoped.where(url_owner_conditions).to_a
def taken_urls
@taken_urls ||= url_owners_class.unscoped.where(url_owner_conditions).pluck(settings.url_attribute)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [109/80]

end

def url_owners_class
Expand Down
4 changes: 2 additions & 2 deletions lib/stringex/acts_as_url/adapter/data_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def read_attribute(instance, attribute)
instance.attributes[attribute]
end

def url_owners
@url_owners ||= url_owners_class.all(:conditions => url_owner_conditions)
def taken_urls
@taken_urls ||= url_owners_class.all(:conditions => url_owner_conditions).pluck(settings.url_attribute)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [113/80]
Use the new Ruby 1.9 hash syntax.

end

def read_attribute(instance, name)
Expand Down