railz_lite 0.1.2 → 0.1.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/lib/railz_lite/cli.rb +8 -3
 - data/lib/railz_lite/controllers/flash.rb +1 -1
 - data/lib/railz_lite/controllers/router.rb +3 -3
 - data/lib/railz_lite/controllers/session.rb +1 -1
 - data/lib/railz_lite/generators/project.rb +11 -5
 - data/lib/railz_lite/generators/templates/server.rb +1 -1
 - data/lib/railz_lite/version.rb +1 -1
 - metadata +2 -9
 - data/exe/railz_lite.rb~ +0 -3
 - data/lib/railz_lite/controllers/templates/rescue.html.erb~ +0 -0
 - data/lib/railz_lite/generators/templates/routes.rb +0 -0
 - data/lib/railz_lite/models/associatable.rb~ +0 -79
 - data/lib/railz_lite/models/associatable2.rb~ +0 -35
 - data/lib/railz_lite/models/searchable.rb~ +0 -21
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e2ebf1f78b9263164fa6d9c864a3344f834171df91856e8f5cfb18b318b7c215
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8844959b357a2ad711666cff1eadfdfd5a963621d09f1d035442162eb4ccd0f1
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 3e2f0f87d0a1cbb225d5987518e3f025446b04c075e28c6faf749f616cc3ac0393f12c09b963e08aaa33ac93fd29b8c9c6cbae43aebd0baa766615b62b4b5c50
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 144b760958c29eaf21ba4c4977af41e47fe068c20eb651798c4fa751e5a2c791e2afd81e24d430a05a506482078f480b0931a9efb53f23846f674ec32d7ea2cc
         
     | 
    
        data/lib/railz_lite/cli.rb
    CHANGED
    
    | 
         @@ -5,13 +5,18 @@ require 'railz_lite/generators/project' 
     | 
|
| 
       5 
5 
     | 
    
         
             
            module RailzLite
         
     | 
| 
       6 
6 
     | 
    
         
             
              class CLI < Thor
         
     | 
| 
       7 
7 
     | 
    
         
             
                desc 'new', 'Generates a new RailzLite project'
         
     | 
| 
       8 
     | 
    
         
            -
                def new
         
     | 
| 
       9 
     | 
    
         
            -
                  RailzLite::Generators::Project.start([])
         
     | 
| 
      
 8 
     | 
    
         
            +
                def new(project_name)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  RailzLite::Generators::Project.start([project_name])
         
     | 
| 
       10 
10 
     | 
    
         
             
                end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                desc 'server', 'Starts up a puma server within RailzLite project'
         
     | 
| 
       13 
13 
     | 
    
         
             
                def server
         
     | 
| 
       14 
     | 
    
         
            -
                   
     | 
| 
      
 14 
     | 
    
         
            +
                  file =  File.join(Dir.pwd, 'config', 'server.rb')
         
     | 
| 
      
 15 
     | 
    
         
            +
                  if File.exist?(file)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    system('ruby', file)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  else
         
     | 
| 
      
 18 
     | 
    
         
            +
                    raise "File not found at #{file}"
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
       15 
20 
     | 
    
         
             
                end
         
     | 
| 
       16 
21 
     | 
    
         
             
              end
         
     | 
| 
       17 
22 
     | 
    
         
             
            end
         
     | 
| 
         @@ -58,11 +58,11 @@ class Router 
     | 
|
| 
       58 
58 
     | 
    
         
             
              # either throw 404 or call run on a matched route
         
     | 
| 
       59 
59 
     | 
    
         
             
              def run(req, res)
         
     | 
| 
       60 
60 
     | 
    
         
             
                matching_route = match(req)
         
     | 
| 
       61 
     | 
    
         
            -
                if matching_route. 
     | 
| 
       62 
     | 
    
         
            -
                  matching_route.run(req, res)
         
     | 
| 
       63 
     | 
    
         
            -
                else
         
     | 
| 
      
 61 
     | 
    
         
            +
                if matching_route.nil?
         
     | 
| 
       64 
62 
     | 
    
         
             
                  res.status = 404
         
     | 
| 
       65 
63 
     | 
    
         
             
                  res.write("Matching route not found for #{req.path}")
         
     | 
| 
      
 64 
     | 
    
         
            +
                else
         
     | 
| 
      
 65 
     | 
    
         
            +
                  matching_route.run(req, res)
         
     | 
| 
       66 
66 
     | 
    
         
             
                end
         
     | 
| 
       67 
67 
     | 
    
         
             
              end
         
     | 
| 
       68 
68 
     | 
    
         
             
            end
         
     | 
| 
         @@ -4,29 +4,35 @@ module RailzLite 
     | 
|
| 
       4 
4 
     | 
    
         
             
              module Generators
         
     | 
| 
       5 
5 
     | 
    
         
             
                class Project < Thor::Group
         
     | 
| 
       6 
6 
     | 
    
         
             
                  include Thor::Actions
         
     | 
| 
      
 7 
     | 
    
         
            +
                  argument :project_name, type: :string
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
9 
     | 
    
         
             
                  def self.source_root
         
     | 
| 
       9 
10 
     | 
    
         
             
                    File.dirname(__FILE__) + "/templates"
         
     | 
| 
       10 
11 
     | 
    
         
             
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  def self.destination_root
         
     | 
| 
      
 14 
     | 
    
         
            +
                    puts "destination for folder #{Dir.pwd}"
         
     | 
| 
      
 15 
     | 
    
         
            +
                    Dir.pwd
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
       11 
17 
     | 
    
         | 
| 
       12 
18 
     | 
    
         
             
                  def add_controllers
         
     | 
| 
       13 
     | 
    
         
            -
                    empty_directory("/controllers")
         
     | 
| 
      
 19 
     | 
    
         
            +
                    empty_directory("#{project_name}/controllers")
         
     | 
| 
       14 
20 
     | 
    
         
             
                  end
         
     | 
| 
       15 
21 
     | 
    
         | 
| 
       16 
22 
     | 
    
         
             
                  def add_models
         
     | 
| 
       17 
     | 
    
         
            -
                    empty_directory("/models")
         
     | 
| 
      
 23 
     | 
    
         
            +
                    empty_directory("#{project_name}/models")
         
     | 
| 
       18 
24 
     | 
    
         
             
                  end
         
     | 
| 
       19 
25 
     | 
    
         | 
| 
       20 
26 
     | 
    
         
             
                  def add_server
         
     | 
| 
       21 
     | 
    
         
            -
                    template( 
     | 
| 
      
 27 
     | 
    
         
            +
                    template('server.rb', "#{project_name}/config/server.rb")
         
     | 
| 
       22 
28 
     | 
    
         
             
                  end
         
     | 
| 
       23 
29 
     | 
    
         | 
| 
       24 
30 
     | 
    
         
             
                  def add_views
         
     | 
| 
       25 
     | 
    
         
            -
                    empty_directory("/views")
         
     | 
| 
      
 31 
     | 
    
         
            +
                    empty_directory("#{project_name}/views")
         
     | 
| 
       26 
32 
     | 
    
         
             
                  end
         
     | 
| 
       27 
33 
     | 
    
         | 
| 
       28 
34 
     | 
    
         
             
                  def add_public
         
     | 
| 
       29 
     | 
    
         
            -
                    empty_directory("/public")
         
     | 
| 
      
 35 
     | 
    
         
            +
                    empty_directory("#{project_name}/public")
         
     | 
| 
       30 
36 
     | 
    
         
             
                  end
         
     | 
| 
       31 
37 
     | 
    
         
             
                end
         
     | 
| 
       32 
38 
     | 
    
         
             
              end
         
     | 
    
        data/lib/railz_lite/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: railz_lite
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.7
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - bryan lynch
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2021-07- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-07-02 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rack
         
     | 
| 
         @@ -141,7 +141,6 @@ email: 
     | 
|
| 
       141 
141 
     | 
    
         
             
            - bml312@nyu.edu
         
     | 
| 
       142 
142 
     | 
    
         
             
            executables:
         
     | 
| 
       143 
143 
     | 
    
         
             
            - railz_lite
         
     | 
| 
       144 
     | 
    
         
            -
            - railz_lite.rb~
         
     | 
| 
       145 
144 
     | 
    
         
             
            extensions: []
         
     | 
| 
       146 
145 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       147 
146 
     | 
    
         
             
            files:
         
     | 
| 
         @@ -156,7 +155,6 @@ files: 
     | 
|
| 
       156 
155 
     | 
    
         
             
            - bin/console
         
     | 
| 
       157 
156 
     | 
    
         
             
            - bin/setup
         
     | 
| 
       158 
157 
     | 
    
         
             
            - exe/railz_lite
         
     | 
| 
       159 
     | 
    
         
            -
            - exe/railz_lite.rb~
         
     | 
| 
       160 
158 
     | 
    
         
             
            - lib/railz_lite.rb
         
     | 
| 
       161 
159 
     | 
    
         
             
            - lib/railz_lite/cli.rb
         
     | 
| 
       162 
160 
     | 
    
         
             
            - lib/railz_lite/controllers/controller_base.rb
         
     | 
| 
         @@ -166,20 +164,15 @@ files: 
     | 
|
| 
       166 
164 
     | 
    
         
             
            - lib/railz_lite/controllers/show_exceptions.rb
         
     | 
| 
       167 
165 
     | 
    
         
             
            - lib/railz_lite/controllers/static.rb
         
     | 
| 
       168 
166 
     | 
    
         
             
            - lib/railz_lite/controllers/templates/rescue.html.erb
         
     | 
| 
       169 
     | 
    
         
            -
            - lib/railz_lite/controllers/templates/rescue.html.erb~
         
     | 
| 
       170 
167 
     | 
    
         
             
            - lib/railz_lite/generators/project.rb
         
     | 
| 
       171 
168 
     | 
    
         
             
            - lib/railz_lite/generators/project.rb~
         
     | 
| 
       172 
169 
     | 
    
         
             
            - lib/railz_lite/generators/templates/application_controller.rb~
         
     | 
| 
       173 
     | 
    
         
            -
            - lib/railz_lite/generators/templates/routes.rb
         
     | 
| 
       174 
170 
     | 
    
         
             
            - lib/railz_lite/generators/templates/server.rb
         
     | 
| 
       175 
171 
     | 
    
         
             
            - lib/railz_lite/models/associatable.rb
         
     | 
| 
       176 
     | 
    
         
            -
            - lib/railz_lite/models/associatable.rb~
         
     | 
| 
       177 
172 
     | 
    
         
             
            - lib/railz_lite/models/associatable2.rb
         
     | 
| 
       178 
     | 
    
         
            -
            - lib/railz_lite/models/associatable2.rb~
         
     | 
| 
       179 
173 
     | 
    
         
             
            - lib/railz_lite/models/attr_accessor_object.rb
         
     | 
| 
       180 
174 
     | 
    
         
             
            - lib/railz_lite/models/db_connection.rb
         
     | 
| 
       181 
175 
     | 
    
         
             
            - lib/railz_lite/models/searchable.rb
         
     | 
| 
       182 
     | 
    
         
            -
            - lib/railz_lite/models/searchable.rb~
         
     | 
| 
       183 
176 
     | 
    
         
             
            - lib/railz_lite/models/sql_object.rb
         
     | 
| 
       184 
177 
     | 
    
         
             
            - lib/railz_lite/models/validatable.rb
         
     | 
| 
       185 
178 
     | 
    
         
             
            - lib/railz_lite/version.rb
         
     | 
    
        data/exe/railz_lite.rb~
    DELETED
    
    
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -1,79 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require_relative '02_searchable'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'active_support/inflector'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            class AssocOptions
         
     | 
| 
       5 
     | 
    
         
            -
              attr_accessor(
         
     | 
| 
       6 
     | 
    
         
            -
                :foreign_key,
         
     | 
| 
       7 
     | 
    
         
            -
                :class_name,
         
     | 
| 
       8 
     | 
    
         
            -
                :primary_key
         
     | 
| 
       9 
     | 
    
         
            -
              )
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
              def model_class
         
     | 
| 
       12 
     | 
    
         
            -
                class_name.constantize
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              def table_name
         
     | 
| 
       16 
     | 
    
         
            -
                model_class.table_name
         
     | 
| 
       17 
     | 
    
         
            -
              end
         
     | 
| 
       18 
     | 
    
         
            -
            end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
            class BelongsToOptions < AssocOptions
         
     | 
| 
       21 
     | 
    
         
            -
              def initialize(name, options = {})
         
     | 
| 
       22 
     | 
    
         
            -
                foreign_key_sym = "#{name}_id".to_sym
         
     | 
| 
       23 
     | 
    
         
            -
                class_name_val = name.to_s.camelcase.singularize
         
     | 
| 
       24 
     | 
    
         
            -
                send("primary_key=", :id)
         
     | 
| 
       25 
     | 
    
         
            -
                send("foreign_key=", foreign_key_sym)
         
     | 
| 
       26 
     | 
    
         
            -
                send("class_name=", class_name_val)
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                options.each do |attr, val|
         
     | 
| 
       29 
     | 
    
         
            -
                  send("#{attr}=", val)
         
     | 
| 
       30 
     | 
    
         
            -
                end
         
     | 
| 
       31 
     | 
    
         
            -
              end
         
     | 
| 
       32 
     | 
    
         
            -
            end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
            class HasManyOptions < AssocOptions
         
     | 
| 
       35 
     | 
    
         
            -
              def initialize(name, self_class_name, options = {})
         
     | 
| 
       36 
     | 
    
         
            -
                foreign_key_sym = "#{self_class_name.underscore}_id".to_sym
         
     | 
| 
       37 
     | 
    
         
            -
                class_name_val = name.to_s.camelcase.singularize
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                send("primary_key=", :id)
         
     | 
| 
       40 
     | 
    
         
            -
                send("foreign_key=", foreign_key_sym)
         
     | 
| 
       41 
     | 
    
         
            -
                send("class_name=", class_name_val)
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                options.each do |attr, val|
         
     | 
| 
       44 
     | 
    
         
            -
                  send("#{attr}=", val)
         
     | 
| 
       45 
     | 
    
         
            -
                end
         
     | 
| 
       46 
     | 
    
         
            -
              end
         
     | 
| 
       47 
     | 
    
         
            -
            end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
            module Associatable
         
     | 
| 
       50 
     | 
    
         
            -
              def belongs_to(name, options = {})
         
     | 
| 
       51 
     | 
    
         
            -
                options = BelongsToOptions.new(name, options)
         
     | 
| 
       52 
     | 
    
         
            -
                assoc_options[name] = options
         
     | 
| 
       53 
     | 
    
         
            -
                define_method(name) do
         
     | 
| 
       54 
     | 
    
         
            -
                 foreign_key = send(options.foreign_key)
         
     | 
| 
       55 
     | 
    
         
            -
                 primary_key = options.primary_key
         
     | 
| 
       56 
     | 
    
         
            -
                 params = [[primary_key, foreign_key]].to_h
         
     | 
| 
       57 
     | 
    
         
            -
                 options.model_class.where(params).first
         
     | 
| 
       58 
     | 
    
         
            -
                end
         
     | 
| 
       59 
     | 
    
         
            -
              end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
              def has_many(name, options = {})
         
     | 
| 
       62 
     | 
    
         
            -
                options = HasManyOptions.new(name, self.name, options)
         
     | 
| 
       63 
     | 
    
         
            -
                define_method(name) do
         
     | 
| 
       64 
     | 
    
         
            -
                 foreign_key = options.foreign_key
         
     | 
| 
       65 
     | 
    
         
            -
                 primary_key = send(options.primary_key)
         
     | 
| 
       66 
     | 
    
         
            -
                 params = [[foreign_key, primary_key]].to_h
         
     | 
| 
       67 
     | 
    
         
            -
                 options.model_class.where(params)
         
     | 
| 
       68 
     | 
    
         
            -
                end
         
     | 
| 
       69 
     | 
    
         
            -
              end
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
              def assoc_options
         
     | 
| 
       72 
     | 
    
         
            -
                @assoc_options ||= {}
         
     | 
| 
       73 
     | 
    
         
            -
                @assoc_options
         
     | 
| 
       74 
     | 
    
         
            -
              end
         
     | 
| 
       75 
     | 
    
         
            -
            end
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
            class SQLObject
         
     | 
| 
       78 
     | 
    
         
            -
              extend Associatable
         
     | 
| 
       79 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,35 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require_relative '03_associatable'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            module Associatable
         
     | 
| 
       4 
     | 
    
         
            -
              def has_one_through(name, through_name, source_name)
         
     | 
| 
       5 
     | 
    
         
            -
                define_method(name) do
         
     | 
| 
       6 
     | 
    
         
            -
                  through_options = self.class.assoc_options[through_name]
         
     | 
| 
       7 
     | 
    
         
            -
                  source_options =
         
     | 
| 
       8 
     | 
    
         
            -
                    through_options.model_class.assoc_options[source_name]
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                  through_table = through_options.table_name
         
     | 
| 
       11 
     | 
    
         
            -
                  through_pk = through_options.primary_key
         
     | 
| 
       12 
     | 
    
         
            -
                  through_fk = through_options.foreign_key
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                  source_table = source_options.table_name
         
     | 
| 
       15 
     | 
    
         
            -
                  source_pk = source_options.primary_key
         
     | 
| 
       16 
     | 
    
         
            -
                  source_fk = source_options.foreign_key
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                  key_val = self.send(through_fk)
         
     | 
| 
       19 
     | 
    
         
            -
                  results = DBConnection.execute(<<-SQL, key_val)
         
     | 
| 
       20 
     | 
    
         
            -
                    SELECT
         
     | 
| 
       21 
     | 
    
         
            -
                      #{source_table}.*
         
     | 
| 
       22 
     | 
    
         
            -
                    FROM
         
     | 
| 
       23 
     | 
    
         
            -
                      #{through_table}
         
     | 
| 
       24 
     | 
    
         
            -
                    JOIN
         
     | 
| 
       25 
     | 
    
         
            -
                      #{source_table}
         
     | 
| 
       26 
     | 
    
         
            -
                    ON
         
     | 
| 
       27 
     | 
    
         
            -
                      #{through_table}.#{source_fk} = #{source_table}.#{source_pk}
         
     | 
| 
       28 
     | 
    
         
            -
                    WHERE
         
     | 
| 
       29 
     | 
    
         
            -
                      #{through_table}.#{through_pk} = ?
         
     | 
| 
       30 
     | 
    
         
            -
                  SQL
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                  source_options.model_class.parse_all(results).first
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
              end
         
     | 
| 
       35 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,21 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require_relative 'db_connection'
         
     | 
| 
       2 
     | 
    
         
            -
            require_relative '01_sql_object'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            module Searchable
         
     | 
| 
       5 
     | 
    
         
            -
              def where(params)
         
     | 
| 
       6 
     | 
    
         
            -
                where_line = params.keys.map { |attr_name| "#{attr_name} = ?" }.join(" AND ")
         
     | 
| 
       7 
     | 
    
         
            -
                results = DBConnection.execute(<<-SQL, *params.values)
         
     | 
| 
       8 
     | 
    
         
            -
                  SELECT
         
     | 
| 
       9 
     | 
    
         
            -
                    *
         
     | 
| 
       10 
     | 
    
         
            -
                  FROM
         
     | 
| 
       11 
     | 
    
         
            -
                    #{self.table_name}
         
     | 
| 
       12 
     | 
    
         
            -
                  WHERE
         
     | 
| 
       13 
     | 
    
         
            -
                    #{where_line}
         
     | 
| 
       14 
     | 
    
         
            -
                SQL
         
     | 
| 
       15 
     | 
    
         
            -
                results.map { |attrs| self.new(attrs) }
         
     | 
| 
       16 
     | 
    
         
            -
              end
         
     | 
| 
       17 
     | 
    
         
            -
            end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
            class SQLObject
         
     | 
| 
       20 
     | 
    
         
            -
              extend Searchable
         
     | 
| 
       21 
     | 
    
         
            -
            end
         
     |