rows_controller 2.0.5 → 2.0.7
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/Rakefile +6 -2
 - data/lib/rows/model.rb +11 -1
 - data/lib/rows/resources.rb +3 -2
 - data/lib/rows/version.rb +1 -1
 - data/lib/rows/version.rb.bak +1 -1
 - metadata +5 -5
 - data/app/controllers/rows_controller.rb.bak +0 -89
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e56282b6de1f22ebb0cecd4c277d4ec0d84615a0
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 14bb4f2ce1ea1b8e0be466f50a9e6276e5280c9c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 89ecd8099220b7c9423234a52df31f0999e1cddc0be6c9e212101169ddce0dcbfe1a3f32f0864fb680ed82fa15f4543c6db76f9f8140c9224602049757328a03
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 1a8c3b8aea0840dd7d027e8330a862a73b291d6ae9e9e117adc6c93af0365bc9ef27ad5fc961a62fb132e01125dbc23dcd4a92a493c218541cac07f99f13b5b9
         
     | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env rake
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require "rubygems"
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            begin
         
     | 
| 
         @@ -6,7 +8,10 @@ rescue LoadError 
     | 
|
| 
       6 
8 
     | 
    
         
             
              puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
         
     | 
| 
       7 
9 
     | 
    
         
             
            end
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
            rails_version = `rails -v`.strip
         
     | 
| 
      
 12 
     | 
    
         
            +
            rails_version =~ /Rails (\d*)\./
         
     | 
| 
      
 13 
     | 
    
         
            +
            dir = "dummy#{$1}"
         
     | 
| 
      
 14 
     | 
    
         
            +
            APP_RAKEFILE = File.expand_path("../test/#{dir}/Rakefile", __FILE__)
         
     | 
| 
       10 
15 
     | 
    
         
             
            load 'rails/tasks/engine.rake'
         
     | 
| 
       11 
16 
     | 
    
         | 
| 
       12 
17 
     | 
    
         
             
            load 'rails/tasks/statistics.rake'
         
     | 
| 
         @@ -16,7 +21,6 @@ Bundler::GemHelper.install_tasks 
     | 
|
| 
       16 
21 
     | 
    
         
             
            require 'rake/testtask'
         
     | 
| 
       17 
22 
     | 
    
         | 
| 
       18 
23 
     | 
    
         
             
            Rake::TestTask.new(:test) do |t|
         
     | 
| 
       19 
     | 
    
         
            -
              puts "Ruby version: #{RUBY_VERSION}"
         
     | 
| 
       20 
24 
     | 
    
         
             
              t.libs << 'lib'
         
     | 
| 
       21 
25 
     | 
    
         
             
              t.libs << 'test'
         
     | 
| 
       22 
26 
     | 
    
         
             
              t.pattern = 'test/**/*_test.rb'
         
     | 
    
        data/lib/rows/model.rb
    CHANGED
    
    | 
         @@ -5,6 +5,7 @@ module Rows::Model 
     | 
|
| 
       5 
5 
     | 
    
         
             
            		       params[:controller].singularize.camelize.constantize
         
     | 
| 
       6 
6 
     | 
    
         
             
              end
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
      
 8 
     | 
    
         
            +
             if Rails::VERSION::MAJOR > 3
         
     | 
| 
       8 
9 
     | 
    
         
             
              def model_name
         
     | 
| 
       9 
10 
     | 
    
         
             
                @_model_name   ||= model_class.model_name.name
         
     | 
| 
       10 
11 
     | 
    
         
             
              end
         
     | 
| 
         @@ -12,9 +13,18 @@ module Rows::Model 
     | 
|
| 
       12 
13 
     | 
    
         
             
              def model_symbol
         
     | 
| 
       13 
14 
     | 
    
         
             
                @_model_symbol ||= model_class.model_name.singular
         
     | 
| 
       14 
15 
     | 
    
         
             
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             else
         
     | 
| 
      
 17 
     | 
    
         
            +
              def model_name
         
     | 
| 
      
 18 
     | 
    
         
            +
                @_model_name ||= model_class.name
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              def model_symbol
         
     | 
| 
      
 22 
     | 
    
         
            +
                @_model_symbol ||= model_name.underscore.gsub( %r{/}, '_' )
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             end
         
     | 
| 
       15 
25 
     | 
    
         | 
| 
       16 
26 
     | 
    
         
             
              def model_symbol_plural
         
     | 
| 
       17 
     | 
    
         
            -
                @_model_symbol_plural ||=  
     | 
| 
      
 27 
     | 
    
         
            +
                @_model_symbol_plural ||= model_symbol.pluralize
         
     | 
| 
       18 
28 
     | 
    
         
             
              end
         
     | 
| 
       19 
29 
     | 
    
         | 
| 
       20 
