lolita 3.2.0.rc.17 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +22 -17
  3. data/Rakefile +3 -0
  4. data/app/assets/javascripts/lolita/list.js +2 -2
  5. data/app/assets/javascripts/lolita/main.js +2 -2
  6. data/app/assets/javascripts/lolita/tab.js +7 -7
  7. data/app/assets/stylesheets/lolita/PIE-custom.htc +87 -87
  8. data/app/assets/stylesheets/lolita/PIE.htc +81 -81
  9. data/app/assets/stylesheets/lolita/application.css +6 -6
  10. data/app/assets/stylesheets/lolita/default.css.erb +169 -169
  11. data/app/assets/stylesheets/lolita/jquery-ui-1.8.16.lolita.css.erb +567 -567
  12. data/app/assets/stylesheets/lolita/style.css.erb +4 -1
  13. data/app/helpers/components/lolita/configuration/list_component.rb +10 -10
  14. data/app/views/components/lolita/configuration/column/_first.html.haml +1 -1
  15. data/app/views/components/lolita/configuration/column/header/_first.html.haml +1 -1
  16. data/app/views/components/lolita/configuration/column/header/_sort.html.haml +6 -6
  17. data/app/views/components/lolita/configuration/columns/header/_display.html.haml +5 -5
  18. data/app/views/components/lolita/configuration/field/array/checkbox/_display.html.haml +7 -7
  19. data/app/views/components/lolita/configuration/filter/_display.html.haml +2 -2
  20. data/app/views/components/lolita/configuration/search/_display.html.haml +2 -2
  21. data/app/views/kaminari/lolita/_first_page.html.erb +11 -11
  22. data/app/views/kaminari/lolita/_gap.html.erb +8 -8
  23. data/app/views/kaminari/lolita/_last_page.html.erb +11 -11
  24. data/app/views/kaminari/lolita/_next_page.html.erb +11 -11
  25. data/app/views/kaminari/lolita/_page.html.erb +12 -12
  26. data/app/views/kaminari/lolita/_paginator.html.erb +23 -23
  27. data/app/views/kaminari/lolita/_prev_page.html.erb +11 -11
  28. data/app/views/lolita/info/index.html.erb +232 -232
  29. data/app/views/lolita/rest/index.html.haml +1 -1
  30. data/config/routes.rb +6 -6
  31. data/lib/generators/lolita/install_generator.rb +2 -4
  32. data/lib/generators/lolita/uninstall_generator.rb +3 -8
  33. data/lib/generators/templates/lolita.rb +13 -16
  34. data/lib/lolita.rb +4 -5
  35. data/lib/lolita/adapter/active_record.rb +4 -4
  36. data/lib/lolita/adapter/common_helper.rb +45 -71
  37. data/lib/lolita/adapter/field_helper.rb +18 -18
  38. data/lib/lolita/adapter/mongoid.rb +8 -8
  39. data/lib/lolita/configuration/field/big_decimal.rb +12 -12
  40. data/lib/lolita/configuration/field/boolean.rb +12 -12
  41. data/lib/lolita/configuration/field/date.rb +12 -12
  42. data/lib/lolita/configuration/field/hidden.rb +12 -12
  43. data/lib/lolita/configuration/field/integer.rb +11 -11
  44. data/lib/lolita/configuration/field/string.rb +16 -16
  45. data/lib/lolita/configuration/field/time.rb +13 -13
  46. data/lib/lolita/configuration/field_set.rb +25 -25
  47. data/lib/lolita/configuration/filter.rb +6 -0
  48. data/lib/lolita/configuration/list.rb +10 -10
  49. data/lib/lolita/configuration/nested_form.rb +104 -104
  50. data/lib/lolita/configuration/search.rb +104 -104
  51. data/lib/lolita/configuration/tab/content.rb +3 -3
  52. data/lib/lolita/controllers/component_helpers.rb +9 -9
  53. data/lib/lolita/controllers/rails_helpers.rb +5 -5
  54. data/lib/lolita/dbi/base.rb +56 -56
  55. data/lib/lolita/hooks.rb +16 -16
  56. data/lib/lolita/hooks/named_hook.rb +125 -125
  57. data/lib/lolita/lazy_loader.rb +54 -54
  58. data/lib/lolita/navigation/tree.rb +132 -132
  59. data/lib/lolita/rails/engine.rb +2 -2
  60. data/lib/lolita/rails/routes.rb +9 -9
  61. data/lib/lolita/ruby_ext/accessors.rb +26 -26
  62. data/lib/lolita/ruby_ext/lolita_model_name.rb +10 -2
  63. data/lib/lolita/search/simple.rb +75 -75
  64. data/lib/lolita/support/formatter.rb +62 -62
  65. data/lib/lolita/support/formatter/rails.rb +56 -56
  66. data/lib/lolita/test/matchers.rb +77 -77
  67. data/lib/lolita/version.rb +2 -2
  68. data/spec/adapter/common_helper_spec.rb +96 -0
  69. data/spec/adapter_helper.rb +3 -4
  70. data/spec/builder_spec.rb +120 -120
  71. data/spec/configuration/base_spec.rb +1 -1
  72. data/spec/configuration/column_spec.rb +1 -1
  73. data/spec/configuration/columns_spec.rb +1 -1
  74. data/spec/configuration/core_spec.rb +1 -1
  75. data/spec/configuration/field_set_spec.rb +1 -1
  76. data/spec/configuration/field_spec.rb +1 -1
  77. data/spec/configuration/filter_spec.rb +30 -1
  78. data/spec/configuration/list_spec.rb +44 -145
  79. data/spec/configuration/nested_list_spec.rb +1 -1
  80. data/spec/configuration/search_spec.rb +1 -1
  81. data/spec/configuration/tab_spec.rb +1 -1
  82. data/spec/configuration/tabs_spec.rb +1 -2
  83. data/spec/controllers/component_helpers_spec.rb +1 -1
  84. data/spec/controllers/configuration_spec.rb +1 -1
  85. data/spec/controllers/internal_helpers_spec.rb +1 -1
  86. data/spec/controllers/lolita_rest_nested_resources_spec.rb +1 -1
  87. data/spec/controllers/lolita_rest_spec.rb +2 -2
  88. data/spec/dbi/base_spec.rb +1 -4
  89. data/spec/extensions/authorization/cancan_adapter_spec.rb +4 -4
  90. data/spec/extensions/extensions_spec.rb +1 -1
  91. data/spec/generators/lolita/install_generator_spec.rb +55 -0
  92. data/spec/generators/lolita/uninstall_generator_spec.rb +49 -0
  93. data/spec/hooks_spec.rb +25 -25
  94. data/spec/mapping_spec.rb +1 -1
  95. data/spec/navigation/branch_spec.rb +1 -1
  96. data/spec/navigation/tree_spec.rb +1 -1
  97. data/spec/rails_app/app/controllers/application_controller.rb +3 -3
  98. data/spec/rails_app/app/helpers/application_helper.rb +3 -3
  99. data/spec/rails_app/app/mongoid/address.rb +7 -7
  100. data/spec/rails_app/app/mongoid/comment.rb +5 -5
  101. data/spec/rails_app/app/mongoid/preference.rb +5 -5
  102. data/spec/rails_app/app/mongoid/profile.rb +13 -13
  103. data/spec/rails_app/app/mongoid/tag.rb +3 -3
  104. data/spec/rails_app/app/views/components/lolita/configuration/list/_body_cell.html.erb +1 -1
  105. data/spec/rails_app/config/boot.rb +4 -9
  106. data/spec/rails_app/config/environment.rb +5 -5
  107. data/spec/rails_app/config/environments/production.rb +37 -37
  108. data/spec/rails_app/config/environments/test.rb +37 -37
  109. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -7
  110. data/spec/rails_app/config/initializers/inflections.rb +2 -2
  111. data/spec/rails_app/config/initializers/secret_token.rb +1 -1
  112. data/spec/rails_app/config/routes.rb +1 -1
  113. data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +13 -13
  114. data/spec/rails_app/log/development.log +12940 -43222
  115. data/spec/rails_app/public/javascripts/jquery-1.5.1.min.js +15 -15
  116. data/spec/rails_app/public/javascripts/lolita/main.js +6 -6
  117. data/spec/rails_app/public/javascripts/modernizr-1.7.min.js +1 -1
  118. data/spec/rails_app/public/javascripts/rails.js +137 -137
  119. data/spec/rails_app/public/javascripts/tinymce/langs/en.js +221 -221
  120. data/spec/rails_app/public/javascripts/tinymce/license.txt +504 -504
  121. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/about.htm +52 -52
  122. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/anchor.htm +26 -26
  123. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/charmap.htm +51 -51
  124. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/color_picker.htm +74 -74
  125. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/editor_template_src.js +1328 -1328
  126. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/image.htm +80 -80
  127. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/about.js +73 -73
  128. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/anchor.js +42 -42
  129. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/charmap.js +354 -354
  130. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/color_picker.js +329 -329
  131. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/image.js +247 -247
  132. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/link.js +153 -153
  133. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/source_editor.js +56 -56
  134. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en.js +68 -68
  135. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en_dlg.js +53 -53
  136. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/link.htm +57 -57
  137. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/shortcuts.htm +47 -47
  138. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
  139. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
  140. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
  141. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/source_editor.htm +25 -25
  142. data/spec/rails_app/public/javascripts/tinymce/tiny_mce_popup.js +4 -4
  143. data/spec/rails_app/public/stylesheets/lolita/default.css +169 -169
  144. data/spec/rails_app/public/stylesheets/lolita/style.css +214 -214
  145. data/spec/routing/routes_spec.rb +1 -1
  146. data/spec/search/simple_spec.rb +1 -1
  147. data/spec/simple_spec_helper.rb +1 -1
  148. data/spec/spec_helper.rb +6 -4
  149. data/spec/support/formatter_spec.rb +1 -1
  150. data/spec/tmp/config/routes.rb +0 -0
  151. data/vendor/assets/javascripts/jquery-numeric.js +279 -279
  152. data/vendor/assets/javascripts/modernizr_1_7_min.js +1 -1
  153. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
  154. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
  155. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
  156. data/vendor/assets/stylesheets/jquery-ui-1.8.16.custom.css +567 -567
  157. metadata +380 -395
  158. data/spec/rails_app/coverage.data +0 -1
  159. data/spec/rails_app/log/test.log +0 -370
@@ -1,105 +1,105 @@
1
- module Lolita
2
- module Configuration
3
- # Proxy class for search. It supports two methods #with and #run.
4
- # By default with method accepts method name or nothing and creates Lolita::Search::Simple instance
5
- # that will be used to run search on current dbi.
6
- # By default search run against all content fields, but when _:fields_ options is passed it search in
7
- # those fields only.
8
- # ==== Example
9
- # class Post < ActiveRecord::Base
10
- # include Lolita::Configuration
11
- # lolita do
12
- # list do
13
- # search :fields => [:name]
14
- # end
15
- # end
16
- # end
17
- # #with method also accepts class or instance of some class, that will be used to run search.
18
- # That class should have #run method that accepts query and request.
19
- # ====Example
20
- # class MyCustomSearch
21
- # def initialize(dbi)
22
- # @dbi = dbi
23
- # end
24
- #
25
- # def run(query,request = nil)
26
- # @dbi.klass.where(:my_field => query)
27
- # end
28
- # end
29
- # Also you can put your search method in model. For more see Lolita::Search::Simple
30
- # ====Example
31
- # class Post < ActiveRecord::Base
32
- # include Lolita::Configuration
33
- # lolita do
34
- # list do
35
- # search :my_custom_search
36
- # end
37
- # end
38
- #
39
- # def self.my_custom_search(query,request)
40
- # self.where(:title => query, :user_id => request.params[:user_id])
41
- # end
42
- # end
43
- class Search
44
- include Lolita::Builder
45
- attr_reader :dbi
46
- attr_writer :with, :fields
47
-
48
- def initialize dbi, *args, &block
49
- @dbi = dbi
50
- set_attributes(args ? args.extract_options! : {})
51
- instance_eval(&block) if block_given?
52
- @with ||= args[0]!=true && args[0] ? args[0] : nil
53
- end
54
-
55
- def with(value = nil)
56
- @with = value if value
57
- if !@with || [String,Symbol].include?(@with.class)
58
- @with = Lolita::Search::Simple.new(dbi,@with, :fields => @fields)
59
- elsif @with.class == Class
60
- initialize_arity = @with.instance_method(:initialize).arity
61
- @with = if initialize_arity < 0 || initialize_arity > 1
62
- @with.new(dbi,:fields => @fields)
63
- else
64
- @with.new(dbi)
65
- end
66
- end
67
- @with
68
- end
69
-
70
- def run(query,request = nil)
71
- if self.with.method(:run).arity < 0 || self.with.method(:run).arity > 1
72
- self.with.run(query,request)
73
- else
74
- self.with.run(query)
75
- end
76
- end
77
-
78
- def update method_name,list,request
79
- if method_name == :paginate && list.search
80
- search_criteria = list.search.run(request && request.params[:q] || "",request)
81
- page_criteria = if search_criteria.respond_to?(:where)
82
- list.page_criteria.merge(search_criteria)
83
- elsif search_criteria.nil?
84
- list.page_criteria
85
- else
86
- search_criteria
87
- end
88
- list.instance_variable_set(:@page_criteria,page_criteria)
89
- end
90
- end
91
-
92
- private
93
-
94
- def set_attributes options
95
- if options.respond_to?(:each)
96
- options.each do |method_name, value|
97
- self.send(:"#{method_name}=",value)
98
- end
99
- end
100
- end
101
-
102
- end
103
-
104
- end
1
+ module Lolita
2
+ module Configuration
3
+ # Proxy class for search. It supports two methods #with and #run.
4
+ # By default with method accepts method name or nothing and creates Lolita::Search::Simple instance
5
+ # that will be used to run search on current dbi.
6
+ # By default search run against all content fields, but when _:fields_ options is passed it search in
7
+ # those fields only.
8
+ # ==== Example
9
+ # class Post < ActiveRecord::Base
10
+ # include Lolita::Configuration
11
+ # lolita do
12
+ # list do
13
+ # search :fields => [:name]
14
+ # end
15
+ # end
16
+ # end
17
+ # #with method also accepts class or instance of some class, that will be used to run search.
18
+ # That class should have #run method that accepts query and request.
19
+ # ====Example
20
+ # class MyCustomSearch
21
+ # def initialize(dbi)
22
+ # @dbi = dbi
23
+ # end
24
+ #
25
+ # def run(query,request = nil)
26
+ # @dbi.klass.where(:my_field => query)
27
+ # end
28
+ # end
29
+ # Also you can put your search method in model. For more see Lolita::Search::Simple
30
+ # ====Example
31
+ # class Post < ActiveRecord::Base
32
+ # include Lolita::Configuration
33
+ # lolita do
34
+ # list do
35
+ # search :my_custom_search
36
+ # end
37
+ # end
38
+ #
39
+ # def self.my_custom_search(query,request)
40
+ # self.where(:title => query, :user_id => request.params[:user_id])
41
+ # end
42
+ # end
43
+ class Search
44
+ include Lolita::Builder
45
+ attr_reader :dbi
46
+ attr_writer :with, :fields
47
+
48
+ def initialize dbi, *args, &block
49
+ @dbi = dbi
50
+ set_attributes(args ? args.extract_options! : {})
51
+ instance_eval(&block) if block_given?
52
+ @with ||= args[0]!=true && args[0] ? args[0] : nil
53
+ end
54
+
55
+ def with(value = nil)
56
+ @with = value if value
57
+ if !@with || [String,Symbol].include?(@with.class)
58
+ @with = Lolita::Search::Simple.new(dbi,@with, :fields => @fields)
59
+ elsif @with.class == Class
60
+ initialize_arity = @with.instance_method(:initialize).arity
61
+ @with = if initialize_arity < 0 || initialize_arity > 1
62
+ @with.new(dbi,:fields => @fields)
63
+ else
64
+ @with.new(dbi)
65
+ end
66
+ end
67
+ @with
68
+ end
69
+
70
+ def run(query,request = nil)
71
+ if self.with.method(:run).arity < 0 || self.with.method(:run).arity > 1
72
+ self.with.run(query,request)
73
+ else
74
+ self.with.run(query)
75
+ end
76
+ end
77
+
78
+ def update method_name,list,request
79
+ if method_name == :paginate && list.search
80
+ search_criteria = list.search.run(request && request.params[:q] || "",request)
81
+ page_criteria = if search_criteria.respond_to?(:where)
82
+ list.page_criteria.merge(search_criteria)
83
+ elsif search_criteria.nil?
84
+ list.page_criteria
85
+ else
86
+ search_criteria
87
+ end
88
+ list.instance_variable_set(:@page_criteria,page_criteria)
89
+ end
90
+ end
91
+
92
+ private
93
+
94
+ def set_attributes options
95
+ if options.respond_to?(:each)
96
+ options.each do |method_name, value|
97
+ self.send(:"#{method_name}=",value)
98
+ end
99
+ end
100
+ end
101
+
102
+ end
103
+
104
+ end
105
105
  end
