spectifly-sequel 0.0.2 → 0.0.3

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spectifly-sequel (0.0.2)
4
+ spectifly-sequel (0.0.3)
5
5
  activesupport
6
6
  sequel
7
7
  spectifly
@@ -12,19 +12,12 @@ GEM
12
12
  activesupport (3.2.13)
13
13
  i18n (= 0.6.1)
14
14
  multi_json (~> 1.0)
15
- builder (3.2.0)
16
- columnize (0.3.6)
17
- debugger (1.5.0)
18
- columnize (>= 0.3.1)
19
- debugger-linecache (~> 1.2.0)
20
- debugger-ruby_core_source (~> 1.2.0)
21
- debugger-linecache (1.2.0)
22
- debugger-ruby_core_source (1.2.0)
15
+ builder (3.2.2)
23
16
  diff-lcs (1.2.4)
24
17
  i18n (0.6.1)
25
18
  json (1.8.0)
26
19
  multi_json (1.7.2)
27
- rake (10.0.4)
20
+ rake (10.1.0)
28
21
  rspec (2.13.0)
29
22
  rspec-core (~> 2.13.0)
30
23
  rspec-expectations (~> 2.13.0)
@@ -33,12 +26,12 @@ GEM
33
26
  rspec-expectations (2.13.0)
34
27
  diff-lcs (>= 1.1.3, < 2.0)
35
28
  rspec-mocks (2.13.1)
36
- sequel (3.47.0)
29
+ sequel (4.0.0)
37
30
  simplecov (0.7.1)
38
31
  multi_json (~> 1.0)
39
32
  simplecov-html (~> 0.7.1)
40
33
  simplecov-html (0.7.1)
41
- spectifly (0.0.1)
34
+ spectifly (0.0.2)
42
35
  builder
43
36
  json
44
37
  rake
@@ -48,7 +41,6 @@ PLATFORMS
48
41
 
49
42
  DEPENDENCIES
50
43
  bundler (~> 1.3)
51
- debugger
52
44
  rake
53
45
  rspec
54
46
  simplecov
data/README.md CHANGED
@@ -84,10 +84,8 @@ Spectifly::Sequel.configure {
84
84
 
85
85
  The YAML configuration file should look something like this:
86
86
  ```yaml
87
- Sequel:
88
- Spectifly:
89
- migration_path: PATH_TO_MIGRATION_DIRECTORY
90
- entity_definition_path: PATH_TO_ENTITY_DEFINITION_DIRECTORY
87
+ sequel_migration_path: PATH_TO_MIGRATION_DIRECTORY
88
+ entity_path: PATH_TO_ENTITY_DEFINITION_DIRECTORY
91
89
  ```
92
90
 
93
91
  ## Contributing
data/Rakefile CHANGED
@@ -10,4 +10,3 @@ require 'sequel'
10
10
  require 'spectifly'
11
11
  require 'spectifly/base'
12
12
  require 'spectifly/sequel'
13
- require 'spectifly/sequel/tasks'
@@ -1,9 +1,8 @@
1
1
  require 'active_support/inflector/methods'
2
2
  require 'spectifly'
3
- require_relative 'sequel/config'
3
+ require_relative 'sequel/configuration'
4
4
  require_relative 'sequel/types'
5
5
  require_relative 'sequel/model'
6
- require_relative 'sequel/tasks'
7
6
  require_relative 'sequel/relationship/base'
8
7
  require_relative 'sequel/relationship/one_to_one'
9
8
  require_relative 'sequel/relationship/belongs_to'
@@ -0,0 +1,34 @@
1
+ module Spectifly
2
+ module Sequel
3
+ class Configuration < Spectifly::Configuration
4
+ VALID_CONFIG_KEYS = [:sequel_migration_path, :sequel_migration_version_type]
5
+
6
+ attr_accessor :migration_path, :migration_version_type
7
+
8
+ def initialize(config)
9
+ if config.is_a? String
10
+ config = YAML.load_file(config)
11
+ end
12
+
13
+ new_config = {}
14
+ config.each { |k, v| new_config[k.to_s] = v }
15
+
16
+ begin
17
+ super new_config
18
+ @migration_path = new_config.fetch('sequel_migration_path')
19
+ @migration_version_type = get_version_type new_config['sequel_migration_version_type']
20
+ rescue KeyError => e
21
+ raise "Spectify::Sequel is not configured properly. \"#{e.message.sub(/"$/, '').sub(/^.*"/, '')}\" must be set via YAML or a hash."
22
+ end
23
+ end
24
+
25
+ def get_version_type type
26
+ if %w(Timestamp Integer).include? type.to_s
27
+ type
28
+ else
29
+ 'Timestamp'
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,10 +1,10 @@
1
1
  module Spectifly
2
2
  module Sequel
3
3
  class MigrationGenerator
4
- def initialize(entity, migration_path=nil, entity_path=nil, migration_version_type=nil)
5
- @migration_path = File.expand_path(migration_path || Spectifly::Sequel.migration_path)
6
- @entity_definition_path = File.expand_path(entity_path || Spectifly::Sequel.entity_definition_path)
7
- @migration_version_type = migration_version_type || Spectifly::Sequel.migration_version_type
4
+ def initialize(entity, configuration)
5
+ @migration_path = File.expand_path(configuration.migration_path)
6
+ @entity_definition_path = File.expand_path(configuration.entity_path)
7
+ @migration_version_type = configuration.migration_version_type
8
8
  @builder = Spectifly::Sequel::Builder.from_path(File.join(@entity_definition_path, entity + '.entity'))
9
9
  end
10
10
 
@@ -1,5 +1,5 @@
1
1
  module Spectifly
2
2
  module Sequel
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -1,12 +1,15 @@
1
1
  require 'rake'
2
2
  require 'spectifly/sequel'
3
+ require 'spectifly/tasks'
3
4
 
4
5
  namespace 'spectifly' do
5
6
  namespace 'sequel' do
6
7
  desc 'Generate migration from entity definition file'
7
- task :generate, [:entity_type] do |t, args|
8
- Spectifly::Sequel.configure_with File.join(Dir.pwd, 'config', 'spectifly.yml')
9
- Spectifly::Sequel::MigrationGenerator.new(args[:entity_type]).run!
8
+ Spectifly::Task.new('generate', [:entity_type]) do |spectifly, args|
9
+ # need to use some sort of factory to determine what type of configuration
10
+ # object we need on the Spectifly::Task#configure! method
11
+ configuration = Spectifly::Sequel::Configuration.new File.join(Dir.pwd, 'config', 'spectifly.yml')
12
+ Spectifly::Sequel::MigrationGenerator.new(args[:entity_type], configuration).run!
10
13
  end
11
14
  end
12
15
  end
@@ -1,7 +1,4 @@
1
- Spectifly: &default
2
- entity_definition_path: ./spec/fixtures/
3
- Sequel:
4
- <<: *default
5
- migration_path: ./spec/tmp/migrations/
6
- migration_version_type: Integer
1
+ entity_path: ./spec/fixtures/
2
+ sequel_migration_path: ./spec/tmp/migrations/
3
+ sequel_migration_version_type: Integer
7
4
 
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spectifly::Sequel::Configuration do
4
+ let(:path_to_config_file) { File.join(base_fixture_path, 'config_file.yml') }
5
+ let(:config_hash) {
6
+ {
7
+ 'sequel_migration_path' => 'foo/bar/baz.yml',
8
+ 'entity_path' => 'blah/blah/',
9
+ 'sequel_migration_version_type' => 'Timestamp',
10
+ }
11
+ }
12
+
13
+ it 'should allow config to be read from yaml in a path specified by the user' do
14
+ subject = described_class.new path_to_config_file
15
+ subject.migration_path.should == './spec/tmp/migrations/'
16
+ subject.entity_path.should == './spec/fixtures/'
17
+ subject.migration_version_type.should == 'Integer'
18
+ end
19
+
20
+ it 'should accept a config in hash format' do
21
+ subject = described_class.new config_hash
22
+ subject.migration_path.should == 'foo/bar/baz.yml'
23
+ subject.entity_path.should == 'blah/blah/'
24
+ subject.migration_version_type.should == 'Timestamp'
25
+ end
26
+
27
+ it 'gives reasonable, instructive error if either path is not set' do
28
+ lambda {
29
+ described_class.new(:entity_path => 'foo')
30
+ }.should raise_error('Spectify::Sequel is not configured properly. "sequel_migration_path" must be set via YAML or a hash.')
31
+
32
+ lambda {
33
+ described_class.new(:sequel_migration_path => 'bar')
34
+ }.should raise_error('Spectify::Sequel is not configured properly. "entity_path" must be set via YAML or a hash.')
35
+
36
+ described_class.
37
+ new(config_hash.merge({:sequel_migration_version_type => 'bsadfklj'})).
38
+ migration_version_type.should == 'Timestamp'
39
+ end
40
+
41
+ it 'defaults to Timestamp migration versions if not set' do
42
+ subject = described_class.new(config_hash.merge({:sequel_migration_version_type => nil}))
43
+ subject.migration_version_type.should == 'Timestamp'
44
+ end
45
+ end
@@ -1,8 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Spectifly::Sequel::MigrationGenerator do
4
+ let(:config) { Spectifly::Sequel::Configuration.new File.join(base_fixture_path, 'config_file.yml') }
5
+
4
6
  before :each do
5
- Spectifly::Sequel.configure_with File.join(base_fixture_path, 'config_file.yml')
6
7
  cleanup_files
7
8
  end
8
9
 
@@ -17,7 +18,7 @@ describe Spectifly::Sequel::MigrationGenerator do
17
18
  end
18
19
 
19
20
  it 'reads a Spectifly entity definition file and outputs a migration that can generate a new table for that entity' do
20
- generator = Spectifly::Sequel::MigrationGenerator.new('individual')
21
+ generator = Spectifly::Sequel::MigrationGenerator.new('individual', config)
21
22
  generator.run!
22
23
  expected_migration_path = File.join(migration_output_path, '001_create_individuals.rb')
23
24
  File.should exist(expected_migration_path)
@@ -27,7 +28,7 @@ describe Spectifly::Sequel::MigrationGenerator do
27
28
  it 'determines what the next migration version should be' do
28
29
  File.open(File.join(migration_output_path, '001_create_cookies.rb'), 'w') { |f| f.write('Hi!') }
29
30
 
30
- generator = Spectifly::Sequel::MigrationGenerator.new('individual')
31
+ generator = Spectifly::Sequel::MigrationGenerator.new('individual', config)
31
32
  generator.run!
32
33
 
33
34
  expected_migration_path = File.join(migration_output_path, '002_create_individuals.rb')
@@ -36,7 +37,12 @@ describe Spectifly::Sequel::MigrationGenerator do
36
37
 
37
38
  it 'uses current datetime if user is assigning timestamps' do
38
39
  DateTime.stub(:now).and_return DateTime.new(2013,01,01)
39
- generator = Spectifly::Sequel::MigrationGenerator.new('individual', migration_output_path, base_fixture_path, 'Timestamp')
40
+ configuration = Spectifly::Sequel::Configuration.new(
41
+ :sequel_migration_path => migration_output_path,
42
+ :entity_path => base_fixture_path,
43
+ :sequel_migration_version_type => 'Timestamp'
44
+ )
45
+ generator = Spectifly::Sequel::MigrationGenerator.new('individual', configuration)
40
46
  generator.run!
41
47
 
42
48
  expected_migration_path = File.join(migration_output_path, '20130101000000_create_individuals.rb')
@@ -25,6 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "rake"
27
27
  spec.add_development_dependency "rspec"
28
- spec.add_development_dependency "debugger"
29
28
  spec.add_development_dependency "simplecov"
30
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectifly-sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-05-25 00:00:00.000000000 Z
15
+ date: 2013-07-30 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: spectifly
@@ -110,22 +110,6 @@ dependencies:
110
110
  - - ! '>='
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
- - !ruby/object:Gem::Dependency
114
- name: debugger
115
- requirement: !ruby/object:Gem::Requirement
116
- none: false
117
- requirements:
118
- - - ! '>='
119
- - !ruby/object:Gem::Version
120
- version: '0'
121
- type: :development
122
- prerelease: false
123
- version_requirements: !ruby/object:Gem::Requirement
124
- none: false
125
- requirements:
126
- - - ! '>='
127
- - !ruby/object:Gem::Version
128
- version: '0'
129
113
  - !ruby/object:Gem::Dependency
130
114
  name: simplecov
131
115
  requirement: !ruby/object:Gem::Requirement
@@ -161,7 +145,7 @@ files:
161
145
  - Rakefile
162
146
  - lib/spectifly/sequel.rb
163
147
  - lib/spectifly/sequel/builder.rb
164
- - lib/spectifly/sequel/config.rb
148
+ - lib/spectifly/sequel/configuration.rb
165
149
  - lib/spectifly/sequel/erb/create_association_tables.erb
166
150
  - lib/spectifly/sequel/erb/create_table.erb
167
151
  - lib/spectifly/sequel/erb/field/many_to_many_association.erb
@@ -193,10 +177,9 @@ files:
193
177
  - spec/fixtures/cow.entity
194
178
  - spec/fixtures/group.entity
195
179
  - spec/fixtures/individual.entity
196
- - spec/fixtures/invalid_config_file.yml
197
180
  - spec/spec_helper.rb
198
181
  - spec/spectifly/sequel/builder_spec.rb
199
- - spec/spectifly/sequel/config_spec.rb
182
+ - spec/spectifly/sequel/configuration_spec.rb
200
183
  - spec/spectifly/sequel/field_spec.rb
201
184
  - spec/spectifly/sequel/migration_generator_spec.rb
202
185
  - spec/spectifly/sequel/model_spec.rb
@@ -218,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
201
  version: '0'
219
202
  segments:
220
203
  - 0
221
- hash: 2662357379730941317
204
+ hash: -3856835324753604270
222
205
  required_rubygems_version: !ruby/object:Gem::Requirement
223
206
  none: false
224
207
  requirements:
@@ -227,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
210
  version: '0'
228
211
  segments:
229
212
  - 0
230
- hash: 2662357379730941317
213
+ hash: -3856835324753604270
231
214
  requirements: []
232
215
  rubyforge_project:
233
216
  rubygems_version: 1.8.23
@@ -243,10 +226,9 @@ test_files:
243
226
  - spec/fixtures/cow.entity
244
227
  - spec/fixtures/group.entity
245
228
  - spec/fixtures/individual.entity
246
- - spec/fixtures/invalid_config_file.yml
247
229
  - spec/spec_helper.rb
248
230
  - spec/spectifly/sequel/builder_spec.rb
249
- - spec/spectifly/sequel/config_spec.rb
231
+ - spec/spectifly/sequel/configuration_spec.rb
250
232
  - spec/spectifly/sequel/field_spec.rb
251
233
  - spec/spectifly/sequel/migration_generator_spec.rb
252
234
  - spec/spectifly/sequel/model_spec.rb
@@ -1,53 +0,0 @@
1
- module Spectifly
2
- module Sequel
3
- @valid_config_keys = [:migration_path, :entity_definition_path, :migration_version_type]
4
- @config = {}
5
-
6
- def self.configure_with(path_to_config_file)
7
- begin
8
- config = YAML.load_file(path_to_config_file)['Spectifly']['Sequel']
9
- rescue NoMethodError
10
- raise config_instructions
11
- end
12
- configure(config)
13
- end
14
-
15
- def self.configure(opts)
16
- opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
17
- end
18
-
19
- def self.migration_path
20
- @config[:migration_path] or raise missing_configuration('migration_path')
21
- end
22
-
23
- def self.entity_definition_path
24
- @config[:entity_definition_path] or raise missing_configuration('entity_definition_path')
25
- end
26
-
27
- def self.migration_version_type
28
- type = @config[:migration_version_type].to_s
29
- if %w(Timestamp Integer).include? type
30
- type
31
- else
32
- 'Timestamp'
33
- end
34
- end
35
-
36
- private
37
- def self.config_instructions
38
- <<-INSTRUCTIONS
39
- Please format config files in the following manner:
40
- ``- begin YAML
41
- Sequel:
42
- Spectifly:
43
- migration_path: PATH_TO_MIGRATION_DIRECTORY
44
- entity_definition_path: PATH_TO_ENTITY_DEFINITION_DIRECTORY
45
- ``- end YAML
46
- INSTRUCTIONS
47
- end
48
-
49
- def self.missing_configuration(config_param)
50
- "Spectify::Sequel is not configured properly. \"#{config_param}\" must be set via YAML or a hash."
51
- end
52
- end
53
- end
@@ -1,2 +0,0 @@
1
- entity_definition_path: ./
2
- migration_path: ../tmp/migrations/
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spectifly::Sequel do
4
- let(:path_to_config_file) { File.join(base_fixture_path, 'config_file.yml') }
5
- let(:path_to_invalid_config_file) { File.join(base_fixture_path, 'invalid_config_file.yml') }
6
- let(:config_hash) {
7
- {
8
- 'migration_path' => 'foo/bar/baz.yml',
9
- 'entity_definition_path' => 'blah/blah/',
10
- 'migration_version_type' => 'Timestamp',
11
- }
12
- }
13
- let(:friendly_config_instructions) {
14
- <<-INSTRUCTIONS
15
- Please format config files in the following manner:
16
- ``- begin YAML
17
- Sequel:
18
- Spectifly:
19
- migration_path: PATH_TO_MIGRATION_DIRECTORY
20
- entity_definition_path: PATH_TO_ENTITY_DEFINITION_DIRECTORY
21
- ``- end YAML
22
- INSTRUCTIONS
23
- }
24
-
25
- it 'should allow config to be read from yaml in a path specified by the user' do
26
- described_class.configure_with path_to_config_file
27
- described_class.migration_path.should == './spec/tmp/migrations/'
28
- described_class.entity_definition_path.should == './spec/fixtures/'
29
- described_class.migration_version_type.should == 'Integer'
30
- end
31
-
32
- it 'should accept a config in hash format' do
33
- described_class.configure config_hash
34
- described_class.migration_path.should == 'foo/bar/baz.yml'
35
- described_class.entity_definition_path.should == 'blah/blah/'
36
- described_class.migration_version_type.should == 'Timestamp'
37
- end
38
-
39
- it 'gives reasonable, instructive error if YAML is misconfigured' do
40
- lambda {
41
- described_class.configure_with path_to_invalid_config_file
42
- }.should raise_error(friendly_config_instructions)
43
- end
44
-
45
- it 'gives reasonable, instructive error if either path is not set' do
46
- described_class.configure({:migration_path => nil, :entity_definition_path => nil, :migration_version_type => 'IDoNotKnow'})
47
- lambda {
48
- described_class.migration_path
49
- }.should raise_error('Spectify::Sequel is not configured properly. "migration_path" must be set via YAML or a hash.')
50
- lambda {
51
- described_class.entity_definition_path
52
- }.should raise_error('Spectify::Sequel is not configured properly. "entity_definition_path" must be set via YAML or a hash.')
53
- described_class.migration_version_type.should == 'Timestamp'
54
- end
55
-
56
- it 'defaults to Timestamp migration versions if not set' do
57
- described_class.configure({:migration_version_type => nil})
58
- described_class.migration_version_type.should == 'Timestamp'
59
- end
60
- end