scoped_attributes 0.1.1 → 0.1.2
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 +4 -4
- data/lib/scoped_attributes.rb +6 -19
- data/lib/scoped_attributes/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15d56a3b639a632bb565907302061da36d9b7beb60d844e157426fea8d24142a
|
4
|
+
data.tar.gz: f5cc9c2f6f9bc58d588c44089bc2aadd2b7def9df3015833efe3ae5727d0720b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a76afbcdcea0737211300f5933824b8077ec6c662cb7377b77b93655e171e42e4782e1189dacc4888fefcc415b98c8cfc774c3110002045051837e812dc8460
|
7
|
+
data.tar.gz: e5e2a01a9822e445834f4e9cbe48862526e9046bd4227498a022d3bad9bdb5979474b082c516be859f315008a1d8f4159bd841d7edcb3b881f4985c964727340
|
data/lib/scoped_attributes.rb
CHANGED
@@ -23,11 +23,9 @@ module ScopedAttributes
|
|
23
23
|
class_methods do
|
24
24
|
def roles(*role_names)
|
25
25
|
role_names.each do |role_name|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
RUBY
|
26
|
+
define_method "#{role_name}?".to_sym do
|
27
|
+
user.public_send("#{role_name}?")
|
28
|
+
end
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
@@ -41,7 +39,7 @@ module ScopedAttributes
|
|
41
39
|
end
|
42
40
|
|
43
41
|
def define_attribute_reader(name, options)
|
44
|
-
only = options
|
42
|
+
only = options[:only]
|
45
43
|
|
46
44
|
define_method name do
|
47
45
|
object.public_send(name) if visible?(only)
|
@@ -66,7 +64,7 @@ module ScopedAttributes
|
|
66
64
|
def attributes(include_key: false)
|
67
65
|
attributes = {}
|
68
66
|
self.class.attributes_registry.each do |name, options|
|
69
|
-
only = options
|
67
|
+
only = options[:only]
|
70
68
|
|
71
69
|
if visible?(only)
|
72
70
|
attributes[name] = object.public_send(name)
|
@@ -91,20 +89,9 @@ module ScopedAttributes
|
|
91
89
|
when Symbol
|
92
90
|
public_send(only)
|
93
91
|
when Proc
|
94
|
-
|
95
|
-
!!unbound_method.bind(self).call
|
92
|
+
instance_exec(&only)
|
96
93
|
else
|
97
94
|
false
|
98
95
|
end
|
99
96
|
end
|
100
|
-
|
101
|
-
def generate_method(method_name, &block)
|
102
|
-
method = nil
|
103
|
-
Module.new do
|
104
|
-
define_method method_name, &block
|
105
|
-
method = instance_method method_name
|
106
|
-
remove_method method_name
|
107
|
-
end
|
108
|
-
method
|
109
|
-
end
|
110
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scoped_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- h1kita
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|