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 +4 -4
- data/README.md +13 -19
- data/lib/extensions/active_record/active_record_extension.rb +1 -1
- data/lib/extensions/active_record/field_helpers.rb +15 -0
- data/lib/extensions/active_record/indentifier_field.rb +1 -5
- data/lib/lib/field_helpers.rb +21 -0
- data/lib/models/exportable_field.rb +2 -0
- data/lib/models/report.rb +1 -0
- data/lib/potpourri/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d64b0b2d194f014dd59f79a25684560647b78428
|
4
|
+
data.tar.gz: 44d3bdcd7a9305589eeec0277bd6115a28248724
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
38
|
-
|
39
|
-
|
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
|
-
-
|
67
|
-
-
|
68
|
-
-
|
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
|
-
|
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::
|
103
|
-
|
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::
|
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,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
|
data/lib/models/report.rb
CHANGED
data/lib/potpourri/version.rb
CHANGED
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.
|
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-
|
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
|