puffs 0.2.03 → 0.2.04

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed275034578496f20029ea6333fca51a1abc47fa
4
- data.tar.gz: 81753c5514e45f504f68772cc0e3472c02e738fd
3
+ metadata.gz: 62f1bbad581f546893650f943280678b704a8e61
4
+ data.tar.gz: 3820cd8108d253066d339e762628ca37545b1599
5
5
  SHA512:
6
- metadata.gz: 63fe1fac7ba793daf239293342504cdd27f82bf789cbb578d0a1d8a15b9f7cab4e1893c3135e030cbb5b21ea3aa89f3156e59d810c6d73135001e900247719df
7
- data.tar.gz: 60eabbfc6f95889a9b9bff8cb129797e7a97d4aee97a39f6393cc11645443fd549c9217887059bf010dbc122891042d8e6cf19d4ba3f601a1941fae6fe8d4029
6
+ metadata.gz: 39b03317cdd9fc533a8212786cde172eb66d0a512adfb32c1723dfa4ea58b21d0aa752bc0d88a5460b4509d9d45d55c98ae9729032018c96488ea6731c9c107e
7
+ data.tar.gz: 5f15695eb605caf6a1ff4ed2454d8d01d571a912e073528e0c98feddb52bc8b88e9af3df9a94fdc789048eae8ee7e2c8f651f5b241c2c6e135b87aaf41acbcb9
@@ -4,7 +4,7 @@ class PostsController < Puffs::ControllerBase
4
4
  end
5
5
 
6
6
  def create
7
- @post = Post.new(body: params['post']['body'], author_id: 6).save
7
+ @post = Post.new(body: params['post']['body'], author_id: 1).save
8
8
  redirect_to ('/posts')
9
9
  end
10
10
 
data/bin/puffs CHANGED
@@ -99,6 +99,12 @@ class CLI < Thor
99
99
  desc 'new', 'creates a new Puffs app'
100
100
  def new(name)
101
101
  Dir.mkdir "./#{name}"
102
+ Dir.mkdir "./#{name}/config"
103
+
104
+ File.open("./#{name}/config/database.yml", "w") do |f|
105
+ f.write("database: #{name}")
106
+ end
107
+
102
108
  Dir.mkdir "./#{name}/app"
103
109
  Dir.mkdir "./#{name}/app/models"
104
110
  Dir.mkdir "./#{name}/app/views"
@@ -106,7 +112,6 @@ class CLI < Thor
106
112
  File.open("./#{name}/app/controllers/application_controller.rb", "w") do |f|
107
113
  f.write File.read(File.expand_path('../../template/app/controllers/application_controller.rb', __FILE__))
108
114
  end
109
- Dir.mkdir "./#{name}/config"
110
115
  File.open("./#{name}/config/routes.rb", "w") do |f|
111
116
  f.write File.read(File.expand_path('../../template/config/routes.rb', __FILE__))
112
117
  end
data/lib/db_connection.rb CHANGED
@@ -1,18 +1,22 @@
1
1
  require 'pg'
2
+ require 'yaml'
2
3
 
3
- APP_NAME = "Puffs"
4
4
  PRINT_QUERIES = ENV['PRINT_QUERIES'] == 'true'
5
5
  MIGRATIONS = Dir.glob('./db/migrate/*.sql').to_a
6
6
 
7
7
  class DBConnection
8
+ def self.app_name
9
+ YAML.load_file(Dir.pwd + '/config/database.yml')['database']
10
+ end
11
+
8
12
  def self.open
9
- @db = PG::Connection.new( :dbname => APP_NAME, :port => 5432 )
13
+ @db = PG::Connection.new( :dbname => DBConnection.app_name, :port => 5432 )
10
14
  end
11
15
 
12
16
  def self.reset
13
17
  commands = [
14
- "dropdb #{APP_NAME}",
15
- "createdb #{APP_NAME}",
18
+ "dropdb #{DBConnection.app_name}",
19
+ "createdb #{DBConnection.app_name}"
16
20
  ]
17
21
 
18
22
  commands.each { |command| `#{command}` }
@@ -22,7 +26,7 @@ class DBConnection
22
26
  ensure_version_table
23
27
  to_migrate = MIGRATIONS.reject { |file| has_migrated?(file) }
24
28
  to_migrate.each { |file| add_to_version(file) }
25
- to_migrate.map {|file| "psql -d #{APP_NAME} -a -f #{file}"}
29
+ to_migrate.map {|file| "psql -d #{DBConnection.app_name} -a -f #{file}"}
26
30
  .each {|command| `#{command}`}
27
31
  end
28
32
 
@@ -28,8 +28,6 @@ class HasManyOptions < AssocOptions
28
28
  def initialize(name, self_class_name, options = {})
29
29
  @primary_key = options[:primary_key] || :id
30
30
  @foreign_key = options[:foreign_key] || "#{self_class_name.to_s.underscore}_id".to_sym
31
-
32
- #I think there is a bug here, investigate.
33
31
  @class_name = options[:class_name] || name.to_s.singularize.camelcase