@@ -8,10 +8,10 @@ module Lolita
8
8
  set_default_fields
9
9
  end
10
10
 
11
- private
11
+ private
12
12
 
13
13
  def set_default_fields
14
- default_fields if @fields.empty?
14
+ default_fields if @fields.empty?
15
15
  end
16
16
 
17
17
  def validate(tab, options={})
@@ -19,7 +19,7 @@ module Lolita
19
19
  raise Lolita::SameTabTypeError, "Same type tabs was detected (#{tab.type})."
20
20
  end
21
21
  end
22
-
22
+
23
23
  end
24
24
  end
25
25
  end
@@ -2,7 +2,7 @@ module Lolita
2
2
  module Controllers
3
3
  # Helper that add #render_component method. That is shortstand for render :partial for lolita
4
4
  # partial files. Also it provide view hooks for Lolita.
5
- # For any component there may be helper module. Modules are include in current view or
5
+ # For any component there may be helper module. Modules are include in current view or
6
6
  # controller instance when component is rendered.
7
7
  # All components ar placed in "app/helpers/components/[your component path]".
8
8
  # Component should have fallowing module structure Components::[NameSpace]::[Component name]Component
@@ -41,10 +41,10 @@ module Lolita
41
41
  @current_component_name = @rendering_components.last
