triumph 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "rails", ">=3.0.0"
6
+ gem 'rails3-generators'
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.6.4"
14
+ gem "rcov", ">= 0"
15
+ gem "rdoc", ">= 0"
16
+ gem "rails", ">=3.0.0"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,88 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.9)
6
+ actionpack (= 3.0.9)
7
+ mail (~> 2.2.19)
8
+ actionpack (3.0.9)
9
+ activemodel (= 3.0.9)
10
+ activesupport (= 3.0.9)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.5.0)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.14)
16
+ rack-test (~> 0.5.7)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.9)
19
+ activesupport (= 3.0.9)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.5.0)
22
+ activerecord (3.0.9)
23
+ activemodel (= 3.0.9)
24
+ activesupport (= 3.0.9)
25
+ arel (~> 2.0.10)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.9)
28
+ activemodel (= 3.0.9)
29
+ activesupport (= 3.0.9)
30
+ activesupport (3.0.9)
31
+ arel (2.0.10)
32
+ builder (2.1.2)
33
+ erubis (2.6.6)
34
+ abstract (>= 1.0.0)
35
+ git (1.2.5)
36
+ i18n (0.5.0)
37
+ jeweler (1.6.4)
38
+ bundler (~> 1.0)
39
+ git (>= 1.2.5)
40
+ rake
41
+ mail (2.2.19)
42
+ activesupport (>= 2.3.6)
43
+ i18n (>= 0.4.0)
44
+ mime-types (~> 1.16)
45
+ treetop (~> 1.4.8)
46
+ mime-types (1.16)
47
+ polyglot (0.3.1)
48
+ rack (1.2.3)
49
+ rack-mount (0.6.14)
50
+ rack (>= 1.0.0)
51
+ rack-test (0.5.7)
52
+ rack (>= 1.0)
53
+ rails (3.0.9)
54
+ actionmailer (= 3.0.9)
55
+ actionpack (= 3.0.9)
56
+ activerecord (= 3.0.9)
57
+ activeresource (= 3.0.9)
58
+ activesupport (= 3.0.9)
59
+ bundler (~> 1.0)
60
+ railties (= 3.0.9)
61
+ rails3-generators (0.17.4)
62
+ railties (>= 3.0.0)
63
+ railties (3.0.9)
64
+ actionpack (= 3.0.9)
65
+ activesupport (= 3.0.9)
66
+ rake (>= 0.8.7)
67
+ rdoc (~> 3.4)
68
+ thor (~> 0.14.4)
69
+ rake (0.9.2)
70
+ rcov (0.9.9)
71
+ rdoc (3.8)
72
+ shoulda (2.11.3)
73
+ thor (0.14.6)
74
+ treetop (1.4.9)
75
+ polyglot (>= 0.3.1)
76
+ tzinfo (0.3.29)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ bundler (~> 1.0.0)
83
+ jeweler (~> 1.6.4)
84
+ rails (>= 3.0.0)
85
+ rails3-generators
86
+ rcov
87
+ rdoc
88
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Adam Bray
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.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = triumph
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to triumph
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Adam Bray. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "triumph"
18
+ gem.homepage = "http://github.com/adambray/triumph"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Trimuph helps you add achievements to your app}
21
+ gem.description = %Q{Triumph makes it easy to add achievements to your app, even dynamically at runtime.}
22
+ gem.email = "adam.bray@gmail.com"
23
+ gem.authors = ["Adam Bray"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ RDoc::Task.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "triumph #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,19 @@
1
+ module Achievements
2
+
3
+ def self.included(base)
4
+ base.class_eval do
5
+ has_many :achievements
6
+ end
7
+ end
8
+
9
+ def grant_achievement(achievement)
10
+ unless self.has_achievement?(achievement)
11
+ CompletedAchievement.create!(:achievemnt_id => achievement.id, :user_id => self.id)
12
+ end
13
+ end
14
+
15
+ def has_achievement?(achievement)
16
+ CompletedAchievements.where("achievement_id = ?", achievement.id).count >= 1
17
+ end
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ class Achievement < ActiveRecord::Base
2
+
3
+ has_many :completed_achievements
4
+
5
+ def self.check_achievements_for(object)
6
+
7
+ user = object.user
8
+ object_class = object.class.underscore.downcase
9
+ potential_achievements = Achievement.where("observe_class = ?", object_class)
10
+
11
+ potential_achievements.each do |achievement|
12
+ total = user.send(object.class.to_s.pluralize.underscore.to_sym).where(achievement.conditions)
13
+ if total > achievment.quantity
14
+ user.grant_achievment(achievement)
15
+ end
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,6 @@
1
+ class CompletedAchievement < ActiveRecord::Base
2
+
3
+ belongs_to :user
4
+ belongs_to :achievement
5
+
6
+ end
data/lib/db/.DS_Store ADDED
Binary file
@@ -0,0 +1,17 @@
1
+ class CreateAchievements < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :achievements do |t|
4
+ t.string :name
5
+ t.text :description
6
+ t.string :observe_class
7
+ t.string :conditions
8
+ t.int :quantity
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ drop_table :achievements
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ class CreateCompletedAchievements < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :completed_achievements do |t|
4
+ t.int :achievement_id
5
+ t.integer :user_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :completed_achievements
13
+ end
14
+ end
15
+
16
+
@@ -0,0 +1,18 @@
1
+ class CreateAchievementConditions < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :achievement_conditions do |t|
4
+ t.int :achievement_id
5
+ t.string :comparison_attribute
6
+ t.string :comparison_operator
7
+ t.string :comparison_value
8
+ t.string :total_operator
9
+ t.string :total_value
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ drop_table :achievement_achievements
17
+ end
18
+ end
Binary file
@@ -0,0 +1,11 @@
1
+ class AchievementObserverGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ argument :model_name, :type => :string, :description => "The name of the model to observe."
5
+
6
+ def generate
7
+ empty_directory "app/models/triumph"
8
+ template "achievement_observer.rb", "app/models/triumph/#{model_name.underscore}_observer.rb"
9
+ end
10
+
11
+ end
@@ -0,0 +1,7 @@
1
+ class <%= model_name %>Observer < ActiveRecord::Observer
2
+ observe :<%= model_name.underscore %>
3
+
4
+ def after_save(<%= model_name.underscore %>)
5
+ Achievement.check_achievements_for(<%= model_name.underscore %>)
6
+ end
7
+ end
Binary file
@@ -0,0 +1,10 @@
1
+ class TriumphGenerator < Rails::Generators::Base
2
+
3
+ source_root File.expand_path('../../lib/db/migrate', __FILE__)
4
+
5
+ def generate
6
+ copy_file "20110711040135_create_achievements.rb", "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_achievements.rb"
7
+ copy_file "20110712025245_create_completed_achievements.rb", "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_completed_achievements.rb"
8
+ copy_file "20110712033351_create_achievement_conditions.rb", "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_achievement_conditions.rb"
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ namespace :db do
2
+ namespace :migrate do
3
+ description = "Migrate the database through scripts in triumph/lib/db/migrate"
4
+ description << "and update db/schema.rb by invoking db:schema:dump."
5
+ description << "Target specific version with VERSION=x. Turn off output with VERBOSE=false."
6
+
7
+ desc description
8
+ task :triumph => :environment do
9
+ ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
10
+ ActiveRecord::Migrator.migrate("triumph/lib/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
11
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
12
+ end
13
+ end
14
+ end
data/lib/triumph.rb ADDED
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + '/achievements'
2
+ require File.dirname(__FILE__) + '/app/models/achievement'
3
+ require File.dirname(__FILE__) + '/app/models/completed_achievement'
4
+ require File.dirname(__FILE__) + '/generators/triumph/triumph_generator'
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'triumph'
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'triumph'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestTriumph < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: triumph
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Adam Bray
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-15 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 7
27
+ segments:
28
+ - 3
29
+ - 0
30
+ - 0
31
+ version: 3.0.0
32
+ type: :runtime
33
+ requirement: *id001
34
+ prerelease: false
35
+ name: rails
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ requirement: *id002
48
+ prerelease: false
49
+ name: rails3-generators
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ requirement: *id003
62
+ prerelease: false
63
+ name: shoulda
64
+ - !ruby/object:Gem::Dependency
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ hash: 23
71
+ segments:
72
+ - 1
73
+ - 0
74
+ - 0
75
+ version: 1.0.0
76
+ type: :development
77
+ requirement: *id004
78
+ prerelease: false
79
+ name: bundler
80
+ - !ruby/object:Gem::Dependency
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ hash: 7
87
+ segments:
88
+ - 1
89
+ - 6
90
+ - 4
91
+ version: 1.6.4
92
+ type: :development
93
+ requirement: *id005
94
+ prerelease: false
95
+ name: jeweler
96
+ - !ruby/object:Gem::Dependency
97
+ version_requirements: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ type: :development
107
+ requirement: *id006
108
+ prerelease: false
109
+ name: rcov
110
+ - !ruby/object:Gem::Dependency
111
+ version_requirements: &id007 !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ type: :development
121
+ requirement: *id007
122
+ prerelease: false
123
+ name: rdoc
124
+ - !ruby/object:Gem::Dependency
125
+ version_requirements: &id008 !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 7
131
+ segments:
132
+ - 3
133
+ - 0
134
+ - 0
135
+ version: 3.0.0
136
+ type: :development
137
+ requirement: *id008
138
+ prerelease: false
139
+ name: rails
140
+ description: Triumph makes it easy to add achievements to your app, even dynamically at runtime.
141
+ email: adam.bray@gmail.com
142
+ executables: []
143
+
144
+ extensions: []
145
+
146
+ extra_rdoc_files:
147
+ - LICENSE.txt
148
+ - README.rdoc
149
+ files:
150
+ - .DS_Store
151
+ - .document
152
+ - Gemfile
153
+ - Gemfile.lock
154
+ - LICENSE.txt
155
+ - README.rdoc
156
+ - Rakefile
157
+ - VERSION
158
+ - lib/.DS_Store
159
+ - lib/achievements.rb
160
+ - lib/app/models/achievement.rb
161
+ - lib/app/models/completed_achievement.rb
162
+ - lib/db/.DS_Store
163
+ - lib/db/migrate/20110711040135_create_achievements.rb
164
+ - lib/db/migrate/20110712025245_create_completed_achievements.rb
165
+ - lib/db/migrate/20110712033351_create_achievement_conditions.rb
166
+ - lib/generators/.DS_Store
167
+ - lib/generators/achievement_observer/achievement_observer_generator.rb
168
+ - lib/generators/achievement_observer/templates/achievement_observer.rb
169
+ - lib/generators/triumph/.DS_Store
170
+ - lib/generators/triumph/triumph_generator.rb
171
+ - lib/tasks/triumph_tasks.rake
172
+ - lib/triumph.rb
173
+ - rails/init.rb
174
+ - test/helper.rb
175
+ - test/test_triumph.rb
176
+ homepage: http://github.com/adambray/triumph
177
+ licenses:
178
+ - MIT
179
+ post_install_message:
180
+ rdoc_options: []
181
+
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ hash: 3
190
+ segments:
191
+ - 0
192
+ version: "0"
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ none: false
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ hash: 3
199
+ segments:
200
+ - 0
201
+ version: "0"
202
+ requirements: []
203
+
204
+ rubyforge_project:
205
+ rubygems_version: 1.8.5
206
+ signing_key:
207
+ specification_version: 3
208
+ summary: Trimuph helps you add achievements to your app
209
+ test_files: []
210
+