can_has_flagz 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in can_has_flagz.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Naomi Kyoto
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,30 @@
1
+ = can_has_flagz
2
+
3
+ Provides handy flags hash for your models
4
+
5
+ == Example Usage
6
+
7
+ User Model
8
+
9
+ class User < ActiveRecord::Base
10
+ can_has_flagz
11
+
12
+ after_save :send_confirmation_email
13
+
14
+ protected
15
+
16
+ def send_confirmation_email
17
+ UserMailer.deliver_confirmation_mail(self) unless flag[:skip_confirmation_email]
18
+ end
19
+
20
+ end
21
+
22
+ Some Controller Method
23
+
24
+ @user = User.new(params[:user])
25
+ @user.flag[:skip_confirmation_email] = true
26
+ @user.save
27
+
28
+ == Copyright
29
+
30
+ Copyright (c) 2011 Naomi Kyoto. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ # ------------------------------------------------------------
5
+ # rspec
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new('spec') do |t|
9
+ t.rspec_opts = ['--options', "spec/.rspec"]
10
+ end
11
+
12
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "can_has_flagz/version"
4
+
5
+ Gem::Specification.new do |s|
6
+
7
+ s.add_development_dependency "rspec"
8
+
9
+ s.name = "can_has_flagz"
10
+ s.version = CanHasFlagz::VERSION
11
+ s.platform = Gem::Platform::RUBY
12
+ s.authors = ["Naomi Kyoto"]
13
+ s.email = ["nakyoto@gmail.com"]
14
+ s.homepage = "http://github.com/naomik/can_has_flagz"
15
+ s.summary = %q{Let's you set flags on your models}
16
+ s.description = %q{Provides a convenient hash for setting flags on your ActiveRecord models}
17
+
18
+ s.rubyforge_project = "can_has_flagz"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,8 @@
1
+ module CanHasFlagz
2
+ autoload :Hook, "can_has_flagz/hook"
3
+ autoload :InstanceMethods, "can_has_flagz/instance_methods"
4
+ end
5
+
6
+ if defined?(ActiveRecord::Base)
7
+ ActiveRecord::Base.extend(CanHasFlagz::Hook)
8
+ end
@@ -0,0 +1,5 @@
1
+ module CanHasFlagz::Hook
2
+ def can_has_flagz
3
+ include CanHasFlagz::InstanceMethods
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module CanHasFlagz::InstanceMethods
2
+ def flag
3
+ @__flags ||= Hash.new { |hash,key| hash[key] = false }
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module CanHasFlagz
2
+ VERSION = "0.1.0"
3
+ end
data/spec/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe :some_model do
4
+
5
+ before do
6
+ @model = SomeModel.new
7
+ end
8
+
9
+ it "should load the hook in ActiveRecord::Base" do
10
+ ActiveRecord::Base.should respond_to(:can_has_flagz)
11
+ end
12
+
13
+ it "should be able to set flag" do
14
+ @model.flag[:foo] = "bar"
15
+ @model.flag[:foo].should == "bar"
16
+ end
17
+
18
+ it "should get default value for unset flag" do
19
+ @model.flag[:some_unset_flag].should == false
20
+ end
21
+
22
+ end
23
+
24
+
@@ -0,0 +1,13 @@
1
+ module ActiveRecord
2
+ class Base
3
+ end
4
+ end
5
+
6
+ require 'rubygems'
7
+ require 'bundler/setup'
8
+ require 'can_has_flagz'
9
+
10
+ class SomeModel
11
+ extend CanHasFlagz::Hook
12
+ can_has_flagz
13
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: can_has_flagz
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Naomi Kyoto
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: Provides a convenient hash for setting flags on your ActiveRecord models
35
+ email:
36
+ - nakyoto@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - can_has_flagz.gemspec
50
+ - lib/can_has_flagz.rb
51
+ - lib/can_has_flagz/hook.rb
52
+ - lib/can_has_flagz/instance_methods.rb
53
+ - lib/can_has_flagz/version.rb
54
+ - spec/.rspec
55
+ - spec/can_has_flagz_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: http://github.com/naomik/can_has_flagz
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project: can_has_flagz
86
+ rubygems_version: 1.7.2
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Let's you set flags on your models
90
+ test_files:
91
+ - spec/can_has_flagz_spec.rb
92
+ - spec/spec_helper.rb