hirb 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/lib/hirb/dynamic_view.rb +6 -5
- data/lib/hirb/version.rb +1 -1
- data/lib/hirb/views/mongo_db.rb +4 -5
- data/test/dynamic_view_test.rb +4 -0
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
data/lib/hirb/dynamic_view.rb
CHANGED
@@ -53,15 +53,16 @@ module Hirb
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def self.generate_single_view_module(output_mod, &block) #:nodoc:
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
mod.
|
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(
|
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.
|
data/lib/hirb/version.rb
CHANGED
data/lib/hirb/views/mongo_db.rb
CHANGED
@@ -4,12 +4,11 @@ module Hirb::Views::MongoDb #:nodoc:
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def mongo_mapper__document_view(obj)
|
7
|
-
|
8
|
-
|
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
|
data/test/dynamic_view_test.rb
CHANGED
@@ -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
|
-
-
|
9
|
-
version: 0.3.
|
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-
|
17
|
+
date: 2010-03-15 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|