schemaker 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,11 +1,17 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
- # gem "activerecord", ">= 3.0.1"
3
+ gem 'sugar-high', '>= 0.6'
4
+ gem 'require_all', '~> 1.2.0'
4
5
 
5
- group :development do
6
+ group :development, :test do
6
7
  gem "activerecord", ">= 3.0.1"
7
8
  gem "rspec", ">= 2.6.0"
8
- gem "bundler", "~> 1.0.6"
9
- gem "jeweler", "~> 1.6.2"
9
+ gem "bundler", ">= 1"
10
+ gem "jeweler", ">= 1.6"
10
11
  gem "rcov", ">= 0"
12
+ gem 'yard'
13
+ gem 'database_cleaner', '~> 0.6.8', :git => "git://github.com/kristianmandrup/database_cleaner.git"
14
+ gem 'sqlite3'
15
+ gem 'shoulda'
16
+ gem 'cutter'
11
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -13,8 +13,8 @@ module Schemaker
13
13
  # @param [Schema::Models] each model needs to have access to the collection of models it may need to create relations with
14
14
  # @param [Class] each model must have a reference to the Class it aims to configure!
15
15
  def initialize models, my_class
16
- raise ArgumentError, "The first argument must be a Schema::Models instance" if !models.is_a?(Schemaker::Models)
17
- raise ArgumentError, "The second argument must be the Class that is to be configured" if !my_class.is_a?(Class)
16
+ raise ArgumentError, "The first argument must be a Schema::Models instance, was #{models}" if !models.is_a?(Schemaker::Models)
17
+ raise ArgumentError, "The second argument must be the Class that is to be configured, was #{my_class}" if !my_class.is_a?(Class)
18
18
 
19
19
  @models = models
20
20
  @my_class = my_class
@@ -116,8 +116,8 @@ module Schemaker
116
116
  # @param [Class, Symbol] the Class that is the object of the relationship, fx Role for a User.has_many relationship
117
117
  # @param [Hash] any extra relationship options, fx for a :through relationship, or to indicate :class_name etc.
118
118
  def make_relationship relationship_name, clazz, options = {}
119
- key_name = options.delete(:key) || key(clazz)
120
-
119
+ # inspect!(binding)
120
+ key_name = (options.delete(:key) || key(clazz)).to_sym # first must be a sym too
121
121
  opts_str = options.empty? ? '' : options.inspect.insert(0, ', ').gsub(/[{}]/ , '')
122
122
  log "#{my_class_name}.#{relationship_name} :#{key_name}#{opts_str}" if log_on?
123
123
 
@@ -27,6 +27,10 @@ module Schemaker
27
27
  # @param join_class [Class]
28
28
  # @param options [Hash] - contains the key to be used for the main field (subject key) and possibly other options to configure the models more precisely as needed
29
29
  def initialize subject_class, object_class, join_class, options = {}
30
+ raise ArgumentError, "subject class not given" if !subject_class
31
+ raise ArgumentError, "object class not given" if !object_class
32
+ raise ArgumentError, "join class not given" if !join_class
33
+
30
34
  @subject_model = SubjectModel.new self, subject_class, options[:subject_key]
31
35
  @object_model = ObjectModel.new self, object_class
32
36
  @join_model = JoinModel.new self, join_class
data/lib/schemaker.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'cutter'
1
2
  module Schemaker
2
3
  class << self
3
4
  attr_accessor :log_on
@@ -11,4 +12,4 @@ module Schemaker
11
12
  autoload :JoinModel, 'schemaker/models/join_model'
12
13
  autoload :ObjectModel, 'schemaker/models/object_model'
13
14
  autoload :SubjectModel, 'schemaker/models/subject_model'
14
- end
15
+ end
data/schemaker.gemspec CHANGED
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{schemaker}
8
- s.version = "0.1.0"
7
+ s.name = "schemaker"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Kristian Mandrup}]
12
- s.date = %q{2011-06-12}
13
- s.description = %q{Configures relationships between subject, join and object model for a given behavior}
14
- s.email = %q{kmandrup@gmail.com}
11
+ s.authors = ["Kristian Mandrup"]
12
+ s.date = "2011-10-12"
13
+ s.description = "Configures relationships between subject, join and object model for a given behavior"
14
+ s.email = "kmandrup@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.textile"
@@ -31,6 +31,10 @@ Gem::Specification.new do |s|
31
31
  "lib/schemaker/models/object_model.rb",
32
32
  "lib/schemaker/models/subject_model.rb",
33
33
  "schemaker.gemspec",
34
+ "spec/active_record/active_record_helper.rb",
35
+ "spec/active_record/active_record_spec.rb",
36
+ "spec/active_record/db/database.yml",
37
+ "spec/active_record/migrations/create_models.rb",
34
38
  "spec/models_helper.rb",
35
39
  "spec/schemaker/model/join_spec.rb",
36
40
  "spec/schemaker/model/object_spec.rb",
@@ -38,34 +42,55 @@ Gem::Specification.new do |s|
38
42
  "spec/schemaker/models_spec.rb",
39
43
  "spec/spec_helper.rb"
40
44
  ]
41
- s.homepage = %q{http://github.com/kristianmandrup/schemaker}
42
- s.licenses = [%q{MIT}]
43
- s.require_paths = [%q{lib}]
44
- s.rubygems_version = %q{1.8.5}
45
- s.summary = %q{Schema maker takes care of configuring your model schemas to map behavior}
45
+ s.homepage = "http://github.com/kristianmandrup/schemaker"
46
+ s.licenses = ["MIT"]
47
+ s.require_paths = ["lib"]
48
+ s.rubygems_version = "1.8.10"
49
+ s.summary = "Schema maker takes care of configuring your model schemas to map behavior"
46
50
 
47
51
  if s.respond_to? :specification_version then
48
52
  s.specification_version = 3
49
53
 
50
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_runtime_dependency(%q<sugar-high>, [">= 0.6"])
56
+ s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
51
57
  s.add_development_dependency(%q<activerecord>, [">= 3.0.1"])
52
58
  s.add_development_dependency(%q<rspec>, [">= 2.6.0"])
53
- s.add_development_dependency(%q<bundler>, ["~> 1.0.6"])
54
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
59
+ s.add_development_dependency(%q<bundler>, [">= 1"])
60
+ s.add_development_dependency(%q<jeweler>, [">= 1.6"])
55
61
  s.add_development_dependency(%q<rcov>, [">= 0"])
62
+ s.add_development_dependency(%q<yard>, [">= 0"])
63
+ s.add_development_dependency(%q<database_cleaner>, ["~> 0.6.8"])
64
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
65
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
66
+ s.add_development_dependency(%q<cutter>, [">= 0"])
56
67
  else
68
+ s.add_dependency(%q<sugar-high>, [">= 0.6"])
69
+ s.add_dependency(%q<require_all>, ["~> 1.2.0"])
57
70
  s.add_dependency(%q<activerecord>, [">= 3.0.1"])
58
71
  s.add_dependency(%q<rspec>, [">= 2.6.0"])
59
- s.add_dependency(%q<bundler>, ["~> 1.0.6"])
60
- s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
72
+ s.add_dependency(%q<bundler>, [">= 1"])
73
+ s.add_dependency(%q<jeweler>, [">= 1.6"])
61
74
  s.add_dependency(%q<rcov>, [">= 0"])
75
+ s.add_dependency(%q<yard>, [">= 0"])
76
+ s.add_dependency(%q<database_cleaner>, ["~> 0.6.8"])
77
+ s.add_dependency(%q<sqlite3>, [">= 0"])
78
+ s.add_dependency(%q<shoulda>, [">= 0"])
79
+ s.add_dependency(%q<cutter>, [">= 0"])
62
80
  end
63
81
  else
82
+ s.add_dependency(%q<sugar-high>, [">= 0.6"])
83
+ s.add_dependency(%q<require_all>, ["~> 1.2.0"])
64
84
  s.add_dependency(%q<activerecord>, [">= 3.0.1"])
65
85
  s.add_dependency(%q<rspec>, [">= 2.6.0"])
66
- s.add_dependency(%q<bundler>, ["~> 1.0.6"])
67
- s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
86
+ s.add_dependency(%q<bundler>, [">= 1"])
87
+ s.add_dependency(%q<jeweler>, [">= 1.6"])
68
88
  s.add_dependency(%q<rcov>, [">= 0"])
89
+ s.add_dependency(%q<yard>, [">= 0"])
90
+ s.add_dependency(%q<database_cleaner>, ["~> 0.6.8"])
91
+ s.add_dependency(%q<sqlite3>, [">= 0"])
92
+ s.add_dependency(%q<shoulda>, [">= 0"])
93
+ s.add_dependency(%q<cutter>, [">= 0"])
69
94
  end
70
95
  end
71
96
 
@@ -0,0 +1,32 @@
1
+ require 'active_record'
2
+ require 'yaml'
3
+ require 'logger'
4
+ require 'database_cleaner'
5
+ require 'require_all'
6
+ require 'active_record/migrations/create_models'
7
+
8
+ dbconfig_path = File.dirname(__FILE__) + '/db/database.yml'
9
+ dbfile = File.open(dbconfig_path)
10
+ dbconfig = YAML::load(dbfile)
11
+
12
+ ActiveRecord::Base.establish_connection(dbconfig)
13
+ ActiveRecord::Base.logger = Logger.new(STDERR)
14
+
15
+ DatabaseCleaner.strategy = :truncation
16
+
17
+ def migration_folder(name)
18
+ path = File.dirname(__FILE__) + "/migrations/#{name}"
19
+ end
20
+
21
+ RSpec.configure do |config|
22
+ config.before(:suite) do
23
+ DatabaseCleaner.drop_tables :user_accounts, :roles, :users_roles
24
+ CreateModels.up
25
+ end
26
+
27
+ config.before(:each) do
28
+ end
29
+
30
+ config.after(:each) do
31
+ end
32
+ end
@@ -0,0 +1,47 @@
1
+ require 'active_record/active_record_helper'
2
+ require 'models_helper'
3
+ describe models_class do
4
+ let(:models) do
5
+ # subject, object, join
6
+ models_class.new UserAccount, Role, UsersRoles, :subject_key => :troles
7
+ end
8
+
9
+ describe '#configure' do
10
+ before(:all) do
11
+ models.configure
12
+ end
13
+
14
+ it 'should configure all models (logs)' do
15
+ logs_matches(models.logs, 'UserAccount.has_many :troles').should be_true
16
+ logs_matches(models.logs, 'UsersRoles.belongs_to :role').should be_true
17
+ logs_matches(models.logs, 'UsersRoles.belongs_to :user_account').should be_true
18
+ logs_matches(models.logs, 'Role.has_many :user_accounts').should be_true
19
+ end
20
+
21
+ it 'should configure all models (shoulda)' do
22
+ UserAccount.create!.should have_many(:troles).through(:user_roles)
23
+ Role.create!.should have_many(:user_accounts).through(:user_roles)
24
+ UsersRoles.create!.should belong_to(:role)
25
+ UsersRoles.create!.should belong_to(:user_account)
26
+ end
27
+
28
+ describe 'should configure all models (manipulations with associations)' do
29
+ before(:each) do
30
+ @user_account = UserAccount.create(:name => "Marixa")
31
+ @role = Role.create(:name => "admin")
32
+ end
33
+
34
+ it "should add roles to account" do
35
+ @user_account.troles << @role
36
+ @role.save!
37
+ @user_account.troles.size.should == 1
38
+ end
39
+
40
+ it "should add accounts to role" do
41
+ @role.user_accounts << @user_account
42
+ @role.save!
43
+ @role.user_accounts.first.should == @user_account
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,4 @@
1
+ adapter: sqlite3
2
+ database: development.sqlite3
3
+ pool: 5
4
+ timeout: 5000
@@ -0,0 +1,27 @@
1
+ class CreateModels < ActiveRecord::Migration
2
+ def self.up
3
+ # down
4
+
5
+ create_table :user_accounts do |t|
6
+ t.string :name
7
+ t.timestamps
8
+ end
9
+
10
+ create_table :roles do |t|
11
+ t.string :name
12
+ t.timestamps
13
+ end
14
+
15
+ create_table :users_roles do |t|
16
+ t.integer :user_account_id
17
+ t.integer :role_id
18
+ end
19
+ end
20
+
21
+ def self.down
22
+ drop_table :user_accounts
23
+ drop_table :roles
24
+ drop_table :users_roles
25
+ end
26
+ end
27
+
@@ -1,3 +1,4 @@
1
+ require 'shoulda' # must be required before rspec
1
2
  require 'rspec'
2
3
  require 'active_record'
3
4
  require 'schemaker'
@@ -1,4 +1,4 @@
1
- require 'troles/common/config/schema/models_helper'
1
+ require 'models_helper'
2
2
 
3
3
  def subject_model_class
4
4
  Schemaker::SubjectModel
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schemaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-12 00:00:00.000000000Z
12
+ date: 2011-10-12 00:00:00.000000000Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sugar-high
16
+ requirement: &2165519220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.6'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2165519220
25
+ - !ruby/object:Gem::Dependency
26
+ name: require_all
27
+ requirement: &2165518620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2165518620
14
36
  - !ruby/object:Gem::Dependency
15
37
  name: activerecord
16
- requirement: &2156091260 !ruby/object:Gem::Requirement
38
+ requirement: &2165518060 !ruby/object:Gem::Requirement
17
39
  none: false
18
40
  requirements:
19
41
  - - ! '>='
@@ -21,10 +43,10 @@ dependencies:
21
43
  version: 3.0.1
22
44
  type: :development
23
45
  prerelease: false
24
- version_requirements: *2156091260
46
+ version_requirements: *2165518060
25
47
  - !ruby/object:Gem::Dependency
26
48
  name: rspec
27
- requirement: &2156086680 !ruby/object:Gem::Requirement
49
+ requirement: &2165517560 !ruby/object:Gem::Requirement
28
50
  none: false
29
51
  requirements:
30
52
  - - ! '>='
@@ -32,32 +54,87 @@ dependencies:
32
54
  version: 2.6.0
33
55
  type: :development
34
56
  prerelease: false
35
- version_requirements: *2156086680
57
+ version_requirements: *2165517560
36
58
  - !ruby/object:Gem::Dependency
37
59
  name: bundler
38
- requirement: &2156085240 !ruby/object:Gem::Requirement
60
+ requirement: &2165517040 !ruby/object:Gem::Requirement
39
61
  none: false
40
62
  requirements:
41
- - - ~>
63
+ - - ! '>='
42
64
  - !ruby/object:Gem::Version
43
- version: 1.0.6
65
+ version: '1'
44
66
  type: :development
45
67
  prerelease: false
46
- version_requirements: *2156085240
68
+ version_requirements: *2165517040
47
69
  - !ruby/object:Gem::Dependency
48
70
  name: jeweler
49
- requirement: &2156084180 !ruby/object:Gem::Requirement
71
+ requirement: &2165516420 !ruby/object:Gem::Requirement
50
72
  none: false
51
73
  requirements:
52
- - - ~>
74
+ - - ! '>='
53
75
  - !ruby/object:Gem::Version
54
- version: 1.6.2
76
+ version: '1.6'
55
77
  type: :development
56
78
  prerelease: false
57
- version_requirements: *2156084180
79
+ version_requirements: *2165516420
58
80
  - !ruby/object:Gem::Dependency
59
81
  name: rcov
60
- requirement: &2156081880 !ruby/object:Gem::Requirement
82
+ requirement: &2165515760 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2165515760
91
+ - !ruby/object:Gem::Dependency
92
+ name: yard
93
+ requirement: &2165515140 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *2165515140
102
+ - !ruby/object:Gem::Dependency
103
+ name: database_cleaner
104
+ requirement: &2165514520 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.6.8
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *2165514520
113
+ - !ruby/object:Gem::Dependency
114
+ name: sqlite3
115
+ requirement: &2165513900 !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: *2165513900
124
+ - !ruby/object:Gem::Dependency
125
+ name: shoulda
126
+ requirement: &2165513240 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *2165513240
135
+ - !ruby/object:Gem::Dependency
136
+ name: cutter
137
+ requirement: &2165512580 !ruby/object:Gem::Requirement
61
138
  none: false
62
139
  requirements:
63
140
  - - ! '>='
@@ -65,7 +142,7 @@ dependencies:
65
142
  version: '0'
66
143
  type: :development
67
144
  prerelease: false
68
- version_requirements: *2156081880
145
+ version_requirements: *2165512580
69
146
  description: Configures relationships between subject, join and object model for a
70
147
  given behavior
71
148
  email: kmandrup@gmail.com
@@ -89,6 +166,10 @@ files:
89
166
  - lib/schemaker/models/object_model.rb
90
167
  - lib/schemaker/models/subject_model.rb
91
168
  - schemaker.gemspec
169
+ - spec/active_record/active_record_helper.rb
170
+ - spec/active_record/active_record_spec.rb
171
+ - spec/active_record/db/database.yml
172
+ - spec/active_record/migrations/create_models.rb
92
173
  - spec/models_helper.rb
93
174
  - spec/schemaker/model/join_spec.rb
94
175
  - spec/schemaker/model/object_spec.rb
@@ -110,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
191
  version: '0'
111
192
  segments:
112
193
  - 0
113
- hash: -374026981416273501
194
+ hash: -1246785679827546613
114
195
  required_rubygems_version: !ruby/object:Gem::Requirement
115
196
  none: false
116
197
  requirements:
@@ -119,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
200
  version: '0'
120
201
  requirements: []
121
202
  rubyforge_project:
122
- rubygems_version: 1.8.5
203
+ rubygems_version: 1.8.10
123
204
  signing_key:
124
205
  specification_version: 3
125
206
  summary: Schema maker takes care of configuring your model schemas to map behavior