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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/rails-dsl/routes_ext.rb +85 -61
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3e0a10e6c90da72b81fb2f994eba5b27f0d321d
4
- data.tar.gz: 156343ca599ac755c44ec0304e71e0f5e3359fdb
3
+ metadata.gz: 9168dea89d575b1fde1e1bac822963ba6a080f3c
4
+ data.tar.gz: 09d12a88261f9f1028ea00f5bfdcd1a32599f5af
5
5
  SHA512:
6
- metadata.gz: b82ff865c0622b449b54a5b90bfbcb99ce5bc14925880ffd751cffadc1c3cfa5abc8e1a717aebfbf35d8fc288c2b5bb44823e299d9f317bf2de8239ffcbf3017
7
- data.tar.gz: b47a5d1fc516320d0de9942b458993a44c46929b411ded28ba344581e6ffc595fcd99dc31a5fbc658489a12a5cdc9b765dd66d28e9a280d39e84a339a59e02ee
6
+ metadata.gz: 1f018d8ed6b1dd70efe9f76d1f333ff5b7fe46c7e3cd10e1501f0723b34b331995589a2c0d3a6663e85aa73ea212bdbf0f5ac249783117afeb5503994701db17
7
+ data.tar.gz: d688d41c9a41d1c0c917afca4638c0ab2cabb613649cfb66da4a297e03879270a8d1bd975aedda32777f26f3158afe61baf2c0229cf5f02850f142b3fdcbef55
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -1,61 +1,85 @@
1
- # module Rails
2
- # module DSL
3
- #
4
- # module ActionDispatchRouteEXT
5
- #
6
- # module BlockParser
7
- #
8
- # def initialize &block
9
- # @values ||= {}
10
- # block.call
11
- # end
12
- #
13
- # def values
14
- # return @values
15
- # end
16
- #
17
- #
18
- # @@methods ||= [:get,:post,:put,:delete]
19
- # def method_missing method_name,*args
20
- #
21
- # Rails.logger.info method_name
22
- # if @@methods.include?(method_name)
23
- # @values[method_name]= args[0]
24
- # end
25
- #
26
- # return nil
27
- # end
28
- #
29
- # end
30
- #
31
- # def mapping opts={}, &block
32
- # raise ArgumentError,"options must be hash!" unless opts.class <= Hash
33
- #
34
- # { scope: [:s,:namespace,:path], resource: [:r,:class], defaults: [:d,:default] }.each do |opts_sym,aliases|
35
- # aliases.each do |alias_sym|
36
- # opts[opts_sym] ||= opts.delete(alias_sym) || opts.delete(alias_sym.to_s)
37
- # end
38
- # end
39
- #
40
- # opts[:defaults] ||= {}
41
- #
42
- # # raise(ArgumentError,"Invalid resource given") if [Symbol,String].select{ |klass| opts[:resource].class <= klass }.empty?
43
- # raise(ArgumentError,"Invalid defaults given") unless opts[:defaults].class <= ::Hash
44
- #
45
- # requests= Rails::DSL::ActionDispatchRouteEXT::BlockParser.new(&block)
46
- #
47
- # generate_calls= lambda { |asd| }
48
- #
49
- # if !opts[:scope].nil? && opts[:scope].class <= String
50
- # scope opts[:scope] do
51
- #
52
- # end
53
- # end
54
- #
55
- # end
56
- #
57
- # end
58
- # end
59
- # end
60
- #
61
- # ActionDispatch::Routing::Mapper.__send__ :include, Rails::DSL::ActionDispatchRouteEXT
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.2.1
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-19 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler