mongoid_taggable_on 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b08b3db38743924d1e0f410742c9b3a0c8d5bb7c
4
- data.tar.gz: 4da58b6cdf8b0a690234b76b72b5e7ca12a1e143
2
+ SHA256:
3
+ metadata.gz: aa9bccd81c373a905c99bfea71aab6777a9635b72973cc26350d4446ba4b55bc
4
+ data.tar.gz: 28d11471201c20eec2daf073fb76f13b06a3ad99af26359ebc305e11469c4d00
5
5
  SHA512:
6
- metadata.gz: cde2d9eb0ec7bb9bb27764f0ff761df3388a9612d91e7c23ff98968668d601bcda13fc4e082e677213d0ce75996a89e59bc9057dd606833c4575d58561db3472
7
- data.tar.gz: 3c601bc33290396701f301883bddcd2abda8ca29d0dfd00dfd44d3a80438eb97669c8d86fd4afad2e5563e0cc0afa368b4f4d9ccf93de955e3098c6c9abaf3c7
6
+ metadata.gz: c4c5f7736ccd32b0763a6b1823c41c3eac2af53dd096358c0ff98d9256c418b6f5af80e6ad16403a86c847b601edb72a05d7388902d2422c772c1b8f1dcbfe86
7
+ data.tar.gz: 9339e982366afaa28de7cd5be07ac6ab2d59f987d2366e2803b8ce09d4f7ed3d5076ef4e307782c00c35e48cc7eab5b976bb2afa22a4e032389173fe8008ab48
data/README.md CHANGED
@@ -4,8 +4,8 @@ Mongoid Taggable provides some helpers to create taggable documents, can use man
4
4
 
5
5
  ## Status
6
6
 
