r_kit 0.4.2 → 0.4.3
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 +31 -4
- data/lib/r_kit/active_record_utility/base/pool.rb +29 -0
- data/lib/r_kit/active_record_utility/base/publisher.rb +28 -0
- data/lib/r_kit/active_record_utility/base/series.rb +141 -0
- data/lib/r_kit/active_record_utility/base/tag.rb +17 -0
- data/lib/r_kit/active_record_utility/base.rb +70 -0
- data/lib/r_kit/active_record_utility/database_schema_error.rb +4 -4
- data/lib/r_kit/active_record_utility.rb +12 -3
- data/lib/r_kit/backtrace.rb +4 -0
- data/lib/r_kit/core/loader/dependency.rb +26 -0
- data/lib/r_kit/core/loader/load_path.rb +58 -0
- data/lib/r_kit/core/loader.rb +3 -89
- data/lib/r_kit/core.rb +10 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/components/btn.scss +8 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/components/pagination.scss +3 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/components.scss +1 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/variables/colors.scss +1 -1
- data/lib/r_kit/css.rb +12 -5
- data/lib/r_kit/{decorator → decoration}/action_view_base_extend.rb +2 -2
- data/lib/r_kit/{decorator → decoration}/active_record_extend.rb +16 -9
- data/lib/r_kit/decoration/base.rb +35 -0
- data/lib/r_kit/decoration/class.rb +22 -0
- data/lib/r_kit/decoration.rb +19 -0
- data/lib/r_kit/dsl/base/local_params.rb +13 -0
- data/lib/r_kit/dsl/base/params.rb +38 -0
- data/lib/r_kit/dsl/base/readonly.rb +16 -0
- data/lib/r_kit/dsl/base/thrust.rb +67 -0
- data/lib/r_kit/dsl/base.rb +68 -0
- data/lib/r_kit/dsl/dsl_definition_error.rb +10 -0
- data/lib/r_kit/dsl/dsl_extend.rb +10 -0
- data/lib/r_kit/dsl/dsl_standard_error.rb +9 -0
- data/lib/r_kit/dsl/module_extend.rb +22 -0
- data/lib/r_kit/dsl/no_lambda_error.rb +10 -0
- data/lib/r_kit/dsl.rb +21 -0
- data/lib/r_kit/pagination/active_record_extend.rb +23 -0
- data/lib/r_kit/pagination/base/page.rb +53 -0
- data/lib/r_kit/pagination/base.rb +153 -0
- data/lib/r_kit/pagination.rb +23 -0
- data/lib/r_kit/struct/collection_delegator.rb +24 -0
- data/lib/r_kit/struct/safe_struct.rb +35 -0
- data/lib/r_kit/struct/strong_struct.rb +17 -0
- data/lib/r_kit/struct.rb +8 -0
- data/lib/r_kit/utility/active_record_extend.rb +7 -0
- data/lib/r_kit/utility/array_extend.rb +10 -1
- data/lib/r_kit/utility/module_extend.rb +43 -0
- data/lib/r_kit/utility/object_extend.rb +33 -0
- data/lib/r_kit/utility/proc_extend.rb +41 -0
- data/lib/r_kit/utility/simple_delegator_extend.rb +12 -0
- data/lib/r_kit/utility/string_extend.rb +20 -0
- data/lib/r_kit/utility/symbol_extend.rb +1 -1
- data/lib/r_kit/utility.rb +4 -1
- data/lib/r_kit/version.rb +1 -1
- data/lib/r_kit.rb +9 -0
- data/r_kit.gemspec +1 -1
- metadata +41 -9
- data/lib/r_kit/active_record_utility/utility/tag.rb +0 -14
- data/lib/r_kit/active_record_utility/utility.rb +0 -53
- data/lib/r_kit/decorator/base.rb +0 -34
- data/lib/r_kit/decorator.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26da20a8c0d5ca239f0b25a5bbd39a3f87a3a115
|
4
|
+
data.tar.gz: 20d9c76c01b2a7fbde0642e280c5ccbdf18fc77a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9eb566e05f243773a8b3e3b5959510b3ea8ca9ca901843d22d19ec00200d984c198c571bfffdfe0b4c9ead1144e88d46ad00b3dd655b55778275e7c6e446c8fc
|
7
|
+
data.tar.gz: 24aa528db16c96d5b1cb6b8bc5989c498a4a3b60ab05775cfc231cbac63196f3fe72894ec47411d576f6c34e5293882eb096fc833f4edae86962b2f4c57b5fb2
|
@@ -1,18 +1,45 @@
|
|
1
1
|
module RKit::ActiveRecordUtility::ActiveRecordExtend
|
2
2
|
|
3
3
|
RKit::ActiveRecordUtility::UTILITIES.each do |utility, method_name|
|
4
|
-
|
5
|
-
|
6
|
-
RKit::ActiveRecordUtility::Utility.const_get(utility.classify).new(self, method: __method__).interfere
|
4
|
+
define_method method_name, ->(*args) do
|
5
|
+
RKit::ActiveRecordUtility::Base.const_get(utility.classify).new(self, method_name: __method__).interfere *args
|
7
6
|
end
|
7
|
+
end
|
8
8
|
|
9
|
+
|
10
|
+
def interferences_options_set utility, **options
|
11
|
+
instance_variable_set "@_active_record_utilities_self", utility
|
12
|
+
instance_variable_set "@_active_record_utilities_#{ utility }_options", options
|
9
13
|
end
|
10
14
|
|
15
|
+
def interferences_options_get utility = @_active_record_utilities_self
|
16
|
+
instance_variable_get "@_active_record_utilities_#{ utility }_options"
|
17
|
+
end
|
18
|
+
|
19
|
+
|
11
20
|
def interfered? utility
|
12
|
-
RKit::ActiveRecordUtility::
|
21
|
+
RKit::ActiveRecordUtility::Base.const_get(utility.classify).interfered? self
|
13
22
|
rescue NameError
|
14
23
|
false
|
15
24
|
end
|
16
25
|
|
26
|
+
|
27
|
+
def collection_finder **options
|
28
|
+
collection = all
|
29
|
+
collection = collection.pool options[:pool] if interfered? :pool
|
30
|
+
collection = collection.published.publication_desc if interfered? :publisher
|
31
|
+
collection = collection.series options[:series] if interfered? :series
|
32
|
+
collection
|
33
|
+
end
|
34
|
+
|
35
|
+
def instance_finder **options
|
36
|
+
if interfered? :tag
|
37
|
+
tagged options[:tag]
|
38
|
+
else
|
39
|
+
find_by id: options[:id]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
17
44
|
ActiveRecord::Base.extend self
|
18
45
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class RKit::ActiveRecordUtility::Base::Pool < RKit::ActiveRecordUtility::Base
|
2
|
+
|
3
|
+
instance_interferences do
|
4
|
+
inclusion_in = interferences_options_get.fetch :in
|
5
|
+
|
6
|
+
validates_presence_of :pool
|
7
|
+
validates_inclusion_of :pool, in: inclusion_in if inclusion_in
|
8
|
+
|
9
|
+
scope :pool, ->(pool){ pool && where(pool: pool) }
|
10
|
+
scope :pools, ->{ group(:pool).pluck(:pool) }
|
11
|
+
end
|
12
|
+
|
13
|
+
decorator_interferences do
|
14
|
+
def pool_url
|
15
|
+
view.url_for [__class__, pool: pool]
|
16
|
+
end
|
17
|
+
|
18
|
+
def link_to_pool
|
19
|
+
view.link_to pool, pool_url, class: :btn
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def can_interfere?
|
25
|
+
base.table_exists? &&
|
26
|
+
base.column_names.include?("pool") &&
|
27
|
+
base.columns_hash["pool"].type == :string
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class RKit::ActiveRecordUtility::Base::Publisher < RKit::ActiveRecordUtility::Base
|
2
|
+
|
3
|
+
instance_interferences do
|
4
|
+
before_validation do
|
5
|
+
self.published_at = Time.now if !published_at && published
|
6
|
+
end
|
7
|
+
|
8
|
+
validates_presence_of :published_at, if: :published
|
9
|
+
|
10
|
+
scope :published, ->{ where(published: true) }
|
11
|
+
scope :publication_asc, ->{ order("published_at ASC") }
|
12
|
+
scope :publication_desc, ->{ order("published_at DESC") }
|
13
|
+
end
|
14
|
+
|
15
|
+
decorator_interferences do
|
16
|
+
def published_at
|
17
|
+
super().strftime "%a %e %b %Y"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def can_interfere?
|
23
|
+
base.table_exists? &&
|
24
|
+
base.column_names.include_all?(["published", "published_at"]) &&
|
25
|
+
base.columns_hash["published"].type == :boolean &&
|
26
|
+
base.columns_hash["published_at"].type == :datetime
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
class RKit::ActiveRecordUtility::Base::Series < RKit::ActiveRecordUtility::Base
|
2
|
+
|
3
|
+
instance_interferences do
|
4
|
+
has_one :followed, class_name: name, foreign_key: "following_id"
|
5
|
+
belongs_to :following, class_name: name
|
6
|
+
|
7
|
+
before_validation if: :following_id_changed? do
|
8
|
+
self.title ||= following.title if __class__.column_exists? "title"
|
9
|
+
self.series = following.series.name
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
# TODO: after save, if series change, all obj in series change
|
16
|
+
|
17
|
+
# TODO: we can add a conditionnal validation on 'inclusion_in' (like pool)
|
18
|
+
|
19
|
+
# TODO: validates presence of serie also on the followed record
|
20
|
+
|
21
|
+
# TODO: validates a record can only have one follower (or is it hadled by the "has_one" relation directly ?)
|
22
|
+
|
23
|
+
validates_presence_of :series, if: :following
|
24
|
+
validates_uniqueness_of :following_id, if: :following
|
25
|
+
|
26
|
+
scope :series, ->(series){ series && where(series: series) }
|
27
|
+
|
28
|
+
# TODO: adapter le scope pour intégrer les published (si interfered)
|
29
|
+
# je laisse en commentaire parceque j'aime pas le nom du scope,
|
30
|
+
# et j'ai pas d'idée là maintenant (à part 'pilotes', ou 'firsts')
|
31
|
+
# scope :firsts_of_series, ->{ where(following_id: nil) }
|
32
|
+
|
33
|
+
# TODO: scope pour l'ordre dans une serie (pour le decorator pagination_tag)
|
34
|
+
|
35
|
+
@@_active_record_utilities_series = {}
|
36
|
+
end
|
37
|
+
|
38
|
+
class_interferences do
|
39
|
+
def series
|
40
|
+
@@_active_record_utilities_series[read_attribute(:series)] ||= series_struct if read_attribute(:series)
|
41
|
+
# TODO: if series cg-hanges, or new element added, series must be re-calculated
|
42
|
+
# maybe pre-calc this in after save
|
43
|
+
end
|
44
|
+
|
45
|
+
def series_struct
|
46
|
+
OpenStruct.new.tap do |series_struct|
|
47
|
+
series_struct.name = read_attribute :series
|
48
|
+
series_struct.collection = __class__.series series_struct.name
|
49
|
+
series_struct.size = series_struct.collection.count
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def position_in_series
|
54
|
+
following ? following.send(__method__) + 1 : 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
decorator_interferences do
|
59
|
+
after_initialize do
|
60
|
+
# TODO: this can't stay this way, if "serie" is pre-calculated
|
61
|
+
# & shared accros instances & kept in memory (class variable)
|
62
|
+
|
63
|
+
# series.collection = series.collection.decorate if series
|
64
|
+
# TODO: infinite loop, need a "unless" on the after_init, or smthng even more smart
|
65
|
+
# ps: i'm not happy with this current decorate
|
66
|
+
end
|
67
|
+
|
68
|
+
def series_url
|
69
|
+
view.url_for [__class__, series: series.name]
|
70
|
+
end
|
71
|
+
|
72
|
+
def link_to_series
|
73
|
+
view.link_to series.name, series_url, class: :btn
|
74
|
+
end
|
75
|
+
|
76
|
+
if decorated_klass.columns_hash["title"]
|
77
|
+
# I don't get this "showcase thing", we can delete that and just look into the view for the params
|
78
|
+
# Or in the collection, to see if the scope is applied (second solution is better)
|
79
|
+
def series_title
|
80
|
+
"#{ __getobj__.title } <small><i class='no-warp'>(vol #{ position_in_series })</i></small>".html_safe
|
81
|
+
end
|
82
|
+
|
83
|
+
def showcase_title
|
84
|
+
"#{ __getobj__.title } <small><i class='no-warp'>(#{ series.size } vols)</i></small>".html_safe
|
85
|
+
end
|
86
|
+
|
87
|
+
def title options = {}
|
88
|
+
if series and false # and showcase
|
89
|
+
showcase_title
|
90
|
+
elsif series
|
91
|
+
series_title
|
92
|
+
else
|
93
|
+
super()
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# TODO: put default locales keys ("vol" is hard coded here) in cluster
|
99
|
+
# same for the 'title' methods before
|
100
|
+
# TODO: the "disabled" link for self doesn't work yet
|
101
|
+
# in fact, the collection does not use the "self" object, so the singleton_class is lost
|
102
|
+
def pagination_tag
|
103
|
+
disable_pagination_link self
|
104
|
+
series.collection.decorate.map(&:pagination_link_to).reduce(:safe_concat)
|
105
|
+
end
|
106
|
+
|
107
|
+
def pagination_link_to
|
108
|
+
view.link_to "vol #{ position_in_series }", self, class: :btn
|
109
|
+
end
|
110
|
+
|
111
|
+
def disabled_pagination_link_to
|
112
|
+
view.content_tag :span, "vol #{ position_in_series }", class: :'btn-disabled'
|
113
|
+
end
|
114
|
+
|
115
|
+
def disable_pagination_link seriable_instance
|
116
|
+
class << seriable_instance
|
117
|
+
alias :pagination_link_to :disabled_pagination_link_to
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
# TODO: put default locales keys (:previous, :next) in cluster
|
123
|
+
def navigation_tag
|
124
|
+
view.content_tag :p do
|
125
|
+
safe_buffer = ActiveSupport::SafeBuffer.new
|
126
|
+
safe_buffer += view.link_to view.t(:previous), following, class: :btn if following
|
127
|
+
safe_buffer += " "
|
128
|
+
safe_buffer += view.link_to view.t(:next), followed, class: :btn if followed
|
129
|
+
safe_buffer
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
def can_interfere?
|
136
|
+
base.table_exists? &&
|
137
|
+
base.column_names.include_all?(["following_id", "series"]) &&
|
138
|
+
base.columns_hash["following_id"].type == :integer &&
|
139
|
+
base.columns_hash["series"].type == :string
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class RKit::ActiveRecordUtility::Base::Tag < RKit::ActiveRecordUtility::Base
|
2
|
+
|
3
|
+
instance_interferences do
|
4
|
+
validates_presence_of :tag
|
5
|
+
validates_uniqueness_of :tag
|
6
|
+
|
7
|
+
def tagged(tag) find_by tag: tag end
|
8
|
+
end
|
9
|
+
|
10
|
+
class_interferences{ def to_param() tag end }
|
11
|
+
|
12
|
+
def can_interfere?
|
13
|
+
base.table_exists? &&
|
14
|
+
base.column_names.include?("tag") &&
|
15
|
+
base.columns_hash["tag"].type == :string
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class RKit::ActiveRecordUtility::Base
|
2
|
+
|
3
|
+
attr_accessor :base, :method_name
|
4
|
+
|
5
|
+
def initialize base, method_name:;
|
6
|
+
@base = base
|
7
|
+
@method_name = method_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
__class__.demodulize.underscore
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def interfere *args
|
16
|
+
if can_interfere?
|
17
|
+
interfere! *args
|
18
|
+
interfered!
|
19
|
+
else
|
20
|
+
raise DatabaseSchemaError.new(base, method_name: method_name) unless running_script? /^rake db:/
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
# TODO: private/protected ?
|
26
|
+
def can_interfere?
|
27
|
+
raise NotImplementedError, 'Subclasses must implement this method'
|
28
|
+
end
|
29
|
+
|
30
|
+
def interfere! **options
|
31
|
+
base.interferences_options_set self, **options
|
32
|
+
|
33
|
+
base.instance_eval &instance_interferences
|
34
|
+
base.class_eval &class_interferences
|
35
|
+
base.decorator_klass.class_eval &decorator_interferences if base.decorator_klass
|
36
|
+
end
|
37
|
+
|
38
|
+
interferences = %i{instance class decorator}
|
39
|
+
interferences.each do |interference|
|
40
|
+
define_method "#{ interference }_interferences" do
|
41
|
+
__class__.send "#{ interference }_interferences_proc"
|
42
|
+
end
|
43
|
+
|
44
|
+
singleton_class.send :attr_reader, "#{ interference }_interferences_proc", default: proc{ Proc.new{} }
|
45
|
+
|
46
|
+
define_singleton_method "#{ interference }_interferences", ->(&block) do
|
47
|
+
instance_variable_set "@#{ interference }_interferences_proc", block
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def interfered!
|
53
|
+
__class__.interfered base
|
54
|
+
end
|
55
|
+
|
56
|
+
class << self
|
57
|
+
def interfered? base
|
58
|
+
@interfered.include? base
|
59
|
+
end
|
60
|
+
|
61
|
+
def interfered base
|
62
|
+
@interfered << base
|
63
|
+
end
|
64
|
+
|
65
|
+
def inherited subclass
|
66
|
+
subclass.instance_variable_set :@interfered, []
|
67
|
+
super
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class DatabaseSchemaError < StandardError
|
2
|
-
def initialize base,
|
2
|
+
def initialize base, method_name:;
|
3
3
|
super %Q{
|
4
|
-
WARNING - You tried to use the '#{
|
5
|
-
|
6
|
-
|
4
|
+
WARNING - You tried to use the '#{ method_name }' DSL on '#{ base }',
|
5
|
+
Your database is not ready for it yet,
|
6
|
+
You can refer to the 'RKit::ActiveRecordUtlity' documentation.
|
7
7
|
}
|
8
8
|
end
|
9
9
|
end
|
@@ -1,15 +1,24 @@
|
|
1
1
|
class RKit::ActiveRecordUtility
|
2
2
|
dependency :utilities
|
3
3
|
|
4
|
-
load_path __FILE__, '
|
4
|
+
load_path __FILE__, 'base.rb'
|
5
5
|
load_path __FILE__, 'database_schema_error.rb'
|
6
|
-
|
6
|
+
|
7
|
+
load_path __FILE__, 'active_record_extend.rb'
|
8
|
+
|
7
9
|
|
8
10
|
UTILITIES = {
|
11
|
+
pool: :acts_as_poolables,
|
12
|
+
publisher: :acts_as_publishables,
|
13
|
+
series: :acts_as_seriables,
|
9
14
|
tag: :acts_as_taggables,
|
10
15
|
}
|
11
16
|
|
17
|
+
|
18
|
+
config :all, true
|
19
|
+
|
12
20
|
UTILITIES.each do |utility, _|
|
13
|
-
|
21
|
+
alias_config utility, :all
|
22
|
+
load_path __FILE__, "base/#{ utility }.rb", if: utility
|
14
23
|
end
|
15
24
|
end
|
data/lib/r_kit/backtrace.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
class RKit::Backtrace
|
2
2
|
|
3
|
+
# TODO: continuation is problematic with views
|
4
|
+
# we may want to put a warning if the gem 'binding_of_caller' is not included
|
5
|
+
# or we could directly include the C enxtention, with permission of the owner of the gem
|
6
|
+
|
3
7
|
load_path __FILE__, 'kernel_extend.rb'
|
4
8
|
|
5
9
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Dependency
|
2
|
+
attr_accessor :base, :service
|
3
|
+
|
4
|
+
def initialize base, service:;
|
5
|
+
@base = base
|
6
|
+
@service = RKit.const_get(service.to_s.classify)
|
7
|
+
end
|
8
|
+
|
9
|
+
def should_load?
|
10
|
+
!service.loaded?
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO: The dependency warning msg should be in service object
|
14
|
+
def dependency!
|
15
|
+
warn %Q{
|
16
|
+
WARNING - #{ service.name } was implicitly loaded,
|
17
|
+
As a dependency for #{ base }.
|
18
|
+
You may want to load it explicitly.
|
19
|
+
}
|
20
|
+
service.load
|
21
|
+
end
|
22
|
+
|
23
|
+
def load!
|
24
|
+
dependency! if should_load?
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class LoadPath
|
2
|
+
attr_accessor :_base,
|
3
|
+
:file, :path, :priority, :conditions
|
4
|
+
|
5
|
+
def initialize base, file:, path:, priority: 1/0.0
|
6
|
+
@_base = base
|
7
|
+
|
8
|
+
@file = file
|
9
|
+
@path = path
|
10
|
+
@priority = priority
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def extname
|
15
|
+
File.extname(file)
|
16
|
+
end
|
17
|
+
|
18
|
+
def fullpath
|
19
|
+
file.chomp! File.extname(file)
|
20
|
+
File.expand_path(path, file)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def should_load?
|
25
|
+
conditions.inject(true) do |should_load, (statement, condition)|
|
26
|
+
should_load && exec_condition(statement, condition)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_path!
|
31
|
+
require fullpath
|
32
|
+
end
|
33
|
+
|
34
|
+
def load!
|
35
|
+
load_path! if should_load?
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def exec_condition statement, condition
|
40
|
+
condition = case condition
|
41
|
+
when Proc
|
42
|
+
condition.call _base::CONFIG
|
43
|
+
when Symbol, String
|
44
|
+
_base::CONFIG.send condition
|
45
|
+
end
|
46
|
+
|
47
|
+
exec_statement statement, condition
|
48
|
+
end
|
49
|
+
|
50
|
+
def exec_statement statement, condition
|
51
|
+
case statement
|
52
|
+
when :if
|
53
|
+
!!condition
|
54
|
+
when :unless
|
55
|
+
!condition
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/r_kit/core/loader.rb
CHANGED
@@ -28,15 +28,15 @@ class RKit::Core::Loader
|
|
28
28
|
end
|
29
29
|
|
30
30
|
|
31
|
-
def load_path file, path, options
|
32
|
-
load_path = LoadPath.new _base, file: file, path: path
|
31
|
+
def load_path file, path, **options
|
32
|
+
load_path = LoadPath.new _base, file: file, path: path, **options.slice(:priority)
|
33
33
|
load_path.conditions = options.slice :if, :unless
|
34
34
|
|
35
35
|
load_paths << load_path
|
36
36
|
end
|
37
37
|
|
38
38
|
def load_paths!
|
39
|
-
load_paths.each &:load!
|
39
|
+
load_paths.sort{ |a, b| a.priority <=> b.priority }.each &:load!
|
40
40
|
end
|
41
41
|
|
42
42
|
|
@@ -51,90 +51,4 @@ class RKit::Core::Loader
|
|
51
51
|
loaded!
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
class LoadPath
|
56
|
-
attr_accessor :_base,
|
57
|
-
:file, :path, :conditions
|
58
|
-
|
59
|
-
def initialize base, file:, path:;
|
60
|
-
@_base = base
|
61
|
-
|
62
|
-
@file = file
|
63
|
-
@path = path
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
def extname
|
68
|
-
File.extname(file)
|
69
|
-
end
|
70
|
-
|
71
|
-
def fullpath
|
72
|
-
file.chomp! File.extname(file)
|
73
|
-
File.expand_path(path, file)
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
def should_load?
|
78
|
-
conditions.inject(true) do |should_load, (statement, condition)|
|
79
|
-
should_load && exec_condition(statement, condition)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def load_path!
|
84
|
-
require fullpath
|
85
|
-
end
|
86
|
-
|
87
|
-
def load!
|
88
|
-
load_path! if should_load?
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
def exec_condition statement, condition
|
93
|
-
condition = case condition
|
94
|
-
when Proc
|
95
|
-
condition.call _base::CONFIG
|
96
|
-
when Symbol, String
|
97
|
-
_base::CONFIG.send condition
|
98
|
-
end
|
99
|
-
|
100
|
-
exec_statement statement, condition
|
101
|
-
end
|
102
|
-
|
103
|
-
def exec_statement statement, condition
|
104
|
-
case statement
|
105
|
-
when :if
|
106
|
-
!!condition
|
107
|
-
when :unless
|
108
|
-
!condition
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
class Dependency
|
115
|
-
attr_accessor :base, :service
|
116
|
-
|
117
|
-
def initialize base, service:;
|
118
|
-
@base = base
|
119
|
-
@service = RKit.const_get(service.to_s.classify)
|
120
|
-
end
|
121
|
-
|
122
|
-
def should_load?
|
123
|
-
!RKit::Core::Loader.class_variable_get(:@@loaded).include? @service.name
|
124
|
-
end
|
125
|
-
|
126
|
-
def dependency!
|
127
|
-
warn %Q{
|
128
|
-
WARNING - #{ @service.name } was implicitly loaded,
|
129
|
-
As a dependency for #{ base }.
|
130
|
-
You may want to load it explicitly.
|
131
|
-
}
|
132
|
-
@service.load
|
133
|
-
end
|
134
|
-
|
135
|
-
def load!
|
136
|
-
dependency! if should_load?
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
54
|
end
|
data/lib/r_kit/core.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
class RKit::Core
|
2
2
|
|
3
|
+
# TODO: add a "warn" method, with a required 'if', that will display a warning msg if the condition is not fullfiled
|
4
|
+
|
5
|
+
# TODO: add a "description" method, wich will contain a descriptive text about the service
|
6
|
+
|
3
7
|
class << self
|
4
8
|
def init!
|
5
9
|
@_config = Configurer.new self
|
@@ -23,6 +27,8 @@ class RKit::Core
|
|
23
27
|
end
|
24
28
|
|
25
29
|
|
30
|
+
# TODO: define a method "config_get" that retreive the rkit config
|
31
|
+
# to do so, we will iterate throug the namespaces until we find somthing that inherit from RKit::Core
|
26
32
|
delegate :config, :alias_config, :preset,
|
27
33
|
to: :@_config
|
28
34
|
|
@@ -60,7 +66,11 @@ class RKit::Core
|
|
60
66
|
|
61
67
|
|
62
68
|
require 'r_kit/core/configurer.rb'
|
69
|
+
|
63
70
|
require 'r_kit/core/engineer.rb'
|
71
|
+
|
64
72
|
require 'r_kit/core/loader.rb'
|
73
|
+
require 'r_kit/core/loader/dependency.rb'
|
74
|
+
require 'r_kit/core/loader/load_path.rb'
|
65
75
|
|
66
76
|
end
|
@@ -27,7 +27,7 @@ $text-info-color
|
|
27
27
|
$text-muted-color
|
28
28
|
*/
|
29
29
|
$background-color: background-color() !default;
|
30
|
-
|
30
|
+
$background-alt-color: background-alt-color() !default;
|
31
31
|
/*$background-success-color
|
32
32
|
$background-warning-color
|
33
33
|
$background-danger-color
|