lux-fw 0.5.36 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/bin/README.md +26 -13
  4. data/bin/cli/benchmark.rb +18 -0
  5. data/bin/cli/cerb.rb +90 -0
  6. data/bin/cli/config.rb +4 -11
  7. data/bin/cli/console.rb +72 -30
  8. data/bin/cli/eval.rb +5 -27
  9. data/bin/cli/generate.rb +9 -11
  10. data/bin/cli/get.rb +14 -6
  11. data/bin/cli/memory.rb +12 -0
  12. data/bin/cli/new.rb +2 -0
  13. data/bin/cli/secrets.rb +3 -31
  14. data/bin/cli/server.rb +28 -9
  15. data/bin/cli/stats.rb +26 -20
  16. data/bin/cli/template.rb +10 -0
  17. data/bin/generate_doc +168 -0
  18. data/bin/lux +73 -10
  19. data/lib/README.md +18 -8
  20. data/lib/common/crypt.rb +60 -9
  21. data/lib/common/string_base.rb +54 -15
  22. data/lib/common/struct_opts.rb +30 -0
  23. data/lib/common/time_difference.rb +75 -0
  24. data/lib/loader.rb +41 -0
  25. data/lib/lux/application/README.md +67 -105
  26. data/lib/lux/application/application.rb +87 -329
  27. data/lib/lux/application/lib/magic_routes.rb +22 -0
  28. data/lib/lux/application/lib/nav.rb +218 -99
  29. data/lib/lux/application/lib/render.rb +47 -67
  30. data/lib/lux/application/lib/routes.rb +242 -0
  31. data/lib/lux/application/lib/shared.rb +47 -0
  32. data/lib/lux/application/lux_adapter.rb +6 -0
  33. data/lib/lux/application/lux_config.rb +26 -0
  34. data/lib/lux/cache/Find Results +24 -0
  35. data/lib/lux/cache/README.md +28 -35
  36. data/lib/lux/cache/cache.rb +78 -26
  37. data/lib/lux/cache/lib/memcached_server.rb +36 -0
  38. data/lib/lux/cache/lib/memory_server.rb +44 -0
  39. data/lib/lux/cache/lib/null_server.rb +33 -0
  40. data/lib/lux/cache/lib/sqlite_server.rb +62 -0
  41. data/lib/lux/cache/lux_adapter.rb +19 -0
  42. data/lib/lux/config/config.rb +93 -144
  43. data/lib/lux/config/lux_adapter.rb +27 -0
  44. data/lib/lux/controller/README.md +67 -12
  45. data/lib/lux/controller/controller.rb +237 -187
  46. data/lib/lux/current/README.md +29 -10
  47. data/lib/lux/current/current.rb +166 -77
  48. data/lib/lux/current/lib/current.rb +6 -0
  49. data/lib/lux/current/lib/encrypt_params.rb +38 -36
  50. data/lib/lux/current/lib/session.rb +86 -65
  51. data/lib/lux/current/lux_adapter.rb +5 -0
  52. data/lib/lux/environment/README.md +24 -0
  53. data/lib/lux/environment/environment.rb +91 -0
  54. data/lib/lux/environment/lux_adapter.rb +13 -0
  55. data/lib/lux/error/README.md +18 -19
  56. data/lib/lux/error/error.rb +207 -152
  57. data/lib/lux/error/lux_adapter.rb +9 -0
  58. data/lib/lux/logger/README.md +45 -0
  59. data/lib/lux/logger/lux_adapter.rb +27 -0
  60. data/lib/lux/lux.rb +72 -129
  61. data/lib/lux/mailer/README.md +12 -5
  62. data/lib/lux/mailer/lux_config.rb +4 -0
  63. data/lib/lux/mailer/mailer.rb +81 -59
  64. data/lib/lux/plugin/README.md +19 -0
  65. data/lib/lux/plugin/lux_adapter.rb +8 -0
  66. data/lib/lux/plugin/plugin.rb +65 -0
  67. data/lib/lux/render/README.md +100 -0
  68. data/lib/lux/render/render.rb +12 -0
  69. data/lib/lux/response/README.md +57 -1
  70. data/lib/lux/response/lib/file.rb +87 -65
  71. data/lib/lux/response/lib/flash.rb +49 -34
  72. data/lib/lux/response/lib/header.rb +34 -33
  73. data/lib/lux/response/response.rb +252 -164
  74. data/lib/lux/template/helper.rb +130 -0
  75. data/lib/lux/template/inline_render_proxy.rb +31 -0
  76. data/lib/lux/template/lux_adapter.rb +5 -0
  77. data/lib/lux/template/template.rb +127 -0
  78. data/lib/lux-fw.rb +15 -33
  79. data/lib/overload/array.rb +33 -7
  80. data/lib/overload/blank.rb +8 -3
  81. data/lib/overload/boolean.rb +46 -0
  82. data/lib/overload/class.rb +28 -0
  83. data/lib/overload/dir.rb +117 -7
  84. data/lib/overload/file.rb +40 -5
  85. data/lib/overload/float.rb +38 -3
  86. data/lib/overload/hash.rb +81 -91
  87. data/lib/overload/integer.rb +15 -0
  88. data/lib/overload/json.rb +26 -0
  89. data/lib/overload/nil.rb +4 -8
  90. data/lib/overload/object.rb +91 -24
  91. data/lib/overload/pathname.rb +11 -0
  92. data/lib/overload/raise_variants.rb +26 -36
  93. data/lib/overload/string.rb +100 -27
  94. data/lib/overload/thread_simple.rb +100 -0
  95. data/lib/overload/time.rb +60 -38
  96. data/tasks/loader.rb +20 -7
  97. metadata +170 -169
  98. data/bin/.DS_Store +0 -0
  99. data/bin/build_gem +0 -77
  100. data/bin/cli/dbconsole.rb +0 -8
  101. data/bin/cli/routes.rb +0 -90
  102. data/lib/.DS_Store +0 -0
  103. data/lib/common/.DS_Store +0 -0
  104. data/lib/common/class_attributes.rb +0 -51
  105. data/lib/common/class_callbacks.rb +0 -47
  106. data/lib/common/free_struct.rb +0 -42
  107. data/lib/common/hash_with_indifferent_access.rb +0 -74
  108. data/lib/common/html_tag_builder.rb +0 -91
  109. data/lib/common/method_attr.rb +0 -69
  110. data/lib/common/url.rb +0 -191
  111. data/lib/lux/.DS_Store +0 -0
  112. data/lib/lux/README.md +0 -10
  113. data/lib/lux/cache/.DS_Store +0 -0
  114. data/lib/lux/cache/lib/memory.rb +0 -36
  115. data/lib/lux/cache/lib/null.rb +0 -21
  116. data/lib/lux/config/README.md +0 -63
  117. data/lib/lux/config/lib/plugin.rb +0 -65
  118. data/lib/lux/config/lib/secrets.rb +0 -48
  119. data/lib/lux/current/.DS_Store +0 -0
  120. data/lib/lux/delayed_job/.DS_Store +0 -0
  121. data/lib/lux/delayed_job/README.md +0 -3
  122. data/lib/lux/delayed_job/delayed_job.rb +0 -51
  123. data/lib/lux/delayed_job/lib/memory.rb +0 -16
  124. data/lib/lux/delayed_job/lib/nsq.rb +0 -3
  125. data/lib/lux/delayed_job/lib/postgre.rb +0 -6
  126. data/lib/lux/delayed_job/lib/redis.rb +0 -19
  127. data/lib/lux/event_bus/README.md +0 -36
  128. data/lib/lux/event_bus/event_bus.rb +0 -27
  129. data/lib/lux/view/README.md +0 -85
  130. data/lib/lux/view/cell.rb +0 -102
  131. data/lib/lux/view/helper.rb +0 -120
  132. data/lib/lux/view/lib/cell_helpers.rb +0 -29
  133. data/lib/lux/view/view.rb +0 -95
  134. data/lib/overload/it.rb +0 -29
  135. data/plugins/api/README.md +0 -49
  136. data/plugins/api/api.rb +0 -153
  137. data/plugins/api/lib/attr.rb +0 -31
  138. data/plugins/api/lib/dsl.rb +0 -52
  139. data/plugins/api/lib/error.rb +0 -3
  140. data/plugins/api/lib/model_api.rb +0 -203
  141. data/plugins/api/lib/response.rb +0 -85
  142. data/plugins/db/.DS_Store +0 -0
  143. data/plugins/db/README.md +0 -29
  144. data/plugins/db/auto_migrate/auto_migrate.rb +0 -268
  145. data/plugins/db/auto_migrate/db.rake +0 -15
  146. data/plugins/db/helpers/array_search.rb +0 -27
  147. data/plugins/db/helpers/before_save_filters.rb +0 -32
  148. data/plugins/db/helpers/composite_primary_keys.rb +0 -36
  149. data/plugins/db/helpers/core.rb +0 -94
  150. data/plugins/db/helpers/dataset_methods.rb +0 -138
  151. data/plugins/db/helpers/enums_plugin.rb +0 -52
  152. data/plugins/db/helpers/find_precache.rb +0 -31
  153. data/plugins/db/helpers/link_objects.rb +0 -84
  154. data/plugins/db/helpers/schema_checks.rb +0 -83
  155. data/plugins/db/helpers/typero_adapter.rb +0 -71
  156. data/plugins/db/logger/config.rb +0 -22
  157. data/plugins/db/logger/lux_response_adapter.rb +0 -10
  158. data/plugins/db/paginate/helper.rb +0 -32
  159. data/plugins/db/paginate/sequel_adapter.rb +0 -23
  160. data/plugins/exceptions/exceptions.rake +0 -43
  161. data/plugins/exceptions/simple_exception.rb +0 -64
  162. data/plugins/favicon/favicon.rb +0 -10
  163. data/plugins/html/README.md +0 -3
  164. data/plugins/html/html_form.rb +0 -118
  165. data/plugins/html/html_input.rb +0 -98
  166. data/plugins/html/html_menu.rb +0 -79
  167. data/plugins/html/input_types.rb +0 -346
  168. data/plugins/js_widgets/README.md +0 -5
  169. data/plugins/js_widgets/js/html_tag.coffee +0 -42
  170. data/plugins/js_widgets/js/widgets.coffee +0 -161
  171. data/plugins/js_widgets/js_widgets.rb +0 -15
  172. data/plugins/oauth/lib/facebook.rb +0 -35
  173. data/plugins/oauth/lib/github.rb +0 -38
  174. data/plugins/oauth/lib/google.rb +0 -41
  175. data/plugins/oauth/lib/linkedin.rb +0 -41
  176. data/plugins/oauth/lib/stackexchange.rb +0 -41
  177. data/plugins/oauth/lib/twitter.rb +0 -38
  178. data/plugins/oauth/oauth.rb +0 -42
  179. data/plugins/policy/policy.rb +0 -53
  180. data/tasks/nginx.rake +0 -23
  181. /data/lib/lux/{view/lib → mailer}/helper_modules.rb +0 -0
data/lib/overload/hash.rb CHANGED
@@ -1,82 +1,21 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../common/free_struct'
4
-
5
1
  class Hash
6
- def h
7
- Hashie::Mash.new(self)
8
- end
9
-
10
- def h_wia
11
- HashWithIndifferentAccess.new(self)
12
- end
13
-
14
- # readonly hash with .to_h
15
- def to_readonly name=nil
16
- Class.new.tap do |c|
17
- c.define_singleton_method(:to_h) do
18
- m_list = methods(false) - [:to_h]
19
- m_list.inject({}) do |h,m|
20
- h[m] = send(m)
21
- h[m] = h[m].to_h if h[m].class == Class
22
- h
23
- end
24
- end
25
-
26
- each do |k, v|
27
- v = v.to_readonly if v.class == Hash
28
- c.define_singleton_method(k) { v }
29
- end
30
- end
31
- end
32
-
33
- # {...}.to_opts :name, :age
34
- # {...}.to_opts name: String, age: Integer
35
- def to_opts *keys
36
- if keys.first.is_a?(Hash)
37
- # if given Hash check opt class types
38
- keys.first.each do |key, target_class|
39
- source = self[key]
40
-
41
- if target_class && !source.nil? && !source.is_a?(target_class)
42
- raise ArgumentError.new(%[Expected argument :#{key} to be of type "#{target_class}" not "#{source.class}"])
43
- end
44
- end
45
-
46
- keys = keys.first.keys
47
- end
48
-
49
- not_allowed = self.keys - keys
50
- raise ArgumentError.new('Key :%s not allowed in option' % not_allowed.first) if not_allowed.first
51
-
52
- FreeStruct.new keys.inject({}) { |total, key|
53
- raise 'Hash key :%s is not allowed!' % key unless keys.include?(key)
54
- total[key] = self[key]
55
- total
56
- }
57
- end
58
-
59
- def to_struct
60
- to_opts *keys
61
- end
62
-
63
- def tag node=nil, text=nil
64
- HtmlTagBuilder.build self, node, text
65
- end
66
-
67
2
  def blank?
68
3
  self.keys.count == 0
69
4
  end
70
5
 
71
6
  def to_query namespace=nil
72
- self.keys.sort.map { |k|
7
+ keys = self.keys.sort
8
+
9
+ return unless keys.first
10
+
11
+ '?' + keys.map do |k|
73
12
  name = namespace ? "#{namespace}[#{k}]" : k
74
13
  "#{name}=#{CGI::escape(self[k].to_s)}"
75
- }.join('&')
14
+ end.join('&')
76
15
  end
77
16
 
78
- def data_attributes
79
- self.keys.sort.map{ |k| 'data-%s="%s"' % [k, self[k].to_s.gsub('"', '"')]}.join(' ')
17
+ def to_attributes
18
+ self.keys.sort.map{ |k| '%s="%s"' % [k, self[k].to_s.gsub('"', '"')]}.join(' ')
80
19
  end
81
20
 
82
21
  def pluck *args
@@ -84,31 +23,15 @@ class Hash
84
23
  self.select{ |k,v| string_args.index(k.to_s) }
85
24
  end
86
25
 
87
- def transform_keys
88
- return enum_for(:transform_keys) unless block_given?
89
- result = self.class.new
90
- each_key do |key|
91
- result[yield(key)] = self[key]
92
- end
93
- result
94
- end
95
-
96
- def transform_keys!
97
- return enum_for(:transform_keys!) unless block_given?
98
- keys.each do |key|
99
- self[yield(key)] = delete(key)
100
- end
101
- self
26
+ def stringify_keys
27
+ transform_keys { |key| key.to_s }
102
28
  end
103
29
 
104
30
  def symbolize_keys
105
- transform_keys{ |key| key.to_sym rescue key }
106
- end
107
-
108
- def symbolize_keys!
109
- transform_keys!{ |key| key.to_sym rescue key }
31
+ transform_keys { |key| key.respond_to?(:to_sym) ? key.to_sym : key }
110
32
  end
111
33
 
34
+ # Returns hash with only selected keys
112
35
  def slice *keys
113
36
  keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
114
37
  keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) }
