potpourri 0.2.0 → 0.2.1

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: 967a37b13ab8e26fda50157cb6fc92d1665e7dcd
4
- data.tar.gz: 0bf7c3a2c6a2a1603a171b86044ec4da19b8fd06
3
+ metadata.gz: d64b0b2d194f014dd59f79a25684560647b78428
4
+ data.tar.gz: 44d3bdcd7a9305589eeec0277bd6115a28248724
5
5
  SHA512:
6
- metadata.gz: 7f1449404d6a6f59bc162151835488c06a8900fcc81d8753b46cb70719a38ba374243376e4649516684b62a253c3e24fec92abab5237d10a83a2380fe3415d44
7
- data.tar.gz: 167ea8d0944bf69d4d5b4a4775639e284ebee459195df3854b6c65bde3edd2b58d2359693ac8b05f97b9398d77b34e9acee7bdf5b9e4be537dfe79ab39f10527
6
+ metadata.gz: 3005829d8de99b8c900fc59f16a23a57a7e8627d7cc9fb789ed2c9ac12f0032bcf5265f6fecb80a0546df90568257b8f06c504b346456b336a158bfca94e14fb
7
+ data.tar.gz: 761b16e880c02dcaae94204b9078036e62507332da8deae8e82d1b211390f73a0a18769838a3b2cfbc84bd5befc7f1e82c12c56b774e6b2749314cea69a1ea35
data/README.md CHANGED
@@ -34,9 +34,9 @@ class StarshipReport < Potpourri::Report
34
34
  resource_class Starship
35
35
 
36
36
  fields [
37
- Potpourri::Field(:captain),
38
- Potpourri::ExportableField(:registration_number),
39
- Potpourri::ImportableField(:shield_frequency)
37
+ field(:captain),
38
+ export_field(:registration_number),
39
+ import_field(:shield_frequency)
40
40
  ]
41
41
  end
42
42
  ```
@@ -63,9 +63,9 @@ report.import # => An array of Starship objects
63
63
  Fields can be customized in a number of ways. It is easy to decide what fields will be imported and which are
64
64
  exported. Extra fields in an import will simply be ignored, so all generated exports are able to be imported.
65
65
 
66
- - Potpourri::Field => These fields will be both imported and exported
67
- - Potpourri::ExportableField => These fields will only be exported
68
- - Potpourri::ImportableField => These fields will only be imported
66
+ - field => These fields will be both imported and exported
67
+ - export_field => These fields will only be exported
68
+ - import_field => These fields will only be imported
69
69
 
70
70
  Fields will interpolate which methods are used to get and set values on a model. They will also use a
71
71
  variation of the Rails `#titleize` method to generate a header for the csv.
@@ -75,15 +75,8 @@ variation of the Rails `#titleize` method to generate a header for the csv.
75
75
  These assumptions can be easily overriden by passing some options into the Field when the report is defined.
76
76
 
77
77
  ```ruby
78
- fields [
79
- Potpourri::Field(:registration_number),
80
- Potpourri::Field(:captain),
81
- Potpourri::ImportableField(:shield_frequency)
82
- ]
83
- ...
84
-
85
78
  fields [
86
- Potpourri::Field(
79
+ field(
87
80
  :captain,
88
81
  export_method: :command_officer,
89
82
  import_method: :fearless_leader=,
@@ -91,19 +84,20 @@ fields [
91
84
  )
92
85
  ]
93
86
 
94
- ...
95
-
96
87
  ```
97
88
  The importable and exportable fields also respond to the same methods, however of course they will only be either importable or exportable.
98
89
 
99
90
  ### ActiveRecord Extension
100
91
 
101
92
  Importing and exporting dynamic models is only so useful. Enter the ActiveRecord extension. It provides a
102
- `Potpourri::ActiveRecord::Report` class. This class is a subclass of `Potpourri::Report` so it responds in
103
- much the same way, with some bells and whistles.
93
+ `Potpourri::ActiveRecordExtention` module. This module includes a new field to indicate which column references
94
+ the unique identifier for the object, and controls the logic for creating and updating records during an
95
+ import.
104
96
 
105
97
  ```ruby
106
- class StarshipReport < Potpourri::ActiveRecord::Report
98
+ class StarshipReport < Potpourri::Report
99
+ include Potpourri::ActiveRecordExtension
100
+
107
101
  resource_class Starship
108
102
 
109
103
  fields [
@@ -3,6 +3,7 @@ module Potpourri
3
3
  def self.included(mod)
4
4
  raise NotAReport unless mod.ancestors.include?(Report)
5
5
  mod.extend ClassMethods
6
+ mod.include ActiveRecord::FieldHelpers
6
7
  end
7
8
 
8
9
  class MissingIdentifierField < StandardError; end
@@ -16,7 +17,6 @@ module Potpourri
16
17
  self.class.instance_variable_get '@can_create_new_records'
17
18
  end
18
19
 
19
-
20
20
  def identifier_field
21
21
  fields.detect &:identifier?
22
22
  end
@@ -0,0 +1,15 @@
1
+ module Potpourri
2
+ module ActiveRecord
3
+ module FieldHelpers
4
+ def self.included(mod)
5
+ mod.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def id_field(name, options = {})
10
+ IdentifierField.new name, options
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,10 +1,6 @@
1
1
  module Potpourri
2
2
  module ActiveRecord
3
- class IdentifierField < Field
4
- def importable?
5
- false
6
- end
7
-
3
+ class IdentifierField < ExportableField
8
4
  def identifier?
9
5
  true
10
6
  end
@@ -0,0 +1,21 @@
1
+ module Potpourri
2
+ module FieldHelpers
3
+ def self.included(mod)
4
+ mod.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def field(name, options = {})
9
+ Field.new name, options
10
+ end
11
+
12
+ def importable_field(name, options = {})
13
+ ImportableField.new name, options
14
+ end
15
+
16
+ def exportable_field(name, options = {})
17
+ ExportableField.new name, options
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,5 @@
1
+ require 'models/field'
2
+
1
3
  module Potpourri
2
4
  class ExportableField < Field
3
5
  def importable?
@@ -3,6 +3,7 @@ require 'csv'
3
3
  module Potpourri
4
4
  class Report
5
5
  include ReportConfigs
6
+ include FieldHelpers
6
7
 
7
8
  attr_reader :path
8
9
 
@@ -1,3 +1,3 @@
1
1
  module Potpourri
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: potpourri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - brendandeere
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2015-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -138,7 +138,9 @@ files:
138
138
  - bin/console
139
139
  - bin/setup
140
140
  - lib/extensions/active_record/active_record_extension.rb
141
+ - lib/extensions/active_record/field_helpers.rb
141
142
  - lib/extensions/active_record/indentifier_field.rb
143
+ - lib/lib/field_helpers.rb
142
144
  - lib/lib/report_configs.rb
143
145
  - lib/lib/titleize.rb
144
146
  - lib/models/exportable_field.rb