can_play 0.2.0 → 0.2.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 +4 -4
- data/lib/can_play/version.rb +1 -1
- data/lib/can_play.rb +29 -26
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cac379c788b3996ff429cb1f575c831b64c411b9
|
|
4
|
+
data.tar.gz: fce69d11a015bd7b31830b48793a20a1790a9636
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 36a995cf2803c25e2eec9fd631386414b1e1efac56b4f63829085b5fd6df14b5ad7c86cf498e0c96c16abb7d448f3358b268f1e6ff0b9e4e02098219315559d6
|
|
7
|
+
data.tar.gz: 092425cd490844e7230f35411288b1494a913c08332ca22dc2adecce934fb74eb2c30850299bf7dfeb79910b18232fc11cb5c98d68cf14c7419a9e7a34c0f69b
|
data/lib/can_play/version.rb
CHANGED
data/lib/can_play.rb
CHANGED
|
@@ -14,9 +14,10 @@ module CanPlay
|
|
|
14
14
|
def included(base)
|
|
15
15
|
base.class_eval <<-RUBY
|
|
16
16
|
include RorHack::ClassLevelInheritableAttributes
|
|
17
|
-
inheritable_attributes(:groups, :current_group)
|
|
17
|
+
inheritable_attributes(:groups, :current_group, :module_name)
|
|
18
18
|
@groups = []
|
|
19
19
|
@current_group = nil
|
|
20
|
+
@module_name = ''
|
|
20
21
|
RUBY
|
|
21
22
|
base.extend ClassMethods
|
|
22
23
|
end
|
|
@@ -26,7 +27,7 @@ module CanPlay
|
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
def grouped_resources
|
|
29
|
-
@grouped_resources ||= CanPlay.resources.
|
|
30
|
+
@grouped_resources ||= CanPlay.resources.multi_group_by(:module_name, :group)
|
|
30
31
|
end
|
|
31
32
|
|
|
32
33
|
def my_resources
|
|
@@ -34,18 +35,20 @@ module CanPlay
|
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
def grouped_resources_with_chinese_desc
|
|
37
|
-
grouped_resources.tap do |
|
|
38
|
-
|
|
39
|
-
group
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
grouped_resources.tap do |e|
|
|
39
|
+
e.each do |i, v|
|
|
40
|
+
v.each do |group, resources|
|
|
41
|
+
group[:chinese_desc] = begin
|
|
42
|
+
name = I18n.t("can_play.class_name.#{group[:name].singularize}", default: '')
|
|
43
|
+
name = group[:klass].model_name.human if name.blank?
|
|
44
|
+
name
|
|
45
|
+
end
|
|
46
|
+
resources.each do |resource|
|
|
47
|
+
resource[:chinese_desc] = I18n.t("can_play.authority_name.#{group[:name].singularize}.#{resource[:verb]}", default: '').presence || I18n.t("can_play.authority_name.common.#{resource[:verb]}")
|
|
48
|
+
end
|
|
46
49
|
end
|
|
50
|
+
v.rehash
|
|
47
51
|
end
|
|
48
|
-
i.rehash
|
|
49
52
|
end
|
|
50
53
|
end
|
|
51
54
|
end
|
|
@@ -69,24 +72,23 @@ module CanPlay
|
|
|
69
72
|
def group(opts, &block)
|
|
70
73
|
if opts.is_a?(Hash)
|
|
71
74
|
opts = opts.with_indifferent_access
|
|
72
|
-
group =
|
|
75
|
+
group = OpenStruct.new(name: opts.delete(:name), klass: opts.delete(:klass))
|
|
73
76
|
elsif opts.is_a?(Module)
|
|
74
77
|
name = opts.try(:table_name).presence || opts.to_s.underscore.gsub('/', '_').pluralize
|
|
75
|
-
group =
|
|
78
|
+
group = OpenStruct.new(name: name, klass: opts)
|
|
76
79
|
else
|
|
77
80
|
# do nothing
|
|
78
81
|
end
|
|
79
|
-
group = group.with_indifferent_access
|
|
80
82
|
@groups << group
|
|
81
|
-
@groups = @groups.uniq
|
|
83
|
+
@groups = @groups.uniq(&:name)
|
|
82
84
|
@current_group = group
|
|
83
|
-
block.call(group
|
|
85
|
+
block.call(group.klass)
|
|
84
86
|
@current_group = nil
|
|
85
87
|
end
|
|
86
88
|
|
|
87
89
|
def limit(name=nil, &block)
|
|
88
90
|
raise "Need define group first" if @current_group.nil?
|
|
89
|
-
Power.power(name||@current_group
|
|
91
|
+
Power.power(name||@current_group.name, &block)
|
|
90
92
|
end
|
|
91
93
|
|
|
92
94
|
def collection(verb_or_verbs, &block)
|
|
@@ -104,10 +106,10 @@ module CanPlay
|
|
|
104
106
|
|
|
105
107
|
if verb_or_verbs.kind_of?(Array)
|
|
106
108
|
verb_or_verbs.each do |verb|
|
|
107
|
-
add_resource(group, verb, group
|
|
109
|
+
add_resource(group, verb, group.klass, 'collection', behavior)
|
|
108
110
|
end
|
|
109
111
|
else
|
|
110
|
-
add_resource(group, verb_or_verbs, group
|
|
112
|
+
add_resource(group, verb_or_verbs, group.klass, 'collection', behavior)
|
|
111
113
|
end
|
|
112
114
|
end
|
|
113
115
|
|
|
@@ -126,24 +128,25 @@ module CanPlay
|
|
|
126
128
|
|
|
127
129
|
if verb_or_verbs.kind_of?(Array)
|
|
128
130
|
verb_or_verbs.each do |verb|
|
|
129
|
-
add_resource(group, verb, group
|
|
131
|
+
add_resource(group, verb, group.klass, 'member', behavior)
|
|
130
132
|
end
|
|
131
133
|
else
|
|
132
|
-
add_resource(group, verb_or_verbs, group
|
|
134
|
+
add_resource(group, verb_or_verbs, group.klass, 'member', behavior)
|
|
133
135
|
end
|
|
134
136
|
end
|
|
135
137
|
|
|
136
138
|
def add_resource(group, verb, object, type, behavior)
|
|
137
|
-
name = "#{verb}_#{group
|
|
138
|
-
resource =
|
|
139
|
+
name = "#{verb}_#{group.name}"
|
|
140
|
+
resource = OpenStruct.new(
|
|
141
|
+
module_name: module_name,
|
|
139
142
|
name: name,
|
|
140
143
|
group: group,
|
|
141
144
|
verb: verb,
|
|
142
145
|
object: object,
|
|
143
146
|
type: type,
|
|
144
147
|
behavior: behavior
|
|
145
|
-
|
|
146
|
-
CanPlay.resources.keep_if { |i| i
|
|
148
|
+
)
|
|
149
|
+
CanPlay.resources.keep_if { |i| i.name != name }
|
|
147
150
|
CanPlay.resources << resource
|
|
148
151
|
end
|
|
149
152
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: can_play
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- happyming9527
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-08-
|
|
11
|
+
date: 2015-08-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|