7
- - [![Gem Version](https://badge.fury.io/rb/mongoid_taggable_on.png)](https://rubygems.org/gems/mongoid_taggable_on)
8
- - [![CI Status](https://api.travis-ci.org/huacnlee/mongoid_taggable_on.png)](http://travis-ci.org/huacnlee/mongoid_taggable_on)
7
+ - [![Gem Version](https://badge.fury.io/rb/mongoid_taggable_on.svg)](https://rubygems.org/gems/mongoid_taggable_on)
8
+ - [![CI Status](https://api.travis-ci.org/huacnlee/mongoid_taggable_on.svg)](http://travis-ci.org/huacnlee/mongoid_taggable_on)
9
9
 
10
10
  ## Installation
11
11
 
@@ -17,20 +17,19 @@ gem install mongoid_taggable_on
17
17
 
18
18
  or in Gemfile:
19
19
 
20
- ```ruby
21
- gem 'mongoid_taggable_on'
20
+ ```rb
21
+ gem "mongoid_taggable_on"
22
22
  ```
23
23
 
24
24
  ## Usage
25
25
 
26
- [中文介绍去这里](http://huacnlee.com/blog/new_gem_mongoid_taggable_on)
27
26
 
28
27
  ```ruby
29
28
  class Movie
30
29
  include Mongoid::Document
31
30
  include Mongoid::TaggableOn
32
31
 
33
- taggable_on :actors, :index => false
32
+ taggable_on :actors, index: false
34
33
  taggable_on :directors
35
34
  taggable_on :countries
36
35
 
@@ -42,26 +41,29 @@ end
42
41
  Now you can use sample:
43
42
 
44
43
  ```bash
45
- irb> m = Movie.new
46
- irb> m.actor_list = "Jason Statham, Joseph Gordon-Levitt, Johnny Depp, Nicolas Cage"
47
- irb> m.actors
44
+ irb> movie = Movie.new
45
+ irb> movie.actor_list = "Jason Statham, Joseph Gordon-Levitt, Johnny Depp, Nicolas Cage"
46
+ irb> movie.actors
48
47
  ["Jason Statham", "Joseph Gordon-Levitt", "Johnny De", "Nicolas Cage"]
49
- irb> m.country_list = "United States| China|Mexico"
50
- irb> m.countries
51
- ["United States","China","Mexico"]
48
+
49
+ irb> movie.country_list = "United States| China|Mexico"
50
+ irb> movie.countries
51
+ ["United States", "China","Mexico"]
52
52
  ```
53
53
 
54
54
  find with tag:
55
55
 
56
56
  ```bash
57
57
  irb> Movie.tagged_with_on(:actors, "Jason Statham, Joseph Gordon-Levitt")
58
- irb> Movie.tagged_with_on(:actors, "Jason Statham, Joseph Gordon-Levitt", :match => :any)
59
- irb> Movie.tagged_with_on(:actors, "Nicolas Cage", :match => :not)
58
+ irb> Movie.tagged_with_on(:actors, "Jason Statham, Joseph Gordon-Levitt", match: :any)
59
+ irb> Movie.tagged_with_on(:actors, "Nicolas Cage", match: :not)
60
60
  ```
61
61
 
62
62
  ## Allow split chars
63
63
 
64
- , ,| /
64
+ ```
65
+ , ,| /
66
+ ```
65
67
 
66
68
  ## Who used that?
67
69
 
@@ -1,72 +1,71 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Mongoid
3
4
  module TaggableOn
4
5
  extend ActiveSupport::Concern
5
6
 
6
7
  included do
7
- =begin rdoc
8
- find items with tag
9
-
10
- *Params*
11
-
12
- * field_name tagged field
13
- * tags match value, allow String or Array, case insensitive, for example: "Ruby,Python" or ["Ruby","Python"] or "ruby"
14
- * match (any,all,not) match type, default: all
15
-
16
- *Usage*
17
-
18
- Person.tagged_with_on(:skills, "ui design, photograph")
19
- Person.tagged_with_on(:skills, "ui design, photograph").tagged_with_on(:languages, "english,chinese")
20
- Person.tagged_with_on(:skills, "ui design, photograph").paginate(:page => params[:page])
21
-
22
- =end
23
- scope :tagged_with_on, Proc.new { |field_name, tags, opts|
8
+ # rdoc
9
+ # find items with tag
10
+ #
11
+ # *Params*
12
+ #
13
+ # * field_name tagged field
14
+ # * tags match value, allow String or Array, case insensitive, for example: "Ruby,Python" or ["Ruby","Python"] or "ruby"
15
+ # * match (any,all,not) match type, default: all
16
+ #
17
+ # *Usage*
18
+ #
19
+ # Person.tagged_with_on(:skills, "ui design, photograph")
20
+ # Person.tagged_with_on(:skills, "ui design, photograph").tagged_with_on(:languages, "english,chinese")
21
+ # Person.tagged_with_on(:skills, "ui design, photograph").paginate(:page => params[:page])
22
+ #
23
+ scope :tagged_with_on, proc { |field_name, tags, opts|
24
24
  return [] if field_name.blank?
25
+
25
26
  opts ||= {}
26
27
  opts[:match] ||= ""
27
28
  field_name = field_name.to_s.tableize
28
29
  tags = split_tag(tags) if tags.is_a?(String)
29
- tags = tags.collect { |t| t.to_s }
30
+ tags = tags.collect(&:to_s)
30
31
  case opts[:match].to_sym
31
32
  when :any then
32
- any_in(:"#{field_name}" => tags)
33
+ any_in("#{field_name}": tags)
33
34
  when :not then
34
- not_in(:"#{field_name}" => tags)
35
+ not_in("#{field_name}": tags)
35
36
  else
36
37
  # ALL
37
- all_in(:"#{field_name}" => tags)
38
+ all_in("#{field_name}": tags)
38
39
  end
39
40
  }
40
41
  end
41
42
 
42
43
  module ClassMethods
43
-
44
- =begin rdoc
45
- =Define a tag field
46
- *For example:*
47
-
48
- class Person
49
- include Mongoid::Document
50
- include Mongoid::TaggableOn
51
- taggable_on :languages
52
- taggable_on :skills
53
- end
54
-
55
- *Then will has there methods and fields:*
56
-
57
- field :languages, :type => Array, :default => []
58
- def language_list; end
59
- def language_list=(value); end
60
- field :skills, :type => Array, :default => []
61
- def skill_list; end
62
- def skill_list=(value); end
63
-
64
- *Params*
65
-
66
- * field_name <em>name for tag field</em>
67
- * opts[:index] <em>(true/false) allow create index in MongoDB, default: true</em>
68
-
69
- =end
44
+ # rdoc
45
+ # =Define a tag field
46
+ # *For example:*
47
+ #
48
+ # class Person
49
+ # include Mongoid::Document
50
+ # include Mongoid::TaggableOn
51
+ # taggable_on :languages
52
+ # taggable_on :skills
53
+ # end
54
+ #
55
+ # *Then will has there methods and fields:*
56
+ #
57
+ # field :languages, :type => Array, :default => []
58
+ # def language_list; end
59
+ # def language_list=(value); end
60
+ # field :skills, :type => Array, :default => []
61
+ # def skill_list; end
62
+ # def skill_list=(value); end
63
+ #
64
+ # *Params*
65
+ #
66
+ # * field_name <em>name for tag field</em>
67
+ # * opts[:index] <em>(true/false) allow create index in MongoDB, default: true</em>
68
+ #
70
69
  def taggable_on(field_name, opts = {})
71
70
  field_name = field_name.to_s.tableize
72
71
  field_name_single = field_name.singularize
@@ -104,7 +103,7 @@ find items with tag
104
103
  end
105
104
 
106
105
  def split_tag(value)
107
- value.split(/,|,|\/|\|/).collect { |tag| tag.strip }.uniq
106
+ value.split(%r{,|,|/|\|}).collect(&:strip).uniq
108
107
  end
109
108
  end
110
109
  end
@@ -1 +1,2 @@
1
- require File.join(File.dirname(__FILE__), 'mongoid/taggable_on')
1
+ # frozen_string_literal: true
2
+ require_relative "./mongoid/taggable_on"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_taggable_on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-26 00:00:00.000000000 Z
11
+ date: 2019-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -53,11 +53,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
56
- rubyforge_project:
57
- rubygems_version: 2.4.7
56
+ rubygems_version: 3.0.3
58
57
  signing_key:
59
58
  specification_version: 4
60
59
  summary: Mongoid Taggable provides some helpers to create taggable documents, can
61
60
  use many fields.
62
61
  test_files: []
63
- has_rdoc: