r_kit 0.4.3 → 0.5
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 +4 -4
- data/lib/r_kit/active_record_utility/active_record_extend.rb +5 -30
- data/lib/r_kit/active_record_utility/database_schema_error.rb +3 -1
- data/lib/r_kit/active_record_utility/utilities/pool.rb +41 -0
- data/lib/r_kit/active_record_utility/utilities/publisher.rb +38 -0
- data/lib/r_kit/active_record_utility/{base → utilities}/series.rb +40 -15
- data/lib/r_kit/active_record_utility/utilities/tag.rb +30 -0
- data/lib/r_kit/active_record_utility.rb +12 -13
- data/lib/r_kit/backtrace.rb +1 -1
- data/lib/r_kit/core/loader/dependency.rb +3 -3
- data/lib/r_kit/core/loader/load_path.rb +5 -3
- data/lib/r_kit/core/loader.rb +14 -11
- data/lib/r_kit/core.rb +3 -1
- data/lib/r_kit/decoration/action_view_base_extend.rb +5 -4
- data/lib/r_kit/decoration/base/collection.rb +20 -0
- data/lib/r_kit/decoration/base/object.rb +21 -0
- data/lib/r_kit/decoration/base.rb +15 -19
- data/lib/r_kit/decoration/class.rb +103 -14
- data/lib/r_kit/decoration/dsl.rb +121 -0
- data/lib/r_kit/decoration/enumerable_extend.rb +9 -0
- data/lib/r_kit/decoration.rb +13 -6
- data/lib/r_kit/dsl/base/local_params.rb +6 -3
- data/lib/r_kit/dsl/base/thrust.rb +4 -2
- data/lib/r_kit/dsl/base.rb +14 -7
- data/lib/r_kit/dsl.rb +62 -11
- data/lib/r_kit/grid.rb +9 -8
- data/lib/r_kit/pagination/base/page.rb +1 -1
- data/lib/r_kit/pagination/base.rb +5 -24
- data/lib/r_kit/pagination/dsl.rb +15 -0
- data/lib/r_kit/pagination.rb +8 -5
- data/lib/r_kit/struct/safe_struct.rb +3 -0
- data/lib/r_kit/struct.rb +4 -2
- data/lib/r_kit/utility/basic_object_extend.rb +5 -0
- data/lib/r_kit/utility/kernel_extend.rb +48 -8
- data/lib/r_kit/utility/module_extend.rb +22 -1
- data/lib/r_kit/utility/simple_delegator_extend.rb +11 -2
- data/lib/r_kit/utility.rb +11 -1
- data/lib/r_kit/version.rb +1 -1
- metadata +12 -9
- data/lib/r_kit/active_record_utility/base/pool.rb +0 -29
- data/lib/r_kit/active_record_utility/base/publisher.rb +0 -28
- data/lib/r_kit/active_record_utility/base/tag.rb +0 -17
- data/lib/r_kit/active_record_utility/base.rb +0 -70
- data/lib/r_kit/decoration/active_record_extend.rb +0 -71
- data/lib/r_kit/pagination/active_record_extend.rb +0 -23
@@ -0,0 +1,121 @@
|
|
1
|
+
class RKit::Decoration::Dsl
|
2
|
+
act_as_a_dsl
|
3
|
+
|
4
|
+
name :decoration_dsl
|
5
|
+
method :acts_as_decorables
|
6
|
+
domain ActiveRecord::Base
|
7
|
+
|
8
|
+
|
9
|
+
params ->(from = nil, &block){}
|
10
|
+
|
11
|
+
methods :class do
|
12
|
+
|
13
|
+
@decorator_class = RKit::Decoration::Class.new self,
|
14
|
+
from: decoration_dsl.params.from,
|
15
|
+
&decoration_dsl.params.block
|
16
|
+
|
17
|
+
def decorator_class
|
18
|
+
@decorator_class
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: this couls move in "ennumerable", cause if the AR::relation is mapped into an array
|
22
|
+
# or if we create an array with decorables objects in it
|
23
|
+
# this will fail
|
24
|
+
# --
|
25
|
+
# in addition, make a "safe_decorate" for collections, wich will decorate if respond_to_decorate,
|
26
|
+
# and will not raise error
|
27
|
+
# TODO: act as paginable can not be used, because of decoration (implicit here)
|
28
|
+
# decorated paginated collection still work fine
|
29
|
+
# but non paginated collection, becomes dumb arrays
|
30
|
+
# def decorate view_context: nil
|
31
|
+
# all.map{ |record| record.decorate view_context: view_context }
|
32
|
+
# end
|
33
|
+
|
34
|
+
def decorate **options
|
35
|
+
RKit::Decoration::Collection.new all, **options
|
36
|
+
end
|
37
|
+
|
38
|
+
def decorated?() false end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
methods :instance do
|
44
|
+
|
45
|
+
def decorate **options
|
46
|
+
__class__.decorator_class.new self, **options
|
47
|
+
end
|
48
|
+
|
49
|
+
def decorated?() false end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# attr_accessor :decorator_klass
|
58
|
+
#
|
59
|
+
# def acts_as_decorables base = nil, &block
|
60
|
+
# define_decorator base || block
|
61
|
+
# define_instance_methods
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# # TODO: all the methods below this comment should be private, even more, they should be in a "decorator_finder_creator_definer", and not included in active_record. SRP guys !
|
65
|
+
# def define_decorator arg
|
66
|
+
# @decorator_klass = decorator_klass_from arg
|
67
|
+
# @decorator_klass
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
#
|
71
|
+
# def decorator_klass_from arg
|
72
|
+
# send "decorator_klass_from_#{ arg.class.name.underscore }", arg
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
# def decorator_klass_from_nil_class *args
|
76
|
+
# decorator_klass_from "#{ name }Decorator".constantize
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# def decorator_klass_from_class base
|
80
|
+
# if base <=> RKit::Decoration::Base
|
81
|
+
# base
|
82
|
+
# else
|
83
|
+
# base.tap do |base|
|
84
|
+
# base.send :include, Module.new{ include refine(RKit::Decoration::Base){} }
|
85
|
+
# base.extend Module.new{ include refine(RKit::Decoration::Base.singleton_class){} }
|
86
|
+
# base.instance_variable_set "@decorated_klass", self
|
87
|
+
# base.class_eval{ alias :"#{ decorated_klass.demodulize.underscore }" :__getobj__ }
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# def decorator_klass_from_module mod
|
93
|
+
# namespace = (mod.name.deconstantize.presence || 'Object').constantize
|
94
|
+
# const_name = mod.name.demodulize
|
95
|
+
#
|
96
|
+
# namespace.send :remove_const, const_name
|
97
|
+
# namespace.const_set const_name, RKit::Decoration::Class.new(self){ include mod }
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# def decorator_klass_from_proc block
|
101
|
+
# (name.deconstantize.presence || 'Object')
|
102
|
+
# .constantize
|
103
|
+
# .const_set "#{ name.demodulize }Decorator", RKit::Decoration::Class.new(self, &block)
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
# # TODO: this couls move in "ennumerable", cause if the AR::relation is mapped into an array
|
107
|
+
# # or if we create an array with decorables objects in it
|
108
|
+
# # this will fail
|
109
|
+
# # --
|
110
|
+
# # in addition, make a "safe_decorate" for collections, wich will decorate if respond_to_decorate,
|
111
|
+
# # and will not raise error
|
112
|
+
# def decorate view_context: nil
|
113
|
+
# all.map{ |record| record.decorate view_context: view_context }
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
#
|
117
|
+
# def define_instance_methods
|
118
|
+
# define_method 'decorate' do |view_context: nil|
|
119
|
+
# self.class.decorator_klass.new self, view_context: view_context
|
120
|
+
# end
|
121
|
+
# end
|
data/lib/r_kit/decoration.rb
CHANGED
@@ -5,15 +5,22 @@ class RKit::Decoration
|
|
5
5
|
# and if not, we do not require the "view_context" (well, we could not, I think)
|
6
6
|
# (the only case is if the user define a block elswhere than in the view or in the controller, and use it)
|
7
7
|
# (but this case will fail today as well, I think)
|
8
|
-
|
8
|
+
# -> pb w/ backtrace in console (Screencast.limit(5).decorate.map{|x|x} -> infinite loop)
|
9
|
+
dependency :backtrace,
|
10
|
+
:dsl,
|
11
|
+
:utility
|
9
12
|
|
10
13
|
|
11
|
-
load_path __FILE__,
|
12
|
-
|
14
|
+
load_path __FILE__,
|
15
|
+
'base',
|
16
|
+
'base/collection',
|
17
|
+
'base/object',
|
18
|
+
'class',
|
19
|
+
'dsl',
|
20
|
+
'enumerable_extend'
|
13
21
|
|
14
|
-
load_path __FILE__, 'action_view_base_extend
|
15
|
-
load_path __FILE__, 'active_record_extend.rb'
|
22
|
+
load_path __FILE__, 'action_view_base_extend', if: :implicit_decoration
|
16
23
|
|
17
24
|
|
18
|
-
config :
|
25
|
+
config :implicit_decoration, true
|
19
26
|
end
|
@@ -5,9 +5,12 @@ module RKit::Dsl::Base::LocalParams
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def method_missing method_name, *args, &block
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
case method_name
|
9
|
+
when *persisting_binding.eval("local_variables")
|
10
|
+
persisting_binding.eval method_name.to_s
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
11
14
|
end
|
12
15
|
|
13
16
|
end
|
@@ -24,7 +24,7 @@ class RKit::Dsl::Base
|
|
24
24
|
end
|
25
25
|
|
26
26
|
@base.send :define_singleton_method, @method do
|
27
|
-
|
27
|
+
RKit::Dsl::Base.dsls[name]
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -53,7 +53,9 @@ class RKit::Dsl::Base
|
|
53
53
|
|
54
54
|
instance_eval &send(name).methods[:class]
|
55
55
|
class_eval &send(name).methods[:instance]
|
56
|
-
|
56
|
+
if respond_to?(:acts_as_decorables?) && acts_as_decorables?
|
57
|
+
decorator_class.class_eval &send(name).methods[:decorator]
|
58
|
+
end
|
57
59
|
|
58
60
|
true
|
59
61
|
end
|
data/lib/r_kit/dsl/base.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
class RKit::Dsl::Base
|
2
2
|
|
3
|
-
|
3
|
+
@dsls = Hash.new{ |hash, key| hash[key] = Array.new }
|
4
4
|
def self.dsls
|
5
|
-
|
5
|
+
@dsls
|
6
6
|
end
|
7
|
+
::DSLS = @dsls
|
8
|
+
|
7
9
|
|
8
10
|
attr_accessor :base
|
9
11
|
|
@@ -19,6 +21,7 @@ class RKit::Dsl::Base
|
|
19
21
|
end
|
20
22
|
|
21
23
|
|
24
|
+
# TODO: vérifier l'unicité du "name"
|
22
25
|
def name name
|
23
26
|
@name = name
|
24
27
|
end
|
@@ -31,12 +34,16 @@ class RKit::Dsl::Base
|
|
31
34
|
def domain domain
|
32
35
|
raise DslDefinitionError.new(@base) if [@name, @method].none?
|
33
36
|
|
34
|
-
@domain
|
37
|
+
@domain ||= domain
|
38
|
+
|
39
|
+
shadow :domain do |shadow_self|
|
40
|
+
shadow_self.instance_variable_set "@domain", domain
|
35
41
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
42
|
+
thrust_dsl!
|
43
|
+
thrust_dsl_interface!
|
44
|
+
thrust_dsl_options!
|
45
|
+
thrust_dsl_extend!
|
46
|
+
end
|
40
47
|
end
|
41
48
|
|
42
49
|
|
data/lib/r_kit/dsl.rb
CHANGED
@@ -2,20 +2,71 @@ class RKit::Dsl
|
|
2
2
|
|
3
3
|
dependency :struct
|
4
4
|
|
5
|
-
load_path __FILE__,
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
load_path __FILE__,
|
6
|
+
'base',
|
7
|
+
'base/local_params',
|
8
|
+
'base/params',
|
9
|
+
'base/readonly'
|
10
10
|
|
11
|
-
load_path __FILE__, '
|
12
|
-
load_path __FILE__, 'dsl_standard_error.rb'
|
13
|
-
load_path __FILE__, 'no_lambda_error.rb'
|
11
|
+
load_path __FILE__, 'base/thrust', priority: 1
|
14
12
|
|
15
|
-
load_path __FILE__,
|
16
|
-
|
13
|
+
load_path __FILE__,
|
14
|
+
'dsl_definition_error',
|
15
|
+
'dsl_standard_error',
|
16
|
+
'no_lambda_error'
|
17
17
|
|
18
|
+
load_path __FILE__,
|
19
|
+
'dsl_extend',
|
20
|
+
'module_extend'
|
18
21
|
|
19
|
-
|
22
|
+
|
23
|
+
|
24
|
+
# TODO: Handle dsl inheritance
|
25
|
+
# class X; acts_as_a_dsl; restricted do ... end; end
|
26
|
+
# class Y < X; name+method+domain end
|
27
|
+
# and allow to use 'super'
|
28
|
+
# ->
|
29
|
+
# this can be achieved defining 'inerited' on dsl_extend (not 'self.inherited')
|
30
|
+
# at this point, we create the @_dsl with a copy of the previous one, except 'name' 'method'
|
31
|
+
# pb is for 'domain', wich is normally the trigger to thrust
|
32
|
+
# ->
|
33
|
+
# and we need to also handle the 'domain' on the parent class
|
34
|
+
# on that, it need not trigger the 'thrust'
|
35
|
+
|
36
|
+
# TODO: semi-linked to inheritance, allow to define methods via multiple blocks
|
37
|
+
# so if a block is already define, just add the new one to the old one
|
38
|
+
# TODO: also allow to 'override' completely the old block declaration
|
39
|
+
# (maybe 'methods instance: :override do ... end')
|
40
|
+
|
41
|
+
# TODO: Handle correctly the possibility to add the dsl in other domains
|
42
|
+
# today, it's done via "shadowing" the @domain
|
43
|
+
|
44
|
+
# TODO: The "readonly" mode should be the default mode for everyone,
|
45
|
+
# except (of course) the dsl_declaration class (the class that used 'act_as_dsl')
|
46
|
+
# -> to do that, either, interchage all the methods (painfull)
|
47
|
+
# -> or, try to replace the const_name when 'act_as_dsl' is used (pb when re-opening the class ?)
|
48
|
+
|
49
|
+
# TODO: rkit: on dsl, I lac of a callback when dsl is put in another class
|
50
|
+
# (like a 'def self.decorated(decorator)' for example).
|
51
|
+
# I know I can put the code in 'class methods',
|
52
|
+
# but I may also want a specific callback from the calling class ?
|
53
|
+
# (maybe smthng like "before_acts_as_X + after_act_as_X") ("self.yanked" "self.X-ed")
|
54
|
+
|
55
|
+
# TODO: make smthing to define methods on the "domain" level
|
56
|
+
# for example, in the series dsl, I could define a method "per_page" in all the domain, that would return '[]'
|
57
|
+
# and when dsl is added, that would return an array with all the series
|
58
|
+
# --> before doing that, find a real use case, it may be a duplication of 'can_as_as_X?'
|
59
|
+
|
60
|
+
# TODO: this service could be totaly rework
|
61
|
+
# instead of actually adding behavior in classes
|
62
|
+
# it only create a Delegator object, with the behavior inside it
|
63
|
+
# then, it delegates all methods defined by the 'dsl' to this Delegator object
|
64
|
+
# --> maybe this is the idea behind the 'context/puppet' service
|
65
|
+
# --> and may be not good for DSL
|
66
|
+
# acts_as_dsl -> will add 'sinpleDelegator' to the ancestors -> then -> name(?)+method+domain
|
67
|
+
# then -> def self.clas_method, -> def instance_method
|
68
|
+
# then, in host class -> act_as_x -> define "@X", X_delegator(self), delegate *X.methods, to: @X
|
69
|
+
|
70
|
+
# load_path __FILE__, 'test'
|
20
71
|
|
21
72
|
end
|
data/lib/r_kit/grid.rb
CHANGED
@@ -3,14 +3,15 @@ class RKit::Grid
|
|
3
3
|
with_engine __FILE__
|
4
4
|
with_sprockets __FILE__
|
5
5
|
|
6
|
-
load_path __FILE__,
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
load_path __FILE__, '
|
6
|
+
load_path __FILE__,
|
7
|
+
'base',
|
8
|
+
'base/grid',
|
9
|
+
'base/grid_col',
|
10
|
+
'base/grid_row',
|
11
|
+
'binding'
|
12
|
+
|
13
|
+
load_path __FILE__, 'enumerable_extend', if: :enumerable_extend
|
14
|
+
load_path __FILE__, 'kernel_extend', if: :kernel_extend
|
14
15
|
|
15
16
|
|
16
17
|
config :extends, true
|
@@ -1,32 +1,15 @@
|
|
1
|
-
class RKit::Pagination::Base <
|
2
|
-
|
3
|
-
# TODO: use collection delegator newly done in 'strcut'
|
4
|
-
|
5
|
-
alias :collection :__getobj__
|
6
|
-
alias :collection= :__setobj__
|
1
|
+
class RKit::Pagination::Base < CollectionDelegator
|
7
2
|
|
8
3
|
attr_accessor :page, :per_page
|
9
4
|
|
10
|
-
# TODO: should raise an error if has "limit" or "offset" values
|
5
|
+
# TODO: should raise (todo custom error) an error if has "limit" or "offset" values
|
11
6
|
def initialize collection, **options
|
12
7
|
raise if collection.values.keys.include_one? [:limit, :offset]
|
13
8
|
|
14
9
|
super collection
|
15
10
|
|
16
|
-
@page = options
|
17
|
-
@per_page = options
|
18
|
-
end
|
19
|
-
|
20
|
-
def method_missing method_name, *args, &block
|
21
|
-
closure = super
|
22
|
-
|
23
|
-
case closure
|
24
|
-
when collection.class
|
25
|
-
self.collection = closure
|
26
|
-
self
|
27
|
-
else
|
28
|
-
closure
|
29
|
-
end
|
11
|
+
@page = options[:page] || 1
|
12
|
+
@per_page = options[:per_page] || RKit::Pagination.config.per_page[collection.klass]
|
30
13
|
end
|
31
14
|
|
32
15
|
tap_attr_accessor :page
|
@@ -47,8 +30,6 @@ class RKit::Pagination::Base < SimpleDelegator
|
|
47
30
|
end
|
48
31
|
|
49
32
|
|
50
|
-
include Enumerable
|
51
|
-
|
52
33
|
def limited_collection
|
53
34
|
collection
|
54
35
|
.limit(per_page)
|
@@ -79,7 +60,7 @@ class RKit::Pagination::Base < SimpleDelegator
|
|
79
60
|
|
80
61
|
|
81
62
|
|
82
|
-
|
63
|
+
RKit::Decoration::Dsl.domain self
|
83
64
|
acts_as_decorables do
|
84
65
|
|
85
66
|
include Enumerable
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RKit::Pagination::Dsl
|
2
|
+
act_as_a_dsl
|
3
|
+
|
4
|
+
name :pagination_dsl
|
5
|
+
method :acts_as_paginables
|
6
|
+
domain ActiveRecord::Base
|
7
|
+
|
8
|
+
methods :class do
|
9
|
+
|
10
|
+
def paginate page: nil, per_page: nil
|
11
|
+
RKit::Pagination::Base.new(all, page: page, per_page: per_page)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/lib/r_kit/pagination.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
class RKit::Pagination
|
2
2
|
|
3
|
-
dependency :decoration
|
4
|
-
|
3
|
+
dependency :decoration,
|
4
|
+
:dsl,
|
5
|
+
:struct,
|
6
|
+
:utility
|
5
7
|
|
6
8
|
|
7
|
-
load_path __FILE__,
|
8
|
-
|
9
|
+
load_path __FILE__,
|
10
|
+
'base',
|
11
|
+
'base/page',
|
12
|
+
'dsl'
|
9
13
|
|
10
|
-
load_path __FILE__, 'active_record_extend.rb'
|
11
14
|
|
12
15
|
# TODO: add a "wrap" option to the config method, that will be used like this
|
13
16
|
# config :per_page, 16, wrap: ->(value){ Hash.new(value) }
|
data/lib/r_kit/struct.rb
CHANGED
@@ -1,19 +1,59 @@
|
|
1
1
|
module Kernel
|
2
2
|
|
3
|
-
def
|
4
|
-
|
3
|
+
def running_script
|
4
|
+
"#{ File.basename($0) } #{ ARGV.join " " }"
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
(
|
7
|
+
def running_script? script
|
8
|
+
Regexp.new(script) =~ running_script
|
9
9
|
end
|
10
10
|
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
# TODO: think about a 'else' method => x.then{}.else{}
|
13
|
+
# it could be done, when the 'then' return 'nil', we define an instance var in the singleton (possible on nil ?)
|
14
|
+
# then reuse that into the else, as an arg to the block
|
15
|
+
def then **options, &block
|
16
|
+
if self && conditionnal_statement(options)
|
17
|
+
block.call(self)
|
18
|
+
else
|
19
|
+
self
|
20
|
+
end
|
14
21
|
end
|
15
22
|
|
16
|
-
def
|
17
|
-
|
23
|
+
def conditionnal_statement **options
|
24
|
+
options.slice(:if, :unless).reduce(true) do |continue, (statement, method_name)|
|
25
|
+
continue && send(method_name).tap do |closure|
|
26
|
+
case statement
|
27
|
+
when :if
|
28
|
+
!!closure
|
29
|
+
when :unless
|
30
|
+
!closure
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
def shadow *names, &block
|
39
|
+
saved_state = names.reduce({}) do |saved_state, name|
|
40
|
+
saved_state[name] = instance_variable_get name.ivar
|
41
|
+
saved_state
|
42
|
+
end
|
43
|
+
|
44
|
+
closure = block.call(self)
|
45
|
+
|
46
|
+
names.each do |name|
|
47
|
+
instance_variable_set name.ivar, saved_state[name]
|
48
|
+
end
|
49
|
+
|
50
|
+
closure
|
18
51
|
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
def dont_respond_to? *args, &block
|
56
|
+
!respond_to? *args, &block
|
57
|
+
end
|
58
|
+
|
19
59
|
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
class Module
|
2
2
|
|
3
|
-
delegate :
|
3
|
+
delegate :deconstantize, :demodulize, :underscore,
|
4
4
|
to: :name
|
5
5
|
|
6
|
+
def namespace
|
7
|
+
(deconstantize.presence || 'Object').constantize
|
8
|
+
end
|
9
|
+
|
10
|
+
|
6
11
|
|
7
12
|
alias :basic_attr_reader :attr_reader
|
8
13
|
def attr_reader *names, default: nil
|
@@ -40,4 +45,20 @@ class Module
|
|
40
45
|
def singleton_attr_reader *args, **options
|
41
46
|
singleton_class.send :attr_reader, *args, **options
|
42
47
|
end
|
48
|
+
|
49
|
+
|
50
|
+
alias :basic_const_get :const_get
|
51
|
+
def const_get name, *args, default: nil
|
52
|
+
if default && !const_defined?(name)
|
53
|
+
name.safe_constantize ||
|
54
|
+
const_set(name, default)
|
55
|
+
else
|
56
|
+
basic_const_get name, *args
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def const_replace name, value
|
61
|
+
remove_const name
|
62
|
+
const_set name, value
|
63
|
+
end
|
43
64
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
class SimpleDelegator
|
2
2
|
|
3
|
-
# TODO:
|
4
|
-
|
3
|
+
# TODO: add delegation for "inspect" to getobj
|
4
|
+
|
5
|
+
# TODO: allow singleton methods to be delegated (note, can not override them)
|
6
|
+
# TODO: by defining a method missing on singleton_class
|
7
|
+
# TODO: or better (?), defining a delegator for the singleton_class
|
8
|
+
|
5
9
|
|
6
10
|
def self.getobj_attr_reader *names
|
7
11
|
names.each do |name|
|
@@ -9,4 +13,9 @@ class SimpleDelegator
|
|
9
13
|
end
|
10
14
|
end
|
11
15
|
|
16
|
+
|
17
|
+
def === object
|
18
|
+
self == object || __getobj__ == object
|
19
|
+
end
|
20
|
+
|
12
21
|
end
|
data/lib/r_kit/utility.rb
CHANGED
@@ -9,11 +9,21 @@ class RKit::Utility
|
|
9
9
|
|
10
10
|
UTILITIES.each do |utility|
|
11
11
|
alias_config "#{ utility }_extend", :extends
|
12
|
-
load_path __FILE__, "#{ utility }_extend
|
12
|
+
load_path __FILE__, "#{ utility }_extend", if: "#{ utility }_extend"
|
13
13
|
end
|
14
14
|
|
15
15
|
# TODO: class_extend: to_module, ancestor=
|
16
16
|
# TODO: module_extend: to_class
|
17
17
|
# TODO: enumerable_extend/or-array_extend: with_indifferent_access
|
18
18
|
# TODO: get back some code from hash_extend && array_extend gems
|
19
|
+
|
20
|
+
|
21
|
+
# TODO: Today, the files are structured by class they extend, not by feature
|
22
|
+
# TODO: we first encounter a feature multi class with the 'then' menthod (kernel, nil, false)
|
23
|
+
# -> not true anymore for 'then', it's only in kernel now
|
24
|
+
# TODO, maybe, we should create a module/feature, then include the modules into corresponding classes
|
25
|
+
# TODO: and, this has the advantage to be more readable on a RKit::CONFIG point of view (POV)
|
26
|
+
|
27
|
+
# TODO: in Module: method "override", qui alias l'ancienne méthode, et redéfinit la nouvelle
|
28
|
+
# TODO: ou, qui crée un module, et le prepend, pour utiliser "super"
|
19
29
|
end
|
data/lib/r_kit/version.rb
CHANGED