34
32
  end
35
33
  end
data/puffs.gemspec CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "puffs"
8
- spec.version = "0.2.03"
8
+ spec.version = "0.2.04"
9
9
  spec.authors = ["Zachary Moroni"]
10
10
  spec.email = ["zachary.moroni@gmail.com"]
11
11
 
data/readme.md CHANGED
@@ -13,25 +13,28 @@ How To Do Puffs
13
13
  * Postgres
14
14
 
15
15
  1. Open command line, enter the following:
16
- 2. gem install puffs
17
- 3. puffs new [name of your app]
18
- 4. puffs db create
16
+ 2. `gem install puffs`
17
+ 3. `puffs new [name of your app]``
18
+ 4. `puffs db create`
19
19
  5. You're all set!
20
20
 
21
+ Command Line Interface
22
+ ----------------------
23
+
21
24
  Enter 'puffs' into the command line with no arguments to see the full
22
25
  list of commands, or just read them below:
23
26
 
24
- * puffs new [app name]
25
- * puffs server
26
- * puffs generate
27
- * model [model name]
28
- * controller [controller name]
29
- * migration [migration name]
30
- * puffs db
31
- * create
32
- * migrate
33
- * seed
34
- * reset
27
+ * `puffs new [app name]``
28
+ * `puffs server`
29
+ * `puffs generate`
30
+ * `model [model name]`
31
+ * `controller [controller name]`
32
+ * `migration [migration name]`
33
+ * `puffs db`
34
+ * `create`
35
+ * `migrate`
36
+ * `seed`
37
+ * `reset`
35
38
 
36
39
  Demo App
37
40
  --------
@@ -44,48 +47,48 @@ The Puffs ORM
44
47
 
45
48
  Puffs' object relational mapping is inspired by Rails' ActiveRecord.
46
49
  It converts tables in a Postgres database into instances of the
47
- Puffs::SQLObject class.
50
+ `Puffs::SQLObject` class.
48
51
 
49
- Puffs::SQLObject is a very lightweight version of ActiveRecord::Base.
50
- It's a great way to use ActiveRecord::Base's CRUD methods and associations
52
+ `Puffs::SQLObject` is a very lightweight version of `ActiveRecord::Base`.
53
+ It's a great way to use `ActiveRecord::Base`'s CRUD methods and associations
51
54
  without all the extra overhead.
52
55
 
53
- Puff::SQLRelation imitates the behavior of ActiveRecord::Relation,
56
+ `Puff::SQLRelation` imitates the behavior of `ActiveRecord::Relation`,
54
57
  making sure no unnecessary queries are made to the DB.
55
58
 
56
59
  ###All of your favorite methods are present, including:
57
- * Create
58
- * Find
59
- * All
60
- * Update
61
- * Destroy
60
+ * `#create`
61
+ * `#find`
62
+ * `#all`
63
+ * `#update`
64
+ * `#destroy`
62
65
 
63
66
  ###Also builds Rails table associations:
64
- * Belongs to
65
- * Has many
66
- * Has one through
67
- * Has many through
67
+ * `::belongs_to`
68
+ * `::has_many`
69
+ * `::has_one_through`
70
+ * `::has_many_through`
68
71
 
69
- ##Puffs::SQLRelation
70
- Has the basic functionality of ActiveRecord::Relation, allowing us to
72
+ ##`Puffs::SQLRelation`
73
+ Has the basic functionality of `ActiveRecord::Relation`, allowing us to
71
74
  order and search DB entries with minimal querying.
72
75
 
73
- All methods are lazy and stackable. Queries are only fired when SQLRelation#load
76
+ All methods are lazy and stackable. Queries are only fired when `SQLRelation#load`
74
77
  is called or when the relation is coerced into an Array.
75
78
 
76
79
  ###Methods included:
77
- * All
78
- * Where
79
- * Includes
80
- * Find
81
- * Order
82
- * Limit
83
- * Count
84
- * First
85
- * Last
80
+ * `::all`
81
+ * `::where`
82
+ * `::includes`
83
+ * `::find`
84
+ * `::order`
85
+ * `::limit`
86
+ * `::count`
87
+ * `::first`
88
+ * `::last`
86
89
 
87
90
  ###Eager loading reduces queries
88
- * Preload has_many and belongs_to associations by calling SQLObject#includes
91
+ * Preload has_many and belongs_to associations by calling `SQLObject::includes`
89
92
  * Lazy and chainable.
90
93
  * Reduces your DB queries from (n + 1) to 2.
91
94
 
@@ -93,29 +96,41 @@ Database
93
96
  --------
94
97
 
95
98
  The Puffs commands prefixed with 'db' interact with the Puffs Postgres database.
96
- * 'puffs db create' drops any Postgres DB named 'Puffs' and creates a new,
99
+ * `puffs db create` drops any Postgres DB named 'Puffs' and creates a new,
97
100
  empty one.
