bblib 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +11 -10
- data/.rspec +2 -2
- data/.travis.yml +4 -4
- data/CODE_OF_CONDUCT.md +13 -13
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +247 -757
- data/Rakefile +6 -6
- data/bblib.gemspec +34 -34
- data/bin/console +14 -14
- data/bin/setup +7 -7
- data/lib/array/bbarray.rb +71 -29
- data/lib/bblib.rb +12 -12
- data/lib/bblib/version.rb +3 -3
- data/lib/class/effortless.rb +23 -0
- data/lib/error/abstract.rb +3 -0
- data/lib/file/bbfile.rb +93 -52
- data/lib/hash/bbhash.rb +130 -46
- data/lib/hash/hash_struct.rb +24 -0
- data/lib/hash/tree_hash.rb +364 -0
- data/lib/hash_path/hash_path.rb +210 -0
- data/lib/hash_path/part.rb +83 -0
- data/lib/hash_path/path_hash.rb +84 -0
- data/lib/hash_path/proc.rb +93 -0
- data/lib/hash_path/processors.rb +239 -0
- data/lib/html/bbhtml.rb +2 -0
- data/lib/html/builder.rb +34 -0
- data/lib/html/tag.rb +49 -0
- data/lib/logging/bblogging.rb +42 -0
- data/lib/mixins/attrs.rb +422 -0
- data/lib/mixins/bbmixins.rb +7 -0
- data/lib/mixins/bridge.rb +17 -0
- data/lib/mixins/family_tree.rb +41 -0
- data/lib/mixins/hooks.rb +139 -0
- data/lib/mixins/logger.rb +31 -0
- data/lib/mixins/serializer.rb +71 -0
- data/lib/mixins/simple_init.rb +160 -0
- data/lib/number/bbnumber.rb +15 -7
- data/lib/object/bbobject.rb +46 -19
- data/lib/opal/bbopal.rb +0 -4
- data/lib/os/bbos.rb +24 -16
- data/lib/os/bbsys.rb +60 -43
- data/lib/string/bbstring.rb +165 -66
- data/lib/string/cases.rb +37 -29
- data/lib/string/fuzzy_matcher.rb +48 -50
- data/lib/string/matching.rb +43 -30
- data/lib/string/pluralization.rb +156 -0
- data/lib/string/regexp.rb +45 -0
- data/lib/string/roman.rb +17 -30
- data/lib/system/bbsystem.rb +42 -0
- data/lib/time/bbtime.rb +79 -58
- data/lib/time/cron.rb +174 -132
- data/lib/time/task_timer.rb +86 -70
- metadata +27 -10
- data/lib/gem/bbgem.rb +0 -28
- data/lib/hash/hash_path.rb +0 -344
- data/lib/hash/hash_path_proc.rb +0 -256
- data/lib/hash/path_hash.rb +0 -81
- data/lib/object/attr.rb +0 -182
- data/lib/object/hooks.rb +0 -69
- data/lib/object/lazy_class.rb +0 -73
data/lib/object/hooks.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
module BBLib::Hooks
|
2
|
-
|
3
|
-
def method_added name
|
4
|
-
before_hooks_for(name).each do |hook|
|
5
|
-
next if before_hooked_methods[hook] && before_hooked_methods[hook].include?(name)
|
6
|
-
add_before_hook(name, hook)
|
7
|
-
end
|
8
|
-
after_hooks_for(name).each do |hook|
|
9
|
-
next if after_hooked_methods[hook] && after_hooked_methods[hook].include?(name)
|
10
|
-
add_after_hook(name, hook)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def before hook, *methods
|
15
|
-
methods.each{ |m| before_hooks[hook] = methods }
|
16
|
-
end
|
17
|
-
|
18
|
-
def before_hooks
|
19
|
-
@before_hooks ||= {}
|
20
|
-
end
|
21
|
-
|
22
|
-
def before_hooked_methods
|
23
|
-
@before_hooked_methods ||= {}
|
24
|
-
end
|
25
|
-
|
26
|
-
def before_hooks_for name
|
27
|
-
before_hooks.map{ |n, m| m.include?(name)? n : nil }.reject(&:nil?)
|
28
|
-
end
|
29
|
-
|
30
|
-
def add_before_hook method, hook
|
31
|
-
before_hooked_methods[hook] = Array.new unless before_hooked_methods[hook]
|
32
|
-
before_hooked_methods[hook] += [method]
|
33
|
-
original = instance_method(method)
|
34
|
-
define_method(method) do |*args, &block|
|
35
|
-
# puts "ARGS: #{args}"
|
36
|
-
method(hook).call
|
37
|
-
original.bind(self).call(*args, &block)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def after hook, *methods
|
42
|
-
methods.each{ |m| after_hooks[hook] = methods }
|
43
|
-
end
|
44
|
-
|
45
|
-
def after_hooks
|
46
|
-
@after_hooks ||= {}
|
47
|
-
end
|
48
|
-
|
49
|
-
def after_hooked_methods
|
50
|
-
@after_hooked_methods ||= {}
|
51
|
-
end
|
52
|
-
|
53
|
-
def after_hooks_for name
|
54
|
-
after_hooks.map{ |n, m| m.include?(name) ? n : nil }.reject(&:nil?)
|
55
|
-
end
|
56
|
-
|
57
|
-
def add_after_hook method, hook
|
58
|
-
after_hooked_methods[hook] = Array.new unless after_hooked_methods[hook]
|
59
|
-
after_hooked_methods[hook] += [method]
|
60
|
-
original = instance_method(method)
|
61
|
-
|
62
|
-
define_method(method) do |*args, &block|
|
63
|
-
rtr = original.bind(self).call(*args, &block)
|
64
|
-
method(hook).call
|
65
|
-
rtr
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
data/lib/object/lazy_class.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
|
2
|
-
module BBLib
|
3
|
-
|
4
|
-
class LazyClass
|
5
|
-
extend Hooks
|
6
|
-
extend Attr
|
7
|
-
attr_reader :_serialize_fields
|
8
|
-
|
9
|
-
def initialize *args
|
10
|
-
_pre_setup
|
11
|
-
lazy_setup
|
12
|
-
_lazy_init(*args)
|
13
|
-
end
|
14
|
-
|
15
|
-
def serialize
|
16
|
-
_serialize_fields.map do |name, h|
|
17
|
-
value = send(h[:method])
|
18
|
-
if !h[:always] && value == h[:ignore]
|
19
|
-
nil
|
20
|
-
else
|
21
|
-
[ name, value ]
|
22
|
-
end
|
23
|
-
end.reject(&:nil?).to_h
|
24
|
-
end
|
25
|
-
|
26
|
-
protected
|
27
|
-
|
28
|
-
def lazy_setup
|
29
|
-
# Instantiate necessary variables here
|
30
|
-
end
|
31
|
-
|
32
|
-
def _lazy_init *args
|
33
|
-
BBLib::named_args(*args).each do |k,v|
|
34
|
-
if self.respond_to?("#{k}=".to_sym)
|
35
|
-
send("#{k}=".to_sym, v)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
lazy_init *args
|
39
|
-
custom_lazy_init BBLib::named_args(*args), *args
|
40
|
-
end
|
41
|
-
|
42
|
-
def _pre_setup
|
43
|
-
self.methods.each do |m|
|
44
|
-
if m.to_s.start_with?('__reset_')
|
45
|
-
send(m) rescue nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def lazy_init *args
|
51
|
-
# Define custom initialization here...
|
52
|
-
end
|
53
|
-
|
54
|
-
def custom_lazy_init *args
|
55
|
-
# Left in for legacy support...don't use this!
|
56
|
-
end
|
57
|
-
|
58
|
-
def serialize_method name, method = nil, ignore: nil, always: false
|
59
|
-
return if method == :serialize || name == :serialize && method.nil?
|
60
|
-
_serialize_fields[name.to_sym] = {
|
61
|
-
method: (method.nil? ? name.to_sym : method.to_sym),
|
62
|
-
ignore: ignore,
|
63
|
-
always: always
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
def _serialize_fields
|
68
|
-
@_serialize_fields ||= Hash.new
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|