to_fixture 0.1.0 → 0.2.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: 84728fd499fbd24418e95b2baf54cac9b6dd357a
4
- data.tar.gz: d51a1d0ccf2e3525cad5baf78638231f509bef2e
3
+ metadata.gz: 352bd039056465b6ad1d143cc9af72bc5468a585
4
+ data.tar.gz: 28ed1e57265ba4f6c16d69abb5c929efc897e933
5
5
  SHA512:
6
- metadata.gz: a0a25b372e51bbdcd4493dca31b9a6f45b31e77f659138091cc0f3253c6408e6106b25f198f3de0b7b4bfca7867916f2165c3c84fed234f767e323297b057df8
7
- data.tar.gz: 695c4150fc29bc2780bb1160858fa672b183489df57210fe503255cce21f6a3ad7f18ed44bd68623a8740a4aa35653e43aa1702138de275c2eccad7322747145
6
+ metadata.gz: 9d53a3fa2e543e43e16c1cc86a8f4b7f05301325aa5477bf31578f093020fcc2a1865e0d1a31c33ee6e8e7518a29800ecfebefd9773e77f22f01975fec311ae5
7
+ data.tar.gz: 88101085a388806eb3cf768ece645d3230c0c5ef418b766ba2e4a17b96b512a61560e5632fcd44df9c4ab292e254529a928157e521791e337679884647d9daf9
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Change Log
2
+
3
+ ## [v0.2.0 (2016-09-17)](https://github.com/y-yagi/to_fixture/tree/HEAD)
4
+
5
+ **Implemented enhancements:**
6
+
7
+ * Add `to_fixture` method to `ActiveRecord::Relation`. [\#1](https://github.com/y-yagi/to_fixture/pull/1)
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
  [![Build Status](https://travis-ci.org/y-yagi/to_fixture.svg?branch=master)](https://travis-ci.org/y-yagi/to_fixture)
6
6
  [![Gem Version](https://badge.fury.io/rb/to_fixture.svg)](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
@@ -4,6 +4,7 @@ require "rake/testtask"
4
4
  Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
+ t.warning = true
7
8
  t.test_files = FileList['test/**/*_test.rb']
8
9
  end
9
10
 
@@ -1,3 +1,3 @@
1
1
  module ToFixture
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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
- def to_fixture(label = nil)
7
- label = "#{self.class.table_name}_#{self.id}" unless label
6
+ module Base
7
+ def to_fixture(label = nil)
8
+ label = "#{self.class.table_name}_#{self.id}" unless label
8
9
 
9
- inspection = if defined?(@attributes) && @attributes
10
- columns_for_fixture.collect do |name|
11
- " #{name}: #{read_attribute(name)}" if has_attribute?(name)
12
- end.compact.join("\n")
13
- else
14
- "not initialized"
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
- "#{label}:\n#{inspection}"
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
- def columns_for_fixture
21
- self.class.column_names - all_timestamp_attributes.map(&:to_s) - %w(id)
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.1.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-08-21 00:00:00.000000000 Z
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