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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58a14ad96009f828c2b5b2c35b5e5ce4d94892bf8b4c2baa91af37a151a4bf41
4
- data.tar.gz: d6b10e21375ec889036324c6898bcde2071b89e7214dc9b738a257f9d25bea07
3
+ metadata.gz: 15d56a3b639a632bb565907302061da36d9b7beb60d844e157426fea8d24142a
4
+ data.tar.gz: f5cc9c2f6f9bc58d588c44089bc2aadd2b7def9df3015833efe3ae5727d0720b
5
5
  SHA512:
6
- metadata.gz: ca6e6dd8d85d5439bc6a2baeca58891b73e2de07867b4d6ec388f3ba5c0b11c9feed39ba2cc4dc7b13f53b5e574a5392e868c878d9193b4e0732058ab33c288a
7
- data.tar.gz: b658d27b41b696b2fa7c73c11ddb7b3e22c11b3184cd9297bc6c761e7fd4acded773e458c8b713658b384a80f424e1afa547d46d48c9201884e28081c0c94ae5
6
+ metadata.gz: 9a76afbcdcea0737211300f5933824b8077ec6c662cb7377b77b93655e171e42e4782e1189dacc4888fefcc415b98c8cfc774c3110002045051837e812dc8460
7
+ data.tar.gz: e5e2a01a9822e445834f4e9cbe48862526e9046bd4227498a022d3bad9bdb5979474b082c516be859f315008a1d8f4159bd841d7edcb3b881f4985c964727340
@@ -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
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
27
- def #{role_name}?
28
- raise NotImplementedError.new("You must implement #{self.class}##{__method__}")
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.fetch(:only, nil)
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.fetch(:only, nil)
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
- unbound_method = generate_method(:only_call, &only)
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
@@ -1,3 +1,3 @@
1
1
  module ScopedAttributes
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  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.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-16 00:00:00.000000000 Z
11
+ date: 2019-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler