sunstone 1.8.2 → 2.0.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: eae0846af813b1c0fc695244c0d5f41c596213cd
4
- data.tar.gz: 8bd60e37e8b04992ea6b60abbc732a6f479f6753
3
+ metadata.gz: 5971616d7a67d451d0d618ed1aaa6f9de9b3daa0
4
+ data.tar.gz: df3a218c951f5070e2cfccdc91cfa88c0c6a895c
5
5
  SHA512:
6
- metadata.gz: 1ae2591677494501e528f9c390c631de45576f47b5154f5e84eb3cce67e00a50bbc2188bfa0d84681eabb1d474055adb6bd6e1983cf0785c89044af08abd66ae
7
- data.tar.gz: 76c26a37f72174c37c52feef35c2837dd298697a805232a917ac9c73a229a20fc7ba559dee2d6c4348a041396a05dd54e6ae7643419698010c1b04530d039f22
6
+ metadata.gz: 6c2eed7323ae88fe0200bfbe83dff412602174d0f3559d94c8bce01117768b1f11b70b95f3b016f75de4751f051db8eb5dbee9ea9efa94743d0e5f9fc49ccfa0
7
+ data.tar.gz: 87f7fe2cf78a6d7b0e8a4d0c10b00f606b31d4058c4a8b0fe1ed5f70ab16d39414da4d8d350e778dc389fa19408fd3c980dd9cf03fc9cf7ec8acc94c6beb91fc
File without changes
File without changes
@@ -63,11 +63,17 @@ module ActiveRecord
63
63
 
64
64
  def construct_association(parent, reflection, attributes, seen, model_cache)
65
65
  return if attributes.nil?
66
- id = attributes[reflection.klass.primary_key]
67
- model = seen[parent.class.base_class][parent.id][reflection.klass][id]
66
+
67
+ klass = if reflection.polymorphic?
68
+ parent.send(reflection.foreign_type).constantize.base_class
69
+ else
70
+ reflection.klass
71
+ end
72
+ id = attributes[klass.primary_key]
73
+ model = seen[parent.class.base_class][parent.id][klass][id]
68
74
 
69
75
  if model
70
- construct(model, attributes.select{|k,v| !reflection.klass.column_names.include?(k.to_s) }, seen, model_cache)
76
+ construct(model, attributes.select{|k,v| !klass.column_names.include?(k.to_s) }, seen, model_cache)
71
77
 
72
78
  other = parent.association(reflection.name)
73
79
 
@@ -79,15 +85,21 @@ module ActiveRecord
79
85
 
80
86
  other.set_inverse_instance(model)
81
87
  else
82
- model = construct_model(parent, reflection, id, attributes.select{|k,v| reflection.klass.column_names.include?(k.to_s) }, seen, model_cache)
88
+ model = construct_model(parent, reflection, id, attributes.select{|k,v| klass.column_names.include?(k.to_s) }, seen, model_cache)
83
89
  seen[parent.class.base_class][parent.id][model.class.base_class][id] = model
84
- construct(model, attributes.select{|k,v| !reflection.klass.column_names.include?(k.to_s) }, seen, model_cache)
90
+ construct(model, attributes.select{|k,v| !klass.column_names.include?(k.to_s) }, seen, model_cache)
85
91
  end
86
92
  end
87
93
 
88
94
 
89
95
  def construct_model(record, reflection, id, attributes, seen, model_cache)
90
- model = model_cache[reflection.klass][id] ||= reflection.klass.instantiate(attributes)
96
+ klass = if reflection.polymorphic?
97
+ record.send(reflection.foreign_type).constantize
98
+ else
99
+ reflection.klass
100
+ end
101
+
102
+ model = model_cache[klass][id] ||= klass.instantiate(attributes)
91
103
  other = record.association(reflection.name)
92
104
 
93
105
  if reflection.collection?
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
  # If the schema is not specified as part of +name+ then it will only find tables within
9
9
  # the current schema search path (regardless of permissions to access tables in other schemas)
