smooth_operator 1.10.16 → 1.10.17

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2VlMDMwZTU0ODVjZTdiZTg2YmY1NDYzODE4MDVkYjlhOWJlZjliYQ==
4
+ ZmU3ZWY3OGVjOTg5NTNmMGNiMTI4N2U5YTAyYjQzOGI1MGQ4NjNhMQ==
5
5
  data.tar.gz: !binary |-
6
- ZDg4ZGQ5NmM5MWFkYWMwYzBjYTQxZTg2ODYwOGY5OWFkZDI3ZjdkNQ==
6
+ NWY2YWE5NmVmZjM4YzBlNTRhZGJmMjVlODM3M2QxY2ViZDRmMmNmMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjZiYjExYmU3MzdjODRjNmIxNjdhMGJkMzM3M2YzOTk3NzQ3OTAzYTAyNWU4
10
- MWE5YjU3MWUyYjAwMmYwN2M3YzE3MTM2NDJmNzNhMTI2ZThlNjljZTM5MmZh
11
- OWQzNzE1OWQ1OGE0MDYxNTcxN2M1NWEwN2E1MmZmNWZmNTU4ODQ=
9
+ YTAxMGQ5YWU1MTFkNzE5OTliZTY0YjU4ZWZiNTVhM2E0Zjg3ODVjZDIzM2Fh
10
+ NzhmN2FlZmEzM2I4NGJjYTM0ZTUzZGYwZmQ3YWJkODdiNDRkMjJiY2YyNjgz
11
+ MzNmNmM4OWJlOThlYjM4ZjlmYzVkODIzNDNkNWIzMDcxOTFhNzM=
12
12
  data.tar.gz: !binary |-
13
- MGJjMzMxZmM0YmFkYmRlMGZiNmZlNGIzMWJlZGM4ZTQ4ZjUwM2E5ZDRlODUy
14
- MzE1YWYwODZmYmE5MDUxZjYzZTVhNmM5YmVmZTdlYTQzY2EzMmIwNjE1NTA1
15
- YTRkZDc2OGJkNjdkM2U5NmFjN2E4NmJkY2Y4NjA1MjA5NmM0ZWM=
13
+ MDZiOTJjNmQ1ZTVjNzZmZTc0MWI3MTU5NjBmYTU0ZTY3ZTBhNmUxY2NkZDg2
14
+ OTk5MzVhNDhmYTBhNTlhYWE0NmFiNmM1MTAyMGM0ZDMxM2VmZTUzZmU2YjE0
15
+ ZWI0MzBiMDI5MDVkZWRlYjUzNmMwMTMyNDk0OWQxMzk4MzM0MTA=
@@ -6,7 +6,7 @@ module SmoothOperator
6
6
 
7
7
  include Enumerable
8
8
 
9
- attr_reader :meta_data, :internal_array, :table_name, :object_class
9
+ attr_reader :meta_data, :internal_array, :object_class
10
10
 
11
11
  def_delegators :internal_array, :length, :<<, :[]
12
12
 
@@ -14,10 +14,10 @@ module SmoothOperator
14
14
  _attributes = attributes.dup
15
15
 
16
16
  @object_class = object_class
17
- @table_name = object_class.table_name
17
+ resources_name = object_class.resources_name
18
18
 
19
- @internal_array = [*_attributes[table_name]].map { |array_entry| object_class.new(array_entry).tap { |object| object.reloaded = true } }
20
- _attributes.delete(table_name)
19
+ @internal_array = [*_attributes[resources_name]].map { |array_entry| object_class.new(array_entry).tap { |object| object.reloaded = true } }
20
+ _attributes.delete(resources_name)
21
21
 
22
22
  @meta_data = _attributes
23
23
  end
@@ -63,8 +63,8 @@ module SmoothOperator
63
63
 
64
64
  attributes = _attributes = Helpers.stringify_keys(_attributes)
65
65
 
66
- if _attributes.include?(model_name)
67
- attributes = _attributes.delete(model_name)
66
+ if _attributes.include?(resource_name)
67
+ attributes = _attributes.delete(resource_name)
68
68
  @_meta_data = _attributes
69
69
  end
70
70
 
@@ -27,7 +27,7 @@ module SmoothOperator
27
27
  if parsed_response.is_a?(Array)
28
28
  parsed_response.map { |array_entry| build_object(array_entry, options, true) }
29
29
  elsif parsed_response.is_a?(Hash)
30
- if !from_array && parsed_response.include?(table_name)
30
+ if !from_array && parsed_response.include?(resources_name)
31
31
  ArrayWithMetaData.new(parsed_response, self)
32
32
  else
33
33
  new(parsed_response, from_server: true)
@@ -14,22 +14,26 @@ module SmoothOperator
14
14
  @internal_structure ||= self.class.internal_structure.dup
15
15
  end
16
16
 
17
- def table_name
18
- @table_name ||= self.class.table_name.dup
17
+ def resources_name
18
+ @resources_name ||= self.class.resources_name.dup
19
19
  end
20
20
 
21
- def model_name
22
- @model_name ||= table_name.singularize
21
+ def resource_name
22
+ @resource_name ||= resources_name.singularize
23
23
  end
24
24
 
25
25
 
26
26
  module ClassMethods
27
+
28
+ def resources_name
29
+ @resources_name ||= self.resource_name.pluralize
30
+ end
31
+ attr_writer :resources_name
27
32
 
28
- attr_writer :table_name
29
-
30
- def table_name
31
- @table_name ||= self.model_name.to_s.underscore.pluralize
33
+ def resource_name
34
+ @resource_name ||= self.model_name.to_s.underscore.pluralize
32
35
  end
36
+ attr_writer :resource_name
33
37
 
34
38
  def schema(structure)