30 
     | 
    
         
             
            end
         
     | 
    
        data/lib/rows/resources.rb
    CHANGED
    
    | 
         @@ -61,12 +61,13 @@ module Rows::Resources 
     | 
|
| 
       61 
61 
     | 
    
         
             
              # Never trust parameters from the scary internet, only allow the white list through.
         
     | 
| 
       62 
62 
     | 
    
         
             
              def resource_params
         
     | 
| 
       63 
63 
     | 
    
         
             
                permits = resource_whitelist
         
     | 
| 
       64 
     | 
    
         
            -
                if  
     | 
| 
      
 64 
     | 
    
         
            +
                if Rails::VERSION::MAJOR > 3
         
     | 
| 
       65 
65 
     | 
    
         
             
                  params.require(model_symbol).permit(permits)
         
     | 
| 
       66 
66 
     | 
    
         
             
                else
         
     | 
| 
       67 
67 
     | 
    
         
             
                  pars = params[model_symbol] || {}
         
     | 
| 
       68 
68 
     | 
    
         
             
                  pars.keys.each { |x|
         
     | 
| 
       69 
     | 
    
         
            -
            	 
     | 
| 
      
 69 
     | 
    
         
            +
            	x = x.to_sym
         
     | 
| 
      
 70 
     | 
    
         
            +
            	unless permits.include?(x) || permits.include?({x => []})
         
     | 
| 
       70 
71 
     | 
    
         
             
            	  pars.delete(x)
         
     | 
| 
       71 
72 
     | 
    
         
             
            	  p "** WARNING: model <#{model_name}> dropping params <#{x}>"
         
     | 
| 
       72 
73 
     | 
    
         
             
            	end
         
     | 
    
        data/lib/rows/version.rb
    CHANGED
    
    
    
        data/lib/rows/version.rb.bak
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,27 +1,27 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: rows_controller
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.0.7
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Dittmar Krall
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015-10- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-10-27 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: sqlite3
         
     | 
| 
       15 
15 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
     | 
    
         
            -
                - - " 
     | 
| 
      
 17 
     | 
    
         
            +
                - - ">="
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
19 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       20 
20 
     | 
    
         
             
              type: :development
         
     | 
| 
       21 
21 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
22 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
23 
     | 
    
         
             
                requirements:
         
     | 
| 
       24 
     | 
    
         
            -
                - - " 
     | 
| 
      
 24 
     | 
    
         
            +
                - - ">="
         
     | 
| 
       25 
25 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
26 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       27 
27 
     | 
    
         
             
            description: YourController < RowsController ( < ApplicationController).
         
     | 
| 
         @@ -35,7 +35,6 @@ files: 
     | 
|
| 
       35 
35 
     | 
    
         
             
            - README.md
         
     | 
| 
       36 
36 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       37 
37 
     | 
    
         
             
            - app/controllers/rows_controller.rb
         
     | 
| 
       38 
     | 
    
         
            -
            - app/controllers/rows_controller.rb.bak
         
     | 
| 
       39 
38 
     | 
    
         
             
            - app/controllers/rows_ext_controller.rb
         
     | 
| 
       40 
39 
     | 
    
         
             
            - app/views/rows/_form.slim
         
     | 
| 
       41 
40 
     | 
    
         
             
            - app/views/rows/_list.slim
         
     | 
| 
         @@ -86,3 +85,4 @@ signing_key: 
     | 
|
| 
       86 
85 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       87 
86 
     | 
    
         
             
            summary: RowsController DRYs your controllers.
         
     | 
| 
       88 
87 
     | 
    
         
             
            test_files: []
         
     | 
| 
      
 88 
     | 
    
         
            +
            has_rdoc: 
         
     | 
| 
         @@ -1,89 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'rows/resources'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'rows/model'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'rows/utils'
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            class RowsController < ApplicationController
         
     | 
| 
       6 
     | 
    
         
            -
              if defined?(before_action)
         
     | 
| 
       7 
     | 
    
         
            -
                before_action :set_resource, only: [:show, :edit, :update, :destroy]
         
     | 
| 
       8 
     | 
    
         
            -
              else
         
     | 
| 
       9 
     | 
    
         
            -
                before_filter :set_resource, only: [:show, :edit, :update, :destroy]
         
     | 
| 
       10 
     | 
    
         
            -
              end
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
              helper_method :set_resource, :set_resources, :resource, :resources
         
     | 
| 
       13 
     | 
    
         
            -
              helper_method :resource_columns, :resource_format
         
     | 
| 
       14 
     | 
    
         
            -
              helper_method :model_class, :model_name
         
     | 
| 
       15 
     | 
    
         
            -
              helper_method :model_symbol, :model_symbol_plural
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
              include Rows::Model
         
     | 
| 
       18 
     | 
    
         
            -
              include Rows::Resources
         
     | 
| 
       19 
     | 
    
         
            -
              include Rows::Utils
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
              def self.model_class(model_class = nil)
         
     | 
| 
       22 
     | 
    
         
            -
                @_model_class = model_class  unless model_class.nil?
         
     | 
| 
       23 
     | 
    
         
            -
                @_model_class
         
     | 
| 
       24 
     | 
    
         
            -
              end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
              # GET /:resources[.json]
         
     | 
| 
       27 
     | 
    
         
            -
              def index
         
     | 
| 
       28 
     | 
    
         
            -
                set_resources
         
     | 
| 
       29 
     | 
    
         
            -
              end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
              # GET /:resource/:id[.json]
         
     | 
| 
       32 
     | 
    
         
            -
              def show
         
     | 
| 
       33 
     | 
    
         
            -
              end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
              # GET /:resource/new
         
     | 
| 
       36 
     | 
    
         
            -
              def new
         
     | 
| 
       37 
     | 
    
         
            -
                resource_new
         
     | 
| 
       38 
     | 
    
         
            -
              end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              # GET /:resource/:id/edit
         
     | 
| 
       41 
     | 
    
         
            -
              def edit
         
     | 
| 
       42 
     | 
    
         
            -
              end
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
              # POST /:resources[.json]
         
     | 
| 
       45 
     | 
    
         
            -
              def create
         
     | 
| 
       46 
     | 
    
         
            -
                create_update(:resource_create, 'created')
         
     | 
| 
       47 
     | 
    
         
            -
              end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
              # PATCH/PUT /:resources/:id[.json]
         
     | 
| 
       50 
     | 
    
         
            -
              def update
         
     | 
| 
       51 
     | 
    
         
            -
                create_update(:resource_update, 'updated')
         
     | 
| 
       52 
     | 
    
         
            -
              end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
              # DELETE /:resources/:id[.json]
         
     | 
| 
       55 
     | 
    
         
            -
              def destroy
         
     | 
| 
       56 
     | 
    
         
            -
                resource_destroy
         
     | 
| 
       57 
     | 
    
         
            -
                flash[:notice] = t('ui.destroyed', model: model_name).html_safe  unless request.xhr?
         
     | 
| 
       58 
     | 
    
         
            -
                respond_to do |format|
         
     | 
| 
       59 
     | 
    
         
            -
                  format.html { redirect_to action: :index }
         
     | 
| 
       60 
     | 
    
         
            -
                  format.js   { render template: 'rows/destroy', layout: false }
         
     | 
| 
       61 
     | 
    
         
            -
                  format.json { head :no_content }
         
     | 
| 
       62 
     | 
    
         
            -
                end
         
     | 
| 
       63 
     | 
    
         
            -
              end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             private
         
     | 
| 
       66 
     | 
    
         
            -
              def create_update(which, msg)
         
     | 
| 
       67 
     | 
    
         
            -
                respond_to do |format|
         
     | 
| 
       68 
     | 
    
         
            -
                  if self.send(which)
         
     | 
| 
       69 
     | 
    
         
            -
            	format.html {
         
     | 
| 
       70 
     | 
    
         
            -
            	  flash[:notice] = t(msg, scope: :ui, model: model_name,
         
     | 
| 
       71 
     | 
    
         
            -
            		  default: "%{model} was successfully #{msg}.").html_safe
         
     | 
| 
       72 
     | 
    
         
            -
            	  if params[:commit] == 'OK'
         
     | 
| 
       73 
     | 
    
         
            -
            	    redirect_to action: :index
         
     | 
| 
       74 
     | 
    
         
            -
            	  else
         
     | 
| 
       75 
     | 
    
         
            -
            	    redirect_to action: 'edit', id: resource.id
         
     | 
| 
       76 
     | 
    
         
            -
            	  end
         
     | 
| 
       77 
     | 
    
         
            -
            	}
         
     | 
| 
       78 
     | 
    
         
            -
            	format.json { render action: 'show',
         
     | 
| 
       79 
     | 
    
         
            -
            			status: msg == 'created' ? :created : :ok,
         
     | 
| 
       80 
     | 
    
         
            -
            			location: resource }
         
     | 
| 
       81 
     | 
    
         
            -
                  else  ## failed
         
     | 
| 
       82 
     | 
    
         
            -
            	format.html { render action: msg == 'created' ? :new : :edit }
         
     | 
| 
       83 
     | 
    
         
            -
            	format.json { render json: resource.errors,
         
     | 
| 
       84 
     | 
    
         
            -
            			     status: :unprocessable_entity }
         
     | 
| 
       85 
     | 
    
         
            -
                  end
         
     | 
| 
       86 
     | 
    
         
            -
                end
         
     | 
| 
       87 
     | 
    
         
            -
              end
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
            end
         
     |