10
10
  def table_exists?(name)
11
- schema_definition[name] != nil
11
+ tables.include?(name)
12
12
  end
13
13
 
14
14
  # Returns the list of all column definitions for a table.
@@ -25,18 +25,13 @@ module ActiveRecord
25
25
  # - format_type includes the column size constraint, e.g. varchar(50)
26
26
  # - ::regclass is a function that gives the id for a table name
27
27
  def column_definitions(table_name) # :nodoc:
28
- definition = schema_definition[table_name]
29
- raise ActiveRecord::StatementInvalid, "Table \"#{table_name}\" does not exist" if definition.nil?
30
-
31
- definition
28
+ Wankel.parse(@connection.get("/#{table_name}/schema").body)
29
+ rescue ::Sunstone::Exception::NotFound
30
+ raise ActiveRecord::StatementInvalid, "Table \"#{table_name}\" does not exist"
32
31
  end
33
32
 
34
- def schema_definition
35
- exec( Arel::Table.new(:schema).project )
36
- end
37
-
38
33
  def tables
39
- Wankel.parse(@connection.get('/schema').body, :symbolize_keys => true).keys
34
+ Wankel.parse(@connection.get('/tables').body)
40
35
  end
41
36
 
42
37
  def new_column(name, cast_type, options={}) # :nodoc:
@@ -54,45 +49,6 @@ module ActiveRecord
54
49
  columns(table).find{ |c| c.primary_key? }.name
55
50
  end
56
51
 
57
- # TODO: do we need this?
58
- # Maps logical Rails types to PostgreSQL-specific data types.
59
- # def type_to_sql(type, limit = nil, precision = nil, scale = nil)
60
- # case type.to_s
61
- # when 'binary'
62
- # # PostgreSQL doesn't support limits on binary (bytea) columns.
63
- # # The hard limit is 1Gb, because of a 32-bit size field, and TOAST.
64
- # case limit
65
- # when nil, 0..0x3fffffff; super(type)
66
- # else raise(ActiveRecordError, "No binary type has byte size #{limit}.")
67
- # end
68
- # when 'text'
69
- # # PostgreSQL doesn't support limits on text columns.
70
- # # The hard limit is 1Gb, according to section 8.3 in the manual.
71
- # case limit
72
- # when nil, 0..0x3fffffff; super(type)
73
- # else raise(ActiveRecordError, "The limit on text can be at most 1GB - 1byte.")
74
- # end
75
- # when 'integer'
76
- # return 'integer' unless limit
77
- #
78
- # case limit
79
- # when 1, 2; 'smallint'
80
- # when 3, 4; 'integer'
81
- # when 5..8; 'bigint'
82
- # else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.")
83
- # end
84
- # when 'datetime'
85
- # return super unless precision
86
- #
87
- # case precision
88
- # when 0..6; "timestamp(#{precision})"
89
- # else raise(ActiveRecordError, "No timestamp type has precision of #{precision}. The allowed range of precision is from 0 to 6")
90
- # end
91
- # else
92
- # super
93
- # end
94
- # end
95
-
96
52
  end
97
53
  end
98
54
  end
data/lib/sunstone.rb CHANGED
@@ -1,51 +1,19 @@
1
1
  require 'wankel'
2
2
  require 'cookie_store'
3
-
4
- require 'active_support'
5
- require 'active_support/core_ext'
6
-
7
- require 'active_model'
8
-
9
3
  require 'active_record'
10
4
 
11
- require 'sunstone/connection'
12
- require 'sunstone/exception'
13
- require 'ext/active_record/statement_cache'
14
- require 'ext/active_record/relation'
15
- require 'ext/active_record/relation/predicate_builder'
16
- require 'ext/active_record/calculations'
17
- require 'ext/active_record/associations/builder/has_and_belongs_to_many'
18
-
19
- require 'ext/arel/select_manager'
20
- require 'ext/arel/nodes/eager_load'
21
- require 'ext/arel/nodes/select_statement'
22
- require 'ext/active_record/finder_methods'
23
- require 'ext/active_record/batches'
24
-
25
- # require 'sunstone/parser'
26
-
27
- module Sunstone
28
- VERSION = '1.7.15'
29
-
30
- # TODO:
31
- #
32
- # # Get a connection from the connection pool and perform the block with
33
- # # the connection
34
- # def with_connection(&block)
35
- # connection_pool.with({}, &block)
36
- # end
37
- #
38
- # private
39
- #
40
- # def request_headers
41
- # headers = {
42
- # 'Content-Type' => 'application/json',
43
- # 'User-Agent' => user_agent
44
- # }
45
- #
46
- # headers['Api-Key'] = api_key if api_key
47
- #
48
- # headers
49
- # end
50
- #
51
- end
5
+ require File.expand_path(File.join(__FILE__, '../sunstone/version'))
6
+ require File.expand_path(File.join(__FILE__, '../sunstone/connection'))
7
+ require File.expand_path(File.join(__FILE__, '../sunstone/exception'))
8
+
9
+ require File.expand_path(File.join(__FILE__, '../../ext/active_record/statement_cache'))
10
+ require File.expand_path(File.join(__FILE__, '../../ext/active_record/relation'))
11
+ require File.expand_path(File.join(__FILE__, '../../ext/active_record/relation/predicate_builder'))
12
+ require File.expand_path(File.join(__FILE__, '../../ext/active_record/calculations'))
13
+ require File.expand_path(File.join(__FILE__, '../../ext/active_record/associations/builder/has_and_belongs_to_many'))
14
+
15
+ require File.expand_path(File.join(__FILE__, '../../ext/arel/select_manager'))
16
+ require File.expand_path(File.join(__FILE__, '../../ext/arel/nodes/eager_load'))
17
+ require File.expand_path(File.join(__FILE__, '../../ext/arel/nodes/select_statement'))
18
+ require File.expand_path(File.join(__FILE__, '../../ext/active_record/finder_methods'))
19
+ require File.expand_path(File.join(__FILE__, '../../ext/active_record/batches'))
@@ -1,11 +1,5 @@
1
1
  module Sunstone
2
2
 
3
- class RecordInvalid < ::Exception
4
- end
5
-
6
- class RecordNotSaved < ::Exception
7
- end
8
-
9
3
  class Exception < ::Exception
10
4
 
11
5
  class UnexpectedResponse < Sunstone::Exception
@@ -0,0 +1,3 @@
1
+ module Sunstone
2
+ VERSION = '2.0.0'
3
+ end
data/sunstone.gemspec CHANGED
@@ -1,6 +1,8 @@
1
+ require File.expand_path("../lib/sunstone/version", __FILE__)
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = "sunstone"
3
- s.version = '1.8.2'
5
+ s.version = Sunstone::VERSION
4
6
  s.authors = ["Jon Bracy"]
5
7
  s.email = ["jonbracy@gmail.com"]
6
8
  s.homepage = "http://sunstonerb.com"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunstone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-28 00:00:00.000000000 Z
11
+ date: 2015-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -261,6 +261,16 @@ files:
261
261
  - README.md
262
262
  - Rakefile.rb
263
263
  - TODO.md
264
+ - ext/active_record/associations/builder/has_and_belongs_to_many.rb
265
+ - ext/active_record/batches.rb
266
+ - ext/active_record/calculations.rb
267
+ - ext/active_record/finder_methods.rb
268
+ - ext/active_record/relation.rb
269
+ - ext/active_record/relation/predicate_builder.rb
270
+ - ext/active_record/statement_cache.rb
271
+ - ext/arel/nodes/eager_load.rb
272
+ - ext/arel/nodes/select_statement.rb
273
+ - ext/arel/select_manager.rb
264
274
  - lib/active_record/connection_adapters/sunstone/column.rb
265
275
  - lib/active_record/connection_adapters/sunstone/database_statements.rb
