render_json_rails 0.1.5 → 0.1.6
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 +4 -4
- data/README.md +1 -12
- data/lib/render_json_rails/concern.rb +24 -19
- data/lib/render_json_rails/helper.rb +2 -2
- data/lib/render_json_rails/version.rb +1 -1
- data/render_json_rails.gemspec +1 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 91137440ff0206a13f4dc35e08b5978dfca32f05efe8a46f057df54ea5e090ad
         | 
| 4 | 
            +
              data.tar.gz: 7552a89149c3407ccd6706681f61b96f91d04740c594f37cc3a587998fabc882
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2574a769223d9deee3a85c227e1a21e3886a4337b1b7d00a925b900c09aea4ecb9c3bdd49e9f5db22f877f5d41b9747114690d17164e7efc56b7d821c9aa85d3
         | 
| 7 | 
            +
              data.tar.gz: 6b8e57f7029b37ce70dbf0f2bcfe6a03a7b1f281bea6ad560561b8d18937a226a96559fffface5fe51fced650f5fe95bf0af84f8c25f95127f04e3a74ec5d488
         | 
    
        data/README.md
    CHANGED
    
    | @@ -80,7 +80,7 @@ render_json_config name: :team, | |
| 80 80 | 
             
            Add this line to your application's Gemfile:
         | 
| 81 81 |  | 
| 82 82 | 
             
            ```ruby
         | 
| 83 | 
            -
            gem 'render_json_rails' | 
| 83 | 
            +
            gem 'render_json_rails'
         | 
| 84 84 | 
             
            ```
         | 
| 85 85 |  | 
| 86 86 | 
             
            And then execute:
         | 
| @@ -95,14 +95,3 @@ Or install it yourself as: | |
| 95 95 |  | 
| 96 96 | 
             
            Bug reports and pull requests are welcome on GitHub at https://github.com/intum/render_json_rails.
         | 
| 97 97 |  | 
| 98 | 
            -
             | 
| 99 | 
            -
            ## TMP
         | 
| 100 | 
            -
             | 
| 101 | 
            -
            Tworzenie gema
         | 
| 102 | 
            -
             | 
| 103 | 
            -
            ```
         | 
| 104 | 
            -
            gem build render_json_rails.gemspec
         | 
| 105 | 
            -
             | 
| 106 | 
            -
            gem push --key github --host https://rubygems.pkg.github.com/intum render_json_rails-0.1.XXX.gem
         | 
| 107 | 
            -
            ```
         | 
| 108 | 
            -
             | 
| @@ -24,10 +24,10 @@ module RenderJsonRails | |
| 24 24 |  | 
| 25 25 | 
             
                    options = {}
         | 
| 26 26 | 
             
                    if fields && fields[name].present?
         | 
| 27 | 
            -
                      options[:only] = fields[name].split(',').find_all{ |el| !except.include?(el.to_sym) }
         | 
| 28 | 
            -
                      options[:methods] = methods&.find_all{ |el| options[:only].include?(el.to_s) }
         | 
| 27 | 
            +
                      options[:only] = fields[name].split(',').find_all { |el| !except.include?(el.to_sym) }
         | 
| 28 | 
            +
                      options[:methods] = methods&.find_all { |el| options[:only].include?(el.to_s) }
         | 
| 29 29 | 
             
                      if allowed_methods
         | 
| 30 | 
            -
                        options[:methods] = (options[:methods] || []) | allowed_methods.find_all{ |el| options[:only].include?(el.to_s) }
         | 
| 30 | 
            +
                        options[:methods] = (options[:methods] || []) | allowed_methods.find_all { |el| options[:only].include?(el.to_s) }
         | 
| 31 31 | 
             
                      end
         | 
| 32 32 | 
             
                    else
         | 
| 33 33 | 
             
                      options[:except] = except
         | 
| @@ -38,10 +38,8 @@ module RenderJsonRails | |
| 38 38 |  | 
| 39 39 | 
             
                  def render_json_config(config)
         | 
| 40 40 | 
             
                    @render_json_config = config
         | 
| 41 | 
            -
                    # @render_json_config[:methods] = [:image]
         | 
| 42 41 | 
             
                  end
         | 
| 43 42 |  | 
| 44 | 
            -
                  # rubocop:disable Lint/UnusedMethodArgument
         | 
| 45 43 | 
             
                  def render_json_options(includes: nil, fields: nil, additional_config: nil)
         | 
| 46 44 | 
             
                    raise "należy skonfigurowac render_json metodą: render_json_config" if !defined?(@render_json_config)
         | 
| 47 45 |  | 
| @@ -58,29 +56,19 @@ module RenderJsonRails | |
| 58 56 | 
             
                      @render_json_config[:includes].each do |name, klass|
         | 
| 59 57 | 
             
                        if includes.include?(name.to_s)
         | 
| 60 58 | 
             
                          includes2 = RenderJsonRails::Concern.includes_for_model(includes: includes, model: name.to_s)
         | 
| 61 | 
            -
                          # raise includes2.inspect + ' ' + includes.inspect
         | 
| 62 59 | 
             
                          include_options << { name => klass.render_json_options(includes: includes2, fields: fields) }
         | 
| 63 60 | 
             
                        end
         | 
| 64 61 | 
             
                      end if @render_json_config[:includes]
         | 
| 65 62 |  | 
| 66 | 
            -
                      # if includes.include?('questions')
         | 
