jungle_path 0.0.32 → 0.0.33
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
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c7a8ea6e5e533ddeed4046ae19001ce4a7b154c0
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: dd6b1b094a6349d5941142bf0035f7f49f94bd39
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5132fe030e382f59d05204ccdb1a65900b8b139a6fe2f6c3159d197e84b13ddc3a0a43df4cec94b273cb9701e87d9709b4f70488e98c67aae7820b9d7f7bfd6e
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c75b6f2b87ef3806bd17ddd92cdfb84580efa56bb0a6c5926e1e8641d9d9905caeb09d1160887fa6c80665889988a18ee449f93b88e65d8f666287be5c66e311
         
     | 
| 
         @@ -3,25 +3,37 @@ require 'set' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            module JunglePath
         
     | 
| 
       4 
4 
     | 
    
         
             
            	module DBModel
         
     | 
| 
       5 
5 
     | 
    
         
             
            		class View
         
     | 
| 
       6 
     | 
    
         
            -
            			attr_reader :create, :drop, :references, :parameters
         
     | 
| 
       7 
     | 
    
         
            -
            			def initialize create=nil, drop=nil, references=nil, parameters=nil
         
     | 
| 
      
 6 
     | 
    
         
            +
            			attr_reader :create, :drop, :references, :parameters, :pre_query_hook
         
     | 
| 
      
 7 
     | 
    
         
            +
            			def initialize create=nil, drop=nil, references=nil, parameters=nil, pre_query_hook=nil
         
     | 
| 
       8 
8 
     | 
    
         
             
            				@create = create
         
     | 
| 
       9 
9 
     | 
    
         
             
            				@drop = drop
         
     | 
| 
       10 
10 
     | 
    
         
             
            				@references = references || []
         
     | 
| 
       11 
11 
     | 
    
         
             
            				@references = Set.new(@references)
         
     | 
| 
       12 
12 
     | 
    
         
             
            				@parameters = parameters || []
         
     | 
| 
      
 13 
     | 
    
         
            +
            				@pre_query_hook = pre_query_hook
         
     | 
| 
       13 
14 
     | 
    
         
             
            			end
         
     | 
| 
       14 
15 
     | 
    
         
             
            			def has_reference_to?(table_name)
         
     | 
| 
       15 
16 
     | 
    
         
             
            				@references.member?(table_name)
         
     | 
| 
       16 
17 
     | 
    
         
             
            			end
         
     | 
| 
       17 
     | 
    
         
            -
            			def build_call(identity, table)
         
     | 
| 
       18 
     | 
    
         
            -
            				parameters  
     | 
| 
      
 18 
     | 
    
         
            +
            			def build_call(identity, table, from_clause_parameters=nil)
         
     | 
| 
      
 19 
     | 
    
         
            +
            				# user identity parameters take precedence, then parameters coming with query. This prevents user supplied parameterss
         
     | 
| 
      
 20 
     | 
    
         
            +
            				# from being used to set identity parameters!
         
     | 
| 
      
 21 
     | 
    
         
            +
            				parameters = identity.alternative_user_keys.select{|k, v| @parameters.include?(k)}.values.map{|n| convert_to_parameter(n)}
         
     | 
| 
      
 22 
     | 
    
         
            +
            				if from_clause_parameters and from_clause_parameters.length > 0
         
     | 
| 
      
 23 
     | 
    
         
            +
            					from_clause_parameters.each do |p|
         
     | 
| 
      
 24 
     | 
    
         
            +
            						parmeters << p
         
     | 
| 
      
 25 
     | 
    
         
            +
            					end
         
     | 
| 
      
 26 
     | 
    
         
            +
            				end
         
     | 
| 
      
 27 
     | 
    
         
            +
            				parameters = parameters.join(', ')
         
     | 
| 
       19 
28 
     | 
    
         
             
            				if parameters.length > 0
         
     | 
| 
       20 
29 
     | 
    
         
             
            					"#{table.table_name}(#{parameters})"
         
     | 
| 
       21 
30 
     | 
    
         
             
            				else
         
     | 
| 
       22 
31 
     | 
    
         
             
            					"#{table.table_name}"
         
     | 
| 
       23 
32 
     | 
    
         
             
            				end
         
     | 
| 
       24 
33 
     | 
    
         
             
            			end
         
     | 
| 
      
 34 
     | 
    
         
            +
            			def run_pre_query_hook(identity, table, db, parameters=nil)
         
     | 
