active_decorator 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ActiveDecorator
2
2
 
3
- A simple and Rubyish view helper for ActiveRecord models. Keep your helpers and views Object-Oriented!
3
+ A simple and Rubyish view helper for Rails 3. Keep your helpers and views Object-Oriented!
4
4
 
5
5
 
6
6
  ## Features ##
@@ -17,6 +17,11 @@ A simple and Rubyish view helper for ActiveRecord models. Keep your helpers and
17
17
  Rails 3.0.x, 3.1.x, and 3.2 (edge)
18
18
 
19
19
 
20
+ ## Supported ORMs ##
21
+
22
+ ActiveRecord, ActiveResource, and any kind of ORMs that uses Ruby Objects as model objects
23
+
24
+
20
25
  ## Usage ##
21
26
 
22
27
  1. bundle 'active_decorator' gem
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Akira Matsuda"]
9
9
  s.email = ["ronnie@dio.jp"]
10
10
  s.homepage = ""
11
- s.summary = %q{A simple and Rubyish view helper for ActiveRecord models}
12
- s.description = %q{A simple and Rubyish view helper for ActiveRecord models}
11
+ s.summary = %q{A simple and Rubyish view helper for Rails 3}
12
+ s.description = %q{A simple and Rubyish view helper for Rails 3}
13
13
 
14
14
  s.rubyforge_project = "active_decorator"
15
15
 
@@ -9,33 +9,29 @@ module ActiveDecorator
9
9
  @@decorators = {}
10
10
  end
11
11
 
12
- def decorate_if_model(obj)
13
- case obj
14
- when ActiveRecord::Base
15
- decorate obj
16
- when ActiveRecord::Relation
12
+ def decorate(obj)
13
+ return if obj.nil?
14
+
15
+ if obj.is_a? Array
16
+ obj.each do |r|
17
+ decorate r
18
+ end
19
+ elsif defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation)
17
20
  class << obj
18
21
  def to_a_with_decorator
19
- arr = to_a_without_decorator
20
- arr.each do |model|
21
- ActiveDecorator::Decorator.instance.decorate model
22
+ to_a_without_decorator.tap do |arr|
23
+ ActiveDecorator::Decorator.instance.decorate arr
22
24
  end
23
25
  end
24
26
  alias_method_chain :to_a, :decorator
25
27
  end
26
- when Array
27
- obj.each do |r|
28
- decorate_if_model r
29
- end
28
+ else
29
+ d = decorator_for obj.class
30
+ return obj unless d
31
+ obj.extend d unless obj.is_a? d
30
32
  end
31
33
  end
32
34
 
33
- def decorate(model)
34
- d = decorator_for model.class
35
- return model unless d
36
- model.extend d unless model.is_a? d
37
- end
38
-
39
35
  private
40
36
  def decorator_for(model_class)
41
37
  return @@decorators[model_class] if @@decorators.has_key? model_class
@@ -3,7 +3,7 @@ module AbstractController
3
3
  def view_assigns_with_decorator
4
4
  hash = view_assigns_without_decorator
5
5
  hash.values.each do |v|
6
- ActiveDecorator::Decorator.instance.decorate_if_model v
6
+ ActiveDecorator::Decorator.instance.decorate v
7
7
  end
8
8
  hash
9
9
  end
@@ -4,12 +4,10 @@ module ActionView
4
4
  setup_without_decorator context, options, block
5
5
 
6
6
  @locals.values.each do |v|
7
- ActiveDecorator::Decorator.instance.decorate_if_model v
7
+ ActiveDecorator::Decorator.instance.decorate v
8
8
  end if @locals.present?
9
- ActiveDecorator::Decorator.instance.decorate_if_model @object
10
- @collection.each do |v|
11
- ActiveDecorator::Decorator.instance.decorate_if_model v
12
- end if @collection.present?
9
+ ActiveDecorator::Decorator.instance.decorate @object if @object.present?
10
+ ActiveDecorator::Decorator.instance.decorate @collection if @collection.present?
13
11
 
