simple_nested_set 0.0.7 → 0.0.8
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.
    
        data/lib/simple_nested_set.rb
    CHANGED
    
    | @@ -8,6 +8,7 @@ module SimpleNestedSet | |
| 8 8 | 
             
              autoload :ClassMethods,    'simple_nested_set/class_methods'
         | 
| 9 9 | 
             
              autoload :InstanceMethods, 'simple_nested_set/instance_methods'
         | 
| 10 10 | 
             
              autoload :NestedSet,       'simple_nested_set/nested_set'
         | 
| 11 | 
            +
              autoload :SqlAbstraction,  'simple_nested_set/sql_abstraction.rb'
         | 
| 11 12 |  | 
| 12 13 | 
             
              module Move
         | 
| 13 14 | 
             
                autoload :ByAttributes,  'simple_nested_set/move/by_attributes'
         | 
| @@ -18,4 +19,4 @@ module SimpleNestedSet | |
| 18 19 | 
             
              end
         | 
| 19 20 | 
             
            end
         | 
| 20 21 |  | 
| 21 | 
            -
            ActiveRecord::Base.send :extend, SimpleNestedSet::ActMacro
         | 
| 22 | 
            +
            ActiveRecord::Base.send :extend, SimpleNestedSet::ActMacro
         | 
| @@ -1,5 +1,7 @@ | |
| 1 1 | 
             
            module SimpleNestedSet
         | 
| 2 2 | 
             
              class NestedSet < ActiveRecord::Relation
         | 
| 3 | 
            +
                include SqlAbstraction
         | 
| 4 | 
            +
             | 
| 3 5 | 
             
                class_inheritable_accessor :node_class, :scope_names
         | 
| 4 6 |  | 
| 5 7 | 
             
                class << self
         | 
| @@ -36,7 +38,7 @@ module SimpleNestedSet | |
| 36 38 | 
             
                  denormalize!
         | 
| 37 39 | 
             
                end
         | 
| 38 40 |  | 
| 39 | 
            -
                # FIXME we don't always want to call this on after_save, do we? it's only relevant when | 
| 41 | 
            +
                # FIXME we don't always want to call this on after_save, do we? it's only relevant when
         | 
| 40 42 | 
             
                # either the structure or the slug has changed
         | 
| 41 43 | 
             
                def denormalize!
         | 
| 42 44 | 
             
                  sql = []
         | 
| @@ -106,11 +108,15 @@ module SimpleNestedSet | |
| 106 108 |  | 
| 107 109 | 
             
                def denormalize_path_query
         | 
| 108 110 | 
             
                  query = arel_table.as(:l)
         | 
| 109 | 
            -
                  query = query.project( | 
| 111 | 
            +
                  query = query.project(group_concat(db_adapter, :slug)).
         | 
| 110 112 | 
             
                          where(query[:lft].lteq(arel_table[:lft])).
         | 
| 111 113 | 
             
                          where(query[:rgt].gteq(arel_table[:rgt])).
         | 
| 112 114 | 
             
                          where(where_clauses.map { |clause| clause.gsub(table_name, 'l') })
         | 
| 113 115 | 
             
                  "path = (#{query.to_sql})"
         | 
| 114 116 | 
             
                end
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                def db_adapter
         | 
| 119 | 
            +
                  node.class.connection.instance_variable_get('@config')[:adapter].to_sym
         | 
| 120 | 
            +
                end
         | 
| 115 121 | 
             
              end
         | 
| 116 | 
            -
            end
         | 
| 122 | 
            +
            end
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            module SimpleNestedSet
         | 
| 2 | 
            +
              module SqlAbstraction
         | 
| 3 | 
            +
                # return a database-specific 'GROUP_CONCAT'-statement, ready to be
         | 
| 4 | 
            +
                # inserted into arel.project()
         | 
| 5 | 
            +
                def group_concat(database, field, separator = '/')
         | 
| 6 | 
            +
                  case database.to_sym
         | 
| 7 | 
            +
                  when :sqlite, :sqlite3
         | 
| 8 | 
            +
                    "GROUP_CONCAT(#{field}, '#{separator}')"
         | 
| 9 | 
            +
                  when :mysql
         | 
| 10 | 
            +
                    "GROUP_CONCAT(`#{field}`, '#{separator}')"
         | 
| 11 | 
            +
                  when :postgresql
         | 
| 12 | 
            +
                    "array_to_string(array_agg(\"#{field}\"), '#{separator}')"
         | 
| 13 | 
            +
                  else
         | 
| 14 | 
            +
                    raise ArgumentError, "#{database} is not supported by SimpleNestedSet::SqlAbstraction#group_concat"
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: simple_nested_set
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 15
         | 
| 5 5 | 
             
              prerelease: false
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 0
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.0. | 
| 9 | 
            +
              - 8
         | 
| 10 | 
            +
              version: 0.0.8
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Sven Fuchs
         | 
| @@ -109,6 +109,7 @@ files: | |
| 109 109 | 
             
            - lib/simple_nested_set/move/protection.rb
         | 
| 110 110 | 
             
            - lib/simple_nested_set/move/to_target.rb
         | 
| 111 111 | 
             
            - lib/simple_nested_set/nested_set.rb
         | 
| 112 | 
            +
            - lib/simple_nested_set/sql_abstraction.rb
         | 
| 112 113 | 
             
            - lib/simple_nested_set/version.rb
         | 
| 113 114 | 
             
            has_rdoc: true
         | 
| 114 115 | 
             
            homepage: http://github.com/svenfuchs/simple_nested_set
         |