98
- * 'puffs db migrate' finds and any SQL files under db/migrate that have not
101
+ * `puffs db migrate` finds and any SQL files under db/migrate that have not
99
102
  been migrated and copies them into the DB.
100
- * 'puffs db seed' calls Seed::populate in db/seeds.rb, allowing you
103
+ * `puffs db seed` calls Seed::populate in db/seeds.rb, allowing you
101
104
  to quickly reset your DB to a seed file while in development.
102
- * 'puffs db reset' executes all three of the above commands, saving you
105
+ * `puffs db reset` executes all three of the above commands, saving you
103
106
  time and energy!
104
107
 
105
- Puffs::ControllerBase
108
+ Migrations
109
+ ----------
110
+
111
+ Entering `puffs generate (or puffs g) migration [migration name]` in the
112
+ command line will create a time-stamped SQL file under db/migrations.
113
+ Write SQL in here to stage changes in the DB (add, drop, or change tables),
114
+ and `puffs db migrate` to implement them.
115
+
116
+ _*NB:*_ To reverse a migration that has been run, you must generate a new
117
+ migration that undoes the changes. Deleting the original migration will
118
+ do nothing.
119
+
120
+ `Puffs::ControllerBase`
106
121
  ---------------------
107
122
 
108
- The Puffs::ControllerBase connects your models to your routes, allowing
123
+ `Puffs::ControllerBase` connects your models to your routes, allowing
109
124
  access to the DB through html.erb views. It's how Puffs takes over the Web.
110
125
 
111
126
  Router
112
127
  ------
113
128
 
114
129
  Routes live in config/routes.rb. New routes are written using Regex.
115
- Open a server connection with the 'puffs server' command.
130
+ Open a server connection with the `puffs server` command.
116
131
 
117
132
  Puffs Console
118
133
  -------------
119
134
 
120
- Access your DB with Puffs::SQLObject methods by simply entering
121
- "require 'puffs'" in Pry (or IRB).
135
+ Access your DB with `Puffs::SQLObject` methods by simply entering
136
+ `require 'puffs'` in Pry (or IRB).
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puffs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.03
4
+ version: 0.2.04
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Moroni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-29 00:00:00.000000000 Z
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -156,13 +156,10 @@ executables:
156
156
  extensions: []
157
157
  extra_rdoc_files: []
158
158
  files:
159
- - ".DS_Store"
160
- - ".byebug_history"
161
159
  - ".gitignore"
162
160
  - ".rspec"
163
161
  - ".travis.yml"
164
162
  - Gemfile
165
- - Gemfile.lock
166
163
  - LICENSE.txt
167
164
  - SamplePuffsApp/Gemfile
168
165
  - SamplePuffsApp/Gemfile.lock
data/.DS_Store DELETED
Binary file
data/.byebug_history DELETED
@@ -1,2 +0,0 @@
1
- c
2
-
data/Gemfile.lock DELETED
@@ -1,65 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- puffs (0.2.01)
5
- activesupport (~> 4.2.5.1)
6
- fileutils (~> 0.7)
7
- pg (~> 0.18)
8
- pry (~> 0.10.3)
9
- rack (~> 1.6.4)
10
- thor (~> 0.19)
11
-
12
- GEM
13
- remote: https://rubygems.org/
14
- specs:
15
- activesupport (4.2.5.1)
16
- i18n (~> 0.7)
17
- json (~> 1.7, >= 1.7.7)
18
- minitest (~> 5.1)
19
- thread_safe (~> 0.3, >= 0.3.4)
20
- tzinfo (~> 1.1)
21
- coderay (1.1.1)
22
- diff-lcs (1.2.5)
23
- fileutils (0.7)
24
- rmagick (>= 2.13.1)
25
- i18n (0.7.0)
26
- json (1.8.3)
27
- method_source (0.8.2)
28
- minitest (5.8.4)
29
- pg (0.18.4)
30
- pry (0.10.3)
31
- coderay (~> 1.1.0)
32
- method_source (~> 0.8.1)
33
- slop (~> 3.4)
34
- rack (1.6.4)
35
- rake (10.5.0)
36
- rmagick (2.15.4)
37
- rspec (3.1.0)
38
- rspec-core (~> 3.1.0)
39
- rspec-expectations (~> 3.1.0)
40
- rspec-mocks (~> 3.1.0)
41
- rspec-core (3.1.7)
42
- rspec-support (~> 3.1.0)
43
- rspec-expectations (3.1.2)
44
- diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.1.0)
46
- rspec-mocks (3.1.3)
47
- rspec-support (~> 3.1.0)
48
- rspec-support (3.1.2)
49
- slop (3.6.0)
50
- thor (0.19.1)
51
- thread_safe (0.3.5)
52
- tzinfo (1.2.2)
53
- thread_safe (~> 0.1)
54
-
55
- PLATFORMS
56
- ruby
57
-
58
- DEPENDENCIES
59
- bundler (~> 1.11)
60
- puffs!
61
- rake (~> 10.0)
62
- rspec (~> 3.0)
63
-
64
- BUNDLED WITH
65
- 1.11.2