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.
- checksums.yaml +4 -4
- data/.version +1 -1
- data/bin/README.md +26 -13
- data/bin/cli/benchmark.rb +18 -0
- data/bin/cli/cerb.rb +90 -0
- data/bin/cli/config.rb +4 -11
- data/bin/cli/console.rb +72 -30
- data/bin/cli/eval.rb +5 -27
- data/bin/cli/generate.rb +9 -11
- data/bin/cli/get.rb +14 -6
- data/bin/cli/memory.rb +12 -0
- data/bin/cli/new.rb +2 -0
- data/bin/cli/secrets.rb +3 -31
- data/bin/cli/server.rb +28 -9
- data/bin/cli/stats.rb +26 -20
- data/bin/cli/template.rb +10 -0
- data/bin/generate_doc +168 -0
- data/bin/lux +73 -10
- data/lib/README.md +18 -8
- data/lib/common/crypt.rb +60 -9
- data/lib/common/string_base.rb +54 -15
- data/lib/common/struct_opts.rb +30 -0
- data/lib/common/time_difference.rb +75 -0
- data/lib/loader.rb +41 -0
- data/lib/lux/application/README.md +67 -105
- data/lib/lux/application/application.rb +87 -329
- data/lib/lux/application/lib/magic_routes.rb +22 -0
- data/lib/lux/application/lib/nav.rb +218 -99
- data/lib/lux/application/lib/render.rb +47 -67
- data/lib/lux/application/lib/routes.rb +242 -0
- data/lib/lux/application/lib/shared.rb +47 -0
- data/lib/lux/application/lux_adapter.rb +6 -0
- data/lib/lux/application/lux_config.rb +26 -0
- data/lib/lux/cache/Find Results +24 -0
- data/lib/lux/cache/README.md +28 -35
- data/lib/lux/cache/cache.rb +78 -26
- data/lib/lux/cache/lib/memcached_server.rb +36 -0
- data/lib/lux/cache/lib/memory_server.rb +44 -0
- data/lib/lux/cache/lib/null_server.rb +33 -0
- data/lib/lux/cache/lib/sqlite_server.rb +62 -0
- data/lib/lux/cache/lux_adapter.rb +19 -0
- data/lib/lux/config/config.rb +93 -144
- data/lib/lux/config/lux_adapter.rb +27 -0
- data/lib/lux/controller/README.md +67 -12
- data/lib/lux/controller/controller.rb +237 -187
- data/lib/lux/current/README.md +29 -10
- data/lib/lux/current/current.rb +166 -77
- data/lib/lux/current/lib/current.rb +6 -0
- data/lib/lux/current/lib/encrypt_params.rb +38 -36
- data/lib/lux/current/lib/session.rb +86 -65
- data/lib/lux/current/lux_adapter.rb +5 -0
- data/lib/lux/environment/README.md +24 -0
- data/lib/lux/environment/environment.rb +91 -0
- data/lib/lux/environment/lux_adapter.rb +13 -0
- data/lib/lux/error/README.md +18 -19
- data/lib/lux/error/error.rb +207 -152
- data/lib/lux/error/lux_adapter.rb +9 -0
- data/lib/lux/logger/README.md +45 -0
- data/lib/lux/logger/lux_adapter.rb +27 -0
- data/lib/lux/lux.rb +72 -129
- data/lib/lux/mailer/README.md +12 -5
- data/lib/lux/mailer/lux_config.rb +4 -0
- data/lib/lux/mailer/mailer.rb +81 -59
- data/lib/lux/plugin/README.md +19 -0
- data/lib/lux/plugin/lux_adapter.rb +8 -0
- data/lib/lux/plugin/plugin.rb +65 -0
- data/lib/lux/render/README.md +100 -0
- data/lib/lux/render/render.rb +12 -0
- data/lib/lux/response/README.md +57 -1
- data/lib/lux/response/lib/file.rb +87 -65
- data/lib/lux/response/lib/flash.rb +49 -34
- data/lib/lux/response/lib/header.rb +34 -33
- data/lib/lux/response/response.rb +252 -164
- data/lib/lux/template/helper.rb +130 -0
- data/lib/lux/template/inline_render_proxy.rb +31 -0
- data/lib/lux/template/lux_adapter.rb +5 -0
- data/lib/lux/template/template.rb +127 -0
- data/lib/lux-fw.rb +15 -33
- data/lib/overload/array.rb +33 -7
- data/lib/overload/blank.rb +8 -3
- data/lib/overload/boolean.rb +46 -0
- data/lib/overload/class.rb +28 -0
- data/lib/overload/dir.rb +117 -7
- data/lib/overload/file.rb +40 -5
- data/lib/overload/float.rb +38 -3
- data/lib/overload/hash.rb +81 -91
- data/lib/overload/integer.rb +15 -0
- data/lib/overload/json.rb +26 -0
- data/lib/overload/nil.rb +4 -8
- data/lib/overload/object.rb +91 -24
- data/lib/overload/pathname.rb +11 -0
- data/lib/overload/raise_variants.rb +26 -36
- data/lib/overload/string.rb +100 -27
- data/lib/overload/thread_simple.rb +100 -0
- data/lib/overload/time.rb +60 -38
- data/tasks/loader.rb +20 -7
- metadata +170 -169
- data/bin/.DS_Store +0 -0
- data/bin/build_gem +0 -77
- data/bin/cli/dbconsole.rb +0 -8
- data/bin/cli/routes.rb +0 -90
- data/lib/.DS_Store +0 -0
- data/lib/common/.DS_Store +0 -0
- data/lib/common/class_attributes.rb +0 -51
- data/lib/common/class_callbacks.rb +0 -47
- data/lib/common/free_struct.rb +0 -42
- data/lib/common/hash_with_indifferent_access.rb +0 -74
- data/lib/common/html_tag_builder.rb +0 -91
- data/lib/common/method_attr.rb +0 -69
- data/lib/common/url.rb +0 -191
- data/lib/lux/.DS_Store +0 -0
- data/lib/lux/README.md +0 -10
- data/lib/lux/cache/.DS_Store +0 -0
- data/lib/lux/cache/lib/memory.rb +0 -36
- data/lib/lux/cache/lib/null.rb +0 -21
- data/lib/lux/config/README.md +0 -63
- data/lib/lux/config/lib/plugin.rb +0 -65
- data/lib/lux/config/lib/secrets.rb +0 -48
- data/lib/lux/current/.DS_Store +0 -0
- data/lib/lux/delayed_job/.DS_Store +0 -0
- data/lib/lux/delayed_job/README.md +0 -3
- data/lib/lux/delayed_job/delayed_job.rb +0 -51
- data/lib/lux/delayed_job/lib/memory.rb +0 -16
- data/lib/lux/delayed_job/lib/nsq.rb +0 -3
- data/lib/lux/delayed_job/lib/postgre.rb +0 -6
- data/lib/lux/delayed_job/lib/redis.rb +0 -19
- data/lib/lux/event_bus/README.md +0 -36
- data/lib/lux/event_bus/event_bus.rb +0 -27
- data/lib/lux/view/README.md +0 -85
- data/lib/lux/view/cell.rb +0 -102
- data/lib/lux/view/helper.rb +0 -120
- data/lib/lux/view/lib/cell_helpers.rb +0 -29
- data/lib/lux/view/view.rb +0 -95
- data/lib/overload/it.rb +0 -29
- data/plugins/api/README.md +0 -49
- data/plugins/api/api.rb +0 -153
- data/plugins/api/lib/attr.rb +0 -31
- data/plugins/api/lib/dsl.rb +0 -52
- data/plugins/api/lib/error.rb +0 -3
- data/plugins/api/lib/model_api.rb +0 -203
- data/plugins/api/lib/response.rb +0 -85
- data/plugins/db/.DS_Store +0 -0
- data/plugins/db/README.md +0 -29
- data/plugins/db/auto_migrate/auto_migrate.rb +0 -268
- data/plugins/db/auto_migrate/db.rake +0 -15
- data/plugins/db/helpers/array_search.rb +0 -27
- data/plugins/db/helpers/before_save_filters.rb +0 -32
- data/plugins/db/helpers/composite_primary_keys.rb +0 -36
- data/plugins/db/helpers/core.rb +0 -94
- data/plugins/db/helpers/dataset_methods.rb +0 -138
- data/plugins/db/helpers/enums_plugin.rb +0 -52
- data/plugins/db/helpers/find_precache.rb +0 -31
- data/plugins/db/helpers/link_objects.rb +0 -84
- data/plugins/db/helpers/schema_checks.rb +0 -83
- data/plugins/db/helpers/typero_adapter.rb +0 -71
- data/plugins/db/logger/config.rb +0 -22
- data/plugins/db/logger/lux_response_adapter.rb +0 -10
- data/plugins/db/paginate/helper.rb +0 -32
- data/plugins/db/paginate/sequel_adapter.rb +0 -23
- data/plugins/exceptions/exceptions.rake +0 -43
- data/plugins/exceptions/simple_exception.rb +0 -64
- data/plugins/favicon/favicon.rb +0 -10
- data/plugins/html/README.md +0 -3
- data/plugins/html/html_form.rb +0 -118
- data/plugins/html/html_input.rb +0 -98
- data/plugins/html/html_menu.rb +0 -79
- data/plugins/html/input_types.rb +0 -346
- data/plugins/js_widgets/README.md +0 -5
- data/plugins/js_widgets/js/html_tag.coffee +0 -42
- data/plugins/js_widgets/js/widgets.coffee +0 -161
- data/plugins/js_widgets/js_widgets.rb +0 -15
- data/plugins/oauth/lib/facebook.rb +0 -35
- data/plugins/oauth/lib/github.rb +0 -38
- data/plugins/oauth/lib/google.rb +0 -41
- data/plugins/oauth/lib/linkedin.rb +0 -41
- data/plugins/oauth/lib/stackexchange.rb +0 -41
- data/plugins/oauth/lib/twitter.rb +0 -38
- data/plugins/oauth/oauth.rb +0 -42
- data/plugins/policy/policy.rb +0 -53
- data/tasks/nginx.rake +0 -23
- /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
|
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
|
-
|
14
|
+
end.join('&')
|
76
15
|
end
|
77
16
|
|
78
|
-
def
|
79
|
-
self.keys.sort.map{ |k| '
|
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
|
88
|
-
|
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
|
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
|
-
|
128
|
-
|
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
|
|
data/lib/overload/integer.rb
CHANGED
@@ -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
data/lib/overload/object.rb
CHANGED
@@ -1,34 +1,55 @@
|
|
1
1
|
class Object
|
2
|
+
LUX_AUTO_LOAD ||= {}
|
2
3
|
|
3
|
-
def self.const_missing klass
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
14
|
-
|
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
|
-
|
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
|
-
|
29
|
+
###
|
19
30
|
|
20
|
-
|
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
|
26
|
-
self
|
40
|
+
def and &block
|
41
|
+
block.call(self) if self.present?
|
27
42
|
end
|
28
43
|
|
29
|
-
def try *args
|
30
|
-
|
31
|
-
|
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
|
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
|
-
|
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 : {}.
|
115
|
+
block_given? || func ? nil : {}.to_hwia
|
84
116
|
end
|
85
117
|
end
|
86
118
|
|
87
119
|
def instance_variables_hash
|
88
|
-
|
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
|
|
@@ -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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
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
|
-
|
22
|
-
|
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
|
33
|
+
def r? object
|
28
34
|
dump = []
|
29
35
|
|
30
|
-
dump.push
|
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
|
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
|
-
|
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
|
-
|