acts_as_activateable 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0b1ce7bfac0e0c2e2ebd1dd2ba227ec9626d3558
4
+ data.tar.gz: 9862c5fcf6a61b5a489f8ffe52437d886305e43e
5
+ SHA512:
6
+ metadata.gz: c8e11758e8530f317dce1482a781ca1c92cadcc1de4b9eef18cb959090faf4be080634d922e52dcf51e883d576315ffe39831520113dfdf2c66a4752291a2f0b
7
+ data.tar.gz: 22697be955ccf5128395240fedc24bc799da7bf66d916279fe50114632e9e5ebb391d7175f10babd35b6da1dadd988738dfc73c3ab739e12cb06232e3cfbb12c
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in acts_as_activateable.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ acts_as_activateable (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (0.9.6)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ acts_as_activateable!
16
+ bundler (~> 1.3)
17
+ rake
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Caleb Adam Haye
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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
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 ADDED
@@ -0,0 +1,15 @@
1
+ ActsAsActiveable
2
+ ================
3
+
4
+ Simple activation plugin.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ class User < ActiveRecord:: Base
11
+ acts_as_activatable
12
+ end
13
+
14
+
15
+ Copyright (c) 2012 Caleb Adam Haye of Presskit Platform & Fire, Inc., released under the MIT license
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # ActsAsActivateable
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'acts_as_activateable'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install acts_as_activateable
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 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'acts_as_activateable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "acts_as_activateable"
8
+ spec.version = ActsAsActivateable::VERSION
9
+ spec.authors = ["Caleb Adam Haye"]
10
+ spec.email = ["caleb@fire.coop"]
11
+ spec.description = %q{Simple activation gem}
12
+ spec.summary = %q{Convenience methods for turning things on and off.}
13
+ spec.homepage = "http://github.com/presskit/acts_as_activateable"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ ActiveRecord::Base.send :include, ActiveRecord::Acts::Activateable
@@ -0,0 +1,3 @@
1
+ module ActsAsActivateable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,88 @@
1
+ require "acts_as_activateable/version"
2
+
3
+ module ActsAsActivateable
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ # Makes a model searchable.
8
+ # Takes a list of fields to use to create the index. It also take an option (:check_for_changes,
9
+ # which defaults to true) to tell the engine wether it should check if the value of a given
10
+ # instance has changed before it actually updates the associated fulltext row.
11
+ # If option :parent_id is not nulled, it is used as the field to be used as the parent of the record,
12
+ # which is useful if you want to limit your queries to a scope.
13
+ # If option :conditions is given, it should be a string containing a ruby expression that
14
+ # equates to true or nil/false. Records are tested with this condition and only those that return true
15
+ # add/update the FullTextRow. A record returning false that is already in FullTextRow is removed.
16
+ #
17
+ def acts_as_activateable(options = {})
18
+ configuration = { :column => "active"}
19
+ configuration.update(options) if options.is_a?(Hash)
20
+ class_eval <<-EOV
21
+
22
+ def acts_as_activateable_class
23
+ ::#{self.name}
24
+ end
25
+
26
+ def enabled_column
27
+ '#{configuration[:column]}'
28
+ end
29
+ EOV
30
+
31
+ extend ActsAsActivateableClassMethods
32
+ include ActsAsActivateableInstanceMethods
33
+ end
34
+ end
35
+
36
+ module ActsAsActivateableClassMethods
37
+ # Client.enable_all!
38
+ def enable_all!
39
+ all.each {|object| object.send("#{enabled_column}=", true); object.save }
40
+ end
41
+
42
+ def disable_all!
43
+ all.each {|object| object.send("#{enabled_column}=", false); object.save; }
44
+ end
45
+
46
+ def find_enabled
47
+ _find_all_by_active_status_of(true)
48
+ end
49
+
50
+ def find_disabled
51
+ _find_all_by_active_status_of(false)
52
+ end
53
+
54
+ private
55
+
56
+ def _find_all_by_active_status_of(status)
57
+ all(:conditions => { enabled_column => status })
58
+ end
59
+ end
60
+
61
+ def self.included(receiver)
62
+ receiver.extend(ClassMethods)
63
+ end
64
+
65
+ module ActsAsActivateableInstanceMethods
66
+ def enable
67
+ # send(:active, false)
68
+ puts "@configuration: #{@configuration}"
69
+ puts "enabled_column: #{enabled_column}"
70
+ self.send("#{enabled_column}=", true); save
71
+ end
72
+
73
+ def disable
74
+ # send(:active, true)
75
+ self.send("#{enabled_column}=", false); save
76
+ end
77
+
78
+ def enabled?
79
+ self.send(enabled_column)
80
+ end
81
+
82
+ def disabled?
83
+ !enabled?
84
+ end
85
+ end
86
+ end
87
+
88
+ ActiveRecord::Base.send :include, ActsAsActivateable
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class ActsAsActiveableTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_activateable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Caleb Adam Haye
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Simple activation gem
42
+ email:
43
+ - caleb@fire.coop
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE.txt
52
+ - MIT-LICENSE
53
+ - README
54
+ - README.md
55
+ - Rakefile
56
+ - acts_as_activateable.gemspec
57
+ - init.rb
58
+ - lib/acts_as_activateable.rb
59
+ - lib/acts_as_activateable/version.rb
60
+ - test/acts_as_activeable_test.rb
61
+ - test/test_helper.rb
62
+ homepage: http://github.com/presskit/acts_as_activateable
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.1.11
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Convenience methods for turning things on and off.
86
+ test_files:
87
+ - test/acts_as_activeable_test.rb
88
+ - test/test_helper.rb