rails-dsl 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3528c38e1f72ffbae37ac8d021b7576922cce617
4
- data.tar.gz: 7bde40e049687a1c3de2697ef35353bed0ec9fca
3
+ metadata.gz: b6ad275135bdefc6f4f2032c9474757afdfaf821
4
+ data.tar.gz: 9cd7624647793e446cfa61ec596fb8f86ba78f66
5
5
  SHA512:
6
- metadata.gz: d4132961a60f75a2abf122b4c66569f7b53b8c8d243988c662eece1924b7b012141eefa5b41348ce442723c36e1ddd7946c14d81fe2b37fe8e35ea3440556119
7
- data.tar.gz: 301d18451dde500795e43ea735b29d1483c934c807246ab416d98a70f10714497fdf3d492c702807bb4a604176e0b8d3d6282f08cc762b48cbc21126550d9372
6
+ metadata.gz: f10fd155005717eeb63fd43f38246f3e173ea6b8d0f7c6291fc15b8b88497d6d0b9da7f22482a19952e2f4a44956e3c605f5f89dc829a97b17ba763e08263f51
7
+ data.tar.gz: ba2cd238f4e7e005da20af073280069928701d6c6add51583d97269f5e969f0f54359388ec2d0c5a6b2e5c4f6d2f227811dc0944e1ad52717386f12a1074db9b
data/README.md CHANGED
@@ -2,5 +2,18 @@ rails-dsl
2
2
  =================
3
3
 
4
4
  Provide Rails with some extra helpers,
5
- for example for to ActionController::Base a 'duck_params' that parse string values into the right obj,
6
- like "123" to Fixnum , or json into Hash
5
+
6
+ For example for to ActionController::Base a 'duck_params' that parse string values into the right obj,
7
+ like:
8
+
9
+ * "123" to Fixnum
10
+ * {"hello":"world"} json into Hash
11
+ * "Fri, 25 Jan 2013 20:02:15 +0100" to DateTime obj
12
+ * "123.123" to Float obj
13
+ * "2011-03-12" to Date obj
14
+ * etc etc etc
15
+
16
+ if you call rails with --kill or -k command from now on, it will kill the application by it's pid file
17
+
18
+ $ rails --kill
19
+ #> At pid: 24922 the app is killed with pidfile: /home/asdf/rails_app/tmp/pids/server.pid
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -1,2 +1,3 @@
1
1
  require 'rails'
2
+
2
3
  Dir.glob(File.join(File.dirname(__FILE__),'rails-dsl','**','*.{rb,ru}')).each{ |p| require(p) }
@@ -1,32 +1,44 @@
1
- require 'str2duck'
1
+ begin
2
2
 
3
- module RailsDuckParams
3
+ require 'str2duck'
4
+ require 'action_controller'
4
5
 
5
- def params_duck
6
+ module Rails
7
+ module DSL
6
8
 
7
- @duck_params_origin ||= params.dup
8
- @duck_params_cache ||= nil
9
+ module ActionControllerEXT
9
10
 
10
- if params == @duck_params_origin && !@duck_params_cache.nil?
11
+ def params_duck
11
12
 
12
- return @duck_params_cache
13
+ @duck_params_origin ||= params.dup
14
+ @duck_params_cache ||= nil
13
15
 
14
- else
16
+ if params == @duck_params_origin && !@duck_params_cache.nil?
15
17
 
16
- @duck_params_cache= params.dup
17
- @duck_params_origin= params.dup
18
+ return @duck_params_cache
18
19
 
19
- params.each do |k,v|
20
- @duck_params_cache[k]=( ::Str2Duck.parse(v) ) if v.class <= String
21
- end
20
+ else
22
21
 
23
- return @duck_params_cache
22
+ @duck_params_cache= params.dup
23
+ @duck_params_origin= params.dup
24
24
 
25
- end
25
+ params.each do |k,v|
26
+ @duck_params_cache[k]=( ::Str2Duck.parse(v) ) if v.class <= String
27
+ end
28
+
29
+ return @duck_params_cache
30
+
31
+ end
26
32
 
33
+ end
34
+ alias duck_params params_duck
35
+
36
+ end
37
+
38
+ end
27
39
  end
28
- alias duck_params params_duck
29
40
 
30
- end
41
+ ActionController::Base.__send__ :include, Rails::DSL::ActionControllerEXT
31
42
 
32
- ActionController::Base.__send__ :include, RailsDuckParams
43
+ rescue LoadError
44
+ end
@@ -0,0 +1,73 @@
1
+ module Rails
2
+ module DSL
3
+
4
+ module Commands
5
+ module Helpers
6
+ class << self
7
+
8
+ def kill(opid_path)
9
+
10
+ opid= File.read(opid_path)
11
+ Process.kill 'HUP', opid.to_i
12
+
13
+ $stdout.puts "At pid: #{opid} the app is killed with pidfile: #{opid_path}"
14
+ true
15
+ rescue Errno::ENOENT
16
+ $stdout.puts "#{opid_path} did not exist: Errno::ENOENT"
17
+ true
18
+ rescue Errno::ESRCH
19
+ $stdout.puts "The process #{opid} did not exist: Errno::ESRCH"
20
+ true
21
+ rescue Errno::EPERM
22
+ $stderr.puts "Lack of privileges to manage the process #{opid}: Errno::EPERM"
23
+ false
24
+ rescue ::Exception => e
25
+ $stderr.puts "While signaling the PID, unexpected #{e.class}: #{e}"
26
+ false
27
+ end
28
+ alias kill! kill
29
+
30
+ end
31
+ end
32
+
33
+ module EXT
34
+
35
+ def kill?
36
+
37
+ unless %W[ -k --kill ].select{|sym| ARGV.include?(sym) }.empty?
38
+
39
+ previous_stderr, $stderr = $stderr, StringIO.new
40
+ previous_stdout, $stdout = $stdout, StringIO.new
41
+
42
+ ::Kernel.at_exit do
43
+
44
+ $stderr= previous_stderr
45
+ $stdout= previous_stdout
46
+
47
+ Rails::Server.new.tap { |server|
48
+ # We need to require application after the server sets environment,
49
+ # otherwise the --environment option given to the server won't propagate.
50
+ require APP_PATH
51
+ Dir.chdir(Rails.application.root)
52
+ Commands::Helpers.kill(server.options[:pid])
53
+
54
+ }
55
+
56
+ # Rails::Server
57
+
58
+ end
59
+
60
+
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+ end
67
+
68
+ extend Commands::EXT
69
+
70
+ end
71
+ end
72
+
73
+ Rails::DSL.kill?
@@ -0,0 +1,61 @@
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
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.1.1
4
+ version: 0.2.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 00:00:00.000000000 Z
11
+ date: 2014-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,6 +82,8 @@ files:
82
82
  - VERSION
83
83
  - lib/rails-dsl.rb
84
84
  - lib/rails-dsl/duck_params.rb
85
+ - lib/rails-dsl/kill_server.rb
86
+ - lib/rails-dsl/routes_ext.rb
85
87
  - rails-dsl.gemspec
86
88
  homepage: https://github.com/adamluzsi/rails-dsl
87
89
  licenses: []