ninja-model 0.4.2 → 0.5.1

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.
Files changed (54) hide show
  1. data/.gitignore +19 -0
  2. data/Rakefile +0 -7
  3. data/autotest/discover.rb +1 -0
  4. data/lib/ninja_model.rb +22 -26
  5. data/lib/ninja_model/adapters.rb +33 -43
  6. data/lib/ninja_model/adapters/abstract_adapter.rb +2 -10
  7. data/lib/ninja_model/adapters/adapter_manager.rb +17 -10
  8. data/lib/ninja_model/adapters/adapter_pool.rb +15 -17
  9. data/lib/ninja_model/adapters/adapter_specification.rb +3 -3
  10. data/lib/ninja_model/associations.rb +25 -106
  11. data/lib/ninja_model/associations/association_proxy.rb +119 -1
  12. data/lib/ninja_model/associations/belongs_to_association.rb +5 -1
  13. data/lib/ninja_model/attribute.rb +130 -0
  14. data/lib/ninja_model/{attributes.rb → attribute_methods.rb} +21 -42
  15. data/lib/ninja_model/base.rb +23 -20
  16. data/lib/ninja_model/callbacks.rb +2 -11
  17. data/lib/ninja_model/identity.rb +6 -11
  18. data/lib/ninja_model/persistence.rb +15 -30
  19. data/lib/ninja_model/predicate.rb +4 -4
  20. data/lib/ninja_model/rails_ext/active_record.rb +187 -0
  21. data/lib/ninja_model/railtie.rb +14 -8
  22. data/lib/ninja_model/reflection.rb +7 -14
  23. data/lib/ninja_model/relation.rb +5 -3
  24. data/lib/ninja_model/relation/finder_methods.rb +4 -8
  25. data/lib/ninja_model/relation/spawn_methods.rb +1 -1
  26. data/lib/ninja_model/validation.rb +6 -23
  27. data/lib/ninja_model/version.rb +1 -1
  28. data/ninja-model.gemspec +28 -0
  29. data/spec/ninja_model/adapters/abstract_adapter_spec.rb +45 -0
  30. data/spec/ninja_model/adapters/adapter_manager_spec.rb +69 -0
  31. data/spec/ninja_model/adapters/adapter_pool_spec.rb +210 -48
  32. data/spec/ninja_model/adapters_spec.rb +77 -0
  33. data/spec/ninja_model/attribute_methods_spec.rb +95 -0
  34. data/spec/ninja_model/attribute_spec.rb +129 -0
  35. data/spec/ninja_model/base_spec.rb +4 -52
  36. data/spec/ninja_model/identity_spec.rb +16 -32
  37. data/spec/ninja_model/persistence_spec.rb +130 -4
  38. data/spec/ninja_model/predicate_spec.rb +40 -6
  39. data/spec/ninja_model/query_methods_spec.rb +76 -74
  40. data/spec/ninja_model/reflection_spec.rb +63 -0
  41. data/spec/ninja_model/relation_spec.rb +213 -20
  42. data/spec/ninja_model/symbol_spec.rb +19 -0
  43. data/spec/ninja_model/validation_spec.rb +18 -0
  44. data/spec/spec_helper.rb +9 -0
  45. data/spec/support/matchers/convert.rb +30 -0
  46. metadata +85 -63
  47. data/lib/ninja_model/associations/active_record_proxy.rb +0 -53
  48. data/lib/ninja_model/associations/ninja_model_proxy.rb +0 -46
  49. data/lib/ninja_model/configuration.rb +0 -20
  50. data/lib/ninja_model/errors.rb +0 -5
  51. data/lib/ninja_model/log_subscriber.rb +0 -18
  52. data/lib/ninja_model/scoping.rb +0 -50
  53. data/spec/ninja_model/attributes_spec.rb +0 -85
  54. data/spec/ninja_model/scoping_spec.rb +0 -40
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Symbol do
4
+ subject { :foobar }
5
+ it { should respond_to(:eq) }
6
+ it { should respond_to(:ne) }
7
+ it { should respond_to(:gt) }
8
+ it { should respond_to(:gte) }
9
+ it { should respond_to(:lt) }
10
+ it { should respond_to(:lte) }
11
+ it { should respond_to(:in) }
12
+ its(:eq) { should be_kind_of(NinjaModel::Predicate) }
13
+ its(:ne) { should be_kind_of(NinjaModel::Predicate) }
14
+ its(:gt) { should be_kind_of(NinjaModel::Predicate) }
15
+ its(:gte) { should be_kind_of(NinjaModel::Predicate) }
16
+ its(:lt) { should be_kind_of(NinjaModel::Predicate) }
17
+ its(:lte) { should be_kind_of(NinjaModel::Predicate) }
18
+ its(:in) { should be_kind_of(NinjaModel::Predicate) }
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe NinjaModel::Validation do
4
+ class ValidationModel < NinjaModel::Base
5
+ attribute :testing, :integer
6
+ validates :testing, :numericality => true
7
+ end
8
+
9
+ before {
10
+ @obj = ValidationModel.new
11
+ }
12
+ subject { @obj }
13
+ it { should respond_to(:save) }
14
+ it { should respond_to(:valid?) }
15
+
16
+ describe 'save' do
17
+ end
18
+ end
@@ -7,3 +7,12 @@ Dir[File.join(File.expand_path('../', __FILE__), 'support/**/*.rb')].each { |f|
7
7
  RSpec.configure do |config|
8
8
  config.mock_with :mocha
9
9
  end
10
+
11
+ class DummyLogger
12
+ def debug(*args)
13
+ end
14
+ def warn(*args)
15
+ end
16
+ end
17
+
18
+ NinjaModel.set_logger(DummyLogger.new)
@@ -0,0 +1,30 @@
1
+ module CustomMatchers
2
+ class ConvertMatcher
3
+ def initialize(value)
4
+ puts "asdfaj;lskdfj;lkasjdf;a"
5
+ @value_to_convert = value
6
+ end
7
+
8
+ def matches?(actual)
9
+ puts "**********************"
10
+ result = actual.convert(@value_to_convert)
11
+ unless defined?(@expected_value)
12
+ false
13
+ end
14
+ #result.eql?(@expected_value)
15
+ false
16
+ end
17
+
18
+ def to(expected)
19
+ @expected_value = expected
20
+ end
21
+
22
+ def description
23
+ "convert #{@value_to_convert} to #{@expected_value}"
24
+ end
25
+ end
26
+
27
+ def convert(value)
28
+ ConvertMatcher.new(value)
29
+ end
30
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ninja-model
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease: false
4
+ hash: 9
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 2
10
- version: 0.4.2
8
+ - 5
9
+ - 1
10
+ version: 0.5.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Williams
@@ -15,16 +15,15 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-30 00:00:00 -05:00
19
- default_executable:
18
+ date: 2011-05-16 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- name: rails
21
+ name: activerecord
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
27
- - - "="
26
+ - - ~>
28
27
  - !ruby/object:Gem::Version
29
28
  hash: 1
30
29
  segments:
@@ -42,12 +41,12 @@ dependencies:
42
41
  requirements:
43
42
  - - ~>
44
43
  - !ruby/object:Gem::Version
45
- hash: 13
44
+ hash: 7
46
45
  segments:
47
46
  - 2
47
+ - 2
48
48
  - 0
49
- - 1
50
- version: 2.0.1
49
+ version: 2.2.0
51
50
  type: :development
52
51
  version_requirements: *id002
53
52
  - !ruby/object:Gem::Dependency
@@ -83,38 +82,38 @@ dependencies:
83
82
  type: :development
84
83
  version_requirements: *id004
85
84
  - !ruby/object:Gem::Dependency
86
- name: cucumber
85
+ name: nokogiri
87
86
  prerelease: false
88
87
  requirement: &id005 !ruby/object:Gem::Requirement
89
88
  none: false
90
89
  requirements:
91
90
  - - ~>
92
91
  - !ruby/object:Gem::Version
93
- hash: 51
92
+ hash: 15
94
93
  segments:
95
- - 0
96
- - 9
94
+ - 1
97
95
  - 4
98
- version: 0.9.4
96
+ - 4
97
+ version: 1.4.4
99
98
  type: :development
100
99
  version_requirements: *id005
101
100
  - !ruby/object:Gem::Dependency
102
- name: nokogiri
101
+ name: autotest
103
102
  prerelease: false
104
103
  requirement: &id006 !ruby/object:Gem::Requirement
105
104
  none: false
106
105
  requirements:
107
106
  - - ~>
108
107
  - !ruby/object:Gem::Version
109
- hash: 15
108
+ hash: 35
110
109
  segments:
111
- - 1
112
110
  - 4
113
111
  - 4
114
- version: 1.4.4
112
+ - 6
113
+ version: 4.4.6
115
114
  type: :development
116
115
  version_requirements: *id006
117
- description: Write a gem description
116
+ description: Pseudo-ORM for Ruby/Rails with an ActiveRecord-like interface
118
117
  email: theprime@codingprime.com
119
118
  executables: []
120
119
 
@@ -123,60 +122,64 @@ extensions: []
123
122
  extra_rdoc_files: []
124
123
 
125
124
  files:
126
- - lib/ninja_model.rb
125
+ - .gitignore
126
+ - Gemfile
127
+ - README.md
128
+ - Rakefile
129
+ - autotest/discover.rb
127
130
  - lib/generators/ninja_model.rb
128
131
  - lib/generators/ninja_model/model/model_generator.rb
129
132
  - lib/generators/ninja_model/model/templates/model.rb
130
133
  - lib/generators/ninja_model/scaffold/scaffold_generator.rb
131
134
  - lib/ninja-model.rb
132
- - lib/ninja_model/configuration.rb
133
- - lib/ninja_model/reflection.rb
134
- - lib/ninja_model/associations/has_many_association.rb
135
- - lib/ninja_model/associations/ninja_model_proxy.rb
136
- - lib/ninja_model/associations/has_one_association.rb
135
+ - lib/ninja_model.rb
136
+ - lib/ninja_model/adapters.rb
137
+ - lib/ninja_model/adapters/abstract_adapter.rb
138
+ - lib/ninja_model/adapters/adapter_manager.rb
139
+ - lib/ninja_model/adapters/adapter_pool.rb
140
+ - lib/ninja_model/adapters/adapter_specification.rb
141
+ - lib/ninja_model/associations.rb
137
142
  - lib/ninja_model/associations/association_proxy.rb
138
- - lib/ninja_model/associations/active_record_proxy.rb
139
143
  - lib/ninja_model/associations/belongs_to_association.rb
140
- - lib/ninja_model/version.rb
141
- - lib/ninja_model/attributes.rb
142
- - lib/ninja_model/associations.rb
143
- - lib/ninja_model/log_subscriber.rb
144
- - lib/ninja_model/persistence.rb
144
+ - lib/ninja_model/associations/has_many_association.rb
145
+ - lib/ninja_model/associations/has_one_association.rb
146
+ - lib/ninja_model/attribute.rb
147
+ - lib/ninja_model/attribute_methods.rb
148
+ - lib/ninja_model/base.rb
145
149
  - lib/ninja_model/callbacks.rb
146
- - lib/ninja_model/predicate.rb
147
150
  - lib/ninja_model/core_ext/symbol.rb
148
- - lib/ninja_model/errors.rb
149
- - lib/ninja_model/adapters.rb
150
- - lib/ninja_model/base.rb
151
151
  - lib/ninja_model/identity.rb
152
+ - lib/ninja_model/persistence.rb
153
+ - lib/ninja_model/predicate.rb
154
+ - lib/ninja_model/rails_ext/active_record.rb
155
+ - lib/ninja_model/railtie.rb
156
+ - lib/ninja_model/reflection.rb
152
157
  - lib/ninja_model/relation.rb
153
- - lib/ninja_model/adapters/adapter_specification.rb
154
- - lib/ninja_model/adapters/abstract_adapter.rb
155
- - lib/ninja_model/adapters/adapter_manager.rb
156
- - lib/ninja_model/adapters/adapter_pool.rb
157
- - lib/ninja_model/validation.rb
158
158
  - lib/ninja_model/relation/finder_methods.rb
159
159
  - lib/ninja_model/relation/query_methods.rb
160
160
  - lib/ninja_model/relation/spawn_methods.rb
161
- - lib/ninja_model/railtie.rb
162
- - lib/ninja_model/scoping.rb
163
- - spec/spec_helper.rb
164
- - spec/support/active_model_lint.rb
165
- - spec/ninja_model_spec.rb
166
- - spec/ninja_model/identity_spec.rb
167
- - spec/ninja_model/attributes_spec.rb
168
- - spec/ninja_model/base_spec.rb
169
- - spec/ninja_model/predicate_spec.rb
170
- - spec/ninja_model/persistence_spec.rb
171
- - spec/ninja_model/relation_spec.rb
161
+ - lib/ninja_model/validation.rb
162
+ - lib/ninja_model/version.rb
163
+ - ninja-model.gemspec
164
+ - spec/ninja_model/adapters/abstract_adapter_spec.rb
165
+ - spec/ninja_model/adapters/adapter_manager_spec.rb
172
166
  - spec/ninja_model/adapters/adapter_pool_spec.rb
173
167
  - spec/ninja_model/adapters_spec.rb
168
+ - spec/ninja_model/attribute_methods_spec.rb
169
+ - spec/ninja_model/attribute_spec.rb
170
+ - spec/ninja_model/base_spec.rb
171
+ - spec/ninja_model/identity_spec.rb
172
+ - spec/ninja_model/persistence_spec.rb
173
+ - spec/ninja_model/predicate_spec.rb
174
174
  - spec/ninja_model/query_methods_spec.rb
175
- - spec/ninja_model/scoping_spec.rb
176
- - Rakefile
177
- - Gemfile
178
- - README.md
179
- has_rdoc: true
175
+ - spec/ninja_model/reflection_spec.rb
176
+ - spec/ninja_model/relation_spec.rb
177
+ - spec/ninja_model/symbol_spec.rb
178
+ - spec/ninja_model/validation_spec.rb
179
+ - spec/ninja_model_spec.rb
180
+ - spec/spec_helper.rb
181
+ - spec/support/active_model_lint.rb
182
+ - spec/support/matchers/convert.rb
180
183
  homepage: http://github.com/t3hpr1m3/ninja-model.git
181
184
  licenses: []
182
185
 
@@ -206,9 +209,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
209
  requirements: []
207
210
 
208
211
  rubyforge_project: ninja-model
209
- rubygems_version: 1.3.7
212
+ rubygems_version: 1.7.2
210
213
  signing_key:
211
214
  specification_version: 3
212
- summary: Write a gem summary
213
- test_files: []
214
-
215
+ summary: Pseudo-ORM for Ruby
216
+ test_files:
217
+ - spec/ninja_model/adapters/abstract_adapter_spec.rb
218
+ - spec/ninja_model/adapters/adapter_manager_spec.rb
219
+ - spec/ninja_model/adapters/adapter_pool_spec.rb
220
+ - spec/ninja_model/adapters_spec.rb
221
+ - spec/ninja_model/attribute_methods_spec.rb
222
+ - spec/ninja_model/attribute_spec.rb
223
+ - spec/ninja_model/base_spec.rb
224
+ - spec/ninja_model/identity_spec.rb
225
+ - spec/ninja_model/persistence_spec.rb
226
+ - spec/ninja_model/predicate_spec.rb
227
+ - spec/ninja_model/query_methods_spec.rb
228
+ - spec/ninja_model/reflection_spec.rb
229
+ - spec/ninja_model/relation_spec.rb
230
+ - spec/ninja_model/symbol_spec.rb
231
+ - spec/ninja_model/validation_spec.rb
232
+ - spec/ninja_model_spec.rb
233
+ - spec/spec_helper.rb
234
+ - spec/support/active_model_lint.rb
235
+ - spec/support/matchers/convert.rb
236
+ has_rdoc:
@@ -1,53 +0,0 @@
1
-
2
- module NinjaModel
3
- module Associations
4
- class ActiveRecordProxy
5
- def initialize(ninja_model)
6
- @klass = ninja_model
7
- @klass.class_eval do
8
- def proxy
9
- @proxy ||= begin
10
- self.class.proxy.instance(self)
11
- end
12
- @proxy.attributes = self.attributes.delete_if { |k,v| k.eql?('id') }
13
- @proxy
14
- end
15
- end
16
-
17
- @proxy_klass = ninja_model.parent.const_set("#{@klass.model_name}Proxy", Class.new(ActiveRecord::Base))
18
- @proxy_klass.class_eval do
19
- cattr_accessor :columns
20
- self.columns = []
21
- def self.column(name, sql_type = nil, default = nil)
22
- self.columns << ActiveRecord::ConnectionAdapters::Column.new(name, nil, sql_type.to_s, default)
23
- end
24
- end
25
-
26
- @klass.model_attributes.each do |attr|
27
- @proxy_klass.send :column, attr.name, attr.type, attr.default
28
- end
29
- end
30
-
31
- def instance(obj)
32
- proxy = @proxy_klass.new
33
- proxy.send :init_with, {'attributes' => obj.attributes}
34
- proxy
35
- end
36
-
37
- def handle_association(macro, association_id, options)
38
- unless macro.eql?(:belongs_to)
39
- options = {:foreign_key => derive_foreign_key}.merge(options)
40
- end
41
-
42
- @proxy = nil
43
- @proxy_klass.send macro, association_id, options
44
- end
45
-
46
- private
47
-
48
- def derive_foreign_key
49
- "#{@klass.name.underscore}_id".to_sym
50
- end
51
- end
52
- end
53
- end
@@ -1,46 +0,0 @@
1
- module NinjaModel
2
- module Associations
3
- class NinjaModelProxy
4
- attr_reader :proxy_klass
5
- def initialize(active_record)
6
- @klass = active_record
7
- @klass.class_eval do
8
- def ninja_proxy
9
- @ninja_proxy ||= begin
10
- self.class.ninja_proxy.instance(self)
11
- end
12
- @ninja_proxy.attributes = self.attributes.delete_if { |k,v| k.eql?('id') }
13
- @ninja_proxy
14
- end
15
- end
16
-
17
- @proxy_klass = active_record.parent.const_set("#{@klass.model_name}Proxy", Class.new(NinjaModel::Base))
18
-
19
- @klass.columns_hash.each_pair do |k,v|
20
- @proxy_klass.send :attribute, k, v.type, v.default, @proxy_klass
21
- end
22
- end
23
-
24
- def instance(obj)
25
- proxy = @proxy_klass.new
26
- proxy.send :instantiate, {'attributes' => obj.attributes}
27
- proxy
28
- end
29
-
30
- def handle_association(macro, association_id, options)
31
- unless macro.eql?(:belongs_to)
32
- options = {:foreign_key => derive_foreign_key}.merge(options)
33
- end
34
-
35
- @proxy = nil
36
- @proxy_klass.send macro, association_id, options
37
- end
38
-
39
- private
40
-
41
- def derive_foreign_key
42
- "#{@klass.name.underscore}_id".to_sym
43
- end
44
- end
45
- end
46
- end
@@ -1,20 +0,0 @@
1
- module NinjaModel
2
-
3
- mattr_accessor :configuration
4
-
5
- class Configuration
6
- attr_accessor :config_file_path, :adapter_path, :specs
7
-
8
- def self.create
9
- NinjaModel.configuration ||= new
10
- end
11
-
12
- private
13
-
14
- def initialize
15
- @config_file_path = 'config/ninja_model.yml'
16
- @adapter_path = 'ninja_model/adapters'
17
- @specs = {}
18
- end
19
- end
20
- end
@@ -1,5 +0,0 @@
1
- module NinjaModel
2
- class NinjaModelError < StandardError; end
3
- class AdapterNotSpecified < NinjaModelError; end
4
- class ConnectionTimeoutError < NinjaModelError; end
5
- end