to_fixture 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +17 -1
- data/Rakefile +1 -0
- data/lib/to_fixture/version.rb +1 -1
- data/lib/to_fixture.rb +22 -12
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 352bd039056465b6ad1d143cc9af72bc5468a585
|
4
|
+
data.tar.gz: 28ed1e57265ba4f6c16d69abb5c929efc897e933
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d53a3fa2e543e43e16c1cc86a8f4b7f05301325aa5477bf31578f093020fcc2a1865e0d1a31c33ee6e8e7518a29800ecfebefd9773e77f22f01975fec311ae5
|
7
|
+
data.tar.gz: 88101085a388806eb3cf768ece645d3230c0c5ef418b766ba2e4a17b96b512a61560e5632fcd44df9c4ab292e254529a928157e521791e337679884647d9daf9
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ToFixture
|
2
2
|
|
3
|
-
Add `to_fixture` method to Active Record object.
|
3
|
+
Add `to_fixture` method to Active Record object. Result of `to_fixture` can directly use the fixture files.
|
4
4
|
|
5
5
|
[](https://travis-ci.org/y-yagi/to_fixture)
|
6
6
|
[](http://badge.fury.io/rb/to_fixture)
|
@@ -42,6 +42,22 @@ puts user.to_fixture("label")
|
|
42
42
|
# email: to_fixture@example.com
|
43
43
|
```
|
44
44
|
|
45
|
+
You can also use to `ActiveRecord::Relation`.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
User.create!(name: 'to_fixture_1', email: 'to_fixture1@example.com')
|
49
|
+
User.create!(name: 'to_fixture_2', email: 'to_fixture2@example.com')
|
50
|
+
puts User.all.to_fixture
|
51
|
+
# =>
|
52
|
+
# users_980190968:
|
53
|
+
# name: to_fixture_1
|
54
|
+
# email: to_fixture1@example.com
|
55
|
+
#
|
56
|
+
# users_980190969:
|
57
|
+
# name: to_fixture_2
|
58
|
+
# email: to_fixture2@example.com
|
59
|
+
```
|
60
|
+
|
45
61
|
## License
|
46
62
|
|
47
63
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/lib/to_fixture/version.rb
CHANGED
data/lib/to_fixture.rb
CHANGED
@@ -3,25 +3,35 @@ require "active_support"
|
|
3
3
|
require "active_record"
|
4
4
|
|
5
5
|
module ToFixture
|
6
|
-
|
7
|
-
label =
|
6
|
+
module Base
|
7
|
+
def to_fixture(label = nil)
|
8
|
+
label = "#{self.class.table_name}_#{self.id}" unless label
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
inspection = if defined?(@attributes) && @attributes
|
11
|
+
columns_for_fixture.collect do |name|
|
12
|
+
" #{name}: #{read_attribute(name)}" if has_attribute?(name)
|
13
|
+
end.compact.join("\n")
|
14
|
+
else
|
15
|
+
"not initialized"
|
16
|
+
end
|
17
|
+
|
18
|
+
"#{label}:\n#{inspection}"
|
15
19
|
end
|
16
20
|
|
17
|
-
|
21
|
+
def columns_for_fixture
|
22
|
+
self.class.column_names - all_timestamp_attributes.map(&:to_s) - %w(id)
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
|
-
|
21
|
-
|
26
|
+
module Relation
|
27
|
+
def to_fixture
|
28
|
+
map(&:to_fixture).join("\n\n")
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
25
33
|
ActiveSupport.on_load(:active_record) do
|
26
|
-
include ToFixture
|
34
|
+
include ToFixture::Base
|
35
|
+
|
36
|
+
ActiveRecord::Relation.include(ToFixture::Relation)
|
27
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_fixture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Yaginuma
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -103,6 +103,7 @@ extra_rdoc_files: []
|
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
105
|
- ".travis.yml"
|
106
|
+
- CHANGELOG.md
|
106
107
|
- CODE_OF_CONDUCT.md
|
107
108
|
- Gemfile
|
108
109
|
- LICENSE.txt
|