tagging_along 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +96 -0
- data/Rakefile +2 -0
- data/lib/tagging_along/array.rb +5 -0
- data/lib/tagging_along/version.rb +3 -0
- data/lib/tagging_along.rb +43 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/tagging_along_spec.rb +34 -0
- data/tagging_along.gemspec +25 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ef68699a9f4aff5b738a137d4d5f2c2e8ce3713
|
4
|
+
data.tar.gz: 65749bf0975e3e88917ff14c5f810cb310f6e315
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8aa517ef5bc3952436b45c1dd6c12c0b1b302c9d9146649692049b1a0844a0ba221ee898ebfd6abb0d4d13d65ed3bd8a18df2d4857b500b01fac005235e14522
|
7
|
+
data.tar.gz: e96c4e0f11149a6c3cacc8456bd9e5b980a86390d1c77ad4b403f790461e631cdf9ac7d09c2e8b33223c822e8f992685015c35393ab0927412e22290225539df
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 CrowdCurity
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Dennis Charles Hackethal
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# TaggingAlong
|
2
|
+
|
3
|
+
Super lightweight alternative to all the other tagging gems out there.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tagging_along'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tagging_along
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Include the gem in the model you want to use it with:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class User
|
25
|
+
include TaggingAlong
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
and define the attributes that are taggable inside the class:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class User
|
33
|
+
include TaggingAlong
|
34
|
+
attr_accessor :cars
|
35
|
+
|
36
|
+
is_taggable_on :cars
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Instances of your class will now have taggable attributes. For example:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
user = User.new
|
44
|
+
user.cars = 'Audi,BMW'
|
45
|
+
|
46
|
+
user.cars_tags
|
47
|
+
# => ['Audi', 'BMW']
|
48
|
+
|
49
|
+
user.cars_list
|
50
|
+
# => 'Audi, BMW'
|
51
|
+
```
|
52
|
+
|
53
|
+
You can also specify a custom separator:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
class User
|
57
|
+
include TaggingAlong
|
58
|
+
attr_accessor :cars
|
59
|
+
|
60
|
+
is_taggable_on :cars, separator: ':'
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
which will play out like this:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
user = User.new
|
68
|
+
user.cars = 'Audi:BMW'
|
69
|
+
|
70
|
+
user.cars_tags
|
71
|
+
# => ['Audi', 'BMW']
|
72
|
+
|
73
|
+
user.cars_list
|
74
|
+
# => 'Audi: BMW'
|
75
|
+
```
|
76
|
+
|
77
|
+
You can define multiple taggable attributes in one go:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
class User
|
81
|
+
include TaggingAlong
|
82
|
+
attr_accessor :cars, :qualifications
|
83
|
+
|
84
|
+
is_taggable_on :cars, :qualifications
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
That's it!
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
1. Fork it ( https://github.com/CrowdCurity/tagging_along/fork )
|
93
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
94
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
95
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
96
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "tagging_along/version"
|
2
|
+
require "pry-debugger"
|
3
|
+
require "tagging_along/array"
|
4
|
+
|
5
|
+
module TaggingAlong
|
6
|
+
module ClassMethods
|
7
|
+
def is_taggable_on(*attributes)
|
8
|
+
options = attributes.extract_options!
|
9
|
+
separator = options[:separator] || ','
|
10
|
+
|
11
|
+
attributes.each do |attribute|
|
12
|
+
# Define method that turns the attribute into an array of its comma-
|
13
|
+
# separated values
|
14
|
+
define_method :"#{attribute}_tags" do
|
15
|
+
send(attribute).nil? ? [] : send(attribute).split(separator)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Define method that turns the attribute into a human readable comma-
|
19
|
+
# space-separated list in one string
|
20
|
+
define_method :"#{attribute}_list" do
|
21
|
+
send(attribute).nil? ? '' : send(attribute).split(separator).join("#{separator} ")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module InstanceMethods
|
28
|
+
def taggable_on?(attribute)
|
29
|
+
begin
|
30
|
+
send(:"#{attribute}_tags")
|
31
|
+
send(:"#{attribute}_list")
|
32
|
+
true
|
33
|
+
rescue Exception => e
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.included(receiver)
|
40
|
+
receiver.extend ClassMethods
|
41
|
+
receiver.send(:include, InstanceMethods)
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "tagging_along"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe TaggingAlong do
|
4
|
+
let(:klass) { Struct.new(:taggable_attribute, :untaggable_attribute) }
|
5
|
+
let(:instance) { klass.new }
|
6
|
+
|
7
|
+
before { klass.send(:include, TaggingAlong) }
|
8
|
+
|
9
|
+
context 'taggable' do
|
10
|
+
it 'is taggable on taggable_attribute' do
|
11
|
+
instance.taggable_attribute = 'one,two'
|
12
|
+
klass.is_taggable_on(:taggable_attribute)
|
13
|
+
|
14
|
+
expect(instance).to be_taggable_on :taggable_attribute
|
15
|
+
expect(instance.taggable_attribute_tags).to eq ['one', 'two']
|
16
|
+
expect(instance.taggable_attribute_list).to eq 'one, two'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'is taggable on taggable_attribute with custom separator' do
|
20
|
+
instance.taggable_attribute = 'one:two'
|
21
|
+
klass.is_taggable_on(:taggable_attribute, separator: ':')
|
22
|
+
|
23
|
+
expect(instance).to be_taggable_on :taggable_attribute
|
24
|
+
expect(instance.taggable_attribute_tags).to eq ['one', 'two']
|
25
|
+
expect(instance.taggable_attribute_list).to eq 'one: two'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'not taggable' do
|
30
|
+
it 'is not taggable on untaggable_attribute' do
|
31
|
+
expect(instance).not_to be_taggable_on :untaggable_attribute
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tagging_along/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tagging_along"
|
8
|
+
spec.version = TaggingAlong::VERSION
|
9
|
+
spec.authors = ["Dennis Charles Hackethal"]
|
10
|
+
spec.email = ["dennis.hackethal@gmail.com"]
|
11
|
+
spec.summary = %q{Lightweight tagging gem}
|
12
|
+
spec.description = %q{Super lightweight alternative to all the other tagging gems out there.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'pry-debugger'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tagging_along
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dennis Charles Hackethal
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-debugger
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Super lightweight alternative to all the other tagging gems out there.
|
70
|
+
email:
|
71
|
+
- dennis.hackethal@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/tagging_along.rb
|
83
|
+
- lib/tagging_along/array.rb
|
84
|
+
- lib/tagging_along/version.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
- spec/tagging_along_spec.rb
|
87
|
+
- tagging_along.gemspec
|
88
|
+
homepage: ''
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.2.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Lightweight tagging gem
|
112
|
+
test_files:
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- spec/tagging_along_spec.rb
|