hirb 0.3.0 → 0.3.1

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.
@@ -1,3 +1,7 @@
1
+ == 0.3.1
2
+ * Bug fix on DynamicView.class_to_method to allow overrides of default views
3
+ * Modified mongo_mapper view to have _id first
4
+
1
5
  == 0.3.0
2
6
  * Added dynamic views.
3
7
  * Added default table views for the following database classes/modules:
@@ -53,15 +53,16 @@ module Hirb
53
53
  end
54
54
 
55
55
  def self.generate_single_view_module(output_mod, &block) #:nodoc:
56
- mod_name = class_to_method output_mod.to_s
57
- Views::Single.send(:remove_const, mod_name) if Views::Single.const_defined?(mod_name)
58
- mod = Views::Single.const_set(mod_name, Module.new)
59
- mod.send(:define_method, mod_name.downcase, block)
56
+ meth = class_to_method output_mod.to_s
57
+ view_mod = meth.capitalize
58
+ Views::Single.send(:remove_const, view_mod) if Views::Single.const_defined?(view_mod)
59
+ mod = Views::Single.const_set(view_mod, Module.new)
60
+ mod.send(:define_method, meth, block)
60
61
  mod
61
62
  end
62
63
 
63
64
  def self.class_to_method(mod) #:nodoc:
64
- mod.gsub("::","__").gsub(/([A-Z])/, '_\1').gsub(/(^|::)_/,'\1') + '_view'
65
+ mod.gsub(/(?!^)([A-Z])/) {|e| '_'+e }.gsub('::_', '__').downcase + '_view'
65
66
  end
66
67
 
67
68
  # Returns a hash of options based on dynamic views defined for the object's ancestry. If no config is found returns nil.
@@ -1,3 +1,3 @@
1
1
  module Hirb
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -4,12 +4,11 @@ module Hirb::Views::MongoDb #:nodoc:
4
4
  end
5
5
 
6
6
  def mongo_mapper__document_view(obj)
7
- {:fields=>obj.class.column_names}
8
- end
9
-
10
- def mongo_mapper__embedded_document_view(obj)
11
- {:fields=>obj.class.column_names}
7
+ fields = obj.class.column_names
8
+ fields.delete('_id') && fields.unshift('_id')
9
+ {:fields=>fields}
12
10
  end
11
+ alias_method :mongo_mapper__embedded_document_view, :mongo_mapper__document_view
13
12
  end
14
13
 
15
14
  Hirb::DynamicView.add Hirb::Views::MongoDb, :helper=>:auto_table
@@ -53,6 +53,10 @@ module Hirb
53
53
  end
54
54
  end
55
55
 
56
+ test "class_to_method converts correctly" do
57
+ DynamicView.class_to_method("DBI::Row").should == 'd_b_i__row_view'
58
+ end
59
+
56
60
  context "dynamic_view" do
57
61
  def define_view(mod_name= :Blah, &block)
58
62
  mod = Views.const_set(mod_name, Module.new)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gabriel Horner
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-11 00:00:00 -05:00
17
+ date: 2010-03-15 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20