acts_as_element_in_category 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aab38c859443ccea510d28132d3cc8b17a135d58
4
+ data.tar.gz: 42c3328b56095fc15e1c455e565ae6dacfa649b5
5
+ SHA512:
6
+ metadata.gz: 9d4c76f780a73d840d7a8e8a20263c0cfde4e334a155df804d3d36f37b4aab2484e1258dd6cb8839d8e402f095fd56861b936900374187852582cf50f51873d4
7
+ data.tar.gz: 06ae9e770ca2ce700f2f7a9784d5cb30f939e7e4acdb1413f724aed1f0975ebd738d937f7e8aacd2050aa0746142e90fd6bbf788fceefedd96b6538deb490956
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /vendor/bundle/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in acts-as-element-in-category.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'guard-rspec'
8
+ end
@@ -0,0 +1,33 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+
17
+ # Rails example
18
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
20
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
21
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
22
+ watch('config/routes.rb') { "spec/routing" }
23
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
24
+ watch('spec/rails_helper.rb') { "spec" }
25
+
26
+ # Capybara features specs
27
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
28
+
29
+ # Turnip features and steps
30
+ watch(%r{^spec/acceptance/(.+)\.feature$})
31
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
32
+ end
33
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 YuZakuro
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.
@@ -0,0 +1,66 @@
1
+ # ActsAsElementInCategory
2
+
3
+ ActsAsElementInCategory is a categorizing plugin literally.
4
+
5
+ You can implement simple categorizing to your Rails applications.
6
+ For instance, posts of a blog, pages of a wiki and more.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'acts_as_element_in_category'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install acts_as_element_in_category
23
+
24
+ ## Usage
25
+
26
+ Setup
27
+
28
+ ```ruby
29
+ class YourCategory < ActiveRecord::Base
30
+ end
31
+
32
+ class Element < ActiveRecord::Base
33
+ acts_as_element_in_your_category
34
+ end
35
+ ```
36
+
37
+ Categorizing:
38
+
39
+ ```ruby
40
+ category = YourCategory.find(params[:category_id])
41
+ element = Element.find(params[:element_id])
42
+ element.cateddgory = category
43
+ element.save
44
+ ```
45
+
46
+ Category filter:
47
+
48
+ ```ruby
49
+ category = YourCategory.find(params[:category_id])
50
+ elements = Element.in category
51
+ ```
52
+
53
+ Query chain:
54
+
55
+ ```ruby
56
+ category = YourCategory.find(params[:category_id])
57
+ elements = Element.where(your conditions).in(category).order(:id)
58
+ ```
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it ( https://github.com/zakuro9715/acts_as_element_in_category/fork )
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -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 'acts_as_element_in_category/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'acts_as_element_in_category'
8
+ spec.version = ActsAsElementInCategory::VERSION
9
+ spec.authors = ['YuZakuro']
10
+ spec.email = ['zakuro@yuzakuro.me']
11
+ spec.summary = 'A categorizing plugin for Rails Applications'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.7'
20
+ spec.add_development_dependency 'rake', '~> 10.0'
21
+ spec.add_development_dependency 'rspec'
22
+ spec.add_development_dependency 'sqlite3'
23
+
24
+ spec.add_dependency 'activerecord', '~> 4.0'
25
+ end
@@ -0,0 +1,4 @@
1
+ require 'acts_as_element_in_category/version'
2
+ require 'acts_as_element_in_category/element'
3
+
4
+ ActiveRecord::Base.send :include, ActsAsElementInCategory::Element
@@ -0,0 +1,27 @@
1
+ require 'active_record'
2
+
3
+ module ActsAsElementInCategory
4
+ module Element
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def acts_as_element_in(category_name, options={})
11
+ @category_column = category_name.to_s
12
+ belongs_to category_name, options
13
+ end
14
+
15
+ def in(category, *args)
16
+ where("#{@category_column}_id = ?", category.id)
17
+ end
18
+
19
+ def method_missing(method_name, *args)
20
+ if /^acts_as_element_in_(?<category_name>.+)$/ =~ method_name
21
+ return acts_as_element_in(category_name.to_sym, *args)
22
+ end
23
+ self
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module ActsAsElementInCategory
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActsAsElementInCategory::Element do
4
+ before :all do
5
+ CategoriesTable.migrate :up
6
+ ElementsTable.migrate :up
7
+ end
8
+
9
+ after :all do
10
+ CategoriesTable.migrate :drop
11
+ ElementsTable.migrate :drop
12
+ end
13
+
14
+ describe ActiveRecord::Base do
15
+ describe 'class methods' do
16
+ subject { ActiveRecord::Base.methods }
17
+
18
+ it 'has .acts_as_element_in' do
19
+ expect(subject).to include(:acts_as_element_in)
20
+ end
21
+
22
+ it 'has .in' do
23
+ expect(subject).to include(:in)
24
+ end
25
+ end
26
+
27
+ describe '.acts_as_element_in' do
28
+ it 'should call belongs_to' do
29
+ expect(Element).to receive(:belongs_to)
30
+ Element.acts_as_element_in :category
31
+ end
32
+ end
33
+
34
+ describe '.in' do
35
+ context 'when element is in category' do
36
+ before do
37
+ @category = Category.create(name: 'name')
38
+ @element = Element.create(category: @category)
39
+ end
40
+
41
+ subject { Element.in @category }
42
+
43
+ it 'return element' do
44
+ expect(subject.present?).to be true
45
+ end
46
+ end
47
+
48
+ context 'when element in not in category' do
49
+ before do
50
+ @category = Category.create(name: 'name')
51
+ @element = Element.create(category: Category.create(name: 'other'))
52
+ end
53
+
54
+ subject { Element.in @category }
55
+
56
+ it 'return nothing' do
57
+ expect(subject.blank?).to be true
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_record'
2
+
3
+ class CategoriesTable < ActiveRecord::Migration
4
+ def self.up
5
+ create_table :categories do |t|
6
+ t.string :name
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :categories
12
+ end
13
+ end
14
+
15
+ class ElementsTable < ActiveRecord::Migration
16
+ def self.up
17
+ create_table :elements do |t|
18
+ t.references :category
19
+ end
20
+ end
21
+
22
+ def self.down
23
+ drop_table :elements
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ require 'active_record'
2
+ require 'acts_as_element_in_category'
3
+
4
+ class Category < ActiveRecord::Base
5
+ end
6
+
7
+ class Element < ActiveRecord::Base
8
+ acts_as_element_in_category
9
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'active_record'
4
+ require 'acts_as_element_in_category'
5
+ require 'models'
6
+ require 'migrations'
7
+
8
+ RSpec.configure do |config|
9
+ config.color = true
10
+ config.mock_framework = :rspec
11
+ config.before(:all) {
12
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
13
+ }
14
+ end
15
+
16
+
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_element_in_category
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - YuZakuro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-04 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: sqlite3
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
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ description:
84
+ email:
85
+ - zakuro@yuzakuro.me
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - Guardfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - acts_as_element_in_category.gemspec
97
+ - lib/acts_as_element_in_category.rb
98
+ - lib/acts_as_element_in_category/element.rb
99
+ - lib/acts_as_element_in_category/version.rb
100
+ - spec/acts_as_element_in_category/elemnet_spec.rb
101
+ - spec/migrations.rb
102
+ - spec/models.rb
103
+ - spec/spec_helper.rb
104
+ homepage:
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: A categorizing plugin for Rails Applications
128
+ test_files:
129
+ - spec/acts_as_element_in_category/elemnet_spec.rb
130
+ - spec/migrations.rb
131
+ - spec/models.rb
132
+ - spec/spec_helper.rb