rails-dsl 0.3.1 → 0.3.3

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
  SHA1:
3
- metadata.gz: 7a6f0f79e172c96e5f0a5f814c73cf3f5abc7fe3
4
- data.tar.gz: 25cbf04133af8f1362088a892022a21d79c62fa4
3
+ metadata.gz: 01f607ff8fd5ab8b6495e6ebdac3a4543115108a
4
+ data.tar.gz: 69e2fe3545fbe251df679ea8950c9669beae733e
5
5
  SHA512:
6
- metadata.gz: 6b390218fc51dc138bfd8a16541d60cb60f4bc7b961ff71b9100cf380b27d2cb1b3a3e8f17f3be406af536355dd903ae1956843e3b4f7a6e32ba92769d1e7f74
7
- data.tar.gz: a9e696e356a0c014c18e10b42950b6be77205ec7eba387b463a1c4331c651248b700066eaf4e87dd15a0b39d7bd30d0cfa71b3c1626d082174e335e86bc9528e
6
+ metadata.gz: 6d738c5f7a6d362c84d168ec7259c7b3349433ea699e99d5a08bac08433d7ba1b72a429b73298cbfbe3884eae916c7f5639b726ae5ee6409d939d032c0d51c10
7
+ data.tar.gz: 6552d5ba39ecb756a58588bceba05e6c1c66b76e75be2656301521d01549f51a73576d99aa4afabaf8a582446bbbf3e31810cfd6572121f360643c97445d12fe
data/README.md CHANGED
@@ -13,7 +13,52 @@ like:
13
13
  * "2011-03-12" to Date obj
14
14
  * etc etc etc
15
15
 
16
- if you call rails with kill / k command from now on, it will kill the application by it's pid file
16
+ if you call rails with 'kill' / 'k' command from now on, it will kill the application by it's pid file
17
17
 
18
18
  $ rails kill
19
19
  #> At pid: 24922 the app is killed with pidfile: /home/asdf/rails_app/tmp/pids/server.pid
20
+
21
+
22
+ ### Routing
23
+
24
+ #### mount controller
25
+
26
+ * mount a controller public methods as routes.
27
+ * the method name will be the path
28
+
29
+ you can use the following options (name: [aliases])
30
+ (the you can specify method(s) rest call type)
31
+
32
+ * scope: [:s,:namespace,:path]
33
+ * resource: [:r,:class]
34
+ * defaults: [:d,:default]
35
+ * get: [:read]
36
+ * post: [:create]
37
+ * put: [:update]
38
+ * delete: [:delete]
39
+
40
+
41
+ ```ruby
42
+
43
+ #> controller
44
+ class PagesController < ApplicationController
45
+
46
+ def test
47
+
48
+ end
49
+
50
+ end
51
+
52
+ #> routes.rb
53
+
54
+ HeartShoot::Application.routes.draw do
55
+
56
+ mount_controller PagesController
57
+ #> or
58
+ mount_controller :pages
59
+
60
+ end
61
+
62
+ #> mount not private methods from PagesController
63
+
64
+ ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.3
@@ -34,7 +34,7 @@ module Rails
34
34
 
35
35
  def kill?
36
36
 
37
- unless %W[ -k --kill kill ].select{|sym| ARGV.include?(sym) }.empty?
37
+ unless %W[ --kill kill k ].select{|sym| ARGV.include?(sym) }.empty?
38
38
 
39
39
  previous_stderr, $stderr = $stderr, StringIO.new
40
40
  previous_stdout, $stdout = $stdout, StringIO.new
@@ -3,44 +3,61 @@ module Rails
3
3
 
4
4
  module ActionDispatchRouteEXT
5
5
 
6
- def mount_controller *args
6
+ module Helpers
7
+ class << self
8
+
9
+ def process_args *args
10
+
11
+ opts= args.select{|e|(e.class <= ::Hash)}.reduce( {}, :merge! )
12
+
13
+ # search for alt keys
14
+ {
15
+
16
+ scope: [:s,:namespace,:path],
17
+ resource: [:r,:class],
18
+ defaults: [:d,:default],
19
+
20
+ get: [:read],
21
+ post: [:create],
22
+ put: [:update],
23
+ delete: [:delete]
24
+
25
+ }.each do |opts_sym,aliases|
26
+ aliases.each do |alias_sym|
27
+ opts[opts_sym] ||= opts.delete(alias_sym) || opts.delete(alias_sym.to_s)
28
+ end
29
+ end
30
+
31
+ # set defaults
32
+ opts[:defaults] ||= {}
33
+ opts[:resource] ||= args.select{|e|([::Class,::String,::Symbol].include?(e.class))}[0]
7
34
 
8
- opts= args.select{|e|(e.class <= ::Hash)}.reduce( {}, :merge! )
35
+ [:get,:post,:put,:delete,:options].each{|sym| opts[sym] ||= [] ; opts[sym]= [opts[sym]] unless opts[sym].class <= ::Array }
9
36
 
10
- # search for alt keys
11
- {
37
+ # validations
38
+ raise(ArgumentError,"Invalid defaults given") unless opts[:defaults].class <= ::Hash
12
39
 
13
- scope: [:s,:namespace,:path],
14
- resource: [:r,:class],
15
- defaults: [:d,:default],
40
+ opts[:short_class_name]= opts[:resource].to_s.underscore.split('_')[0]
41
+ opts[:class] = ( opts[:resource].class == Class ? opts[:resource] : opts[:resource].to_s.concat('_controller').classify.constantize )
16
42
 
17
- get: [:read],
18
- post: [:create],
19
- put: [:update],
20
- delete: [:delete]
21
43
 
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)
44
+ return opts
45
+
25
46
  end
26
- end
27
47
 
28
- # set defaults
29
- opts[:defaults] ||= {}
30
- opts[:resource] ||= args.select{|e|([::Class,::String,::Symbol].include?(e.class))}[0]
31
48
 
32
- [:get,:post,:put,:delete,:options].each{|sym| opts[sym] ||= [] ; opts[sym]= [opts[sym]] unless opts[sym].class <= ::Array }
49
+ end
50
+ end
51
+
52
+ def mount_controller *args
33
53
 
34
- # validations
35
- raise(ArgumentError,"Invalid defaults given") unless opts[:defaults].class <= ::Hash
54
+ opts= Rails::DSL::ActionDispatchRouteEXT::Helpers.process_args(*args)
36
55
 
37
56
  # helper lambdas
38
57
 
39
58
  create_mapping= lambda do
40
59
 
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|
60
+ opts[:class].public_instance_methods(false).each do |method_name|
44
61
 
45
62
  method_to_use= nil
46
63
  [:get,:post,:put,:delete,:options].each do |pre_spec_method_call_type|
@@ -50,7 +67,7 @@ module Rails
50
67
  end
51
68
  method_to_use ||= :get
52
69
 
53
- self.__send__ method_to_use,"/#{method_name}",{to: "#{class_rails_name}##{method_name}"}.merge({defaults: opts[:defaults]})
70
+ self.__send__ method_to_use,"/#{method_name}",{to: "#{opts[:short_class_name]}##{method_name}"}.merge({defaults: opts[:defaults]})
54
71
 
55
72
  end
56
73
 
@@ -68,15 +85,17 @@ module Rails
68
85
  end
69
86
 
70
87
  # def mount_controller_api *args
88
+ # opts= Rails::DSL::ActionDispatchRouteEXT::Helpers.process_args(*args)
71
89
  #
72
- # respond_to do |format|
73
- # format.html
74
- # format.json{
75
- # render :json => {hello: 'world'}
76
- # }
77
- # end
90
+ # # respond_to do |format|
91
+ # # format.html
92
+ # # format.json{
93
+ # # render :json => {hello: 'world'}
94
+ # # }
95
+ # # end
78
96
  #
79
97
  # end
98
+ # alias mount_controller_as_api mount_controller_api
80
99
 
81
100
  end
82
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi