dropkiq 0.1.0 → 0.1.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: 67f91deee2e77eadf3639d16853d4c5c4e3fbff7
4
- data.tar.gz: b506e1be0dcaeeecbc0bef0b01bd228a9658116a
3
+ metadata.gz: 870702ba0f303232074a4f4c1d217615845c66f5
4
+ data.tar.gz: 167038a34aa51b3b1f0ee9071c0609f852c922f2
5
5
  SHA512:
6
- metadata.gz: c0b21a001f69663a377d163df25d0fa3ba26c868675348127b6e1f7228263137dedb95cbd48c0819b59647d489fa31e688855a12143c1cde734fcd5ba11c6c36
7
- data.tar.gz: ce674e523319eaaa6c1f2ea8e435e693f9edb2ebbf359943e816be9b66c9e959e375ad4702c22dd01fb558dad868a68838cb0c29a95bfb0936699111a4194511
6
+ metadata.gz: 69f78f513c67744275c65ed9128be60c3eb0fb6a07e0650c621dd94f656ba22d55a174f724f0a75e3c38394dec3200b5ca72a3fd3e44a2757091afbbd9a3a5b2
7
+ data.tar.gz: 02b69534482e6b999e57da7fbea7c7a9cf550b213d179fd44dab2275dee5b5085bc3d5bc8b216fbabb61536fe719ceeb6bfeabf115f8ed8a85b125fe59c27448
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dropkiq (0.1.0)
4
+ dropkiq (0.1.1)
5
5
  activerecord (>= 4.2)
6
6
  liquid (~> 4.0)
7
7
 
@@ -27,6 +27,7 @@ GEM
27
27
  liquid (4.0.3)
28
28
  method_source (0.9.2)
29
29
  minitest (5.13.0)
30
+ mocha (1.11.2)
30
31
  pry (0.12.2)
31
32
  coderay (~> 1.1.0)
32
33
  method_source (~> 0.9.0)
@@ -43,6 +44,7 @@ DEPENDENCIES
43
44
  bundler (~> 2.0)
44
45
  dropkiq!
45
46
  minitest (~> 5.0)
47
+ mocha (~> 1.11.2)
46
48
  pry (~> 0.12.2)
47
49
  rake (~> 10.0)
48
50
  sqlite3 (~> 1.3.13)
data/README.md CHANGED
@@ -36,14 +36,92 @@ This Gem makes several assumptions about your Ruby on Rails application:
36
36
 
37
37
  This Gem provides a rake command to generate a schema file that can be used to manage Fixtures on Dropkiq. Create the `db/dropkiq_schema.yaml` file by running the following command:
38
38
 
39
+
39
40
  ```
40
41
  bundle exec rake dropkiq:schema
41
42
  ```
42
43
 
44
+
43
45
  You should now have a `db/dropkiq_schema.yaml` file. This file describes all tables associated to Drop classes in your application, along with all methods avaialble to the Drop class. It is important that you **DO** allow this file to be checked in to version control so that you can maintain your Dropkiq schema over time as you add/remove/modify your Drop classes.
44
46
 
45
47
  Notice that `type` has NOT been set on all methods. The Dropkiq Gem is only able to infer the method type for methods that correspond to a column or relationship on the ActiveRecord model. Please take a moment to manually add `type` values for all methods that were not able to be inferred. Notice that if you run `bundle exec rake dropkiq:schema` again, your changes are saved!
46
48
 
49
+
50
+ #### Ruby on Rails Column to Dropkiq Data Type Mappings
51
+
52
+ | Ruby on Rails Column Type | Dropkiq Data Type |
53
+ | --- | --- |
54
+ | `string` | `ColumnTypes::String` |
55
+ | `integer` | `ColumnTypes::Numeric` |
56
+ | `boolean` | `ColumnTypes::Boolean` |
57
+ | `datetime` | `ColumnTypes::DateTime` |
58
+ | `date` | `ColumnTypes::DateTime` |
59
+ | `decimal` | `ColumnTypes::Numeric` |
60
+ | `float` | `ColumnTypes::Numeric` |
61
+ | `text` | `ColumnTypes::Text` |
62
+ | `time` | `ColumnTypes::DateTime` |
63
+ | `binary` | `ColumnTypes::Numeric` |
64
+
65
+ #### Ruby on Rails Associations to Dropkiq Data Type Mappings
66
+
67
+ | Ruby on Rails Association Type | Dropkiq Data Type |
68
+ | --- | --- |
69
+ | `belongs_to` | `ColumnTypes::HasOne` |
70
+ | `has_one` | `ColumnTypes::HasOne` |
71
+ | `has_many` | `ColumnTypes::HasMany` |
72
+ | `has_one through:` | `ColumnTypes::HasOne` |
73
+ | `has_many through:` | `ColumnTypes::HasMany` |
74
+ | `has_and_belongs_to_many` | `ColumnTypes::HasMany` |
75
+
76
+ **Please note:** You must also specify a `foreign_table_name` for any Association column in Dropkiq. These types can also be used for arbitrary methods within your Drop class that simply returns a single instance or array of instances of a Drop Class.
77
+
78
+ ```ruby
79
+ class PersonDrop < Liquid::Drop
80
+ # ...
81
+ end
82
+
83
+ class GroupDrop < Liquid::Drop
84
+ def initialize(group)
85
+ @group = group
86
+ end
87
+
88
+ # Use the ColumnTypes::HasOne column type and specify the foreign_table_name as "people"
89
+ def owner
90
+ owner_membership = @group.memberships.find_by!(owner: true)
91
+ PersonDrop.new(owner_membership.person)
92
+ end
93
+
94
+ # Use the ColumnTypes::HasMany column type and specify the foreign_table_name as "people"
95
+ def managers
96
+ @group.memberships.where(manager: true).map{|m| PersonDrop.new(m.person)}
97
+ end
98
+ end
99
+ ```
100
+
101
+
102
+ Dropkiq also provides a `ColumnTypes::YAML` Column Type if your Drop class model has any methods that simply return an Array or Hash, such as this example:
103
+
104
+ ```ruby
105
+ class ProductDrop < Liquid::Drop
106
+ def initialize(product)
107
+ @product = product
108
+ end
109
+
110
+ # Use the ColumnTypes::YAML column type and serialize the Array as Yaml
111
+ def possible_sku_numbers
112
+ [12345, 67890, 45678, 12390]
113
+ end
114
+
115
+ # Use the ColumnTypes::YAML column type and serialize the Hash as Yaml
116
+ def custom_data
117
+ {
118
+ description: "This is a book about bananas",
119
+ price: 12.95
120
+ }
121
+ end
122
+ end
123
+ ```
124
+
47
125
  ## Development
48
126
 
49
127
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/dropkiq.gemspec CHANGED
@@ -41,6 +41,7 @@ Gem::Specification.new do |spec|
41
41
  spec.add_development_dependency "rake", "~> 10.0"
42
42
  spec.add_development_dependency "minitest", "~> 5.0"
43
43
  spec.add_development_dependency "sqlite3", "~> 1.3.13"
44
+ spec.add_development_dependency "mocha", "~> 1.11.2"
44
45
 
45
46
  spec.add_dependency "activerecord", ">= 4.2"
46
47
  spec.add_dependency "liquid", "~> 4.0"
@@ -9,6 +9,11 @@ module Dropkiq
9
9
 
10
10
  def analyze
11
11
  self.active_record_class = find_active_record_class
12
+
13
+ if active_record_class.blank?
14
+ raise "No ActiveRecord Class found for #{liquid_drop_class.name}"
15
+ end
16
+
12
17
  self.table_name = active_record_class.table_name
13
18
  self.drop_method_params = find_drop_method_params
14
19
  end
@@ -1,3 +1,3 @@
1
1
  module Dropkiq
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropkiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Darrah
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-12 00:00:00.000000000 Z
11
+ date: 2020-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.3.13
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.11.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.11.2
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: activerecord
85
99
  requirement: !ruby/object:Gem::Requirement