achiever 1.0.0

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/Gemfile ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012
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.
@@ -0,0 +1,25 @@
1
+ Achiever
2
+ ========
3
+
4
+ Achiever is a simple way to add achievements into your rails application.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ In *Rails 3*, add this to your Gemfile and run bundle install.
10
+
11
+ gem "achiever"
12
+
13
+ Run the migration
14
+
15
+ bundle exec rake db:migrate
16
+
17
+ Getting Started
18
+ ---------------
19
+
20
+ 1. Define your achievements
21
+
22
+ achieves :award, :for => :user
23
+
24
+
25
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc "Run RSpec"
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.verbose = false
8
+ end
9
+
10
+ task :default => :spec
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'achiever'
@@ -0,0 +1,6 @@
1
+ require "achiever/achievement"
2
+ require "achiever/achiever"
3
+
4
+ if defined?(ActiveRecord::Base)
5
+ ActiveRecord::Base.extend Achiever
6
+ end
@@ -0,0 +1,11 @@
1
+ class Achievement < ActiveRecord::Base
2
+
3
+ belongs_to :user
4
+
5
+ validates :type, :uniqueness => {:scope => :user_id}
6
+
7
+ after_save :awarded
8
+
9
+ attr_accessor :model
10
+
11
+ end
@@ -0,0 +1,26 @@
1
+ module Achiever
2
+
3
+ ALL_ACHIEVEMENTS = []
4
+
5
+ def achieves(award, options={})
6
+ ALL_ACHIEVEMENTS << award
7
+
8
+ user = options[:for]
9
+
10
+ class_eval <<-EOF
11
+ after_save :award_#{award.to_s}?
12
+
13
+ def award_#{award.to_s}?
14
+ achievement = Achievements::#{award.to_s.camelize}.new :user => self.#{user}
15
+ achievement.model = self
16
+
17
+ if achievement.award?
18
+ achievement.save
19
+ end
20
+ end
21
+
22
+ EOF
23
+ end
24
+
25
+ end
26
+
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ Bundler.require(:default)
5
+
6
+ require 'supermodel'
7
+ require 'active_support/all'
8
+ require 'achiever/achiever'
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.filter_run :focus => true
13
+ config.run_all_when_everything_filtered = true
14
+ config.mock_with :rr
15
+ config.before(:each) do
16
+ Project.delete_all
17
+ Category.delete_all
18
+ end
19
+ config.extend WithModel
20
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: achiever
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Scott Raio
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70316751757740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.6.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70316751757740
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &70316751757100 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 3.2.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70316751757100
36
+ description: Achiever is a simple way to add achievements into your rails application.
37
+ email: scottraio@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/achiever/achievement.rb
43
+ - lib/achiever/achiever.rb
44
+ - lib/achiever.rb
45
+ - spec/spec_helper.rb
46
+ - Gemfile
47
+ - LICENSE
48
+ - Rakefile
49
+ - README.markdown
50
+ - init.rb
51
+ homepage: http://github.com/scottraio/achiever
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.4
69
+ requirements: []
70
+ rubyforge_project: achiever
71
+ rubygems_version: 1.8.15
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Achiever is a simple way to add achievements into your rails application.
75
+ test_files: []