badgeable_active_record 0.1.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,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in badgeable_active_record.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Scott Burton
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,29 @@
1
+ # BadgeableActiveRecord
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'badgeable_active_record'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install badgeable_active_record
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/badgeable_active_record/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Scott Burton"]
6
+ gem.email = ["scott@chaione.com"]
7
+ gem.description = %q{ActiveRecord adapter for Badgeable}
8
+ gem.summary = %q{ActiveRecord adapter for Badgeable}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "badgeable_active_record"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = BadgeableActiveRecord::VERSION
17
+
18
+ gem.add_runtime_dependency "badgeable", "~> 0.5.0"
19
+ gem.add_runtime_dependency "activerecord", "> 2.1.0"
20
+
21
+ gem.add_development_dependency "rake", "~> 0.8"
22
+ end
@@ -0,0 +1,11 @@
1
+ require 'badgeable'
2
+
3
+ require "badgeable_active_record/version"
4
+ require "badgeable_active_record/adapter"
5
+ require "badgeable_active_record/badge"
6
+ require "badgeable_active_record/badging"
7
+
8
+ require "badgeable_active_record/generators/badgeable_generators"
9
+ require "badgeable_active_record/generators/migrations/migrations_generator"
10
+
11
+ Badgeable::Adapters.use :active_record
@@ -0,0 +1,19 @@
1
+ module Badgeable
2
+ module Adapters
3
+ module ActiveRecordAdapter
4
+ extend ActiveSupport::Concern
5
+
6
+ def self.included(receiver)
7
+ receiver.class_eval %Q{
8
+ has_many :badgings, :as => :subject
9
+ has_many :badges, :through => :badgings
10
+ }
11
+
12
+
13
+ Badge.class_eval %Q{
14
+ has_many :#{receiver.to_s.tableize}, :through => :badgings, :source => :subject, :source_type => "#{receiver.to_s.camelize}"
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ class Badge < ActiveRecord::Base
2
+ has_many :badgings
3
+
4
+ def icon
5
+ "/images/#{name.parameterize}.jpg"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ class Badging < ActiveRecord::Base
2
+ belongs_to :badge
3
+ belongs_to :subject, :polymorphic => true
4
+ scope :unseen, {:where => {:seen => false}}
5
+
6
+ def mark_as_seen
7
+ update_attributes(:seen => true)
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails/generators'
2
+
3
+ module Badgeable
4
+ module Generators
5
+ class Base < Rails::Generators::Base
6
+ def self.source_root
7
+ @source_root ||= File.expand_path("../templates", __FILE__)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails/generators/migration'
2
+ require 'rails/generators/active_record/migration'
3
+
4
+ module Badgeable
5
+ module Generators
6
+ class MigrationsGenerator < Badgeable::Generators::Base
7
+ include Rails::Generators::Migration
8
+ extend ActiveRecord::Generators::Migration
9
+
10
+ def generate_badges_migration
11
+ migration_template "badge_migration.rb", "db/migrate/create_badges.rb"
12
+ end
13
+
14
+ def generate_badgings_migration
15
+ migration_template "badging_migration.rb", "db/migrate/create_badgings.rb"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ class CreateBadges < ActiveRecord::Migration
2
+ def change
3
+ create_table :badges do |t|
4
+ t.string :name
5
+ t.string :description
6
+ t.string :icon
7
+ end
8
+
9
+ add_index :badges, :name
10
+ end
11
+
12
+ end
@@ -0,0 +1,15 @@
1
+ class CreateBadgings < ActiveRecord::Migration
2
+ def change
3
+ create_table :badgings do |t|
4
+ t.boolean :seen, :default => false
5
+
6
+ t.references :badge
7
+ t.references :subject, :polymorphic => true
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :badgings, :seen
13
+ end
14
+
15
+ end
@@ -0,0 +1,3 @@
1
+ module BadgeableActiveRecord
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: badgeable_active_record
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Scott Burton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: badgeable
16
+ requirement: &2156009840 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.5.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2156009840
25
+ - !ruby/object:Gem::Dependency
26
+ name: activerecord
27
+ requirement: &2156008660 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>'
31
+ - !ruby/object:Gem::Version
32
+ version: 2.1.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2156008660
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &2156007280 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.8'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2156007280
47
+ description: ActiveRecord adapter for Badgeable
48
+ email:
49
+ - scott@chaione.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - badgeable_active_record.gemspec
60
+ - lib/badgeable_active_record.rb
61
+ - lib/badgeable_active_record/adapter.rb
62
+ - lib/badgeable_active_record/badge.rb
63
+ - lib/badgeable_active_record/badging.rb
64
+ - lib/badgeable_active_record/generators/badgeable_generators.rb
65
+ - lib/badgeable_active_record/generators/migrations/migrations_generator.rb
66
+ - lib/badgeable_active_record/generators/templates/badge_migration.rb
67
+ - lib/badgeable_active_record/generators/templates/badging_migration.rb
68
+ - lib/badgeable_active_record/version.rb
69
+ homepage: ''
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ segments:
82
+ - 0
83
+ hash: 1734826066005482921
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ segments:
91
+ - 0
92
+ hash: 1734826066005482921
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.17
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: ActiveRecord adapter for Badgeable
99
+ test_files: []