| 
      
 35 
     | 
    
         
            +
            				@pre_query_hook.call(identity, table, db) if @pre_query_hook
         
     | 
| 
      
 36 
     | 
    
         
            +
            			end
         
     | 
| 
       25 
37 
     | 
    
         
             
            			def convert_to_parameter(value)
         
     | 
| 
       26 
38 
     | 
    
         
             
            				return value if value.class == Fixnum
         
     | 
| 
       27 
39 
     | 
    
         
             
            				return "'#{value}'" if value.class == String
         
     | 
| 
         @@ -7,13 +7,14 @@ require 'jungle_path/query/nested_hash_sorter' 
     | 
|
| 
       7 
7 
     | 
    
         
             
            module JunglePath
         
     | 
| 
       8 
8 
     | 
    
         
             
              module Query
         
     | 
| 
       9 
9 
     | 
    
         
             
                class Engine
         
     | 
| 
       10 
     | 
    
         
            -
                  attr_reader :root, :tables, :identity, :apply_limit_offset_to_sql
         
     | 
| 
      
 10 
     | 
    
         
            +
                  attr_reader :root, :tables, :identity, :apply_limit_offset_to_sql, :db
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                  #def initialize(tables_hash, identity=nil, apply_limit_offset_to_sql=true)
         
     | 
| 
       13 
     | 
    
         
            -
                  def initialize(node_tree, identity=nil, apply_limit_offset_to_sql=true)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  def initialize(node_tree, identity=nil, apply_limit_offset_to_sql=true, db=nil)
         
     | 
| 
       14 
14 
     | 
    
         
             
                    @tables = node_tree.tables_hash
         
     | 
| 
       15 
15 
     | 
    
         
             
                    @identity = identity
         
     | 
| 
       16 
16 
     | 
    
         
             
                    @apply_limit_offset_to_sql = apply_limit_offset_to_sql
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @db = db
         
     | 
| 
       17 
18 
     | 
    
         
             
                    #@root = Gen.gen_node_tree(tables_hash)
         
     | 
| 
       18 
19 
     | 
    
         
             
                    @root = node_tree
         
     | 
| 
       19 
20 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -132,6 +133,8 @@ module JunglePath 
     | 
|
| 
       132 
133 
     | 
    
         
             
                          break
         
     | 
| 
       133 
134 
     | 
    
         
             
                        end
         
     | 
| 
       134 
135 
     | 
    
         
             
                        expect_sort = true
         
     | 
| 
      
 136 
     | 
    
         
            +
                      elsif expect_fields and token == "[" # got parameters which should be passed to the entity in sql as a table function.
         
     | 
| 
      
 137 
     | 
    
         
            +
                        entity.parameters = process_parameters(entity, tokens)
         
     | 
| 
       135 
138 
     | 
    
         
             
                      elsif expect_fields and token == "("
         
     | 
| 
       136 
139 
     | 
    
         
             
                        expect_fields = false
         
     | 
| 
       137 
140 
     | 
    
         
             
                        entity.fields = process_fields(entity, tokens, aliases, values, root_entity)
         
     | 
| 
         @@ -149,6 +152,36 @@ module JunglePath 
     | 
|
| 
       149 
152 
     | 
    
         
             
                    entity
         
     | 
| 
       150 
153 
     | 
    
         
             
                  end
         
     | 
| 
       151 
154 
     | 
    
         | 
| 
      
 155 
     | 
    
         
            +
                  def process_parameters(entity, tokens)
         
     | 
| 
      
 156 
     | 
    
         
            +
                    parameters = []
         
     | 
| 
      
 157 
     | 
    
         
            +
                    token = next_token(tokens)
         
     | 
| 
      
 158 
     | 
    
         
            +
                    while token
         
     | 
| 
      
 159 
     | 
    
         
            +
                      if token == "]"
         
     | 
| 
      
 160 
     | 
    
         
            +
                        break
         
     | 
| 
      
 161 
     | 
    
         
            +
                      elsif token == ','
         
     | 
| 
      
 162 
     | 
    
         
            +
                        # ignore a comma
         
     | 
| 
      
 163 
     | 
    
         
            +
                      elsif token == 'null'
         
     | 
| 
      
 164 
     | 
    
         
            +
                        parameters << nil
         
     | 
| 
      
 165 
     | 
    
         
            +
                      elsif token =~ /^[0-9]/ # starts with number
         
     | 