42
42
  self.respond_to?(:raw) ? raw(output) : output
43
43
  end
44
-
44
+
45
45
  def get_render_options *args
46
46
  options=args.extract_options!
47
- if args.first.respond_to?(:build)
47
+ if args.first.respond_to?(:build)
48
48
  name,state,options=args[0].build("",args[1],options)
49
49
  elsif args.first.class.ancestors.include?(Lolita::Configuration)
50
50
  raise ArgumentError, "Include Lolita::Builder in #{args.first.class}"
@@ -107,7 +107,7 @@ module Lolita
107
107
  class_name=possible_component_name.to_s.camelize
108
108
  helper_module = "Components::#{class_name}Component".constantize rescue nil
109
109
  if helper_module
110
- self.extend(helper_module)
110
+ self.extend(helper_module)
111
111
  end
112
112
  end
113
113
  @used_component_helpers[possible_component_name] = helper_module
@@ -118,7 +118,7 @@ module Lolita
118
118
  end
119
119
  end
120
120
  end
121
-
121
+
122
122
  def helpers_for_component component_name
123
123
  names=component_name.to_s.gsub(/^\//,"").split("/")
124
124
  start_index=1 # first is lolita
@@ -128,7 +128,7 @@ module Lolita
128
128
  end
129
129
 
130
130
  # Find path for given component.
131
- #
131
+ #
132
132
  # component_helper_path :"lolita/list" #=> [path_to_lolita]/app/helpers/components/lolita/list_component.rb
133
133
  def component_helper_path component_name
134
134
  @helper_paths||=$:.reject{|p| !p.match(/\/helpers$/) rescue nil}
@@ -137,10 +137,10 @@ module Lolita
137
137
  component=extra_path.pop
138
138
  paths.each do |path|
139
139
  new_path=File.join(path,"components",*extra_path,"#{component}_component.rb")
140
- if File.exist?(new_path)
140
+ if File.exist?(new_path)
141
141
  return new_path
142
142
  end
143
- end
143
+ end
144
144
  nil
145
145
  }
