effective_resources 0.2.3 → 0.2.4
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/app/assets/javascripts/effective_resources/effective_ujs.js +2 -2
- data/app/controllers/concerns/effective/crud_controller.rb +10 -6
- data/app/models/effective/attribute.rb +0 -4
- data/app/models/effective/resources/associations.rb +1 -1
- data/app/models/effective/resources/init.rb +8 -3
- data/app/models/effective/resources/naming.rb +1 -1
- data/app/models/effective/resources/paths.rb +27 -10
- data/app/models/effective/resources/relation.rb +2 -1
- data/lib/effective_resources/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: b55e4948a32a2526cc0ce43230a6bee620c09a14
         | 
| 4 | 
            +
              data.tar.gz: d0b8bf59119514d156e4b63428cc068960cb779e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 508301a27e166a14290d8085066c773d584ab2e39c294106b7361d973219712f359e227178904f7f58f9849e551204d317d042d49de594f85c2417e896f818e4
         | 
| 7 | 
            +
              data.tar.gz: c96b6875d7685e62b288fef2e8892eb7a1c664cfd6839ac0e491e876e103224e75d1fcced5ba2c83d427ec98322767f61fb99915ebc4f3bfd18b0da0aee9cfe5
         | 
| @@ -35,10 +35,10 @@ | |
| 35 35 | 
             
                    formGroup.find('abbr').remove();
         | 
| 36 36 | 
             
                    input.parent().find('abbr').remove();
         | 