| 67 | 
            -
                      #   includes2 = RenderJsonRails::Concern.includes_for_model(includes: includes, model: 'questions')
         | 
| 68 | 
            -
                      #   # raise includes2.inspect + ' ' + includes.inspect
         | 
| 69 | 
            -
                      #   include_options << { questions: Organize::Question.render_json_options(includes: includes2, fields: fields) }
         | 
| 70 | 
            -
                      # end
         | 
| 71 63 | 
             
                      options[:include] = include_options
         | 
| 72 64 | 
             
                    end
         | 
| 73 65 |  | 
| 66 | 
            +
                    options = RenderJsonRails::Concern.deep_meld(options, additional_config) if additional_config
         | 
| 74 67 | 
             
                    options
         | 
| 75 68 | 
             
                  end # render_json_options
         | 
| 76 | 
            -
                  # rubocop:enable Lint/UnusedMethodArgument
         | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 69 | 
             
                end # class_methods
         | 
| 80 70 |  | 
| 81 71 | 
             
                def self.includes_for_model(includes:, model:)
         | 
| 82 | 
            -
                  # include.split(',')
         | 
| 83 | 
            -
                  # includes.delete(to_remove)
         | 
| 84 72 | 
             
                  includes = includes.map do |el|
         | 
| 85 73 | 
             
                    if el.start_with?(model + '.')
         | 
| 86 74 | 
             
                      el = el.gsub(/^#{model}\./, '')
         | 
| @@ -88,8 +76,25 @@ module RenderJsonRails | |
| 88 76 | 
             
                      el = nil
         | 
| 89 77 | 
             
                    end
         | 
| 90 78 | 
             
                  end
         | 
| 91 | 
            -
                  includes.find_all{ |el| el.present? }
         | 
| 92 | 
            -
             | 
| 79 | 
            +
                  includes.find_all { |el| el.present? }
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                private
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                def self.deep_meld(h1, h2)
         | 
| 85 | 
            +
                  h1.deep_merge(h2) do |key, this_val, other_val|
         | 
| 86 | 
            +
                    if this_val != nil && other_val == nil
         | 
| 87 | 
            +
                      this_val
         | 
| 88 | 
            +
                    elsif this_val == nil && other_val != nil
         | 
| 89 | 
            +
                      other_val
         | 
| 90 | 
            +
                    elsif this_val.is_a?(Array) && other_val.is_a?(Array)
         | 
| 91 | 
            +
                      this_val | other_val
         | 
| 92 | 
            +
                    elsif this_val.is_a?(Hash) && other_val.is_a?(Hash)
         | 
| 93 | 
            +
                      deep_meld(this_val, other_val)
         | 
| 94 | 
            +
                    else
         | 
| 95 | 
            +
                      [this_val, other_val]
         | 
| 96 | 
            +
                    end
         | 
| 97 | 
            +
                  end
         | 
| 93 98 | 
             
                end
         | 
| 94 99 | 
             
              end
         | 
| 95 | 
            -
            end
         | 
| 100 | 
            +
            end
         | 
| @@ -27,7 +27,7 @@ module RenderJsonRails | |
| 27 27 | 
             
                  else
         | 
| 28 28 | 
             
                    class_object = object.class
         | 
| 29 29 | 
             
                  end
         | 
| 30 | 
            -
                  includes = params[:include].to_s.split(',').map{ |el| el.to_s.strip } if params[:include]
         | 
| 30 | 
            +
                  includes = params[:include].to_s.split(',').map { |el| el.to_s.strip } if params[:include]
         | 
| 31 31 | 
             
                  options = class_object.render_json_options(
         | 
| 32 32 | 
             
                    includes: includes,
         | 
| 33 33 | 
             
                    fields: params[:fields],
         | 
| @@ -44,4 +44,4 @@ module RenderJsonRails | |
| 44 44 | 
             
                  end
         | 
| 45 45 | 
             
                end
         | 
| 46 46 | 
             
              end
         | 
| 47 | 
            -
            end
         | 
| 47 | 
            +
            end
         | 
    
        data/render_json_rails.gemspec
    CHANGED
    
    | @@ -20,7 +20,7 @@ Gem::Specification.new do |spec| | |
| 20 20 |  | 
| 21 21 | 
             
              # Specify which files should be added to the gem when it is released.
         | 
| 22 22 | 
             
              # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
         | 
| 23 | 
            -
              spec.files | 
| 23 | 
            +
              spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
         | 
| 24 24 | 
             
                `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 25 25 | 
             
              end
         | 
| 26 26 | 
             
              spec.bindir        = "exe"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: render_json_rails
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.6
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Marcin
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020- | 
| 11 | 
            +
            date: 2020-09-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: render json with 'includes' and 'fields' with simple config
         | 
| 14 14 | 
             
            email:
         | 
| @@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 48 48 | 
             
                - !ruby/object:Gem::Version
         | 
| 49 49 | 
             
                  version: '0'
         | 
| 50 50 | 
             
            requirements: []
         | 
| 51 | 
            -
            rubygems_version: 3. | 
| 51 | 
            +
            rubygems_version: 3.0.3
         | 
| 52 52 | 
             
            signing_key: 
         | 
| 53 53 | 
             
            specification_version: 4
         | 
| 54 54 | 
             
            summary: Simle JSON API render like JonApi
         |