146
146
  path=get_path.call(@helper_paths)
@@ -151,7 +151,7 @@ module Lolita
151
151
  def component_locals
152
152
  @component_locals[@current_component_name]
153
153
  end
154
-
154
+
155
155
  end
156
156
  end
157
157
  end
@@ -5,10 +5,10 @@ module Lolita
5
5
  include Lolita::Controllers::InternalHelpers
6
6
  included do
7
7
  if self.ancestors.include?(ActionController::Base)
8
- helpers = %w(resource resource_name use_mapping
8
+ helpers = %w(resource resource_name use_mapping
9
9
  resource_class lolita_mapping show_response current_form current_form=)
10
10
  hide_action *helpers
11
-
11
+
12
12
  helper_method *helpers
13
13
  prepend_before_filter :is_lolita_resource?
14
14
  prepend_around_filter :switch_locale
@@ -17,8 +17,8 @@ module Lolita
17
17
 
18
18
  # Return instance variable named as resource
19
19
  # For 'posts' instance variable will be @posts
20
-
21
-
20
+
21
+
22
22
  protected
23
23
 
24
24
  def notice(msg, options = {})
@@ -84,7 +84,7 @@ module Lolita
84
84
  end
85
85
  @component_builder = @component_object.build(@component_options)
86
86
  end
87
-
87
+
88
88
 
89
89
  private
90
90
 
@@ -1,56 +1,56 @@
1
- module Lolita
2
- module DBI
3
- # Lolita::DBI::Base is ORM Interface class, that handle the request to ORM classes.
4
- # Depending on given class DBI::Base detect which ORM class is used and include right adapter
5
- # for that class. Other Lolita classes that need to manipulate with data need to have dbi object
6
- # or it can be created in that class.
7
- # Lolita::DBI::Base support Mongoid and ActiveRecord::Base, or details see Lolita::Adapter.
8
- class Base
9
-
10
- def self.create(class_object)
11
- dbi = self.new(class_object)
12
- return dbi.adapter
13
- end
14
-
15
- attr_reader :adapter_name #return connected adapter name
16
- attr_reader :klass # return related orm class object
17
- attr_reader :adapter # connected Adaptee for adapter
18
-
19
- # Expect ORM class that is supported by Lolita. See Adapter for available adapters.
20
- def initialize(class_object)
21
- @klass=class_object
22
- detect_adapter
23
- connect_adapter
24
- end
25
-
26
- # Detect which ORM class is given and based on it connect Adapter.
27
- def detect_adapter
28
- if defined?(Mongoid) && defined?(Mongoid::Document) && self.klass.ancestors.include?(Mongoid::Document)
29
- @adapter_name=:mongoid
30
- elsif defined?(ActiveRecord) && defined?(ActiveRecord::Base) && self.klass.ancestors.include?(ActiveRecord::Base)
31
- @adapter_name=:active_record
32
- else
33
- raise NotORMClassError.new("Lolita::DBI::Base can not find appropriate #{self.klass} class adapter.")
34
- end
35
- end
36
-
37
- # Connect Adapter by including adapter module into DBI::Base class.
38
- def connect_adapter()
39
- @adapter="Lolita::Adapter::#{self.adapter_name.to_s.camelize}".constantize.new(self)
40
- end
41
-
42
- def method_missing(metod,*args,&block)
43
- @adapter.send(metod,*args,&block)
44
- end
45
-
46
- class << self
47
- # Return Array of available adapters.
48
- def adapters
49
- Dir[File.expand_path(File.join(File.dirname(__FILE__),'..','adapter','**','*.rb'))].map {|f|
50
- File.basename(f,".rb").to_sym
51
- }.reject{|el| el==:abstract_adapter}
52
- end
53
- end
54
- end
55
- end
56
- end
1
+ module Lolita
2
+ module DBI
3
+ # Lolita::DBI::Base is ORM Interface class, that handle the request to ORM classes.
4
+ # Depending on given class DBI::Base detect which ORM class is used and include right adapter
5
+ # for that class. Other Lolita classes that need to manipulate with data need to have dbi object
6
+ # or it can be created in that class.
7
+ # Lolita::DBI::Base support Mongoid and ActiveRecord::Base, or details see Lolita::Adapter.
8
+ class Base
9
+
10
+ def self.create(class_object)
11
+ dbi = self.new(class_object)
12
+ return dbi.adapter
13
+ end
14
+
15
+ attr_reader :adapter_name #return connected adapter name
16
+ attr_reader :klass # return related orm class object
17
+ attr_reader :adapter # connected Adaptee for adapter
18
+
19
+ # Expect ORM class that is supported by Lolita. See Adapter for available adapters.
20
+ def initialize(class_object)
21
+ @klass=class_object
22
+ detect_adapter
23
+ connect_adapter
24
+ end
25
+
26
+ # Detect which ORM class is given and based on it connect Adapter.
27
+ def detect_adapter
28
+ if defined?(Mongoid) && defined?(Mongoid::Document) && self.klass.ancestors.include?(Mongoid::Document)
29
+ @adapter_name=:mongoid
30
+ elsif defined?(ActiveRecord) && defined?(ActiveRecord::Base) && self.klass.ancestors.include?(ActiveRecord::Base)
31
+ @adapter_name=:active_record
32
+ else
33
+ raise NotORMClassError.new("Lolita::DBI::Base can not find appropriate #{self.klass} class adapter.")
34
+ end
35
+ end
36
+
37
+ # Connect Adapter by including adapter module into DBI::Base class.
38
+ def connect_adapter()
39
+ @adapter="Lolita::Adapter::#{self.adapter_name.to_s.camelize}".constantize.new(self)
40
+ end
41
+
42
+ def method_missing(metod,*args,&block)
43
+ @adapter.send(metod,*args,&block)
44
+ end
45
+
46
+ class << self
47
+ # Return Array of available adapters.
48
+ def adapters
49
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'..','adapter','**','*.rb'))].map {|f|
50
+ File.basename(f,".rb").to_sym
51
+ }.reject{|el| el==:abstract_adapter}
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
data/lib/lolita/hooks.rb CHANGED
@@ -3,7 +3,7 @@ module Lolita
3
3
  # Next step is hook definition. This may be done using Lolita::Hooks#add_hook method.
