inherited_rails_views 1.0.0 → 1.1.0

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.
data/Readme.md CHANGED
@@ -17,5 +17,7 @@ Add the inherited_rails_views gem to your Applications Gemfile:
17
17
 
18
18
  # now all attributes of collection are shown in the views.
19
19
  # You can, however, specify which ones should be used.
20
- inherited_attributes :attr1, :attr2, :attr3 => {:value => "Custom Titled Attribute", :type => :checkbox}
20
+ before_filter do
21
+ inherited_attributes :attr1, :attr2, :attr3 => {:value => "Custom Titled Attribute", :type => :checkbox}
22
+ end
21
23
  end
@@ -19,9 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # specify any dependencies here; for example:
22
- s.add_development_dependency "rspec"
23
- s.add_development_dependency "activesupport"
24
- s.add_development_dependency "actionpack"
25
- # s.add_runtime_dependency "rest-client"
26
- s.add_dependency "dsl_accessors"
22
+ s.add_dependency "activesupport"
23
+
24
+ s.add_development_dependency "rspec"
25
+ s.add_development_dependency "actionpack"
27
26
  end
@@ -1,42 +1,46 @@
1
1
  require "inherited_rails_views/version"
2
2
 
3
- require 'dsl_accessors'
4
-
5
3
  require 'active_support/core_ext/class'
6
4
  require 'active_support/core_ext/array'
7
5
  require 'active_support/core_ext/module'
8
6
 
9
7
  require 'active_support/concern'
10
8
 
9
+
10
+ # sets the attributes to be displayed by inherited_rails_views
11
+ #
12
+ # inherited_attributes :method1, :method2, :method3
13
+ #
14
+ # It is also possible to set the form_helper method to be used, and the title of the label
15
+ #
16
+ # inherited_attributes :method1 => {:value => true, :type => :text_field},
17
+ # :method2 => {:value => "Password", :type => :password_field}
18
+ #
19
+ # They array and hash can also be combined
20
+ #
21
+ # inherited_attributes :method1, :method2, :method3 => {:value => "Password", :type => :password_field}
22
+ #
11
23
  module InheritedRailsViews
12
24
  extend ActiveSupport::Concern
13
25
 
14
26
  included do
15
27
  append_view_path(File.expand_path "../inherited_rails_views/views", __FILE__)
28
+
16
29
  helper_method :inherited_attributes
17
30
  end
18
31
 
32
+
19
33
  module InstanceMethods
20
- include DslAccessors
21
- attr_accessor :inherited_attributes
34
+ def inherited_attributes(*args)
35
+ if args.empty?
36
+ @_inherited_attributes || _default_inherited_attributes
37
+ else
38
+ _set_inherited_attributes(*args)
39
+ end
40
+ end
22
41
 
23
- # sets the attributes to be displayed by inherited_rails_views
24
- #
25
- # inherited_attributes :method1, :method2, :method3
26
- #
27
- # It is also possible to provide a hash
28
- # inherited_attributes :method1 => true, :method2 => "Title of Method 2"
29
- #
30
- # It is even possible to set the form_helper method to be used
31
- #
32
- # inherited_attributes :method1 => {:value => true, :type => :text_field},
33
- # :method2 => {:value => "Password", :type => :password_field}
34
- #
35
- # They array and hash can also be combined
36
- #
37
- # inherited_attributes :method1, :method2, :method3 => {:value => "Password", :type => :password_field}
38
- #
39
- def set_inherited_attributes(*args)
42
+ private
43
+ def _set_inherited_attributes(*args)
40
44
  # extract the hash attributes
41
45
  options = args.extract_options!
42
46
 
@@ -48,19 +52,13 @@ module InheritedRailsViews
48
52
  end
49
53
 
50
54
  # add array methods to the hash and store the result in @inherited_attributes
51
- @inherited_attributes = args.inject(options) do |h, e|
55
+ @_inherited_attributes = args.inject(options) do |h, e|
52
56
  h[e] = {:value => e.to_s.titleize, :type => :text_field}
53
57
  h
54
58
  end
55
59
  end
56
60
 
57
- def inherited_attributes_with_defaults(*args)
58
- inherited_attributes_without_defaults(*args) || default_inherited_attributes
59
- end
60
- alias_method_chain :inherited_attributes, :defaults
61
-
62
- private
63
- def default_inherited_attributes
61
+ def _default_inherited_attributes
64
62
  klass = collection.respond_to?(:klass) ? collection.klass : collection.class
65
63
  attributes = klass.attribute_names - %w(id created_at updated_at)
66
64
  self.inherited_attributes *attributes.map(&:to_sym)
@@ -1,3 +1,3 @@
1
1
  module InheritedRailsViews
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -20,8 +20,9 @@ describe "InheritedRailsViews" do
20
20
 
21
21
  it "should transform a list of methods to a hash" do
22
22
  @klass.inherited_attributes :a, :hello_world
23
- @klass.inherited_attributes.should eql({:a => {:value => 'A', :type => :text_field},
24
- :hello_world => {:value => "Hello World", :type => :text_field}})
23
+ @klass.inherited_attributes.
24
+ should eql({:a => {:value => 'A', :type => :text_field},
25
+ :hello_world => {:value => "Hello World", :type => :text_field}})
25
26
  end
26
27
 
27
28
  it "should accept a hash" do
@@ -29,10 +30,12 @@ describe "InheritedRailsViews" do
29
30
  :bar_foo => {:value => "Bar Foo",
30
31
  :type => :checkbox}
31
32
 
32
- @klass.instance_variable_get(:@inherited_attributes).should eql({
33
- :hello_world => {:value => "Hello World", :type => :text_field},
34
- :foo_bar => {:value => "FBar", :type => :text_field},
35
- :bar_foo => {:value => "Bar Foo", :type => :checkbox}
36
- })
33
+ @klass.instance_variable_get(:@_inherited_attributes).
34
+ should eql({
35
+ :hello_world => {:value => "Hello World", :type => :text_field},
36
+ :foo_bar => {:value => "FBar", :type => :text_field},
37
+ :bar_foo => {:value => "Bar Foo", :type => :checkbox}
38
+ })
37
39
  end
38
- end
40
+
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inherited_rails_views
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-11 00:00:00.000000000Z
12
+ date: 2011-09-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &70105623241200 !ruby/object:Gem::Requirement
15
+ name: activesupport
16
+ requirement: &70208295656260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
- type: :development
22
+ type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70105623241200
24
+ version_requirements: *70208295656260
25
25
  - !ruby/object:Gem::Dependency
26
- name: activesupport
27
- requirement: &70105623240600 !ruby/object:Gem::Requirement
26
+ name: rspec
27
+ requirement: &70208295655360 !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: *70105623240600
35
+ version_requirements: *70208295655360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: actionpack
38
- requirement: &70105623240020 !ruby/object:Gem::Requirement
38
+ requirement: &70208295654380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,18 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70105623240020
47
- - !ruby/object:Gem::Dependency
48
- name: dsl_accessors
49
- requirement: &70105623239360 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- type: :runtime
56
- prerelease: false
57
- version_requirements: *70105623239360
46
+ version_requirements: *70208295654380
58
47
  description:
59
48
  email:
60
49
  - robin@wenglewski.de