14
12
  self
15
13
  end
@@ -4,13 +4,13 @@ module ActiveDecorator
4
4
  class Railtie < ::Rails::Railtie
5
5
  initializer 'active_decorator' do
6
6
  ActiveSupport.on_load(:action_view) do
7
- require 'monkey/action_view/partial_renderer'
7
+ require 'active_decorator/monkey/action_view/partial_renderer'
8
8
  end
9
9
  ActiveSupport.on_load(:action_controller) do
10
- require 'monkey/abstract_controller/rendering'
10
+ require 'active_decorator/monkey/abstract_controller/rendering'
11
11
  end
12
12
  ActiveSupport.on_load(:action_mailer) do
13
- require 'monkey/abstract_controller/rendering'
13
+ require 'active_decorator/monkey/abstract_controller/rendering'
14
14
  end
15
15
  end
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveDecorator
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_decorator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-02 00:00:00.000000000 Z
12
+ date: 2011-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70282934150240 !ruby/object:Gem::Requirement
16
+ requirement: &70315505555960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70282934150240
24
+ version_requirements: *70315505555960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-rails
27
- requirement: &70282934149800 !ruby/object:Gem::Requirement
27
+ requirement: &70315505555540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70282934149800
35
+ version_requirements: *70315505555540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: capybara
38
- requirement: &70282934149380 !ruby/object:Gem::Requirement
38
+ requirement: &70315505555120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70282934149380
46
+ version_requirements: *70315505555120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &70282934148940 !ruby/object:Gem::Requirement
49
+ requirement: &70315505554700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,8 +54,8 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70282934148940
58
- description: A simple and Rubyish view helper for ActiveRecord models
57
+ version_requirements: *70315505554700
58
+ description: A simple and Rubyish view helper for Rails 3
59
59
  email:
60
60
  - ronnie@dio.jp
61
61
  executables: []
@@ -73,6 +73,8 @@ files:
73
73
  - lib/active_decorator.rb
74
74
  - lib/active_decorator/decorator.rb
75
75
  - lib/active_decorator/helpers.rb
76
+ - lib/active_decorator/monkey/abstract_controller/rendering.rb
77
+ - lib/active_decorator/monkey/action_view/partial_renderer.rb
76
78
  - lib/active_decorator/railtie.rb
77
79
  - lib/active_decorator/version.rb
78
80
  - lib/generators/rails/decorator_generator.rb
@@ -81,8 +83,6 @@ files:
81
83
  - lib/generators/rspec/templates/decorator_spec.rb
82
84
  - lib/generators/test_unit/decorator_generator.rb
83
85
  - lib/generators/test_unit/templates/decorator_test.rb
84
- - lib/monkey/abstract_controller/rendering.rb
85
- - lib/monkey/action_view/partial_renderer.rb
86
86
  - spec/fake_app/authors/index.html.erb
87
87
  - spec/fake_app/authors/show.html.erb
88
88
  - spec/fake_app/books/_book.html.erb
@@ -105,18 +105,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  - - ! '>='
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
+ segments:
109
+ - 0
110
+ hash: 965343407426954688
108
111
  required_rubygems_version: !ruby/object:Gem::Requirement
109
112
  none: false
110
113
  requirements:
111
114
  - - ! '>='
112
115
  - !ruby/object:Gem::Version
113
116
  version: '0'
117
+ segments:
118
+ - 0
119
+ hash: 965343407426954688
114
120
  requirements: []
115
121
  rubyforge_project: active_decorator
116
122
  rubygems_version: 1.8.10
117
123
  signing_key:
118
124
  specification_version: 3
119
- summary: A simple and Rubyish view helper for ActiveRecord models
125
+ summary: A simple and Rubyish view helper for Rails 3
120
126
  test_files:
121
127
  - spec/fake_app/authors/index.html.erb
122
128
  - spec/fake_app/authors/show.html.erb