4
4
  # Hooks are stored in class <i>@hooks</i> variable, that is Hash and each key is hook name
5
5
  # and each hook also is Hash that have <em>:methods</em> and <em>:blocks</em>
6
- # keys. Both of those are Array, and each time you call callback method, like <i>before_save</i> and so on, block
6
+ # keys. Both of those are Array, and each time you call callback method, like <i>before_save</i> and so on, block
7
7
  # and/or methods is stored. <b>Each time</b> #run is called all blocks and methods will be executed.
8
8
  # It may look like this.
9
9
  # class MyClass
@@ -28,10 +28,10 @@ module Lolita
28
28
  # my_object.before_save do
29
29
  # puts "instance callback"
30
30
  # end
31
- #
32
- # MyClass.run(:before_save) #=>
31
+ #
32
+ # MyClass.run(:before_save) #=>
33
33
  # class_callback
34
- #
34
+ #
35
35
  # my_object.run(:before_save) #=>
36
36
  # class_callback
37
37
  # instance_callback
@@ -46,7 +46,7 @@ module Lolita
46
46
  # puts "replaced text"
47
47
  # end
48
48
  # # will produce #=> replaced text
49
- #
49
+ #
50
50
  # MyClass.run(:before_save) do
51
51
  # puts "before callback"
52
52
  # let_content
@@ -84,7 +84,7 @@ module Lolita
84
84
  @singleton_hooks || {}
85
85
  end
86
86
  end
87
-
87
+
88
88
  attr_accessor :hooks_run_scope, :given_callback_content
89
89
  attr_writer :hooks_scope
90
90
 
@@ -104,7 +104,7 @@ module Lolita
104
104
  if !@options[:once] || (@options[:once] && !self.class.runned?(@options[:once],@hook_name))
105
105
  self.class.singleton_hook(@options[:once],@hook_name)
106
106
  result = nil
107
- in_hooks_scope(@options[:scope],@options[:run_scope]) do
107
+ in_hooks_scope(@options[:scope],@options[:run_scope]) do
108
108
  callback = get_callback(@hook_name)
109
109
  result = run_callback(callback,&block)
110
110
  end
@@ -114,7 +114,7 @@ module Lolita
114
114
 
115
115
  # Call callback block inside of run block.
116
116
  # ====Example
117
- # MyClass.run(:before_save) do
117
+ # MyClass.run(:before_save) do
118
118
  # do_stuff
119
119
  # let_content # execute callback block(-s) in same scope as run is executed.
120
120
  # end
@@ -155,7 +155,7 @@ module Lolita
155
155
  # class callbacks always will be called before scope callbacks.
156
156
  def get_callback(name)
157
157
  scope_callbacks = hooks_scope.callbacks[name.to_sym] || {}
158
-
158
+
159
159
  @hook_class.superclasses.each do |const_name|
160
160
  scope_callbacks = @hook_class.collect_callbacks_from(name,const_name,scope_callbacks)
161
161
  end
@@ -199,7 +199,7 @@ module Lolita
199
199
  result
200
200
  end
201
201
 
202
- # Run block in scope.
202
+ # Run block in scope.
203
203
  def run_block block, &given_block
204
204
  hooks_run_scope.instance_eval(&block)
205
205
  end
@@ -220,14 +220,14 @@ module Lolita
220
220
  def self.method_missing method_name,*args, &block
221
221
  if named_hook=(Lolita::Hooks::NamedHook.by_name(method_name))
222
222
  named_hook[:_class]
223
- else
223
+ else
224
224
  super
225
225
  end
226
226
  end
227
227
 
228
228
  # Shared methods between class and instance.
229
229
  module CommonMethods
230
-
230
+
231
231
  # All callbacks for class or instance.
232
232
  def callbacks
233
233
  var=self.instance_variable_get(:@callbacks)
@@ -245,7 +245,7 @@ module Lolita
245
245
  @hooks_scope = value
246
246
  end
247
247
 
248
- def hooks_scope
248
+ def hooks_scope
249
249
  @hooks_scope || self
250
250
  end
251
251
  # All hooks for class. This is Array of hook names.
@@ -279,7 +279,7 @@ module Lolita
279
279
  # ====Example
280
280
  # add_hook :before_save
281
281
  # MyClass.add_hooks :after_save, :around_save
282
- def add_hook(*names)
282
+ def add_hook(*names)
283
283
  (names||[]).each{|hook_name|
284
284
  self.class_eval <<-HOOK,__FILE__,__LINE__+1
285
285
  def self.#{hook_name}(*methods,&block)
@@ -325,8 +325,8 @@ module Lolita
325
325
  self.all_hooks.include?(name.to_sym)
326
326
  end
327
327
 
328
- # Try to recognize named run methods like
329
- # MyClass.run_after_save # will call MyClass.run(:after_save)
328
+ # Try to recognize named run methods like
329
+ # MyClass.run_after_save # will call MyClass.run(:after_save)
330
330
  def method_missing(*args, &block)
331
331
  unless self.recognize_hook_methods(*args,&block)
332
332
  super