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 +8 -8
- data/lib/smooth_operator/array_with_meta_data.rb +4 -4
- data/lib/smooth_operator/attribute_assignment.rb +2 -2
- data/lib/smooth_operator/finder_methods.rb +1 -1
- data/lib/smooth_operator/model_schema.rb +12 -8
- data/lib/smooth_operator/operator.rb +3 -3
- data/lib/smooth_operator/persistence.rb +3 -3
- data/lib/smooth_operator/translation.rb +2 -2
- data/lib/smooth_operator/version.rb +1 -1
- data/spec/smooth_operator/finder_methods_spec.rb +5 -7
- data/spec/support/models/address.rb +1 -1
- data/spec/support/models/user.rb +2 -2
- data/spec/support/models/user_with_address_and_posts.rb +3 -3
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,15 +1,15 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            !binary "U0hBMQ==":
         | 
| 3 3 | 
             
              metadata.gz: !binary |-
         | 
| 4 | 
            -
                 | 
| 4 | 
            +
                ZmU3ZWY3OGVjOTg5NTNmMGNiMTI4N2U5YTAyYjQzOGI1MGQ4NjNhMQ==
         | 
| 5 5 | 
             
              data.tar.gz: !binary |-
         | 
| 6 | 
            -
                 | 
| 6 | 
            +
                NWY2YWE5NmVmZjM4YzBlNTRhZGJmMjVlODM3M2QxY2ViZDRmMmNmMg==
         | 
| 7 7 | 
             
            SHA512:
         | 
| 8 8 | 
             
              metadata.gz: !binary |-
         | 
| 9 | 
            -
                 | 
| 10 | 
            -
                 | 
| 11 | 
            -
                 | 
| 9 | 
            +
                YTAxMGQ5YWU1MTFkNzE5OTliZTY0YjU4ZWZiNTVhM2E0Zjg3ODVjZDIzM2Fh
         | 
| 10 | 
            +
                NzhmN2FlZmEzM2I4NGJjYTM0ZTUzZGYwZmQ3YWJkODdiNDRkMjJiY2YyNjgz
         | 
| 11 | 
            +
                MzNmNmM4OWJlOThlYjM4ZjlmYzVkODIzNDNkNWIzMDcxOTFhNzM=
         | 
| 12 12 | 
             
              data.tar.gz: !binary |-
         | 
| 13 | 
            -
                 | 
| 14 | 
            -
                 | 
| 15 | 
            -
                 | 
| 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, : | 
| 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 | 
            -
                   | 
| 17 | 
            +
                  resources_name = object_class.resources_name
         | 
| 18 18 |  | 
| 19 | 
            -
                  @internal_array = [*_attributes[ | 
| 20 | 
            -
                  _attributes.delete( | 
| 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?( | 
| 67 | 
            -
                    attributes = _attributes.delete( | 
| 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?( | 
| 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  | 
| 18 | 
            -
                  @ | 
| 17 | 
            +
                def resources_name
         | 
| 18 | 
            +
                  @resources_name ||= self.class.resources_name.dup
         | 
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 | 
            -
                def  | 
| 22 | 
            -
                  @ | 
| 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 | 
            -
                   | 
| 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 | 
            -
                   | 
| 78 | 
            +
                  resources_name = options[:resources_name] || self.resources_name
         | 
| 79 79 |  | 
| 80 | 
            -
                  if Helpers.present?( | 
| 81 | 
            -
                    Helpers.present?(relative_path) ? "#{ | 
| 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[: | 
| 118 | 
            -
                      relative_path = "#{parent_object. | 
| 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 | 
            -
                  {  | 
| 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.#{ | 
| 9 | 
            -
                  defaults << "activerecord.attributes.#{ | 
| 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
         | 
| @@ -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. | 
| 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" | 
| 94 | 
            -
                  it "it should return  | 
| 95 | 
            -
                    remote_call = subject.find(' | 
| 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( | 
| 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
         | 
    
        data/spec/support/models/user.rb
    CHANGED
    
    | @@ -2,7 +2,7 @@ module User | |
| 2 2 |  | 
| 3 3 | 
             
              class Base < SmoothOperator::Base
         | 
| 4 4 |  | 
| 5 | 
            -
                self. | 
| 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. | 
| 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. | 
| 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. | 
| 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. | 
| 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. | 
| 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- | 
| 11 | 
            +
            date: 2014-05-14 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         |