api_resource 0.4.3 → 0.5.0

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 (89) hide show
  1. data/VERSION +1 -1
  2. data/api_resource.gemspec +4 -74
  3. data/coverage/assets/0.5.3/app.js +88 -0
  4. data/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
  5. data/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
  6. data/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
  7. data/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
  8. data/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
  9. data/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
  10. data/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
  11. data/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
  12. data/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
  13. data/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
  14. data/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
  15. data/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
  16. data/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
  17. data/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
  18. data/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
  19. data/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
  20. data/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
  21. data/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
  22. data/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
  23. data/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
  24. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +363 -0
  25. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
  26. data/coverage/assets/0.5.3/favicon_green.png +0 -0
  27. data/coverage/assets/0.5.3/favicon_red.png +0 -0
  28. data/coverage/assets/0.5.3/favicon_yellow.png +0 -0
  29. data/coverage/assets/0.5.3/highlight.css +129 -0
  30. data/coverage/assets/0.5.3/highlight.pack.js +1 -0
  31. data/coverage/assets/0.5.3/jquery-1.6.2.min.js +18 -0
  32. data/coverage/assets/0.5.3/jquery.dataTables.min.js +152 -0
  33. data/coverage/assets/0.5.3/jquery.timeago.js +141 -0
  34. data/coverage/assets/0.5.3/jquery.url.js +174 -0
  35. data/coverage/assets/0.5.3/loading.gif +0 -0
  36. data/coverage/assets/0.5.3/magnify.png +0 -0
  37. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  38. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  39. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  40. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  41. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  42. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  43. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  44. data/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  45. data/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
  46. data/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  47. data/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
  48. data/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
  49. data/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  50. data/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +295 -0
  51. data/coverage/assets/0.5.3/stylesheet.css +383 -0
  52. data/coverage/index.html +3573 -0
  53. data/lib/api_resource/associations/abstract_scope.rb +191 -0
  54. data/lib/api_resource/associations/association_scope.rb +47 -0
  55. data/lib/api_resource/associations/belongs_to_remote_object_proxy.rb +5 -6
  56. data/lib/api_resource/associations/has_many_remote_object_proxy.rb +5 -8
  57. data/lib/api_resource/associations/has_one_remote_object_proxy.rb +12 -13
  58. data/lib/api_resource/associations/multi_object_proxy.rb +65 -39
  59. data/lib/api_resource/associations/resource_scope.rb +6 -17
  60. data/lib/api_resource/associations/scope.rb +23 -121
  61. data/lib/api_resource/associations/single_object_proxy.rb +41 -50
  62. data/lib/api_resource/associations.rb +32 -11
  63. data/lib/api_resource/attributes.rb +108 -69
  64. data/lib/api_resource/base.rb +114 -106
  65. data/lib/api_resource/local.rb +1 -1
  66. data/lib/api_resource/model_errors.rb +9 -6
  67. data/lib/api_resource/scopes.rb +53 -16
  68. data/lib/api_resource.rb +3 -1
  69. data/spec/lib/api_resource_spec.rb +3 -7
  70. data/spec/lib/associations/association_scope_spec.rb +19 -0
  71. data/spec/lib/associations_spec.rb +251 -162
  72. data/spec/lib/attributes_spec.rb +33 -15
  73. data/spec/lib/base_spec.rb +302 -64
  74. data/spec/lib/callbacks_spec.rb +4 -2
  75. data/spec/lib/local_spec.rb +5 -1
  76. data/spec/spec_helper.rb +2 -3
  77. data/spec/support/mocks/association_mocks.rb +9 -1
  78. data/spec/support/requests/association_requests.rb +5 -5
  79. data/spec/support/requests/test_resource_requests.rb +16 -4
  80. data/spec/tmp/api_resource_test_db.sqlite +0 -0
  81. metadata +68 -22
  82. data/.document +0 -5
  83. data/.rspec +0 -5
  84. data/.travis.yml +0 -4
  85. data/lib/api_resource/associations/association_proxy.rb +0 -121
  86. data/lib/api_resource/associations/dynamic_resource_scope.rb +0 -23
  87. data/lib/api_resource/associations/generic_scope.rb +0 -68
  88. data/lib/api_resource/associations/multi_argument_resource_scope.rb +0 -15
  89. data/lib/api_resource/associations/relation_scope.rb +0 -25
@@ -2,23 +2,23 @@ HashDealer.define(:test_association_resource) do
2
2
  id{Kernel.rand(99999)}
3
3
  name{Faker::Name.first_name}
4
4
  age{Kernel.rand(99999)}
5
- active(false)
5
+ is_active(false)
6
6
  end
7
7
 
8
8
  HashDealer.define(:active_test_association_resource, :parent => :test_association_resource) do
9
- active(true)
9
+ is_active(true)
10
10
  end
11
11
 
12
12
  HashDealer.define(:active_birthday_test_association_resource, :parent => :active_test_association_resource) do
13
- birthday{Date.today}
13
+ bday{Date.today}
14
14
  end
15
15
 
16
16
  HashDealer.define(:inactive_test_association_resource, :parent => :test_association_resource) do
17
- active(false)
17
+ is_active(false)
18
18
  end
19
19
 
20
20
  HashDealer.define(:inactive_birthday_test_association_resource, :parent => :inactive_test_association_resource) do
21
- birthday{Date.today}
21
+ bday{Date.today}
22
22
  end
23
23
 
24
24
  HashDealer.define(:has_one_object) do
@@ -1,14 +1,25 @@
1
1
  HashDealer.define(:new_test_object) do
2
2
  attributes({
3
- :protected => [:id],
3
+ :protected => [:id, :protected_attr],
4
4
  :public => [:name, :age, :is_active, [:bday, :date], [:roles, :array]]
5
5
  })
6
6
  scopes({
7
- :active => {:active => :opt},
8
- :paginate => {:per_page => :opt, :current_page => :opt}
7
+ :active => {},
8
+ :paginate => {
9
+ :per_page => :opt,
10
+ :current_page => :opt
11
+ },
12
+ :birthday => {
13
+ :date => :req
14
+ }
9
15
  })
10
16
  associations({
11
- :has_many => {:has_many_objects => {}},
17
+ :has_many => {
18
+ :has_many_objects => {},
19
+ :has_many_service_uri => {
20
+ :class_name => "HasManyObject"
21
+ }
22
+ },
12
23
  :belongs_to => {:belongs_to_object => {}, :custom_name => {:class_name => "BelongsToObject"}},
13
24
  :has_one => {:has_one_object => {}},
14
25
  })
@@ -28,6 +39,7 @@ end
28
39
  HashDealer.define(:test_resource_with_proxies, :parent => :test_resource) do
29
40
  has_one_object{HashDealer.roll(:has_one_object)}
30
41
  has_many_objects{(0..4).to_a.collect{HashDealer.roll(:has_many_object)}}
42
+ has_many_service_uri{[{:service_uri => "/test_resource/1/has_many"}]}
31
43
  end
32
44
 
33
45
  HashDealer.define(:test_resource_errors) do
metadata CHANGED
@@ -1,11 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ethan Langevin
9
+ - Dan Langevin
10
+ - Brian Howald
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
@@ -413,53 +415,92 @@ dependencies:
413
415
  version: '0'
414
416
  description: A replacement for ActiveResource for RESTful APIs that handles associated
415
417
  object and multiple data sources
416
- email: ejl6266@gmail.com
418
+ email: developers@lifebooker.com
417
419
  executables: []
418
420
  extensions: []
419
421
  extra_rdoc_files:
420
422
  - LICENSE.txt
421
423
  - README.rdoc
422
424
  files:
423
- - .document
424
- - .rspec
425
- - .travis.yml
425
+ - api_resource.gemspec
426
+ - coverage/assets/0.5.3/app.js
427
+ - coverage/assets/0.5.3/fancybox/blank.gif
428
+ - coverage/assets/0.5.3/fancybox/fancy_close.png
429
+ - coverage/assets/0.5.3/fancybox/fancy_loading.png
430
+ - coverage/assets/0.5.3/fancybox/fancy_nav_left.png
431
+ - coverage/assets/0.5.3/fancybox/fancy_nav_right.png
432
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_e.png
433
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_n.png
434
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png
435
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png
436
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_s.png
437
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_se.png
438
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png
439
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_w.png
440
+ - coverage/assets/0.5.3/fancybox/fancy_title_left.png
441
+ - coverage/assets/0.5.3/fancybox/fancy_title_main.png
442
+ - coverage/assets/0.5.3/fancybox/fancy_title_over.png
443
+ - coverage/assets/0.5.3/fancybox/fancy_title_right.png
444
+ - coverage/assets/0.5.3/fancybox/fancybox-x.png
445
+ - coverage/assets/0.5.3/fancybox/fancybox-y.png
446
+ - coverage/assets/0.5.3/fancybox/fancybox.png
447
+ - coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css
448
+ - coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js
449
+ - coverage/assets/0.5.3/favicon_green.png
450
+ - coverage/assets/0.5.3/favicon_red.png
451
+ - coverage/assets/0.5.3/favicon_yellow.png
452
+ - coverage/assets/0.5.3/highlight.css
453
+ - coverage/assets/0.5.3/highlight.pack.js
454
+ - coverage/assets/0.5.3/jquery-1.6.2.min.js
455
+ - coverage/assets/0.5.3/jquery.dataTables.min.js
456
+ - coverage/assets/0.5.3/jquery.timeago.js
457
+ - coverage/assets/0.5.3/jquery.url.js
458
+ - coverage/assets/0.5.3/loading.gif
459
+ - coverage/assets/0.5.3/magnify.png
460
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
461
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
462
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
463
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
464
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png
465
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
466
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
467
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
468
+ - coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png
469
+ - coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png
470
+ - coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png
471
+ - coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png
472
+ - coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png
473
+ - coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css
474
+ - coverage/assets/0.5.3/stylesheet.css
475
+ - coverage/index.html
426
476
  - Gemfile
427
477
  - Gemfile.lock
428
478
  - Guardfile
429
- - LICENSE.txt
430
- - README.rdoc
431
- - Rakefile
432
- - VERSION
433
- - api_resource.gemspec
434
- - lib/api_resource.rb
435
479
  - lib/api_resource/association_activation.rb
436
- - lib/api_resource/associations.rb
437
- - lib/api_resource/associations/association_proxy.rb
480
+ - lib/api_resource/associations/abstract_scope.rb
481
+ - lib/api_resource/associations/association_scope.rb
438
482
  - lib/api_resource/associations/belongs_to_remote_object_proxy.rb
439
- - lib/api_resource/associations/dynamic_resource_scope.rb
440
- - lib/api_resource/associations/generic_scope.rb
441
483
  - lib/api_resource/associations/has_many_remote_object_proxy.rb
442
484
  - lib/api_resource/associations/has_many_through_remote_object_proxy.rb
443
485
  - lib/api_resource/associations/has_one_remote_object_proxy.rb
444
- - lib/api_resource/associations/multi_argument_resource_scope.rb
445
486
  - lib/api_resource/associations/multi_object_proxy.rb
446
487
  - lib/api_resource/associations/related_object_hash.rb
447
- - lib/api_resource/associations/relation_scope.rb
448
488
  - lib/api_resource/associations/resource_scope.rb
449
489
  - lib/api_resource/associations/scope.rb
450
490
  - lib/api_resource/associations/single_object_proxy.rb
491
+ - lib/api_resource/associations.rb
451
492
  - lib/api_resource/attributes.rb
452
493
  - lib/api_resource/base.rb
453
494
  - lib/api_resource/callbacks.rb
454
495
  - lib/api_resource/connection.rb
455
496
  - lib/api_resource/core_extensions.rb
456
497
  - lib/api_resource/custom_methods.rb
457
- - lib/api_resource/decorators.rb
458
498
  - lib/api_resource/decorators/caching_decorator.rb
499
+ - lib/api_resource/decorators.rb
459
500
  - lib/api_resource/exceptions.rb
460
- - lib/api_resource/formats.rb
461
501
  - lib/api_resource/formats/json_format.rb
462
502
  - lib/api_resource/formats/xml_format.rb
503
+ - lib/api_resource/formats.rb
463
504
  - lib/api_resource/local.rb
464
505
  - lib/api_resource/log_subscriber.rb
465
506
  - lib/api_resource/mocks.rb
@@ -467,8 +508,13 @@ files:
467
508
  - lib/api_resource/observing.rb
468
509
  - lib/api_resource/railtie.rb
469
510
  - lib/api_resource/scopes.rb
511
+ - lib/api_resource.rb
512
+ - LICENSE.txt
470
513
  - nohup.out
514
+ - Rakefile
515
+ - README.rdoc
471
516
  - spec/lib/api_resource_spec.rb
517
+ - spec/lib/associations/association_scope_spec.rb
472
518
  - spec/lib/associations_spec.rb
473
519
  - spec/lib/attributes_spec.rb
474
520
  - spec/lib/base_spec.rb
@@ -488,7 +534,9 @@ files:
488
534
  - spec/support/requests/prefix_model_requests.rb
489
535
  - spec/support/requests/test_resource_requests.rb
490
536
  - spec/support/test_resource.rb
537
+ - spec/tmp/api_resource_test_db.sqlite
491
538
  - spec/tmp/DIR
539
+ - VERSION
492
540
  homepage: http://github.com/ejlangev/resource
493
541
  licenses:
494
542
  - MIT
@@ -502,9 +550,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
502
550
  - - ! '>='
503
551
  - !ruby/object:Gem::Version
504
552
  version: '0'
505
- segments:
506
- - 0
507
- hash: 1111483963078583304
508
553
  required_rubygems_version: !ruby/object:Gem::Requirement
509
554
  none: false
510
555
  requirements:
@@ -519,3 +564,4 @@ specification_version: 3
519
564
  summary: A replacement for ActiveResource for RESTful APIs that handles associated
520
565
  object and multiple data sources
521
566
  test_files: []
567
+ has_rdoc:
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rspec DELETED
@@ -1,5 +0,0 @@
1
- --color
2
- --format nested
3
- --backtrace
4
- --fail-fast
5
- -X
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.2
4
- - 1.9.3
@@ -1,121 +0,0 @@
1
- module ApiResource
2
-
3
- module Associations
4
-
5
- class AssociationProxy
6
-
7
-
8
- cattr_accessor :remote_path_element; self.remote_path_element = :service_uri
9
- cattr_accessor :include_class_scopes; self.include_class_scopes = true
10
-
11
- attr_accessor :owner, :loaded, :klass, :internal_object, :remote_path, :scopes, :times_loaded
12
-
13
- # TODO: added owner - moved it to the end because the tests don't use it - it's useful here though
14
- def initialize(klass_name, contents, owner = nil)
15
- raise "Cannot create an association proxy to the unknown object #{klass_name}" unless defined?(klass_name.to_s.classify)
16
- # A simple attr_accessor for testing purposes
17
- self.times_loaded = 0
18
- self.owner = owner
19
- self.klass = klass_name.to_s.classify.constantize
20
- # make sure we have the remote definition
21
- self.klass.load_class_data
22
- self.load(contents)
23
- self.loaded = {}.with_indifferent_access
24
-
25
- #debugger
26
-
27
- if self.class.include_class_scopes
28
- self.scopes = self.scopes.reverse_merge(self.klass.scopes)
29
- end
30
- # Now that we have set up all the scopes with the load method we need to create methods
31
- self.scopes.each do |key, _|
32
- next if self.respond_to?(key)
33
- self.instance_eval <<-EOE, __FILE__, __LINE__ + 1
34
- def #{key}(opts = {})
35
- @#{key} ||= ApiResource::Associations::RelationScope.new(self, :#{key}, opts)
36
- end
37
- EOE
38
- end
39
- end
40
-
41
- def serializable_hash(options = {})
42
- raise "Not Implemented: This method must be implemented in a subclass"
43
- end
44
-
45
- def scopes
46
- @scopes ||= {}.with_indifferent_access
47
- end
48
-
49
- def scope?(scp)
50
- self.scopes.keys.include?(scp.to_s)
51
- end
52
-
53
- def internal_object
54
- @internal_object ||= self.load_scope_with_options(:all, {})
55
- end
56
-
57
- def blank?
58
- self.internal_object.blank?
59
- end
60
- alias_method :empty?, :blank?
61
-
62
- def method_missing(method, *args, &block)
63
- self.internal_object.send(method, *args, &block)
64
- end
65
-
66
- def reload
67
- if self
68
- remove_instance_variable(:@internal_object) if instance_variable_defined?(:@internal_object)
69
- self.load(self.load_from_remote({}))
70
- self
71
- end
72
- end
73
-
74
- def to_s
75
- self.internal_object.to_s
76
- end
77
-
78
- def inspect
79
- self.internal_object.inspect
80
- end
81
-
82
- def ==(other)
83
- raise "Not Implemented: This method must be implemented in a subclass"
84
- end
85
-
86
- protected
87
- # This method loads a particular scope with a set of options from the remote server
88
- def load_scope_with_options(scope, options)
89
- raise "Not Implemented: This method must be implemented in a subclass"
90
- end
91
- # This method is a helper to initialize for loading the data passed in to create this object
92
- def load(contents)
93
- raise "Not Implemented: This method must be implemented in a subclass"
94
- end
95
-
96
- # get the remote URI based on our config and options
97
- def build_load_path(options)
98
- path = self.remote_path
99
- # add a format if it doesn't exist and there is no query string yet
100
- path += ".#{self.klass.format.extension}" unless path =~ /\./ || path =~/\?/
101
- # add the query string, allowing for other user-provided options in the remote_path if we have options
102
- unless options.blank?
103
- path += (path =~ /\?/ ? "&" : "?") + options.to_query
104
- end
105
- path
106
- end
107
-
108
- # get data from the remote server
109
- def load_from_remote(options)
110
- self.klass.connection.get(self.build_load_path(options))
111
- end
112
- # This method create the key for the loaded hash, it ensures that a unique set of scopes
113
- # with a unique set of options is only loaded once
114
- def loaded_hash_key(scope, options)
115
- options.to_a.sort.inject(scope) {|accum,(k,v)| accum << "_#{k}_#{v}"}
116
- end
117
- end
118
-
119
- end
120
-
121
- end
@@ -1,23 +0,0 @@
1
- require 'api_resource/associations/resource_scope'
2
-
3
- module ApiResource
4
- module Associations
5
- class DynamicResourceScope < ResourceScope
6
-
7
- attr_accessor :dynamic_value
8
- # initializer - set up the dynamic value
9
- def initialize(klass, current_scope, dynamic_value, opts = {})
10
- self.dynamic_value = dynamic_value
11
- super(klass, current_scope, opts)
12
- end
13
- # get the to_query value for this resource scope
14
- def to_hash
15
- hsh = self.scopes[self.current_scope].clone
16
- hsh.each_pair do |k,v|
17
- hsh[k] = self.dynamic_value
18
- end
19
- self.parent_hash.merge(hsh)
20
- end
21
- end
22
- end
23
- end
@@ -1,68 +0,0 @@
1
- require 'api_resource/associations/resource_scope'
2
-
3
- module ApiResource
4
- module Associations
5
-
6
- class GenericScope < ResourceScope
7
- attr_reader :name
8
- attr_reader :params
9
- attr_reader :types
10
- attr_reader :values
11
-
12
- # Gets called when a scope is called. Stores everything in
13
- # this class. Sorry, couldn't be bothered to figure out the
14
- # class hierarchy.
15
- #
16
- # klass - ApiResourceBase class
17
- # current_scope - sym for the scope
18
- # *args - arguments being passed to the scope
19
- def initialize(klass, current_scope, *args)
20
-
21
- @name = current_scope # contains sym with scope ie :for_provider
22
- @params = klass.related_objects[:scopes][current_scope].keys
23
- @types = klass.related_objects[:scopes][current_scope].values
24
-
25
- # Bail if we have crap
26
- if @params == nil
27
- raise "Scope #{@name} does not exist #{klass.name}. Scopes: #{klass.related_objects[:scopes]}"
28
- end
29
-
30
- # extract parent scope stuff
31
- opts = {}
32
- last_arg = args[args.count - 1]
33
- if last_arg != nil && last_arg.is_a?(Hash) && last_arg[:parent] != nil
34
- args = args.slice(0, args.count - 1)
35
- opts = last_arg
36
- end
37
-
38
- # walk through parameters and types and assign values from *args to parameters
39
- @values = []
40
- @params.count.times do |i|
41
- if @types[i] == :rest
42
- @values << args.slice(i, args.count)
43
- else
44
- @values << args[i]
45
- end
46
- end
47
-
48
- # Let the parent class do its magic.
49
- super(klass, current_scope, opts)
50
- end
51
-
52
- # get the to_query value for this resource scope
53
- def to_hash
54
- # debugger
55
- if @params.count == 0
56
- scope_arguments = true
57
- else
58
- scope_arguments = {}
59
- @params.count.times do |i|
60
- scope_arguments[@params[i]] = @values[i] if @values[i] != nil
61
- end
62
- end
63
- self.parent_hash.merge({@name => scope_arguments})
64
- end
65
- end
66
- end
67
- end
68
-
@@ -1,15 +0,0 @@
1
- require 'api_resource/associations/dynamic_resource_scope'
2
-
3
- module ApiResource
4
- module Associations
5
- class MultiArgumentResourceScope < DynamicResourceScope
6
- # initialize with a variable number of dynamic arguments
7
- def initialize(klass, current_scope, *dynamic_value)
8
- # pull off opts
9
- opts = dynamic_value.extract_options!
10
- # we always dynamic value to be an Array, so we don't use the splat here
11
- super(klass, current_scope, dynamic_value.flatten, opts)
12
- end
13
- end
14
- end
15
- end
@@ -1,25 +0,0 @@
1
- require 'api_resource/associations/scope'
2
-
3
- module ApiResource
4
-
5
- module Associations
6
-
7
- class RelationScope < Scope
8
-
9
- # Use this method to access the internal data, this guarantees that loading only occurs once per object
10
- def internal_object
11
- ApiResource.with_ttl(ttl) do
12
- @internal_object ||= self.klass.send(:load_scope_with_options, self.current_scope, self.to_hash)
13
- end
14
- end
15
- #
16
- # class factory
17
- def self.class_factory(hsh)
18
- ApiResource::Associations::RelationScope
19
- end
20
-
21
- end
22
-
23
- end
24
-
25
- end