rails-dsl 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rails-dsl/routes_ext.rb +85 -61
- 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: 9168dea89d575b1fde1e1bac822963ba6a080f3c
|
4
|
+
data.tar.gz: 09d12a88261f9f1028ea00f5bfdcd1a32599f5af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f018d8ed6b1dd70efe9f76d1f333ff5b7fe46c7e3cd10e1501f0723b34b331995589a2c0d3a6663e85aa73ea212bdbf0f5ac249783117afeb5503994701db17
|
7
|
+
data.tar.gz: d688d41c9a41d1c0c917afca4638c0ab2cabb613649cfb66da4a297e03879270a8d1bd975aedda32777f26f3158afe61baf2c0229cf5f02850f142b3fdcbef55
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/rails-dsl/routes_ext.rb
CHANGED
@@ -1,61 +1,85 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
#
|
60
|
-
|
61
|
-
|
1
|
+
module Rails
|
2
|
+
module DSL
|
3
|
+
|
4
|
+
module ActionDispatchRouteEXT
|
5
|
+
|
6
|
+
def mount_controller *args
|
7
|
+
|
8
|
+
opts= args.select{|e|(e.class <= ::Hash)}.reduce( {}, :merge! )
|
9
|
+
|
10
|
+
# search for alt keys
|
11
|
+
{
|
12
|
+
|
13
|
+
scope: [:s,:namespace,:path],
|
14
|
+
resource: [:r,:class],
|
15
|
+
defaults: [:d,:default],
|
16
|
+
|
17
|
+
get: [:read],
|
18
|
+
post: [:create],
|
19
|
+
put: [:update],
|
20
|
+
delete: [:delete]
|
21
|
+
|
22
|
+
}.each do |opts_sym,aliases|
|
23
|
+
aliases.each do |alias_sym|
|
24
|
+
opts[opts_sym] ||= opts.delete(alias_sym) || opts.delete(alias_sym.to_s)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# set defaults
|
29
|
+
opts[:defaults] ||= {}
|
30
|
+
opts[:resource] ||= args.select{|e|([::Class,::String,::Symbol].include?(e.class))}[0]
|
31
|
+
|
32
|
+
[:get,:post,:put,:delete,:options].each{|sym| opts[sym] ||= [] ; opts[sym]= [opts[sym]] unless opts[sym].class <= ::Array }
|
33
|
+
|
34
|
+
# validations
|
35
|
+
raise(ArgumentError,"Invalid defaults given") unless opts[:defaults].class <= ::Hash
|
36
|
+
|
37
|
+
# helper lambdas
|
38
|
+
|
39
|
+
create_mapping= lambda do
|
40
|
+
|
41
|
+
class_rails_name= opts[:resource].to_s.underscore.split('_')[0]
|
42
|
+
klass_name = ( opts[:resource].class == Class ? opts[:resource] : opts[:resource].to_s.concat('_controller').classify.constantize )
|
43
|
+
klass_name.public_instance_methods(false).each do |method_name|
|
44
|
+
|
45
|
+
method_to_use= nil
|
46
|
+
[:get,:post,:put,:delete,:options].each do |pre_spec_method_call_type|
|
47
|
+
if opts[pre_spec_method_call_type].include?(method_name)
|
48
|
+
method_to_use ||= pre_spec_method_call_type
|
49
|
+
end
|
50
|
+
end
|
51
|
+
method_to_use ||= :get
|
52
|
+
|
53
|
+
self.__send__ method_to_use,"/#{method_name}",{to: "#{class_rails_name}##{method_name}"}.merge({defaults: opts[:defaults]})
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
# make scope
|
60
|
+
if !opts[:scope].nil? && opts[:scope].class <= String
|
61
|
+
self.scope opts[:scope] do
|
62
|
+
create_mapping.call
|
63
|
+
end
|
64
|
+
else
|
65
|
+
create_mapping.call
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
# def mount_controller_api *args
|
71
|
+
#
|
72
|
+
# respond_to do |format|
|
73
|
+
# format.html
|
74
|
+
# format.json{
|
75
|
+
# render :json => {hello: 'world'}
|
76
|
+
# }
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
ActionDispatch::Routing::Mapper.__send__ :include, Rails::DSL::ActionDispatchRouteEXT
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|