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

thread safe configuration #463

Merged
merged 1 commit into from
Jan 25, 2014
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ As such, a _Feature_ would map to either major or minor. A _bug fix_ to a patch.
* [@bzbnhang #440 Did not respect strict_case_match](https://github.com/mbleigh/acts-as-taggable-on/pull/440)
* [@znz #456 Fix breaking encoding of tag](https://github.com/mbleigh/acts-as-taggable-on/pull/456)
* Misc
* [@billychan #463 Thread safe support](https://github.com/mbleigh/acts-as-taggable-on/pull/463)
* [@billychan #386 Add parse:true instructions to README](https://github.com/mbleigh/acts-as-taggable-on/pull/386)
* [@seuros #449 Improve README/UPGRADING/post install docs](https://github.com/mbleigh/acts-as-taggable-on/pull/449)
* [@seuros #452 Remove I18n deprecation warning in specs](https://github.com/mbleigh/acts-as-taggable-on/pull/452)
Expand Down
41 changes: 26 additions & 15 deletions lib/acts-as-taggable-on.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,40 @@
require "digest/sha1"

module ActsAsTaggableOn
mattr_accessor :delimiter
@@delimiter = ','

mattr_accessor :force_lowercase
@@force_lowercase = false

mattr_accessor :force_parameterize
@@force_parameterize = false
def self.setup
@configuration ||= Configuration.new
yield @configuration if block_given?
end

mattr_accessor :strict_case_match
@@strict_case_match = false
def self.method_missing(method_name, *args, &block)
@configuration.respond_to?(method_name) ?
@configuration.send(method_name, *args, &block) : super
end

mattr_accessor :remove_unused_tags
self.remove_unused_tags = false
def self.respond_to?(method_name, include_private=false)
@configuration.respond_to? method_name
end

def self.glue
delimiter = @@delimiter.kind_of?(Array) ? @@delimiter[0] : @@delimiter
setting = @configuration.delimiter
delimiter = setting.kind_of?(Array) ? setting[0] : setting
delimiter.ends_with?(" ") ? delimiter : "#{delimiter} "
end

def self.setup
yield self
class Configuration
attr_accessor :delimiter, :force_lowercase, :force_parameterize,
:strict_case_match, :remove_unused_tags

def initialize
@delimiter = ','
@force_lowercase = false
@force_parameterize = false
@strict_case_match = false
@remove_unused_tags = false
end
end

setup
end


Expand Down