266
276
  - lib/active_record/connection_adapters/sunstone/schema_statements.rb
@@ -269,20 +279,10 @@ files:
269
279
  - lib/active_record/connection_adapters/sunstone_adapter.rb
270
280
  - lib/arel/collectors/sunstone.rb
271
281
  - lib/arel/visitors/sunstone.rb
272
- - lib/ext/active_record/associations/builder/has_and_belongs_to_many.rb
273
- - lib/ext/active_record/batches.rb
274
- - lib/ext/active_record/calculations.rb
275
- - lib/ext/active_record/finder_methods.rb
276
- - lib/ext/active_record/relation.rb
277
- - lib/ext/active_record/relation/predicate_builder.rb
278
- - lib/ext/active_record/statement_cache.rb
279
- - lib/ext/arel/nodes/eager_load.rb
280
- - lib/ext/arel/nodes/select_statement.rb
281
- - lib/ext/arel/select_manager.rb
282
282
  - lib/sunstone.rb
283
283
  - lib/sunstone/connection.rb
284
284
  - lib/sunstone/exception.rb
285
- - lib/sunstone/parser.rb
285
+ - lib/sunstone/version.rb
286
286
  - sunstone.gemspec
287
287
  - test/sunstone/connection_test.rb
288
288
  - test/sunstone/parser_test.rb
@@ -1,93 +0,0 @@
1
- module Sunstone
2
- class Parser < Wankel::SaxParser
3
-
4
- attr_reader :object
5
-
6
- def self.parse(instance_or_class, response_or_body)
7
- parser = self.new(instance_or_class)
8
-
9
- if response_or_body.is_a?(Net::HTTPResponse)
10
- response_or_body.read_body do |chunk|
11
- parser << chunk
12
- end
13
- else
14
- parser << response_or_body
15
- end
16
-
17
- parser.complete
18
- end
19
-
20
- def initialize(klass, options=nil)
21
- super(options)
22
-
23
- @object = klass.class == Class ? klass.new : klass
24
- @stack = []
25
- end
26
-
27
- def on_map_start
28
- if @stack.size == 0
29
- @stack << @object
30
- elsif @stack.last.is_a?(Array)
31
- key = @stack[-2].to_sym
32
- if @stack[-3].reflect_on_associations[key]
33
- @stack << @stack[-3].reflect_on_associations[key][:klass].new
34
- end
35
- else
36
- key = @stack.last.to_sym
37
- if @stack[-2].reflect_on_associations[key]
38
- @stack << @stack[-2].reflect_on_associations[key][:klass].new
39
- end
40
- end
41
- end
42
-
43
- def on_map_end
44
- value = @stack.pop
45
-
46
- on_value(value) if @stack.size > 0
47
-
48
- value
49
- end
50
-
51
- def on_map_key(key)
52
- @stack << key
53
- end
54
-
55
- def on_value(value)
56
- if @stack.last.is_a?(Array)
57
- @stack.last << value
58
- else
59
- attribute = @stack.pop
60
- @stack.last.send(:"#{attribute}=", value) if @stack.last.respond_to?(:"#{attribute}=")
61
- end
62
- end
63
-
64
- def on_null; on_value(nil) ;end
65
- alias :on_boolean :on_value
66
- alias :on_integer :on_value
67
- alias :on_double :on_value
68
- alias :on_string :on_value
69
-
70
- def on_array_start
71
- @stack << Array.new
72
- end
73
-
74
- def on_array_end
75
- value = @stack.pop
76
- attribute = @stack.pop
77
- @stack.last.send(:"#{attribute}=", value) if @stack.last.respond_to?(:"#{attribute}=")
78
- end
79
-
80
- # Override to return the account
81
- def parse(*args, &block)
82
- super(*args, &block)
83
- @object
84
- end
85
-
86
- # Override to return the account
87
- def complete
88
- super
89
- @object
90
- end
91
-
92
- end
93
- end