easy_save 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f86c6567772019207e0b8650c491d018a6f44774
4
- data.tar.gz: 8f06b4b6afd654bbfac92d95a8a0d261fddb282a
3
+ metadata.gz: 43de1c6f3d6cdd41f228e922141992b5375cf85d
4
+ data.tar.gz: 929b8badc55e6cbcc883a8c1e8a5d45cde780249
5
5
  SHA512:
6
- metadata.gz: 9292ce9e1d5d99e876e6877897938e15e6def954249df21c5665516b656f9fafcb390b316bc4d04232fc23e064fcf98a729d9aee09ed769890d6d4463a472321
7
- data.tar.gz: 76b2da6c75726a84b0df2e86f50bcb00d82df407188505e01b719a56d24de0f6433f86b70d5cf147f519569f65175b1c5666e87756b493a6a7dc19c652a2a908
6
+ metadata.gz: df6cfb4df7c7b646c67fe1dbf5b7f08028259b348744f1841ecbaa7b96148badb9c74ee193efe98b2746e4122c06b1fdb23af7074a178ff58d2b2fcf385bf02b
7
+ data.tar.gz: c20cdbf9f16cad339e982af03d562c3c68107cf7b736889c1f43374dd24381828e8292133a775db00e21ba0d772cdd07438a8ee8da8e30f3c683173203e9d5ec
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # EasySave
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/easy_save`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ EasySave is a lightweight ORM written in Ruby that abstracts away the
4
+ complexities of working with SQL databases.
6
5
 
7
6
  ## Installation
8
7
 
@@ -22,20 +21,93 @@ Or install it yourself as:
22
21
 
23
22
  ## Usage
24
23
 
25
- TODO: Write usage instructions here
24
+ ### Setting up for your own usage:
25
+
26
+ Place your sql file in the root of the project directory, and in
27
+ `lib/easy_save/db_connection.rb` change `'example.sql'` to your sql file's
28
+ name.
29
+
30
+ ```ruby
31
+ #lib/easy_save/db_connection.rb
32
+ USERS_SQL_FILE = File.join(ROOT_FOLDER, 'example.sql')
33
+ USERS_DB_FILE = File.join(ROOT_FOLDER, 'example.db')
34
+
35
+ ```
36
+
37
+ Once that's done, in each model that is involved in the database, require
38
+ 'easy_gem', subclass it from SQLObject and `finalize!` it to create the methods.
39
+
40
+ ```ruby
41
+ require 'easy_gem'
42
+
43
+ class User < SQLObject
44
+
45
+ self.finalize!
46
+ end
47
+ ```
48
+
49
+ ### Setting up demo:
50
+
51
+ A demo database has been included as well, in the example folder.
52
+
53
+ Run Pry or IRB in the examples folder, and `load 'example.rb'`.
54
+
55
+ At that point `Users`, `Comments`, `Photos`, and their respective associations can all
56
+ be explored.
57
+
58
+ #### A step by step guide:
59
+
60
+ 1. Clone the repo.
61
+ 2. Open `EasySave/examples` and Pry / IRB in that same folder.
62
+ 3. `load 'example.rb'`
63
+ 4. Try out different things like User.find(1) or Comment.find(2).
64
+
65
+ ## Features
66
+
67
+ ### Example Methods
68
+
69
+ Methods will return an instance of the object using the information from
70
+ the database if appropriate.
71
+
72
+ #### Object methods:
73
+
74
+ * `::all`: Returns an array of all the objects from the corresponding table.
75
+ * `::find(id)`: Returns the object corresponding to the row with the ID.
76
+ * `::first`: Returns the first row from that table.
77
+ * `::table_name`: Returns the instance variable of the table name, or creates
78
+ the table name name and sets the instance variable for future reference.
79
+ * `::table_name=(table_name)`: Takes an argument and sets the table name to
80
+ that.
81
+ * `#insert`: Inserts the object into it's correponsind table as a new row.
82
+ * `#update`: Updates an objects information in the database.
83
+ * `#save`: Either updates or inserts an entry in the database, depending on if
84
+ you're already
85
+ * `#finalize!`: Necessary to create the attribute accessors based on database
86
+ columns. Called at the end of the class declaration..
26
87
 
27
- ## Development
88
+ #### Association methods:
28
89
 
29
- 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.
90
+ * `::belongs_to(name, options)`: Take a model name and an optional options hash
91
+ and creates a method called `#name`. The method returns the instance of the
92
+ model name to whose ID matches the foreign key held by the object calling the
93
+ method.
94
+ * `::has_many(name, options)`: Similar to `#belongs_to` but instead returns
95
+ instances of the model name whose foreign key matches the ID help by object
96
+ calling the method.
97
+ * `::has_one_through(name, through_name, source_name)`: Requires three
98
+ arguments, the name of the target model class, the through name of the
99
+ intermediary, and the source name of the method in the intermediary. The
100
+ generated method returns an instance of `#name` whose id matches the foreign
101
+ key of the `through_name` object whose id matches the foreign key of the
102
+ `source name` object that is calling the method.
30
103
 
31
- 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).
32
104
 
33
- ## Contributing
34
105
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/easy_save. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
106
+ ## Future Work
36
107
 
108
+ 1. `has_many_through` associations
109
+ 2. Validation check methods
110
+ 3. `joins` to perform SQL joins
37
111
 
38
- ## License
39
112
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
113
 
@@ -1,4 +1,4 @@
1
- require_relative 'lib/easy_save.rb'
1
+ require_relative '../lib/easy_save'
2
2
 
3
3
  DBConnection.reset
4
4
 
@@ -23,3 +23,19 @@ class Comment < SQLObject
23
23
  self.finalize!
24
24
  end
25
25
 
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
@@ -1,5 +1,4 @@
1
1
  require 'sqlite3'
2
- require 'byebug'
3
2
 
4
3
  PRINT_QUERIES = ENV['PRINT_QUERIES'] == 'true'
5
4
  # https://tomafro.net/2010/01/tip-relative-paths-with-file-expand-path
@@ -18,10 +17,9 @@ class DBConnection
18
17
  end
19
18
 
20
19
  def self.reset
21
- commands = [
22
- "rm '#{USERS_DB_FILE}'",
23
- "cat '#{USERS_SQL_FILE}' | sqlite3 '#{USERS_DB_FILE}'"
24
- ]
20
+ commands = []
21
+ commands << "rm '#{USERS_DB_FILE}'" if File.exist?(USERS_DB_FILE)
22
+ commands << "cat '#{USERS_SQL_FILE}' | sqlite3 '#{USERS_DB_FILE}'"
25
23
 
26
24
  commands.each { |command| `#{command}` }
27
25
  DBConnection.open(USERS_DB_FILE)
@@ -1,3 +1,3 @@
1
1
  module EasySave
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_save
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akshith Yellapragada
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-02 00:00:00.000000000 Z
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,8 +88,6 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
- - ".rspec"
92
- - ".travis.yml"
93
91
  - CODE_OF_CONDUCT.md
94
92
  - Gemfile
95
93
  - LICENSE.txt
@@ -98,8 +96,8 @@ files:
98
96
  - bin/console
99
97
  - bin/setup
100
98
  - easy_save.gemspec
101
- - example.rb
102
- - example.sql
99
+ - examples/example.rb
100
+ - examples/example.sql
103
101
  - lib/easy_save.rb
104
102
  - lib/easy_save/associatable.rb
105
103
  - lib/easy_save/db_connection.rb
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.14.6
File without changes