acts_as_status 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in acts_as_status.gemspec
4
+ gemspec
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "acts_as_status/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "acts_as_status"
7
+ s.version = ActsAsStatus::VERSION
8
+ s.authors = ["alepaez"]
9
+ s.email = ["alepaezseq@gmail.com"]
10
+ s.homepage = "https://github.com/iugu/acts_as_status"
11
+ s.summary = %q{Make ActiveRecord Attributes to act as status}
12
+ s.description = %q{Make ActiveRecord Attributes to act as status}
13
+
14
+ s.rubyforge_project = "acts_as_status"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'acts_as_status'
@@ -0,0 +1,3 @@
1
+ module ActsAsStatus
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ module ActsAsStatus
2
+ def acts_as_status( field, valid_values )
3
+
4
+ status_variable = '@' + field.to_s.upcase() + '_STATUS'
5
+ instance_variable_set status_variable, valid_values
6
+
7
+ self.validates field, :inclusion => { :in => instance_variable_get(status_variable) }
8
+
9
+ valid_values.each do |valid_value|
10
+ define_method "#{valid_value}?" do
11
+ self.send("#{field}") == valid_value
12
+ end
13
+
14
+ (class << self; self; end).send(:define_method, "only_#{valid_value}") do
15
+ where(["#{field} = ?", valid_value])
16
+ end
17
+
18
+ (class << self; self; end).send(:define_method, "#{valid_value}") do
19
+ valid_value
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+
26
+ if defined?(ActiveRecord::Base)
27
+ ActiveRecord::Base.extend ActsAsStatus
28
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_status
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - alepaez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-27 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Make ActiveRecord Attributes to act as status
15
+ email:
16
+ - alepaezseq@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README
24
+ - Rakefile
25
+ - acts_as_status.gemspec
26
+ - init.rb
27
+ - lib/acts_as_status.rb
28
+ - lib/acts_as_status/version.rb
29
+ homepage: https://github.com/iugu/acts_as_status
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project: acts_as_status
49
+ rubygems_version: 1.8.11
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Make ActiveRecord Attributes to act as status
53
+ test_files: []