| 37 37 |  | 
| 38 | 
            -
                    if(input.parent().is('label')) {
         | 
| 38 | 
            +
                    if(input.parent().is('label') && input.parent().parent().hasClass('radio') == false) {
         | 
| 39 39 | 
             
                      input.after("<abbr title='required'>*</abbr> ");
         | 
| 40 40 | 
             
                    } else if(formGroup.length > 0) {
         | 
| 41 | 
            -
                      formGroup.find('label').prepend("<abbr title='required'>*</abbr> ");
         | 
| 41 | 
            +
                      formGroup.find('label').first().prepend("<abbr title='required'>*</abbr> ");
         | 
| 42 42 | 
             
                    } else {
         | 
| 43 43 | 
             
                      input.parent().find('label').prepend("<abbr title='required'>*</abbr> ");
         | 
| 44 44 | 
             
                    }
         | 
| @@ -43,10 +43,10 @@ module Effective | |
| 43 43 | 
             
                  EffectiveResources.authorized?(self, :create, resource)
         | 
| 44 44 |  | 
| 45 45 | 
             
                  if resource.save
         | 
| 46 | 
            -
                    flash[:success] = "Successfully created #{ | 
| 46 | 
            +
                    flash[:success] = "Successfully created #{resource_human_name}"
         | 
| 47 47 | 
             
                    redirect_to(resource_redirect_path)
         | 
| 48 48 | 
             
                  else
         | 
| 49 | 
            -
                    flash.now[:danger] = "Unable to create #{ | 
| 49 | 
            +
                    flash.now[:danger] = "Unable to create #{resource_human_name}: #{resource.errors.full_messages.to_sentence}"
         | 
| 50 50 | 
             
                    render :new
         | 
| 51 51 | 
             
                  end
         | 
| 52 52 | 
             
                end
         | 
| @@ -72,10 +72,10 @@ module Effective | |
| 72 72 | 
             
                  EffectiveResources.authorized?(self, :update, resource)
         | 
| 73 73 |  | 
| 74 74 | 
             
                  if resource.update_attributes(send(resource_params_method_name))
         | 
| 75 | 
            -
                    flash[:success] = "Successfully updated #{ | 
| 75 | 
            +
                    flash[:success] = "Successfully updated #{resource_human_name}"
         | 
| 76 76 | 
             
                    redirect_to(resource_redirect_path)
         | 
| 77 77 | 
             
                  else
         | 
| 78 | 
            -
                    flash.now[:danger] = "Unable to update #{ | 
| 78 | 
            +
                    flash.now[:danger] = "Unable to update #{resource_human_name}: #{resource.errors.full_messages.to_sentence}"
         | 
| 79 79 | 
             
                    render :edit
         | 
| 80 80 | 
             
                  end
         | 
| 81 81 | 
             
                end
         | 
| @@ -87,9 +87,9 @@ module Effective | |
| 87 87 | 
             
                  EffectiveResources.authorized?(self, :destroy, resource)
         | 
| 88 88 |  | 
| 89 89 | 
             
                  if resource.destroy
         | 
| 90 | 
            -
                    flash[:success] = "Successfully deleted #{ | 
| 90 | 
            +
                    flash[:success] = "Successfully deleted #{resource_human_name}"
         | 
| 91 91 | 
             
                  else
         | 
| 92 | 
            -
                    flash[:danger] = "Unable to delete #{ | 
| 92 | 
            +
                    flash[:danger] = "Unable to delete #{resource_human_name}: #{resource.errors.full_messages.to_sentence}"
         | 
| 93 93 | 
             
                  end
         | 
| 94 94 |  | 
| 95 95 | 
             
                  request.referer.present? ? redirect_to(request.referer) : redirect_to(send(resource_index_path))
         | 
| @@ -132,6 +132,10 @@ module Effective | |
| 132 132 | 
             
                  effective_resource.name
         | 
| 133 133 | 
             
                end
         | 
| 134 134 |  | 
| 135 | 
            +
                def resource_human_name
         | 
| 136 | 
            +
                  effective_resource.human_name
         | 
| 137 | 
            +
                end
         | 
| 138 | 
            +
             | 
| 135 139 | 
             
                def resource_plural_name # 'things'
         | 
| 136 140 | 
             
                  effective_resource.plural_name
         | 
| 137 141 | 
             
                end
         | 
| @@ -28,7 +28,7 @@ module Effective | |
| 28 28 |  | 
| 29 29 | 
             
                  def nested_resources
         | 
| 30 30 | 
             
                    return [] unless klass.respond_to?(:reflect_on_all_associations)
         | 
| 31 | 
            -
                    @nested_resources ||= klass.reflect_on_all_associations(:has_many).select { |ass| ass.options[:autosave] }
         | 
| 31 | 
            +
                    @nested_resources ||= klass.reflect_on_all_associations(:has_many).select { |ass| ass.options[:autosave] && ass.options[:class_name] != 'Effective::Attachment' }
         | 
| 32 32 | 
             
                  end
         | 
| 33 33 |  | 
| 34 34 | 
             
                  def scopes
         | 
| @@ -15,9 +15,13 @@ module Effective | |
| 15 15 | 
             
                    when String ; input
         | 
| 16 16 | 
             
                    when Symbol ; input
         | 
| 17 17 | 
             
                    when Class  ; input.name
         | 
| 18 | 
            -
                    when ActiveRecord::Relation | 
| 19 | 
            -
             | 
| 20 | 
            -
                    when  | 
| 18 | 
            +
                    when ActiveRecord::Relation
         | 
| 19 | 
            +
                      input.klass
         | 
| 20 | 
            +
                    when ActiveRecord::Reflection::AbstractReflection
         | 
| 21 | 
            +
                      @model_klass = input.klass
         | 
| 22 | 
            +
                      input.name
         | 
| 23 | 
            +
                    when ActionDispatch::Journey::Route
         | 
| 24 | 
            +
                      input.defaults[:controller]
         | 
| 21 25 | 
             
                    when nil    ; raise 'expected a string or class'
         | 
| 22 26 | 
             
                    else        ; input.class.name
         | 
| 23 27 | 
             
                    end.to_s.underscore
         | 
| @@ -48,6 +52,7 @@ module Effective | |
| 48 52 |  | 
| 49 53 | 
             
                      if first && last
         | 
| 50 54 | 
             
                        @written_attributes = reader.select(from: first+1, to: last-1).map do |line|
         | 
| 55 | 
            +
             | 
| 51 56 | 
             
                          Effective::Attribute.parse_written(line).presence
         | 
| 52 57 | 
             
                        end.compact
         | 
| 53 58 | 
             
                      end
         | 
| @@ -3,24 +3,41 @@ module Effective | |
| 3 3 | 
             
                module Paths
         | 
| 4 4 |  | 
| 5 5 | 
             
                  # Controller REST helper paths
         | 
| 6 | 
            -
                  def index_path
         | 
| 7 | 
            -
                    [namespace, plural_name, 'path'].compact * '_'
         | 
| 6 | 
            +
                  def index_path(check: false)
         | 
| 7 | 
            +
                    path = [namespace, plural_name, 'path'].compact * '_'
         | 
| 8 | 
            +
                    path if (!check || path_exists?(path))
         | 
| 8 9 | 
             
                  end
         | 
| 9 10 |  | 
| 10 | 
            -
                  def new_path
         | 
| 11 | 
            -
                    ['new', namespace, name, 'path'].compact * '_'
         | 
| 11 | 
            +
                  def new_path(check: false)
         | 
| 12 | 
            +
                    path = ['new', namespace, name, 'path'].compact * '_'
         | 
| 13 | 
            +
                    path if (!check || path_exists?(path))
         | 
| 12 14 | 
             
                  end
         | 
| 13 15 |  | 
| 14 | 
            -
                  def show_path
         | 
| 15 | 
            -
                    [namespace, name, 'path'].compact * '_'
         | 
| 16 | 
            +
                  def show_path(check: false)
         | 
| 17 | 
            +
                    path = [namespace, name, 'path'].compact * '_'
         | 
| 18 | 
            +
                    path if (!check || path_exists?(path, 1))
         | 
| 16 19 | 
             
                  end
         | 
| 17 20 |  | 
| 18 | 
            -
                  def  | 
| 19 | 
            -
                    [ | 
| 21 | 
            +
                  def destroy_path(check: false)
         | 
| 22 | 
            +
                    path = [namespace, name, 'path'].compact * '_'
         | 
| 23 | 
            +
                    path if (!check || path_exists?(path, 1, :delete))
         | 
| 20 24 | 
             
                  end
         | 
| 21 25 |  | 
| 22 | 
            -
                  def  | 
| 23 | 
            -
                    [ | 
| 26 | 
            +
                  def edit_path(check: false)
         | 
| 27 | 
            +
                    path = ['edit', namespace, name, 'path'].compact * '_'
         | 
| 28 | 
            +
                    path if (!check || path_exists?(path, 1))
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  def action_path(action, check: false)
         | 
| 32 | 
            +
                    path = [action, namespace, name, 'path'].compact * '_'
         | 
| 33 | 
            +
                    path if (!check || path_exists?(path, 1))
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  def path_exists?(path, param = nil, verb = :get)
         | 
| 37 | 
            +
                    routes = Rails.application.routes
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    return false unless routes.url_helpers.respond_to?(path)
         | 
| 40 | 
            +
                    (routes.recognize_path(routes.url_helpers.send(path, param), method: verb).present? rescue false)
         | 
| 24 41 | 
             
                  end
         | 
| 25 42 |  | 
| 26 43 | 
             
                  # _helper methods also put in the (@thing)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: effective_resources
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Code and Effect
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017- | 
| 11 | 
            +
            date: 2017-03-10 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |