minimalizer 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cd12461b740324f36bb3072f0eeb571bd365622
4
- data.tar.gz: 41f079b1df0c15dcdb95df53e3152ae68d504233
3
+ metadata.gz: 638219c0b09d1604e575443a92adff59ab42bf91
4
+ data.tar.gz: 7fc17e2bcd5e66ea82d2494e1b36a49cbe17119f
5
5
  SHA512:
6
- metadata.gz: 971c722baef967057363bee256938a458924e83fa36e6fcf3774e8ae291feb2f8f5222585c15580b89a807908ac4626ad70469c021fc3a89fdd085a0d437e7e8
7
- data.tar.gz: 6e877f226ad28106c14295a8d98a6dc828c88ecf11b8d7ad6c36011c61b6957e95fb1a482e15a650b522ddd07dfd02abd5672b31b28a77b58719590924c98a60
6
+ metadata.gz: 08dc267a2969d516b50f1e8c119b802969463ce0ad837e65134e6e091eb1cbab4eaad6798bd4d89481ff270cc3ec2f8f3c95582f56168825cc04fcc783cfcd61
7
+ data.tar.gz: 6ad803728c6fb8ae2804dffb18046307d7507919458bf411a811221c02dc44f56ff69076f33678c75070f50d764a43dc7afc53fd703e54b53142051cf54cfcaa
@@ -43,12 +43,25 @@ module Minimalizer
43
43
  # create_resource [@parent, @record], record_params
44
44
  # end
45
45
  #
46
+ # An optional :context argument will be passed to the record’s #save method
47
+ # to set the validation context.
48
+ #
49
+ # def create
50
+ # create_resource @record, record_params, context: :scenario
51
+ # end
52
+ #
46
53
  # An optional :location argument will override the redirect location.
47
54
  #
48
55
  # def create
49
56
  # create_resource @record, record_params, location: :records
50
57
  # end
51
58
  #
59
+ # An optional :template argument will override the default :new template.
60
+ #
61
+ # def create
62
+ # create_resource @record, record_params, template: :alternate
63
+ # end
64
+ #
52
65
  # Passing a block will yield true if the model saves successfully, false
53
66
  # otherwise.
54
67
  #
@@ -61,11 +74,11 @@ module Minimalizer
61
74
  # end
62
75
  # end
63
76
  # end
64
- def create_resource(resource, attributes, location: nil)
77
+ def create_resource(resource, attributes, context: nil, location: nil, template: nil)
65
78
  model = resource.is_a?(Array) ? resource.last : resource
66
79
  model.assign_attributes attributes
67
80
 
68
- if model.save
81
+ if model.save(context: context)
69
82
  flash.notice = t('.notice')
70
83
  yield true if block_given?
71
84
  redirect_to location || resource
@@ -73,7 +86,7 @@ module Minimalizer
73
86
  flash.now.alert = t('.alert')
74
87
  response.status = 422
75
88
  yield false if block_given?
76
- render :new
89
+ render template || :new
77
90
  end
78
91
  end
79
92
 
@@ -94,12 +107,25 @@ module Minimalizer
94
107
  # update_resource [@parent, @record], record_params
95
108
  # end
96
109
  #
110
+ # An optional :context argument will be passed to the record’s #save method
111
+ # to set the validation context.
112
+ #
113
+ # def update
114
+ # update_resource @record, record_params, context: :scenario
115
+ # end
116
+ #
97
117
  # An optional :location argument will override the redirect location.
98
118
  #
99
119
  # def update
100
120
  # update_resource @record, record_params, location: :records
101
121
  # end
102
122
  #
123
+ # An optional :template argument will override the default :edit template.
124
+ #
125
+ # def update
126
+ # update_resource @record, record_params, template: :alternate
127
+ # end
128
+ #
103
129
  # Passing a block will yield true if the model updates successfully, false
104
130
  # otherwise.
105
131
  #
@@ -112,10 +138,11 @@ module Minimalizer
112
138
  # end
113
139
  # end
114
140
  # end
115
- def update_resource(resource, attributes, location: nil)
141
+ def update_resource(resource, attributes, context: nil, location: nil, template: nil)
116
142
  model = resource.is_a?(Array) ? resource.last : resource
143
+ model.assign_attributes(attributes)
117
144
 
118
- if model.update(attributes)
145
+ if model.save(context: context)
119
146
  flash.notice = t('.notice')
120
147
  yield true if block_given?
121
148
  redirect_to location || resource
@@ -123,7 +150,7 @@ module Minimalizer
123
150
  flash.now.alert = t('.alert')
124
151
  response.status = 422
125
152
  yield false if block_given?
126
- render :edit
153
+ render template || :edit
127
154
  end
128
155
  end
129
156
 
@@ -1,12 +1,4 @@
1
1
  module Minimalizer
2
2
  class Engine < ::Rails::Engine
3
- initializer 'minimalizer.add_controller_helpers' do
4
- end
5
-
6
- initializer 'minimalizer.add_controller_test_helpers' do
7
- end
8
-
9
- initializer 'minimalizer.add_model_test_helpers' do
10
- end
11
3
  end
12
4
  end
@@ -1,3 +1,3 @@
1
1
  module Minimalizer
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minimalizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theodore Kimble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-07 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-test