soil_sample_orm 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a6c1c7d89fa2bc69cb39c709535a10487c932c7
4
+ data.tar.gz: 2907512e004b2a8b56e21f1bef4557187c1d01a1
5
+ SHA512:
6
+ metadata.gz: ba8fc15b4264038288602cb7f123af863b973f4dda6de59e4b58527ec055093be15a0ef3fc95b9830c7bd870ae677caf6701dab32ff7307aeaeaaaa5a3432adc
7
+ data.tar.gz: bdb158194600583c2ec944658e3bbf8e79656344a181d56f60eb453ad0a59ba1bf7c489d5c3909ebc2d3215d106c7d953523697ecacbfa0a030f534316c66f91
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ # vscode
15
+ .vscode/*
16
+ !.vscode/settings.json
17
+ !.vscode/tasks.json
18
+ !.vscode/launch.json
19
+ !.vscode/extensions.json
20
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.15.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in soil_sample_orm.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 cptbrkfst
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Soil Sample ORM
2
+
3
+ [![Code Climate](https://img.shields.io/codeclimate/github/kabisaict/flow.svg)](https://codeclimate.com/github/cptbrkfst/soil_sample_orm)
4
+ [![Coverage Status](https://coveralls.io/repos/github/cptbrkfst/soil_sample_orm/badge.svg?branch=master)](https://coveralls.io/github/cptbrkfst/soil_sample_orm?branch=master)
5
+
6
+
7
+
8
+ Soil Sample ORM is a dynamic object-relational mapper for documenting soil samples.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'soil_sample_orm'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install soil_sample_orm
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cptbrkfst/soil_sample_orm.
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require_relative 'config/environment'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+ desc 'Will load a console with the environment'
10
+ task :console do
11
+ def reload!
12
+ load_all 'lib'
13
+ end
14
+
15
+ Pry.start
16
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ DB = { :conn => SQLite3::Database.new('db/soil_sample.db') }.freeze
5
+
6
+ require_all 'lib'
data/db/soil_sample.db ADDED
Binary file
@@ -0,0 +1,6 @@
1
+ require 'awesome_print'
2
+ require 'pry'
3
+ require 'require_all'
4
+ require 'sqlite3'
5
+
6
+ require_all 'lib/soil_sample_orm'
@@ -0,0 +1,126 @@
1
+ module Persistable
2
+ DB = { :conn => SQLite3::Database.new('db/soil_sample.db') }.freeze
3
+ # Class methods for ORM persistence
4
+ module ClassMethods
5
+ def self.extended(base) # Hook
6
+ puts "#{base} has been extended by #{self}"
7
+ end
8
+
9
+ def column_names
10
+ DB[:conn].results_as_hash = true
11
+
12
+ sql = "pragma table_info('#{table_name}')"
13
+
14
+ table_info = DB[:conn].execute(sql)
15
+ column_names = []
16
+ table_info.each do |row|
17
+ column_names << row['name']
18
+ end
19
+ column_names.compact
20
+ end
21
+
22
+ def attributes
23
+ self::ATTRIBUTES
24
+ end
25
+
26
+ def attribute_names_for_insert
27
+ self.attributes.keys[1..-1].join(',')
28
+ end
29
+
30
+ def question_marks_for_insert
31
+ (self.attributes.keys.size - 1).times.collect { '?' }.join(',')
32
+ end
33
+
34
+ def sql_for_update
35
+ self.attributes.keys[1..-1].collect{ |attr_name| "#{attr_name} = ?" }.join(',')
36
+ end
37
+
38
+ def table_name
39
+ "#{self.to_s.downcase}s"
40
+ end
41
+
42
+ def create_sql
43
+ self.attributes.collect do |attr_name, schema|
44
+ "#{attr_name} #{schema}"
45
+ end.join(',')
46
+ end
47
+
48
+ def create_table
49
+ sql = <<-SQL
50
+ CREATE TABLE IF NOT EXISTS #{self.table_name} (
51
+ #{self.create_sql}
52
+ )
53
+ SQL
54
+ DB[:conn].execute(sql)
55
+ end
56
+
57
+ def find(id)
58
+ DB[:conn].results_as_hash = false
59
+ sql = <<-SQL
60
+ SELECT * FROM #{self.table_name} WHERE id = ?
61
+ SQL
62
+ row = DB[:conn].execute(sql, id).flatten
63
+ row.first ? self.reify_from_row(row) : nil
64
+ end
65
+
66
+ def reify_from_row(row)
67
+ options = {}
68
+ Sample.column_names.each.with_index do |k, v|
69
+ options[:"#{k}"] = row[v]
70
+ end
71
+ Sample.new(options)
72
+ end
73
+ end
74
+ # Instance methods for ORM persistence
75
+ module InstanceMethods
76
+ def self.included(base) # Hook
77
+ puts "#{base} has mixed in #{self}"
78
+ end
79
+
80
+ def initialize(options = {})
81
+ options.each do |key, value|
82
+ self.send("#{key}=", value)
83
+ end
84
+ end
85
+
86
+ def attribute_values
87
+ self.class.attributes.keys[1..-1].collect do |attr_name|
88
+ self.send(attr_name)
89
+ end
90
+ end
91
+
92
+ def persisted?
93
+ !!self.id
94
+ end
95
+
96
+ def insert
97
+ sql = <<-SQL
98
+ INSERT INTO #{self.class.table_name} (#{self.class.attribute_names_for_insert})
99
+ VALUES (#{self.class.question_marks_for_insert})
100
+ SQL
101
+ DB[:conn].execute(sql, *attribute_values)
102
+ self.id = DB[:conn].execute('SELECT last_insert_rowid();')[0][0]
103
+ end
104
+
105
+ def destroy
106
+ sql = <<-SQL
107
+ DELETE FROM #{self.class.table_name} WHERE id = ?
108
+ SQL
109
+
110
+ DB[:conn].execute(sql, self.id)
111
+ end
112
+
113
+ def update
114
+ sql = <<-SQL
115
+ UPDATE #{self.class.table_name}
116
+ SET #{self.class.sql_for_update} WHERE id = ?
117
+ SQL
118
+
119
+ DB[:conn].execute(sql, *attribute_values, self.id)
120
+ end
121
+
122
+ def save
123
+ persisted? ? update : insert
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,16 @@
1
+ # Sample Object Class
2
+ class Sample
3
+ ATTRIBUTES = {
4
+ id: 'INTEGER PRIMARY KEY',
5
+ name: 'TEXT',
6
+ description: 'TEXT',
7
+ location: 'TEXT'
8
+ }
9
+
10
+ include Persistable::InstanceMethods
11
+ extend Persistable::ClassMethods
12
+
13
+ self.column_names.each do |col_name|
14
+ attr_accessor col_name.to_sym
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module SoilSampleOrm
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soil_sample_orm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'soil_sample_orm'
8
+ spec.version = SoilSampleOrm::VERSION
9
+ spec.authors = ['Dylan Bromell']
10
+ spec.email = ['dmbromell@gmail.com']
11
+
12
+ spec.summary = 'A Dynamic ORM for Soil Sample DB'
13
+ spec.description = 'Dynamic CRUD functionality for soil sample db'
14
+ spec.homepage = 'https://rubygems.org/gems/soil_sample_orm'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_runtime_dependency 'require_all', '~> 1.4'
25
+ spec.add_runtime_dependency 'sqlite3', '~> 1.3', '>= 1.3.13'
26
+ spec.add_development_dependency 'awesome_print', '~> 1.8'
27
+ spec.add_development_dependency 'bundler', '~> 1.15'
28
+ spec.add_development_dependency 'coveralls'
29
+ spec.add_development_dependency 'pry', '~> 0.10.4'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soil_sample_orm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dylan Bromell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: require_all
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.3.13
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.3'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.3.13
47
+ - !ruby/object:Gem::Dependency
48
+ name: awesome_print
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.8'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.8'
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.15'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.15'
75
+ - !ruby/object:Gem::Dependency
76
+ name: coveralls
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: pry
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.10.4
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.10.4
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '10.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '10.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rspec
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.0'
131
+ description: Dynamic CRUD functionality for soil sample db
132
+ email:
133
+ - dmbromell@gmail.com
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - ".gitignore"
139
+ - ".rspec"
140
+ - ".travis.yml"
141
+ - Gemfile
142
+ - LICENSE.txt
143
+ - README.md
144
+ - Rakefile
145
+ - bin/setup
146
+ - config/environment.rb
147
+ - db/soil_sample.db
148
+ - lib/soil_sample_orm.rb
149
+ - lib/soil_sample_orm/concerns/persistable.rb
150
+ - lib/soil_sample_orm/models/sample.rb
151
+ - lib/soil_sample_orm/version.rb
152
+ - soil_sample_orm.gemspec
153
+ homepage: https://rubygems.org/gems/soil_sample_orm
154
+ licenses:
155
+ - MIT
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.6.12
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: A Dynamic ORM for Soil Sample DB
177
+ test_files: []