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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/r_kit/active_record_utility/active_record_extend.rb +5 -30
  3. data/lib/r_kit/active_record_utility/database_schema_error.rb +3 -1
  4. data/lib/r_kit/active_record_utility/utilities/pool.rb +41 -0
  5. data/lib/r_kit/active_record_utility/utilities/publisher.rb +38 -0
  6. data/lib/r_kit/active_record_utility/{base → utilities}/series.rb +40 -15
  7. data/lib/r_kit/active_record_utility/utilities/tag.rb +30 -0
  8. data/lib/r_kit/active_record_utility.rb +12 -13
  9. data/lib/r_kit/backtrace.rb +1 -1
  10. data/lib/r_kit/core/loader/dependency.rb +3 -3
  11. data/lib/r_kit/core/loader/load_path.rb +5 -3
  12. data/lib/r_kit/core/loader.rb +14 -11
  13. data/lib/r_kit/core.rb +3 -1
  14. data/lib/r_kit/decoration/action_view_base_extend.rb +5 -4
  15. data/lib/r_kit/decoration/base/collection.rb +20 -0
  16. data/lib/r_kit/decoration/base/object.rb +21 -0
  17. data/lib/r_kit/decoration/base.rb +15 -19
  18. data/lib/r_kit/decoration/class.rb +103 -14
  19. data/lib/r_kit/decoration/dsl.rb +121 -0
  20. data/lib/r_kit/decoration/enumerable_extend.rb +9 -0
  21. data/lib/r_kit/decoration.rb +13 -6
  22. data/lib/r_kit/dsl/base/local_params.rb +6 -3
  23. data/lib/r_kit/dsl/base/thrust.rb +4 -2
  24. data/lib/r_kit/dsl/base.rb +14 -7
  25. data/lib/r_kit/dsl.rb +62 -11
  26. data/lib/r_kit/grid.rb +9 -8
  27. data/lib/r_kit/pagination/base/page.rb +1 -1
  28. data/lib/r_kit/pagination/base.rb +5 -24
  29. data/lib/r_kit/pagination/dsl.rb +15 -0
  30. data/lib/r_kit/pagination.rb +8 -5
  31. data/lib/r_kit/struct/safe_struct.rb +3 -0
  32. data/lib/r_kit/struct.rb +4 -2
  33. data/lib/r_kit/utility/basic_object_extend.rb +5 -0
  34. data/lib/r_kit/utility/kernel_extend.rb +48 -8
  35. data/lib/r_kit/utility/module_extend.rb +22 -1
  36. data/lib/r_kit/utility/simple_delegator_extend.rb +11 -2
  37. data/lib/r_kit/utility.rb +11 -1
  38. data/lib/r_kit/version.rb +1 -1
  39. metadata +12 -9
  40. data/lib/r_kit/active_record_utility/base/pool.rb +0 -29
  41. data/lib/r_kit/active_record_utility/base/publisher.rb +0 -28
  42. data/lib/r_kit/active_record_utility/base/tag.rb +0 -17
  43. data/lib/r_kit/active_record_utility/base.rb +0 -70
  44. data/lib/r_kit/decoration/active_record_extend.rb +0 -71
  45. data/lib/r_kit/pagination/active_record_extend.rb +0 -23
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Petrachi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-03 00:00:00.000000000 Z
11
+ date: 2014-10-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rails tools box
14
14
  email:
@@ -25,12 +25,11 @@ files:
25
25
  - lib/r_kit.rb
26
26
  - lib/r_kit/active_record_utility.rb
27
27
  - lib/r_kit/active_record_utility/active_record_extend.rb
28
- - lib/r_kit/active_record_utility/base.rb
29
- - lib/r_kit/active_record_utility/base/pool.rb
30
- - lib/r_kit/active_record_utility/base/publisher.rb
31
- - lib/r_kit/active_record_utility/base/series.rb
32
- - lib/r_kit/active_record_utility/base/tag.rb
33
28
  - lib/r_kit/active_record_utility/database_schema_error.rb
29
+ - lib/r_kit/active_record_utility/utilities/pool.rb
30
+ - lib/r_kit/active_record_utility/utilities/publisher.rb
31
+ - lib/r_kit/active_record_utility/utilities/series.rb
32
+ - lib/r_kit/active_record_utility/utilities/tag.rb
34
33
  - lib/r_kit/backtrace.rb
35
34
  - lib/r_kit/backtrace/kernel_extend.rb
36
35
  - lib/r_kit/core.rb
@@ -66,9 +65,12 @@ files:
66
65
  - lib/r_kit/css/sass_extend.rb
67
66
  - lib/r_kit/decoration.rb
68
67
  - lib/r_kit/decoration/action_view_base_extend.rb
69
- - lib/r_kit/decoration/active_record_extend.rb
70
68
  - lib/r_kit/decoration/base.rb
69
+ - lib/r_kit/decoration/base/collection.rb
70
+ - lib/r_kit/decoration/base/object.rb
71
71
  - lib/r_kit/decoration/class.rb
72
+ - lib/r_kit/decoration/dsl.rb
73
+ - lib/r_kit/decoration/enumerable_extend.rb
72
74
  - lib/r_kit/dsl.rb
73
75
  - lib/r_kit/dsl/base.rb
74
76
  - lib/r_kit/dsl/base/local_params.rb
@@ -94,9 +96,9 @@ files:
94
96
  - lib/r_kit/grid/lib/assets/stylesheets/r_kit/variables/grid.scss
95
97
  - lib/r_kit/grid/sass_extend.rb
96
98
  - lib/r_kit/pagination.rb
97
- - lib/r_kit/pagination/active_record_extend.rb
98
99
  - lib/r_kit/pagination/base.rb
99
100
  - lib/r_kit/pagination/base/page.rb
101
+ - lib/r_kit/pagination/dsl.rb
100
102
  - lib/r_kit/struct.rb
101
103
  - lib/r_kit/struct/collection_delegator.rb
102
104
  - lib/r_kit/struct/safe_struct.rb
@@ -104,6 +106,7 @@ files:
104
106
  - lib/r_kit/utility.rb
105
107
  - lib/r_kit/utility/active_record_extend.rb
106
108
  - lib/r_kit/utility/array_extend.rb
109
+ - lib/r_kit/utility/basic_object_extend.rb
107
110
  - lib/r_kit/utility/hash_extend.rb
108
111
  - lib/r_kit/utility/kernel_extend.rb
109
112
  - lib/r_kit/utility/module_extend.rb
@@ -1,29 +0,0 @@
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
@@ -1,28 +0,0 @@
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
@@ -1,17 +0,0 @@
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
@@ -1,70 +0,0 @@
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,71 +0,0 @@
1
- module RKit::Decoration::ActiveRecordExtend
2
-
3
- attr_accessor :decorator_klass
4
-
5
- def acts_as_decorables base = nil, &block
6
- define_decorator base || block
7
- define_instance_methods
8
- end
9
-
10
- # 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 !
11
- def define_decorator arg
12
- @decorator_klass = decorator_klass_from arg
13
- @decorator_klass
14
- end
15
-
16
-
17
- def decorator_klass_from arg
18
- send "decorator_klass_from_#{ arg.class.name.underscore }", arg
19
- end
20
-
21
- def decorator_klass_from_nil_class *args
22
- decorator_klass_from "#{ name }Decorator".constantize
23
- end
24
-
25
- def decorator_klass_from_class base
26
- if base <=> RKit::Decoration::Base
27
- base
28
- else
29
- base.tap do |base|
30
- base.send :include, Module.new{ include refine(RKit::Decoration::Base){} }
31
- base.extend Module.new{ include refine(RKit::Decoration::Base.singleton_class){} }
32
- base.instance_variable_set "@decorated_klass", self
33
- base.class_eval{ alias :"#{ decorated_klass.demodulize.underscore }" :__getobj__ }
34
- end
35
- end
36
- end
37
-
38
- def decorator_klass_from_module mod
39
- namespace = (mod.name.deconstantize.presence || 'Object').constantize
40
- const_name = mod.name.demodulize
41
-
42
- namespace.send :remove_const, const_name
43
- namespace.const_set const_name, RKit::Decoration::Class.new(self){ include mod }
44
- end
45
-
46
- def decorator_klass_from_proc block
47
- (name.deconstantize.presence || 'Object')
48
- .constantize
49
- .const_set "#{ name.demodulize }Decorator", RKit::Decoration::Class.new(self, &block)
50
- end
51
-
52
- # TODO: this couls move in "ennumerable", cause if the AR::relation is mapped into an array
53
- # or if we create an array with decorables objects in it
54
- # this will fail
55
- # --
56
- # in addition, make a "safe_decorate" for collections, wich will decorate if respond_to_decorate,
57
- # and will not raise error
58
- def decorate view_context: nil
59
- all.map{ |record| record.decorate view_context: view_context }
60
- end
61
-
62
-
63
- def define_instance_methods
64
- define_method 'decorate' do |view_context: nil|
65
- self.class.decorator_klass.new self, view_context: view_context
66
- end
67
- end
68
-
69
-
70
- ActiveRecord::Base.extend self
71
- end
@@ -1,23 +0,0 @@
1
- module RKit::Pagination::ActiveRecordExtend
2
-
3
- # TODO: use rkit::dsl for this
4
- # class X < RKit::Dsl::Base
5
- # for Y #this is the targeted class
6
- # name :act_as_xable
7
- # instance_interfere do; end #class methods
8
- # class_interfere do; end #instance_methods
9
- # decorator_interfere do; end #decorator_methods
10
- # can_interfere? do; #auth to load the dsl in a specific class
11
- # end
12
- # All of this is largely inspired by the work on ARutility
13
-
14
- def acts_as_paginables
15
- define_singleton_method "paginate", ->(page: nil, per_page: nil) do
16
- RKit::Pagination::Base.new(all, page: page, per_page: per_page)
17
- end
18
- end
19
-
20
- # we need to create a "paginate" scope, that will create a Pagination::base object
21
-
22
- ActiveRecord::Base.extend self
23
- end