activatable 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -17
- data/activatable.gemspec +3 -3
- data/lib/activatable.rb +5 -23
- data/lib/activatable/class_methods.rb +8 -0
- data/lib/activatable/instance_methods.rb +17 -0
- data/lib/activatable/version.rb +1 -1
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab08b83d0efc3f1b4a0220570eaec962fb4fa34a
|
4
|
+
data.tar.gz: 5d7cbbea7646c1dcf0da241829a273db5d654240
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 549b32918ab143a8ecd8ab220bce0647e593a0da052efbf3c634e59e8e62ab589d88da9482dadf22f17d673cb224d6450736876854fa14f70caf4099d9ac796b
|
7
|
+
data.tar.gz: 4656e25c5247ca0e1b45b065f66a74d3744e3e5db1e952159e4dae8fcacf36c9003f63014b1062edfd7859daea09f93c373097fbf9b95c8c439071e90fefc819
|
data/README.md
CHANGED
@@ -4,32 +4,53 @@ Do you want to make your model activatable? No problem.
|
|
4
4
|
|
5
5
|
## How to use
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
To use hstorable you should add this line to your Gemfile:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'activatable', '~> 0.0.2'
|
11
|
+
```
|
12
|
+
|
13
|
+
To use activatable you should create table like this:
|
10
14
|
|
11
|
-
|
15
|
+
```ruby
|
16
|
+
create_table :wrappers do |t|
|
17
|
+
t.integer :company_id
|
18
|
+
t.boolean :active, default: false
|
19
|
+
t.timestamps
|
12
20
|
end
|
13
21
|
```
|
14
22
|
|
15
|
-
|
23
|
+
And now you can make your model activatable in some scope:
|
16
24
|
|
17
|
-
|
25
|
+
```ruby
|
26
|
+
class Api::Wrapper < ActiveRecord::Base
|
27
|
+
include Activatable
|
18
28
|
|
19
|
-
|
29
|
+
activatable :active, -> (wrapper) { where(company_id: wrapper.company_id) }
|
30
|
+
end
|
31
|
+
```
|
20
32
|
|
21
|
-
|
33
|
+
## License
|
22
34
|
|
23
|
-
|
35
|
+
Copyright (c) 2014 Sergey Tsvetkov
|
24
36
|
|
25
|
-
|
37
|
+
MIT License
|
26
38
|
|
27
|
-
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
40
|
+
a copy of this software and associated documentation files (the
|
41
|
+
"Software"), to deal in the Software without restriction, including
|
42
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
43
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
44
|
+
permit persons to whom the Software is furnished to do so, subject to
|
45
|
+
the following conditions:
|
28
46
|
|
29
|
-
|
47
|
+
The above copyright notice and this permission notice shall be
|
48
|
+
included in all copies or substantial portions of the Software.
|
30
49
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
50
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
51
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
52
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
53
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
54
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
55
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
56
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/activatable.gemspec
CHANGED
@@ -10,14 +10,14 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["sergey.a.tsvetkov@gmail.com"]
|
11
11
|
spec.summary = %q{Do you want to make your model activatable? No problem.}
|
12
12
|
spec.description = %q{Do you want to make your model activatable? No problem.}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/kimrgrey/activatable"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split(
|
16
|
+
spec.files = `git ls-files`.split("\n")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
-
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
23
23
|
end
|
data/lib/activatable.rb
CHANGED
@@ -1,31 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require 'activatable/class_methods'
|
2
|
+
require 'activatable/instance_methods'
|
2
3
|
|
3
4
|
module Activatable
|
4
5
|
def self.included(base)
|
5
|
-
base.extend ClassMethods
|
6
|
+
base.extend Activatable::ClassMethods
|
7
|
+
base.include Activatable::InstanceMethods
|
8
|
+
|
6
9
|
base.class_eval do
|
7
10
|
class_attribute :activatable_fields
|
8
11
|
end
|
9
12
|
end
|
10
|
-
|
11
|
-
def activate_by(field_name)
|
12
|
-
scope_name_or_lambda = activatable_fields[field_name]
|
13
|
-
if scope_name_or_lambda.present?
|
14
|
-
if scope_name_or_lambda.is_a? Symbol
|
15
|
-
scope = self.class.send(scope_name_or_lambda)
|
16
|
-
scope.update_all(field_name => false)
|
17
|
-
elsif scope_name_or_lambda.is_a? Proc
|
18
|
-
scope = self.class.class_exec(self, &scope_name_or_lambda)
|
19
|
-
scope.update_all(field_name => false)
|
20
|
-
end
|
21
|
-
self.update(field_name => true)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module ClassMethods
|
26
|
-
def activatable(field_name, scope_name_or_lambda)
|
27
|
-
self.activatable_fields ||= {}
|
28
|
-
self.activatable_fields = self.activatable_fields.merge({field_name => scope_name_or_lambda})
|
29
|
-
end
|
30
|
-
end
|
31
13
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Activatable
|
2
|
+
module InstanceMethods
|
3
|
+
def activate_by(field_name)
|
4
|
+
scope_name_or_lambda = activatable_fields[field_name]
|
5
|
+
if scope_name_or_lambda.present?
|
6
|
+
if scope_name_or_lambda.is_a? Symbol
|
7
|
+
scope = self.class.send(scope_name_or_lambda)
|
8
|
+
scope.update_all(field_name => false)
|
9
|
+
elsif scope_name_or_lambda.is_a? Proc
|
10
|
+
scope = self.class.class_exec(self, &scope_name_or_lambda)
|
11
|
+
scope.update_all(field_name => false)
|
12
|
+
end
|
13
|
+
self.update(field_name => true)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/activatable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Tsvetkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.3'
|
41
41
|
description: Do you want to make your model activatable? No problem.
|
42
42
|
email:
|
43
43
|
- sergey.a.tsvetkov@gmail.com
|
@@ -52,8 +52,10 @@ files:
|
|
52
52
|
- Rakefile
|
53
53
|
- activatable.gemspec
|
54
54
|
- lib/activatable.rb
|
55
|
+
- lib/activatable/class_methods.rb
|
56
|
+
- lib/activatable/instance_methods.rb
|
55
57
|
- lib/activatable/version.rb
|
56
|
-
homepage:
|
58
|
+
homepage: https://github.com/kimrgrey/activatable
|
57
59
|
licenses:
|
58
60
|
- MIT
|
59
61
|
metadata: {}
|