decanter 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -18
- data/lib/decanter.rb +5 -2
- data/lib/decanter/extensions.rb +6 -0
- data/lib/decanter/railtie.rb +13 -4
- data/lib/decanter/version.rb +1 -1
- data/lib/generators/rails/decanter_generator.rb +1 -1
- data/lib/generators/rails/parser_generator.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20aabb357aad0ae6ac3571bdc051640eee091e0a
|
4
|
+
data.tar.gz: 7e1015a86d9e56d0f647bd2c561b40795b471a2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee971b831f97166213985551f11c36f22f6b4eddb89acb8e1559ab0344172ac08a7ddb88cc10ead3a744add6d950d0d127e79ee3129e2e0e4984b62529f53cdb
|
7
|
+
data.tar.gz: 394c5b2fe99e781fc393b1b27580269a202189261044d57b30a370e1ef2cc2d06c298238726d0a09f2988ca39d29b8649403a4dec3658f811e3e15890a8c7d1e
|
data/README.md
CHANGED
@@ -23,17 +23,6 @@ gem "decanter"
|
|
23
23
|
bundle
|
24
24
|
```
|
25
25
|
|
26
|
-
Add the following to application.rb so we can load your decanters properly:
|
27
|
-
|
28
|
-
```
|
29
|
-
config.paths.add "app/decanter", eager_load: true
|
30
|
-
config.to_prepare do
|
31
|
-
Dir[ File.expand_path(Rails.root.join("app/decanter/**/*.rb")) ].each do |file|
|
32
|
-
require_dependency file
|
33
|
-
end
|
34
|
-
end
|
35
|
-
```
|
36
|
-
|
37
26
|
Basic Usage
|
38
27
|
---
|
39
28
|
|
@@ -41,7 +30,7 @@ Basic Usage
|
|
41
30
|
rails g decanter Trip name:string start_date:date end_date:date
|
42
31
|
```
|
43
32
|
|
44
|
-
**app/
|
33
|
+
**app/decanters/trip_decanter.rb**
|
45
34
|
|
46
35
|
```ruby
|
47
36
|
class TripDecanter < Decanter::Base
|
@@ -137,7 +126,7 @@ From terminal we ran:
|
|
137
126
|
rails g decanter Trip name:string start_date:date end_date:date
|
138
127
|
```
|
139
128
|
|
140
|
-
Which generates app/
|
129
|
+
Which generates app/decanters/trip_decanter.rb:
|
141
130
|
|
142
131
|
```ruby
|
143
132
|
class TripDecanter < Decanter::Base
|
@@ -191,7 +180,7 @@ end
|
|
191
180
|
You'll notice that the above ```parser do``` block takes a ```:parse_format``` option. This allows you to specify the format your date string will come in. For example, if you expect "2016-01-15" instead of "01/15/2016", you can adjust the TripDecanter like so:
|
192
181
|
|
193
182
|
```ruby
|
194
|
-
# app/
|
183
|
+
# app/decanters/trip_decanter.rb
|
195
184
|
|
196
185
|
class TripDecanter < Decanter::Base
|
197
186
|
input :name, :string
|
@@ -206,7 +195,7 @@ You can add your own parser if you want more control over the logic, or if you h
|
|
206
195
|
rails g parser Date
|
207
196
|
```
|
208
197
|
|
209
|
-
**
|
198
|
+
**lib/decanter/parsers/date_parser**
|
210
199
|
|
211
200
|
```ruby
|
212
201
|
class DateParser < Decanter::ValueParser::Base
|
@@ -245,7 +234,7 @@ rails g decanter Trip name destinations:has_many
|
|
245
234
|
rails g decanter Destination city state arrival_date:date departure_date:date
|
246
235
|
```
|
247
236
|
|
248
|
-
Which produces app/
|
237
|
+
Which produces app/decanters/trip and app/decanters/destination:
|
249
238
|
|
250
239
|
```ruby
|
251
240
|
class TripDecanter < Decanter::Base
|
@@ -293,7 +282,7 @@ rails g decanter SearchFilter start_date:date end_date:date city:string state:st
|
|
293
282
|
```
|
294
283
|
|
295
284
|
```ruby
|
296
|
-
# app/
|
285
|
+
# app/decanters/search_filter_decanter.rb
|
297
286
|
|
298
287
|
class SearchFilterDecanter < Decanter::Base
|
299
288
|
|
@@ -346,7 +335,7 @@ rails g parser SquashDate
|
|
346
335
|
```
|
347
336
|
|
348
337
|
```ruby
|
349
|
-
#
|
338
|
+
# lib/decanter/parsers/squash_date_parser.rb
|
350
339
|
|
351
340
|
class SquashDateParser < Decanter::Parser::Base
|
352
341
|
parser do |name, values, options|
|
data/lib/decanter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
|
1
3
|
module Decanter
|
2
4
|
|
3
5
|
@@decanters = {}
|
@@ -13,12 +15,13 @@ module Decanter
|
|
13
15
|
full_name = name.include?('Decanter') ? name : "#{name}Decanter"
|
14
16
|
@@decanters[full_name] || (raise NameError.new("unknown decanter #{name}Decanter"))
|
15
17
|
end
|
18
|
+
|
19
|
+
ActiveSupport.run_load_hooks(:decanter, self)
|
16
20
|
end
|
17
21
|
|
18
22
|
require 'decanter/version'
|
19
|
-
require 'active_support/all'
|
20
23
|
require 'decanter/base'
|
21
24
|
require 'decanter/core'
|
22
25
|
require 'decanter/extensions'
|
23
26
|
require 'decanter/value_parser'
|
24
|
-
require 'decanter/railtie' if defined?
|
27
|
+
require 'decanter/railtie' if defined?(::Rails)
|
data/lib/decanter/extensions.rb
CHANGED
data/lib/decanter/railtie.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
|
-
require '
|
2
|
-
require_relative 'extensions'
|
1
|
+
require 'decanter'
|
3
2
|
|
4
3
|
class Decanter::Railtie < Rails::Railtie
|
5
4
|
|
6
|
-
initializer 'decanter.
|
7
|
-
|
5
|
+
initializer 'decanter.active_record' do
|
6
|
+
ActiveSupport.on_load :active_record do
|
7
|
+
require 'decanter/extensions'
|
8
|
+
Decanter::Extensions::ActiveRecord.enable!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
config.to_prepare do
|
13
|
+
Dir[
|
14
|
+
File.expand_path(Rails.root.join("app/decanters/*")),
|
15
|
+
File.expand_path(Rails.root.join("lib/decanter/parsers/*"))
|
16
|
+
].each { |file| require file }
|
8
17
|
end
|
9
18
|
|
10
19
|
generators do |app|
|
data/lib/decanter/version.rb
CHANGED
@@ -10,7 +10,7 @@ module Rails
|
|
10
10
|
class_option :parent, :type => :string, :desc => 'The parent class for the generated decanter'
|
11
11
|
|
12
12
|
def create_decanter_file
|
13
|
-
template 'decanter.rb.erb', File.join('app/
|
13
|
+
template 'decanter.rb.erb', File.join('app/decanters', class_path, "#{file_name}_decanter.rb")
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
@@ -7,7 +7,7 @@ module Rails
|
|
7
7
|
class_option :parent, :type => :string, :desc => 'The parent class for the generated parser'
|
8
8
|
|
9
9
|
def create_parser_file
|
10
|
-
template 'parser.rb.erb', File.join('
|
10
|
+
template 'parser.rb.erb', File.join('lib/decanter/parsers', class_path, "#{file_name}_parser.rb")
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decanter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Francis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-02-
|
12
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|