| 
      
 166 
     | 
    
         
            +
                        if token.include? "."
         
     | 
| 
      
 167 
     | 
    
         
            +
                          parameters << JunglePath::Query::FloatValue.parse(token)
         
     | 
| 
      
 168 
     | 
    
         
            +
                        else
         
     | 
| 
      
 169 
     | 
    
         
            +
                          parameters << JunglePath::Query::IntValue.parse(token)
         
     | 
| 
      
 170 
     | 
    
         
            +
                        end
         
     | 
| 
      
 171 
     | 
    
         
            +
                      elsif token =~ /^["']/ # starts with quote
         
     | 
| 
      
 172 
     | 
    
         
            +
                        parameters << JunglePath::Query::StringValue.parse(token)
         
     | 
| 
      
 173 
     | 
    
         
            +
                      elsif token.downcase == "true"
         
     | 
| 
      
 174 
     | 
    
         
            +
                        parameters << true
         
     | 
| 
      
 175 
     | 
    
         
            +
                      elsif token.downcase == "false"
         
     | 
| 
      
 176 
     | 
    
         
            +
                        parameters << false
         
     | 
| 
      
 177 
     | 
    
         
            +
                      else
         
     | 
| 
      
 178 
     | 
    
         
            +
                        raise "unexpected token: #{token}"
         
     | 
| 
      
 179 
     | 
    
         
            +
                      end
         
     | 
| 
      
 180 
     | 
    
         
            +
                      token = next_token(tokens)
         
     | 
| 
      
 181 
     | 
    
         
            +
                    end
         
     | 
| 
      
 182 
     | 
    
         
            +
                    parameters
         
     | 
| 
      
 183 
     | 
    
         
            +
                  end
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
       152 
185 
     | 
    
         
             
                  def process_fields(entity, tokens, aliases, values, root_entity)
         
     | 
| 
       153 
186 
     | 
    
         
             
                    #puts "process_fields - entity.name: #{entity.name}."
         
     | 
| 
       154 
187 
     | 
    
         
             
                    fields = []
         
     | 
| 
         @@ -7,7 +7,7 @@ require 'set' 
     | 
|
| 
       7 
7 
     | 
    
         
             
            module JunglePath
         
     | 
| 
       8 
8 
     | 
    
         
             
              module Query
         
     | 
| 
       9 
9 
     | 
    
         
             
                class Entity
         
     | 
| 
       10 
     | 
    
         
            -
                  attr_accessor :name, :alias_, :node, :parent, :symbol, :fields, :filter, :sort, :limit, :offset, :field_node, :join_field_override
         
     | 
| 
      
 10 
     | 
    
         
            +
                  attr_accessor :name, :alias_, :node, :parent, :symbol, :fields, :filter, :sort, :limit, :offset, :field_node, :join_field_override, :parameters
         
     | 
| 
       11 
11 
     | 
    
         
             
                  attr_reader :left_join
         
     | 
| 
       12 
12 
     | 
    
         
             
                  def initialize(token, alias_, node, parent, symbol)
         
     | 
| 
       13 
13 
     | 
    
         
             
                    @name = Entity.get_name_from_token(token)
         
     | 
| 
         @@ -7,9 +7,9 @@ require 'set' 
     | 
|
| 
       7 
7 
     | 
    
         
             
            module JunglePath
         
     | 
| 
       8 
8 
     | 
    
         
             
              module Query
         
     | 
| 
       9 
9 
     | 
    
         
             
                class From
         
     | 
| 
       10 
     | 
    
         
            -
                  attr_reader :join_text, :table_name, :table_alias, :on_a_column_name, :on_b_alias, :on_b_column_name
         
     | 
| 
      
 10 
     | 
    
         
            +
                  attr_reader :join_text, :table_name, :table_alias, :on_a_column_name, :on_b_alias, :on_b_column_name, :parameters
         
     | 
| 
       11 
11 
     | 
    
         
             
                  attr_accessor :table_replacement_text
         
     | 
| 
       12 
     | 
    
         
            -
                  def initialize join_text, table_name, table_alias, on_a_column_name=nil, on_b_alias=nil, on_b_column_name=nil
         
     | 
| 
      
 12 
     | 
    
         
            +
                  def initialize join_text, table_name, table_alias, on_a_column_name=nil, on_b_alias=nil, on_b_column_name=nil, parameters=nil
         
     | 
| 
       13 
13 
     | 
    
         
             
                    @join_text = join_text
         
     | 
| 
       14 
14 
     | 
    
         
             
                    @table_name = table_name.to_sym
         
     | 
| 
       15 
15 
     | 
    
         
             
                    @table_alias = table_alias
         
     | 
| 
         @@ -17,6 +17,7 @@ module JunglePath 
     | 
|
| 
       17 
17 
     | 
    
         
             
                    @on_b_alias = on_b_alias
         
     | 
| 
       18 
18 
     | 
    
         
             
                    @on_b_column_name = on_b_column_name
         
     | 
| 
       19 
19 
     | 
    
         
             
                    @table_replacement_text = nil
         
     | 
| 
      
 20 
     | 
    
         
            +
                    @parameters = parameters
         
     | 
| 
       20 
21 
     | 
    
         
             
                  end
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
       22 
23 
     | 
    
         
             
                  def to_s
         
     | 
| 
         @@ -38,7 +38,7 @@ module JunglePath 
     | 
|
| 
       38 
38 
     | 
    
         | 
| 
       39 
39 
     | 
    
         
             
                  def self.generate_from(from, entity, aliases, tables, symbols)
         
     | 
| 
       40 
40 
     | 
    
         
             
                    if from.length == 0
         
     | 
| 
       41 
     | 
    
         
            -
                      from << From.new(nil, entity.node.name, entity.alias_)
         
     | 
| 
      
 41 
     | 
    
         
            +
                      from << From.new(nil, entity.node.name, entity.alias_, nil, nil, nil, entity.parameters)
         
     | 
| 
       42 
42 
     | 
    
         
             
                      aliases[entity.alias_.to_sym] = AliasInfo.new(entity.name, entity.alias_.to_sym, nil, tables[entity.node.name.to_sym].primary_key_columns.count)
         
     | 
| 
       43 
43 
     | 
    
         
             
                    else
         
     | 
| 
       44 
44 
     | 
    
         
             
                      if entity.left_join
         
     | 
| 
         @@ -46,7 +46,7 @@ module JunglePath 
     | 
|
| 
       46 
46 
     | 
    
         
             
                      else
         
     | 
| 
       47 
47 
     | 
    
         
             
                        join_text = "join"
         
     | 
| 
       48 
48 
     | 
    
         
             
                      end
         
     | 
| 
       49 
     | 
    
         
            -
                      from << From.new(join_text, entity.node.child_table_name, entity.alias_, entity.node.child_table_join_column_name, entity.parent.alias_, entity.node.parent_table_join_column_name)
         
     | 
| 
      
 49 
     | 
    
         
            +
                      from << From.new(join_text, entity.node.child_table_name, entity.alias_, entity.node.child_table_join_column_name, entity.parent.alias_, entity.node.parent_table_join_column_name, entity.parameters)
         
     | 
| 
       50 
50 
     | 
    
         
             
                      aliases[entity.alias_.to_sym] = AliasInfo.new(entity.name, entity.alias_.to_sym, entity.find_parent_alias, tables[entity.node.child_table_name.to_sym].primary_key_columns.count)
         
     | 
| 
       51 
51 
     | 
    
         
             
                        #puts "aliases: #{aliases}."
         
     | 
| 
       52 
52 
     | 
    
         
             
                      if entity.fields.count > entity.fields_that_are_entities_count
         
     | 
| 
         @@ -134,6 +134,8 @@ module JunglePath 
     | 
|
| 
       134 
134 
     | 
    
         
             
                          table_replacement_text = nil
         
     | 
| 
       135 
135 
     | 
    
         
             
                          if replacement_table.view
         
     | 
| 
       136 
136 
     | 
    
         
             
                            puts "has view"
         
     | 
| 
      
 137 
     | 
    
         
            +
                            #also run any pre query hook for view:
         
     | 
| 
      
 138 
     | 
    
         
            +
                            replacement_table.view.pre_query_hook(engine.identity, replacement_table, engine.db, from.parameters)
         
     | 
| 
       137 
139 
     | 
    
         
             
                            table_replacement_text = replacement_table.view.build_call(engine.identity, replacement_table)
         
     | 
| 
       138 
140 
     | 
    
         
             
                          else
         
     | 
| 
       139 
141 
     | 
    
         
             
                            puts "no view"
         
     | 
    
        data/lib/jungle_path/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: jungle_path
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.33
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Michael VanZant
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2017- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-09-25 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |