flextures 4.1.0 → 4.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: 2712b12b0de4f85effbdb3be89c88fc0217397ef
4
- data.tar.gz: 348adf4807760f5155eaa8d3b3e9b0d3a702aff2
3
+ metadata.gz: c41afb887951f1e3623d2747268339ddf6f63e5e
4
+ data.tar.gz: 7a24ceb00d32dc9ab13b5798ffaed6100bfe1500
5
5
  SHA512:
6
- metadata.gz: bbc454cc0aa60de6d9562dced99c7a5c13bf2eb2a3dc4ccb83c92b5015bf254269a45650c11224d19265be01f94a9b216930e8a729d85db6c27cc1805199b0b2
7
- data.tar.gz: 487d9167c8150ff3e416ef02db0d2147526694c7004205cc386d0061b4f9c4a81b70b6e7e4067f2c6a00da3417aaf0b12d3addb1c5a83513c481ceff55d83aba
6
+ metadata.gz: 3c3c5a75aa95ab7a9ecc68ceb87d87686c0329720537483d16223209b74cf90ed83ac3345ceac3a8b07bff7244029f9edcdf4f7fde066f9a3edc904fd71810e1
7
+ data.tar.gz: f060b8c9630a7c43b2f53ae7c9024ddb1326ccb4a09616d624dab14e545cb767b49059e94117bf153a01f67e8a351d38ec6092c585184c4082769ffb37f2b955
data/Gemfile.lock CHANGED
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flextures (4.1.0)
4
+ flextures (4.2.0)
5
5
  activerecord
6
- activerecord-import
7
6
  activesupport
8
7
 
9
8
  GEM
@@ -16,8 +15,6 @@ GEM
16
15
  activemodel (= 4.2.6)
17
16
  activesupport (= 4.2.6)
18
17
  arel (~> 6.0)
19
- activerecord-import (0.13.0)
20
- activerecord (>= 3.0)
21
18
  activesupport (4.2.6)
22
19
  i18n (~> 0.7)
23
20
  json (~> 1.7, >= 1.7.7)
data/README.ja.md CHANGED
@@ -30,7 +30,12 @@ gem化されているので、bundlerで次のように記述して、普通にb
30
30
  gem "flextures"
31
31
  ```
32
32
 
33
- ちなみに開発環境はruby1.9以上のバージョン、rails3以上、もしくはPadrinoを想定しています
33
+ ```
34
+ bundle install
35
+ bundle exec rails generator flextures:initializer
36
+ ```
37
+
38
+ ちなみに開発環境はruby2.1以上のバージョン、rails4以上を想定しています
34
39
 
35
40
  ## 使い方
36
41
 
@@ -102,7 +107,7 @@ end
102
107
 
103
108
  ```ruby
104
109
  describe ItemShopController do
105
- flextures :items, :users => :users_for_itmshop # users_for_itemshop.csv をロードする
110
+ flextures :items, :users => :users_for_itemshop # users_for_itemshop.csv をロードする
106
111
  end
107
112
  ```
108
113
 
@@ -155,12 +160,10 @@ Flextures::DumpFilter.define :users, {
155
160
 
156
161
  ### 設定ファイル
157
162
 
158
- `config/flextures.config.rb` で設定ファイルを作成すると、データをロード&ダンプするディレクトリなどの設定を変更できます
159
-
160
-
163
+ `config/initializers/flextures.rb` で設定ファイルを作成すると、データをロード&ダンプするディレクトリなどの設定を変更できます
161
164
 
162
165
  ```ruby
163
- Flextures.configure do |config|
166
+ Flextures::Configuration.configure do |config|
164
167
  # Load and dump directory change "spec/fixtures/" to "test/fixtures/"
165
168
  config.load_directory = "test/fixtures/"
166
169
  config.dump_directory = "test/fixtures/"
data/README.md CHANGED
@@ -23,14 +23,23 @@ Major different point is four.
23
23
  ## How to install
24
24
 
25
25
  This program is implemented Rails Plug-in.
26
- You want to install this plug-in.
26
+ If You want to install this plug-in.
27
27
  Please use bundler.
28
28
 
29
+ In `Gemfile`
30
+
29
31
  ```
30
32
  gem "flextures"
31
33
  ```
32
34
 
33
- (Development emnvoriment must be ruby1.9 higer and rails3 higher)
35
+ And execute below commands.
36
+
37
+ ```
38
+ bundle install
39
+ bundle exec rails generator flextures:initializer
40
+ ```
41
+
42
+ (Development emnvoriment must be ruby2.1 higer and rails3 higher)
34
43
 
35
44
  ## How to use
36
45
 
@@ -82,6 +91,7 @@ Fixture load function implemented for Unittes Tools (for example, RSpec, Shoulda
82
91
  ```ruby
83
92
  describe ItemShopController do
84
93
  flextures :users, :items
94
+ end
85
95
  ```
86
96
 
87
97
  flexture function can write like a "fixture" function, implemented in RSpec.
@@ -91,7 +101,8 @@ Flextures function can change load file name.
91
101
 
92
102
  ```ruby
93
103
  describe ItemShopController do
94
- flextures :items, :users => :users_for_itmshop # load "users_for_itemshop.csv"
104
+ flextures :items, :users => :users_for_itemshop # load "users_for_itemshop.csv"
105
+ end
95
106
  ```
96
107
 
97
108
  Other option information
@@ -147,7 +158,7 @@ Other options please see [wiki](https://github.com/baban/flextures/wiki/Factoryf
147
158
  In `config/initializers/flextures.rb`, configuration file can change load and dump directory
148
159
 
149
160
  ```ruby
150
- Flextures.configure do |config|
161
+ Flextures::Configuration.configure do |config|
151
162
  # Load and dump directory change "spec/fixtures/" to "test/fixtures/"
152
163
  config.load_directory = "test/fixtures/"
153
164
  config.dump_directory = "test/fixtures/"
data/flextures.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'flextures/version'
@@ -20,7 +19,6 @@ Gem::Specification.new do |spec|
20
19
 
21
20
  spec.add_dependency "activerecord"
22
21
  spec.add_dependency "activesupport"
23
- spec.add_dependency "activerecord-import"
24
22
 
25
23
  spec.add_development_dependency "bundler", "~> 1.6"
26
24
  spec.add_development_dependency "rake"
@@ -30,7 +30,7 @@ module Flextures
30
30
  def self.load_configurations
31
31
  if defined?(Rails) and Rails.root
32
32
  [
33
- File.join( Rails.root.to_path,"/config/flextures.factory.rb" ),
33
+ File.join(Rails.root.to_path, "/config/flextures.factory.rb"),
34
34
  ].each { |fn| File.exist?(fn) && load(fn) }
35
35
  end
36
36
  end
@@ -38,7 +38,7 @@ module Flextures
38
38
  # @return [Array] flextures useable table names
39
39
  def self.deletable_tables
40
40
  tables = ActiveRecord::Base.connection.tables
41
- Flextures::Configuration.ignore_tables.each { |name| tables.delete( name.to_s ) }
41
+ Flextures::Configuration.ignore_tables.each { |name| tables.delete(name.to_s) }
42
42
  tables
43
43
  end
44
44
 
@@ -95,7 +95,7 @@ module Flextures
95
95
 
96
96
  table_names = Flextures::deletable_tables.map{ |name| { table: name, file: name } } if table_names.empty?
97
97
 
98
- # parse env["FIXTURES"] paameter
98
+ # parse env["FIXTURES"] parameter
99
99
  fixtures_args_parser = ->(s){
100
100
  names = s.split(',')
101
101
  if env["TABLE"] or env["T"] or env["MODEL"] or env["M"]
@@ -105,9 +105,9 @@ module Flextures
105
105
  end
106
106
  }
107
107
  # parse filename and define parameters.
108
- table_names = fixtures_args_parser.call env["FIXTURES"] if env["FIXTURES"]
109
- table_names = fixtures_args_parser.call env["FILE"] if env["FILE"]
110
- table_names = fixtures_args_parser.call env["F"] if env["F"]
108
+ table_names = fixtures_args_parser.call(env["FIXTURES"]) if env["FIXTURES"]
109
+ table_names = fixtures_args_parser.call(env["FILE"]) if env["FILE"]
110
+ table_names = fixtures_args_parser.call(env["F"]) if env["F"]
111
111
 
112
112
  table_names = table_names.map{ |option| option.merge(dir: env["DIR"]) } if env["DIR"]
113
113
  table_names = table_names.map{ |option| option.merge(dir: env["D"]) } if env["D"]
@@ -127,8 +127,10 @@ module Flextures
127
127
 
128
128
  # check exist filename block
129
129
  def self.exist
130
- return->(name){ File.exists?(File.join(Flextures::Configuration.load_directory, "#{name}.csv")) or
131
- File.exists?(File.join(Flextures::Configuration.load_directory, "#{name}.yml")) }
130
+ return ->(name) {
131
+ File.exist?(File.join(Flextures::Configuration.load_directory, "#{name}.csv")) or
132
+ File.exist?(File.join(Flextures::Configuration.load_directory, "#{name}.yml"))
133
+ }
132
134
  end
133
135
  end
134
136
  end
@@ -3,7 +3,6 @@ require 'csv'
3
3
  require 'erb'
4
4
 
5
5
  require 'active_record'
6
- require 'activerecord-import'
7
6
 
8
7
  require 'flextures/flextures_base_config'
9
8
  require 'flextures/flextures'
@@ -18,9 +17,9 @@ module Flextures
18
17
  # @return [Hash] tanslated Hash data
19
18
  def to_hash(keys)
20
19
  values = self
21
- values = values[0..keys.size-1] if keys.size < values.size
22
- values = values+[nil]*(keys.size-values.size) if keys.size > values.size
23
- [keys,values].transpose.reduce({}){ |h,pair| k,v=pair; h[k]=v; h }
20
+ values = values[0..keys.size-1] if keys.size < values.size
21
+ values = values + [nil] * (keys.size-values.size) if keys.size > values.size
22
+ [keys, values].transpose.reduce({}){ |h,(k,v)| h[k]=v; h }
24
23
  end
25
24
  end
26
25
  end
@@ -321,7 +320,7 @@ module Flextures
321
320
  end
322
321
 
323
322
  # print warinig message that lack or not exist colum names
324
- def self.warning( format, attributes, keys )
323
+ def self.warning(format, attributes, keys)
325
324
  (attributes-keys).each { |name| puts "Warning: #{format} colum is missing! [#{name}]" }
326
325
  (keys-attributes).each { |name| puts "Warning: #{format} colum is left over! [#{name}]" }
327
326
  end
@@ -1,3 +1,3 @@
1
1
  module Flextures
2
- VERSION="4.1.0"
2
+ VERSION="4.2.0"
3
3
  end
@@ -0,0 +1,17 @@
1
+ module Flextures
2
+ module Generators
3
+ class InitializerGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ def create_initializer_file
7
+ copy_file "flextures.rb", "config/initializers/flextures.rb"
8
+ copy_file "flextures.factory.rb", "config/flextures.factory.rb"
9
+ end
10
+
11
+ desc <<-MSG
12
+ Description:
13
+ Creates flextures configuration files.
14
+ MSG
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ # Flextures::Factory.define :users do |f|
2
+ # f.password = "hogehoge"
3
+ # f
4
+ # end
5
+
6
+ # Flextures::DumpFilter.define :users, {
7
+ # :encrypted_password => lambda { |v| Base64.encode64(v) }
8
+ # }
@@ -0,0 +1,6 @@
1
+ Flextures::Configuration.configure do |config|
2
+ # config.init_all_tables = true
3
+ # config.ignore_tables = ["schema_migrations"]
4
+ # config.load_directory = "test/fixtures/"
5
+ # config.dump_directory = "test/fixtures/"
6
+ end
@@ -5,8 +5,7 @@ require 'test_helper'
5
5
  describe Flextures::ARGS do
6
6
  describe "if set TABLE='table_name' option " do
7
7
  before do
8
- ENV["TABLE"] = "users"
9
- @format = Flextures::ARGS.parse
8
+ @format = Flextures::ARGS.parse("TABLE"=>"users")
10
9
  end
11
10
 
12
11
  it "return table_name" do
@@ -16,16 +15,11 @@ describe Flextures::ARGS do
16
15
  it "filename is same table_name" do
17
16
  assert_equal "users", @format.first[:file]
18
17
  end
19
-
20
- after do
21
- ENV.delete("TABLE")
22
- end
23
18
  end
24
19
 
25
20
  describe "if set T=table_name option " do
26
21
  before do
27
- ENV["T"] = "s_user"
28
- @format = Flextures::ARGS.parse
22
+ @format = Flextures::ARGS.parse("T"=>"s_user")
29
23
  end
30
24
 
31
25
  it "retrun table_name" do
@@ -35,17 +29,11 @@ describe Flextures::ARGS do
35
29
  it "filename is same table_name" do
36
30
  assert_equal "s_user", @format.first[:file]
37
31
  end
38
-
39
- after do
40
- ENV.delete("T")
41
- end
42
32
  end
43
33
 
44
34
  describe " DIR=option " do
45
35
  before do
46
- ENV["T"] = "users"
47
- ENV["DIR"] = "test/fixtures/"
48
- @format = Flextures::ARGS.parse
36
+ @format = Flextures::ARGS.parse("T"=>"users", "DIR"=>"test/fixtures/")
49
37
  end
50
38
 
51
39
  it "directory name is exist" do
@@ -59,18 +47,11 @@ describe Flextures::ARGS do
59
47
  it "file name is equal table name" do
60
48
  assert_equal "users", @format.first[:file]
61
49
  end
62
-
63
- after do
64
- ENV.delete("T")
65
- ENV.delete("DIR")
66
- end
67
50
  end
68
51
 
69
52
  describe " D=option " do
70
53
  before do
71
- ENV["T"] = "users"
72
- ENV["D"] = "test/fixtures/"
73
- @format = Flextures::ARGS.parse
54
+ @format = Flextures::ARGS.parse("T"=>"users", "D"=>"test/fixtures/")
74
55
  end
75
56
 
76
57
  it "directory name" do
@@ -84,18 +65,11 @@ describe Flextures::ARGS do
84
65
  it "file name is equal table name" do
85
66
  assert_equal "users", @format.first[:file]
86
67
  end
87
-
88
- after do
89
- ENV.delete("T")
90
- ENV.delete("D")
91
- end
92
68
  end
93
69
 
94
70
  describe " FIXTURES=option " do
95
71
  before do
96
- ENV["T"] = "users"
97
- ENV["FIXTURES"] = "user_another"
98
- @format = Flextures::ARGS.parse
72
+ @format = Flextures::ARGS.parse("T"=>"users", "FIXTURES"=>"user_another")
99
73
  end
100
74
 
101
75
  it "table name is exist" do
@@ -105,19 +79,12 @@ describe Flextures::ARGS do
105
79
  it " file name is changed by option's name " do
106
80
  assert_equal "user_another", @format.first[:file]
107
81
  end
108
-
109
- after do
110
- ENV.delete("T")
111
- ENV.delete("FIXTURES")
112
- end
113
82
  end
114
83
 
115
84
  describe " MINUS option " do
116
85
  describe "only one columns" do
117
86
  before do
118
- ENV["T"]="users"
119
- ENV["MINUS"]="id"
120
- @format = Flextures::ARGS.parse
87
+ @format = Flextures::ARGS.parse("T"=>"users", "MINUS"=>"id")
121
88
  end
122
89
 
123
90
  it " option contain 'minus' parameters" do
@@ -127,31 +94,19 @@ describe Flextures::ARGS do
127
94
 
128
95
  describe "many columns" do
129
96
  before do
130
- ENV["T"]="users"
131
- ENV["MINUS"]="id,created_at,updated_at"
132
- @format = Flextures::ARGS.parse
97
+ @format = Flextures::ARGS.parse("T"=>"users", "MINUS"=>"id,created_at,updated_at")
133
98
  end
134
99
 
135
100
  it " option contain 'minus' parameters" do
136
101
  assert_equal ["id","created_at","updated_at"], @format.first[:minus]
137
102
  end
138
103
  end
139
-
140
- after do
141
- ENV.delete("T")
142
- ENV.delete("MINUS")
143
- end
144
104
  end
145
105
 
146
106
  describe " PLUS options " do
147
- before do
148
- ENV["T"]="users"
149
- end
150
-
151
107
  describe "only one columns" do
152
108
  before do
153
- ENV["PLUS"]="hoge"
154
- @format = Flextures::ARGS.parse
109
+ @format = Flextures::ARGS.parse("T"=>"users", "PLUS"=>"hoge")
155
110
  end
156
111
 
157
112
  it " option contain 'plus' parameters" do
@@ -161,18 +116,12 @@ describe Flextures::ARGS do
161
116
 
162
117
  describe "many columns" do
163
118
  before do
164
- ENV["PLUS"]="hoge,mage"
165
- @format = Flextures::ARGS.parse
119
+ @format = Flextures::ARGS.parse("T"=>"users", "PLUS"=>"hoge,mage")
166
120
  end
167
121
 
168
122
  it " option contain 'plus' parameters" do
169
123
  assert_equal ["hoge","mage"], @format.first[:plus]
170
124
  end
171
125
  end
172
-
173
- after do
174
- ENV.delete("T")
175
- ENV.delete("PLUS")
176
- end
177
126
  end
178
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flextures
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - baban
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: activerecord-import
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +94,9 @@ files:
108
94
  - lib/flextures/flextures_railtie.rb
109
95
  - lib/flextures/rspec_flextures_support.rb
110
96
  - lib/flextures/version.rb
97
+ - lib/generators/flextures/initializer_generator.rb
98
+ - lib/generators/flextures/templates/flextures.factory.rb
99
+ - lib/generators/flextures/templates/flextures.rb
111
100
  - test/models/flextures_test.rb
112
101
  - test/test_helper.rb
113
102
  - test/unit/flextures_args_test.rb