Skip to content

Fixing deprecated finders #7

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion labelized.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'labelized/version'

Gem::Specification.new do |spec|
spec.name = 'labelized'
spec.version = Labelized::VERSION
spec.version = Labelized::VERSION.dup
spec.authors = ['Peter T. Brown']
spec.email = '[email protected]'
spec.description = 'A better tag library'
Expand Down
14 changes: 12 additions & 2 deletions lib/labelized/label_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@ def find_or_build_by_list(labels, labeled, label_set_name = nil)

unless label_set_name.blank?
label_set_name.strip! # ooh lah lah
label_set = label_set_class.label_scope(labeled).find_or_initialize_by_name(label_set_name)
scope = label_set_class.label_scope labeled
label_set = scope.where(:name => label_set_name).first ||
scope.new{ |label| label.name = label_set_name }
end

LabelList.from(labels).map do |label|
self.label_scope(labeled).find_or_initialize_by_name_and_label_set_id(label.strip, label_set.id)
scope = self.label_scope labeled
name = label.strip
label_set_id = label_set.id

scope.where(:name => name, :label_set_id => label_set_id).first ||
scope.new do |label|
label.name = name
label.label_set_id = label_set_id
end
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/labelized/labelized_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def labelized(*params)

define_method('label_for') do |label_set_name|
label_set_class = (labelized_options[:label_set_class_name] || 'LabelSet').constantize
label_set = label_set_class.label_scope(self).find_or_initialize_by_name(label_set_name)
scope = label_set_class.label_scope self
label_set = scope.where(:name => label_set_name).first ||
scope.new{ |label_set| label_set.name = label_set_name }
cache_label_get(label_set_name) || self.labels.where(:label_set_id => label_set.id)
end
alias_method :labels_for, :label_for
Expand Down