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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db2d47fb35516ad171707804d74d599dfc9f4275
4
- data.tar.gz: 9de4216e15cef03ab046d1dc68372ce3de6f834d
3
+ metadata.gz: 20aabb357aad0ae6ac3571bdc051640eee091e0a
4
+ data.tar.gz: 7e1015a86d9e56d0f647bd2c561b40795b471a2d
5
5
  SHA512:
6
- metadata.gz: f5a4887ef4cebe7358b2a57a25ef558647ebc4760369636c91dd65aa266649e0a85df014f02b746849d3fd301f603cb865154349aedba8a8232684d0ff1da127
7
- data.tar.gz: 3efb3ee49fc50aaa223c2205fe4e2ff9bde46fc482529510d86735bc16d31db7243f7d1e58bc2433b852f46ec74358312fb748544f268e37176c3c9512f35eb8
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/decanter/decanters/trip_decanter.rb**
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/decanter/decanters/trip_decanter.rb:
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/decanter/decanters/trip_decanter.rb
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
- **app/decanter/parsers/date_parser**
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/decanter/decanters/trip and app/decanter/decanters/destination:
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/decanter/decanters/search_filter_decanter.rb
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
- # app/decanter/squashers/date_squasher.rb
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? ::Rails::Railtie
27
+ require 'decanter/railtie' if defined?(::Rails)
@@ -40,5 +40,11 @@ module Decanter
40
40
  .decant(args)
41
41
  end
42
42
  end
43
+
44
+ module ActiveRecord
45
+ def self.enable!
46
+ ::ActiveRecord::Base.include(Decanter::Extensions)
47
+ end
48
+ end
43
49
  end
44
50
  end
@@ -1,10 +1,19 @@
1
- require 'rails'
2
- require_relative 'extensions'
1
+ require 'decanter'
3
2
 
4
3
  class Decanter::Railtie < Rails::Railtie
5
4
 
6
- initializer 'decanter.configure' do
7
- ActiveRecord::Base.include(Decanter::Extensions) if defined? ActiveRecord
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|
@@ -1,3 +1,3 @@
1
1
  module Decanter
2
- VERSION = '0.6.3'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -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/decanter/decanters', class_path, "#{file_name}_decanter.rb")
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('app/decanter/parsers', class_path, "#{file_name}_parser.rb")
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.6.3
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-22 00:00:00.000000000 Z
12
+ date: 2016-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport