Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request mbleigh#463 from billychan/replace-class-variables
Browse files Browse the repository at this point in the history
Thread safe support
  • Loading branch information
seuros committed Jan 25, 2014
2 parents 3c703f5 + ead2a48 commit e562e0f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
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

0 comments on commit e562e0f

Please sign in to comment.