@@ -124,8 +47,75 @@ class Hash
124
47
  omit
125
48
  end
126
49
 
127
- def pretty_generate
128
- JSON.pretty_generate(self).gsub(/"([\w\-]+)":/) { %["#{$1.yellow}":] }
50
+ # Returns a hash that includes everything but the given keys.
51
+ # hash = { a: true, b: false, c: nil}
52
+ # hash.except(:c) # => { a: true, b: false}
53
+ # hash # => { a: true, b: false, c: nil}
54
+ #
55
+ # This is useful for limiting a set of parameters to everything but a few known toggles:
56
+ # @person.update(params[:person].except(:admin))
57
+ def except(*keys)
58
+ dup.except!(*keys)
59
+ end
60
+
61
+ # Hash#except in place, modifying current hash
62
+ def except!(*keys)
63
+ keys.each { |key| delete(key.to_s); delete(key.to_sym) }
64
+ self
65
+ end
66
+
67
+ def remove_empty covert_to_s = false
68
+ self.keys.inject({}) do |t, el|
69
+ v = self[el]
70
+ t[covert_to_s ? el.to_s : el] = v if el.present? && v.present?
71
+ t
72
+ end
73
+ end
74
+
75
+ def to_js opts = {}
76
+ data = opts[:empty] ? self : remove_empty
77
+ data = data.to_json.gsub(/"(\w+)":/, "\\1:")
78
+ data = data.gsub(/",(\w)/, '", \1') unless opts[:narrow]
79
+ data
80
+ end
81
+
82
+ def transform_keys &block
83
+ if block
84
+ Hash.new.tap do |result|
85
+ for key, value in self
86
+ value = value.transform_keys(&block) if value.is_a?(Hash)
87
+ result[block.call(key)] = value
88
+ end
89
+ end
90
+ else
91
+ enum_for(:transform_keys)
92
+ end
93
+ end
94
+
95
+ # clean empty values from hash, deep
96
+ def deep_compact value = nil
97
+ value ||= self
98
+
99
+ res_hash = value.map do |key, value|
100
+ value = deep_compact(value) if value.is_a?(Hash)
101
+
102
+ # we need to remove '0' because that is what empty checkbox inserts, but it is nil
103
+ value = nil if [{}, [], '0'].include?(value)
104
+ value = nil if value.blank?
105
+ [key, value]
106
+ end
107
+
108
+ res_hash.to_h.compact
109
+ end
110
+
111
+ def self.deep_compact value
112
+ (value || {}).deep_compact
113
+ end
114
+
115
+ def html_safe key
116
+ if data = self[key]
117
+ self[key] = data.html_safe
118
+ end
129
119
  end
130
120
  end
131
121
 
@@ -12,4 +12,19 @@ class Integer
12
12
  def dotted
13
13
  self.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse
14
14
  end
15
+
16
+ def to_filesize
17
+ base = 1024
18
+ out = lambda do
19
+ {
20
+ 'B' => base,
21
+ 'KB' => base * base,
22
+ 'MB' => base * base * base,
23
+ 'GB' => base * base * base * base,
24
+ 'TB' => base * base * base * base * base
25
+ }.each_pair { |e, s| return "#{(self.to_f / (s / base)).round(1)} #{e}" if self < s }
26
+ end.call
27
+
28
+ out.sub('.0 B', ' B')
29
+ end
15
30
  end
@@ -0,0 +1,26 @@
1
+ module LuxJson
2
+ # to json smart - pretty in dev
3
+ def to_jsons
4
+ Lux.env.screen_log? ? to_jsonp : to_json
5
+ end
6
+
7
+ # to json pretty
8
+ def to_jsonp colorize_keys = false
9
+ out = JSON.pretty_generate(self)
10
+ colorize_keys ? out.gsub(/(\n\s|)"([\w\-]+)":/) { '%s"%s":' % [$1, $2.yellow] } : out
11
+ end
12
+
13
+ # to json compact (for javascript)
14
+ def to_jsonc
15
+ to_json.gsub(/"(\w+)":/, '\1:')
16
+ end
17
+ end
18
+
19
+ class Hash
20
+ include LuxJson
21
+ end
22
+
23
+ class Array
24
+ include LuxJson
25
+ end
26
+
data/lib/overload/nil.rb CHANGED
@@ -1,13 +1,9 @@
1
1
  class NilClass
2
- def empty?
3
- true
4
- end
5
-
6
- def present?
7
- false
8
- end
9
-
10
2
  def dup
11
3
  nil
12
4
  end
5
+
6
+ def is? klass
7
+ true
8
+ end
13
9
  end
@@ -1,34 +1,55 @@
1
1
  class Object
2
+ LUX_AUTO_LOAD ||= {}
2
3
 
3
- def self.const_missing klass
4
- file = klass.to_s.tableize.singularize
5
- paths = [
6
- 'models',
7
- 'lib',
8
- 'lib/vendor',
9
- 'vendor',
10
- file.split('_').last.pluralize
11
- ].map { |it| './app/%s/%s.rb' % [it, file] }
4
+ def self.const_missing klass, path=nil
5
+ unless LUX_AUTO_LOAD.keys.first
6
+ for file in `find ./app -type f -name '*.rb'`.split($/)
7
+ klass_file = file.split('/').last.sub('.rb', '').classify
8
+ LUX_AUTO_LOAD[klass_file] ||= [false, file]
9
+ end
10
+ end
12
11
 
13
- klass_file = paths.find { |it| File.exist?(it) } or
14
- raise NameError.new('Can not find and autoload class "%s", looked in %s' % [klass, paths.map{ |it| "\n#{it}" }.join('')])
12
+ klass = klass.to_s if klass.class == Symbol
13
+ path = LUX_AUTO_LOAD[klass]
14
+ error = %{Can't find and autoload module/class "%s"} % klass
15
15
 
16
- # puts '* autoload: %s from %s' % [file, klass_file]
16
+ if path
17
+ if path[0]
18
+ raise NameError.new('%s, found file "%s" is not defineing it.' % [error, path[1]])
19
+ else
20
+ path[0] = true
21
+ require path[1].sub('.rb', '')
22
+ Object.const_get(klass)
23
+ end
24
+ else
25
+ raise NameError.new('%s. Scanned all files in ./app folder' % error)
26
+ end
27
+ end
17
28
 
18
- require klass_file
29
+ ###
19
30
 
20
- Object.const_get(klass)
31
+ # @foo.or(2)
32
+ def or _or = nil, &block
33
+ self.blank? || self == 0 ? (block ? block.call : _or) : self
21
34
  end
22
35
 
23
- ###
36
+ def nil _or = nil, &block
37
+ self.nil? ? (block ? block.call : _or) : self
38
+ end
24
39
 
25
- def or _or
26
- self.blank? || self == 0 ? _or : self
40
+ def and &block
41
+ block.call(self) if self.present?
27
42
  end
28
43
 
29
- def try *args
30
- return nil if self.class == NilClass
31
- self.send(*args)
44
+ def try *args, &block
45
+ if self.class == NilClass
46
+ nil
47
+ elsif block_given?
48
+ data = args.first.nil? ? self : self.send(*args)
49
+ yield data
50
+ else
51
+ self.send(*args)
52
+ end
32
53
  end
33
54
 
34
55
  def die desc=nil, exp_object=nil
@@ -39,7 +60,7 @@ class Object
39
60
  raise desc
40
61
  end
41
62
 
42
- # this will capture plain Hash and HashWithIndifferentAccess
63
+ # this will capture plain Hash and Hash With Indifferent Access
43
64
  def is_hash?
44
65
  self.class.to_s.index('Hash') ? true : false
45
66
  end
@@ -57,7 +78,7 @@ class Object
57
78
  end
58
79
 
59
80
  def is_true?
60
- self ? true :false
81
+ ['true', 'on', '1'].include?(to_s)
61
82
  end
62
83
 
63
84
  def is_numeric?
@@ -72,6 +93,17 @@ class Object
72
93
  self.class == TrueClass || self.class == FalseClass
73
94
  end
74
95
 
96
+ def is_a! klass, error = nil
97
+ ancestors.each { |kind| return true if kind == klass }
98
+
99
+ if error
100
+ message = error.class == String ? error : %[Expected "#{self}" to be of "#{klass}"]
101
+ raise ArgumentError.new(message)
102
+ else
103
+ false
104
+ end
105
+ end
106
+
75
107
  def andand func=nil
76
108
  if present?
77
109
  if block_given?
@@ -80,12 +112,47 @@ class Object
80
112
  func ? send(func) : self
81
113
  end
82
114
  else
83
- block_given? || func ? nil : {}.h
115
+ block_given? || func ? nil : {}.to_hwia
84
116
  end
85
117
  end
86
118
 
87
119
  def instance_variables_hash
88
- Hash[instance_variables.map { |name| [name, instance_variable_get(name)] } ]
120
+ vars = instance_variables - [:@current]
121
+ vars = vars.reject { |var| var[0,2] == '@_' }
122
+ Hash[vars.map { |name| [name, instance_variable_get(name)] }]
123
+ end
124
+
125
+ # value should be Float
126
+ # value.is! Float
127
+ def is! value = :_nil
128
+ if value == :_nil
129
+ if self.present?
130
+ self
131
+ else
132
+ raise ArgumentError.new('Expected not not empty value')
133
+ end
134
+ elsif value == self.class
135
+ self
136
+ else
137
+ if self.class == Class && self.superclass != Object
138
+ if self.ancestors.include?(value)
139
+ self
140
+ else
141
+ raise ArgumentError.new('There is no %s in %s ancestors in %s' % [value, self, caller[0]])
142
+ end
143
+ else
144
+ raise ArgumentError.new('Expected %s but got %s in %s' % [value, self.class, caller[0]])
145
+ end
146
+ end
147
+ end
148
+
149
+ # value can be nil but if defined should be Float
150
+ # value.is? Float
151
+ def is? value = nil
152
+ is! value
153
+ true
154
+ rescue ArgumentError
155
+ false
89
156
  end
90
157
  end
91
158
 
@@ -0,0 +1,11 @@
1
+ require 'fileutils'
2
+
3
+ class Pathname
4
+ def touch
5
+ FileUtils.touch to_s
6
+ end
7
+
8
+ def write_p data
9
+ File.write_p to_s, data
10
+ end
11
+ end
@@ -1,33 +1,39 @@
1
- class LocalRaiseError < StandardError
2
- end
3
-
4
1
  class Object
5
2
  # raise object
6
3
  def r what
7
- opath = what.class.ancestors
8
- out = opath.join("\n> ")
9
-
10
- data = what.is_a?(Hash) ? JSON.pretty_generate(what) : what.ai(plain:true)
11
- out = [data, out, ''].join("\n\n-\n\n")
12
-
13
- # unique_methods = what.methods - what.class.ancestors[0].instance_methods
14
- # raise unique_methods
4
+ if what.is_a?(Method)
5
+ rr [:source_location, what.source_location.join(':')]
6
+ else
7
+ rr what
8
+ end
15
9
 
16
- raise LocalRaiseError.new out
10
+ what = what.respond_to?(:to_jsonp) ? what.to_jsonp : what.inspect
11
+ raise StandardError.new(what.nil? ? 'nil' : what)
17
12
  end
18
13
 
19
14
  # better console log dump
20
- def rr what
21
- src = caller[0].sub(Lux.root.to_s+'/', '').sub(Lux.fw_root.to_s, 'lux-fw').split(':in `').first
22
- ap ['--- START (%s) %s ---' % [what.class, src], what, '--- END ---']
15
+ def rr what, as_jsonp = false
16
+ klass = what.class
17
+ klass = '%s at %s' % [klass, what.source_location.join(':').sub(Lux.root.to_s, '.')] if klass == Method
18
+ from = caller[0].include?('raise_variants.rb') ? caller[1] : caller[0]
19
+ from = from.sub(Lux.root.to_s+'/', './').split(':in ').first
20
+ header = '--- START (%s) %s - %s ---' % [klass, from, Lux.current.request.url]
21
+ as_jsonp = true if ['HashWia', 'Hash'].include?(what.class.to_s)
22
+ if as_jsonp
23
+ puts header
24
+ puts what.to_jsonp
25
+ puts '--- END ---'
26
+ else
27
+ ap [header, what, '--- END ---']
28
+ end
23
29
  end
24
30
 
25
31
  # unique methods for object
26
32
  # includes methods from modules
27
- def rm object
33
+ def r? object
28
34
  dump = []
29
35
 
30
- dump.push ['Class', object.class]
36
+ dump.push 'Class: %s' % object.class
31
37
 
32
38
  instance_unique = object.methods - object.class.ancestors[0].instance_methods
33
39
  class_unique = object.methods
@@ -36,31 +42,16 @@ class Object
36
42
  class_unique -= _.instance_methods
37
43
 
38
44
  if _.class != Module
39
- dump.push ['Parent Class', _]
45
+ dump.push 'Parent Class: %s' % _
40
46
  break
41
47
  end
42
48
  end
43
49
 
44
50
  dump.push ['Instance uniqe', instance_unique.sort] if instance_unique[0]
45
- dump.push ['Uniqe from parent', class_unique.sort]
51
+ dump.push ['Uniqe from parent', class_unique.sort.join(', ')]
46
52
  dump.push ['Uniqe from parent simple', object.class.instance_methods(false)]
47
53
 
48
- r dump
49
- end
50
-
51
- def rr! what
52
- print "\e[H\e[2J\e[3J" # clear osx screen :)
53
- rr what
54
- end
55
-
56
- # show method info
57
- # show User, :secure_hash
58
- def rr? instance, m
59
- el = instance.class.instance_method(m)
60
- puts el.source_location.join(':').yellow
61
- puts '-'
62
- puts el.source if el.respond_to?(:source)
63
- nil
54
+ rr dump
64
55
  end
65
56
  end
66
57
 
@@ -74,4 +65,3 @@ method(:ap) rescue Proc.new do
74
65
  end
75
66
  end
76
67
  end.call
77
-