35
39
  internal_structure.merge! Helpers.stringify_keys(structure)
@@ -75,10 +75,10 @@ module SmoothOperator
75
75
  end
76
76
 
77
77
  def resource_path(relative_path, options)
78
- table_name = options[:table_name] || self.table_name
78
+ resources_name = options[:resources_name] || self.resources_name
79
79
 
80
- if Helpers.present?(table_name)
81
- Helpers.present?(relative_path) ? "#{table_name}/#{relative_path}" : table_name
80
+ if Helpers.present?(resources_name)
81
+ Helpers.present?(relative_path) ? "#{resources_name}/#{relative_path}" : resources_name
82
82
  else
83
83
  relative_path.to_s
84
84
  end
@@ -114,8 +114,8 @@ module SmoothOperator
114
114
  if parent_object.nil? || options[:ignore_parent] == true
115
115
  relative_path = id.to_s
116
116
  else
117
- options[:table_name] = ''
118
- relative_path = "#{parent_object.table_name}/#{parent_object.id}/#{table_name}/#{id}"
117
+ options[:resources_name] = ''
118
+ relative_path = "#{parent_object.resources_name}/#{parent_object.id}/#{resources_name}/#{id}"
119
119
  end
120
120
  end
121
121
 
@@ -133,7 +133,7 @@ module SmoothOperator
133
133
 
134
134
  hash.delete('id')
135
135
 
136
- { model_name => hash }.merge(data)
136
+ { resource_name => hash }.merge(data)
137
137
  end
138
138
 
139
139
  end
@@ -5,8 +5,8 @@ module SmoothOperator
5
5
  def human_attribute_name(attribute_key_name, options = {})
6
6
  no_translation = "-- no translation --"
7
7
 
8
- defaults = ["smooth_operator.attributes.#{name.underscore}.#{attribute_key_name}".to_sym]
9
- defaults << "activerecord.attributes.#{name.underscore}.#{attribute_key_name}".to_sym
8
+ defaults = ["smooth_operator.attributes.#{model_name.i18n_key}.#{attribute_key_name}".to_sym]
9
+ defaults << "activerecord.attributes.#{model_name.i18n_key}.#{attribute_key_name}".to_sym
10
10
  defaults << options[:default] if options[:default]
11
11
  defaults.flatten!
12
12
  defaults << no_translation
@@ -1,3 +1,3 @@
1
1
  module SmoothOperator
2
- VERSION = "1.10.16"
2
+ VERSION = "1.10.17"
3
3
  end
@@ -78,7 +78,7 @@ describe SmoothOperator::FinderMethods do
78
78
  end
79
79
  end
80
80
 
81
- context "when the server returns a hash with a key (equal to subject's call.table_name) containing an array" do
81
+ context "when the server returns a hash with a key (equal to subject's call.resources_name) containing an array" do
82
82
  it "it should return a RemoteCall instance an instance of ArrayWithMetaData" do
83
83
  remote_call = subject.find('with_metadata')
84
84
  users = remote_call.data
@@ -90,14 +90,12 @@ describe SmoothOperator::FinderMethods do
90
90
  end
91
91
  end
92
92
 
93
- context "when the server returns an array with nested object on each entry, with the same name has the resource", current: true do
94
- it "it should return a RemoteCall instance an instance of ArrayWithMetaData" do
95
- remote_call = subject.find('with_metadata')
93
+ context "when the server returns an array with nested object on each entry, with the same name has the resource" do
94
+ it "it should return an Array with Class instances" do
95
+ remote_call = subject.find('array_with_nested_users')
96
96
  users = remote_call.data
97
97
 
98
- expect(users).to be_instance_of(SmoothOperator::ArrayWithMetaData)
99
- expect(users.page).to be(1)
100
- expect(users.total).to be(6)
98
+ expect(users).to be_instance_of(Array)
101
99
  users.each { |user| expect(user).to be_instance_of(subject) }
102
100
  end
103
101
  end
@@ -2,7 +2,7 @@ class Address < SmoothOperator::Base
2
2
 
3
3
  self.dirty_attributes
4
4
 
5
- self.model_name = :none
5
+ self.resource_name = ''
6
6
 
7
7
  self.endpoint_user = 'admin'
8
8
  self.endpoint_pass = 'admin'
@@ -2,7 +2,7 @@ module User
2
2
 
3
3
  class Base < SmoothOperator::Base
4
4
 
5
- self.model_name = 'user'
5
+ self.resource_name = 'user'
6
6
 
7
7
  self.endpoint_user = 'admin'
8
8
 
@@ -36,7 +36,7 @@ module User
36
36
 
37
37
  class TimeoutConnection < Base
38
38
  self.timeout = 1
39
- self.model_name = 'user'
39
+ self.resource_name = 'user'
40
40
  end
41
41
 
42
42
  end
@@ -2,7 +2,7 @@ module UserWithAddressAndPosts
2
2
 
3
3
  class Father < User::Base
4
4
 
5
- self.table_name = 'users'
5
+ self.resources_name = 'users'
6
6
 
7
7
  schema(
8
8
  posts: Post,
@@ -13,7 +13,7 @@ module UserWithAddressAndPosts
13
13
 
14
14
  class Son < Father
15
15
 
16
- self.table_name = 'users'
16
+ self.resources_name = 'users'
17
17
 
18
18
  schema(
19
19
  age: :int,
@@ -28,7 +28,7 @@ module UserWithAddressAndPosts
28
28
 
29
29
  class WithPatch < Son
30
30
 
31
- self.table_name = 'users'
31
+ self.resources_name = 'users'
32
32
 
33
33
  self.update_http_verb = :patch
34
34
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smooth_operator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.16
4
+ version: 1.10.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Gonçalves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-13 00:00:00.000000000 Z
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler