vidibus-category_tag 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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Andre Pankratz, Martin Jagusch
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Vidibus::CategoryTag [![](http://travis-ci.org/vidibus/vidibus-category_tag.png)](http://travis-ci.org/vidibus/vidibus-category_tag) [![](http://stillmaintained.com/vidibus/vidibus-category_tag.png)](http://stillmaintained.com/vidibus/vidibus-category_tag)
2
+
3
+ This gem is part of [Vidibus](http://vidibus.org), an open source toolset for building distributed applications.
4
+
5
+ ## Installation
6
+
7
+ Add `gem "vidibus-category_tag"` to your Gemfile. Then call `bundle install` on your console.
8
+
9
+ ## Copyright
10
+
11
+ © 2011 Andre Pankratz, Martin Jagusch. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'bundler'
2
+ require 'rdoc/task'
3
+ require 'rspec'
4
+ require 'rspec/core/rake_task'
5
+
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
9
+ require 'vidibus/category_tag/version'
10
+
11
+ RSpec::Core::RakeTask.new(:rcov) do |t|
12
+ t.pattern = 'spec/**/*_spec.rb'
13
+ t.rcov = true
14
+ t.rcov_opts = ['--exclude', '^spec,/gems/']
15
+ end
16
+
17
+ Rake::RDocTask.new do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = "vidibus-category_tag #{Vidibus::CategoryTag::VERSION}"
20
+ rdoc.rdoc_files.include('README*')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ rdoc.options << '--charset=utf-8'
23
+ end
24
+
25
+ task :default => :rcov
@@ -0,0 +1,32 @@
1
+ class TagCategory
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+ include Mongoid::Acts::Tree
5
+ include Vidibus::Uuid::Mongoid
6
+
7
+ field :label
8
+ field :callname
9
+ field :context, :type => Array
10
+ field :tags, :type => Array
11
+ field :position, :type => Integer, :default => 0
12
+
13
+ validates :label, :callname, :presence => true
14
+
15
+ before_validation :set_callname
16
+
17
+ acts_as_tree
18
+
19
+ def set_callname
20
+ self.callname = label.parameterize if callname.blank?
21
+ end
22
+
23
+ def self.context_list(context_hash)
24
+ return [] unless context_hash
25
+ context_hash.map { |key,value| "#{key}:#{value}" }
26
+ end
27
+
28
+ def self.context(context_hash)
29
+ return all if context_hash.blank?
30
+ all_in(:context => context_list(context_hash))
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ module Vidibus
2
+ module CategoryTag
3
+ module Mongoid
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ field :tags_hash, :type => Hash
8
+ end
9
+
10
+ module ClassMethods
11
+ def tags_separator(separator = nil)
12
+ @tags_separator = separator if separator
13
+ @tags_separator || ','
14
+ end
15
+ end
16
+
17
+ module InstanceMethods
18
+ def tags
19
+ (tags_hash || {}).inject({}) do |categories, (key,tags)|
20
+ categories[key] = tags.join(self.class.tags_separator)
21
+ categories
22
+ end
23
+ end
24
+
25
+ def tags=(categories)
26
+ raise Error unless categories.kind_of?(Hash)
27
+
28
+ tags_hash = {}
29
+ categories.each do |category, tags|
30
+ tags = tags.split(self.class.tags_separator)
31
+ tags_hash[category.to_s] = tags.map(&:strip).reject(&:blank?)
32
+ end
33
+ self.tags_hash = tags_hash
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ module Vidibus
2
+ module CategoryTag
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'vidibus/category_tag/mongoid'
2
+
3
+ module Vidibus
4
+ module CategoryTag
5
+ class Error < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'active_support'
2
+ require 'mongoid'
3
+
4
+ require 'vidibus/category_tag'
5
+
6
+ if defined?(Rails)
7
+ module Vidibus::CategoryTag
8
+ class Engine < ::Rails::Engine; end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vidibus-category_tag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Martin Jagusch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70314828026100 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70314828026100
25
+ - !ruby/object:Gem::Dependency
26
+ name: mongoid
27
+ requirement: &70314828025580 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70314828025580
36
+ - !ruby/object:Gem::Dependency
37
+ name: mongoid_acts_as_tree
38
+ requirement: &70314828025200 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70314828025200
47
+ - !ruby/object:Gem::Dependency
48
+ name: vidibus-uuid
49
+ requirement: &70314828024720 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70314828024720
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &70314828024200 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70314828024200
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &70314828023700 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70314828023700
80
+ - !ruby/object:Gem::Dependency
81
+ name: factory_girl
82
+ requirement: &70314828023180 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70314828023180
91
+ - !ruby/object:Gem::Dependency
92
+ name: rcov
93
+ requirement: &70314828022740 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70314828022740
102
+ - !ruby/object:Gem::Dependency
103
+ name: rdoc
104
+ requirement: &70314828022260 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70314828022260
113
+ description: Tags organized in categories for Mongoid documents.
114
+ email:
115
+ - async@mj.io
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - lib/vidibus/category_tag/mongoid.rb
121
+ - lib/vidibus/category_tag/version.rb
122
+ - lib/vidibus/category_tag.rb
123
+ - lib/vidibus-category_tag.rb
124
+ - app/models/tag_category.rb
125
+ - LICENSE
126
+ - README.md
127
+ - Rakefile
128
+ homepage: https://github.com/vidibus/vidibus-category_tag
129
+ licenses: []
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 1.8.7
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: Tags organized in categories for Mongoid documents.
152
+ test_files: []