gazebo 0.1.4 → 0.1.5

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: 3caf7eb2b5c292239e33599a497f33f4be01304e
4
- data.tar.gz: f50c6437c9004bdc3b1c8c2fa4bb69b214e8a826
3
+ metadata.gz: d5c14436278d592380d44ffa550c277e34e05eb6
4
+ data.tar.gz: 1aa58b42e9c3c2899fdccf09ef67cd1c2c05b17e
5
5
  SHA512:
6
- metadata.gz: 768a61351e7eb4f8edc73d550961d3f7e8d458d6061fc939f2e1d17924ac4406d77dbdb947e7f1c1961c4408c25b044b36bd16da4aed0f3fa341a6f502d47425
7
- data.tar.gz: 43c7aaee21973bd6b6d3710dc4555afea40b6f3e7769d0e2902b1447343046c2bbd8bbb8be437075c17b8e69793093571f042ce41e35d3a91093660173b3d792
6
+ metadata.gz: db0f3948122fe2b822eb1999c78e75daee1aecffb5c9d8b8bb40f38599c25573fa12f26efcef67b6c2db4c1be573a792e9002d6bacad34dc77c905fbf352bb76
7
+ data.tar.gz: ed32ef2d9818a8a5eb5c26f3d5a45b90e5752e066fb6d8f997d585c3970550b5ce399a4e28dd289b22327c2713b71a83578c2d79f317057808e1b2a7681fdb4f
data/README.md CHANGED
@@ -1,9 +1,191 @@
1
1
  # Gazebo
2
2
 
3
3
  A light-weight MVC framework inspired by Rails.
4
+ Check out my beat-making app built to demonstrate using this gem.
5
+ [Github](https://github.com/Tassosb/gazebo-demo "Gazebo Github") |
6
+ [Live](http://gazebo-demo.herokuapp.com/ "Live Link")
4
7
 
5
- ## ActiveLeopard
6
- An ORM with many of the features of Rails ActiveRecord at a fraction of the overhead.
8
+ ## Installation
7
9
 
8
- ## ActionCondor
9
- A Controller Base Class that is combined with a custom router and asset server to handle requests and build responses.
10
+ `gem install gazebo`
11
+
12
+ ## Project Setup
13
+
14
+ You will need to create a project directory with the following structure (need to add a `gazebo new` command):
15
+
16
+ - /app_name
17
+ - /app
18
+ - /controllers
19
+ - /models
20
+ - /views
21
+ - /config
22
+ - /db
23
+ - /migrations
24
+
25
+ Add `gazebo ~> '^0.1.4'` to your Gemfile.
26
+
27
+ Additionally, at the root of the project you will need a file named `config.ru` with the following code:
28
+
29
+ ```
30
+ require 'gazebo'
31
+
32
+ Gazebo.root = File.expand_path(File.dirname(__FILE__))
33
+
34
+ run Gazebo.app
35
+ ```
36
+
37
+ ## Migrations
38
+
39
+ Files in `db/migrations/` will be read and executed as raw sql. Specify the order in which the files will be executed by prefixing each filename with a two digit number (01, 02, 03, ...). This is necessary for migrations to work as expected.
40
+
41
+ `gazebo migrate` runs any new migrations. Migrations are deemed to be new based on the presence of the filename in a 'migrations' table. At the moment there is no command to rollback migrations. Simply add new ones to reverse the changes you made.
42
+
43
+ ```
44
+ #lib/activeleopard/db_connection.rb
45
+
46
+ def self.run_migration_file(file_name)
47
+ migration_name = file_name.match(/\w+/).to_s
48
+
49
+ return if migration_name.empty? || already_run?(migration_name)
50
+
51
+ file = File.join(Gazebo::ROOT, "db/migrations", file_name)
52
+ migration_sql = File.read(file)
53
+ execute(migration_sql)
54
+
55
+ record_migration!(migration_name)
56
+ end
57
+ ```
58
+
59
+ ## Models and ActiveLeopard
60
+
61
+ Model files should be named the singular version of their associated table name. Add model files in `app/models/`. All model classes need to inherit from ActiveLeopard::Base. Additionally, users need to call `::finalize!` at the end of the model class definition.
62
+
63
+ ### Validations
64
+
65
+ Gazebo supports presence and uniqueness validators. The ::validates method can be invoked inside of the class definition, accepting a column_name and an options hash.
66
+
67
+ Example:
68
+ `validates :name, presence: true, uniqueness: true`
69
+
70
+ Validations are checked for upon saving. If any validations fail, `#save` will return false. Additionally, the errors will be accessible with the `#errors` method and can be displayed by `#show_errors`.
71
+
72
+ ### Associations
73
+
74
+ All association creators use sensible defaults generated based on the model class name when explicit primary keys or class names are not given.
75
+
76
+ `::belongs_to(association_name, options)`
77
+ example: `belongs_to :human, foreign_key: :owner_id`
78
+
79
+ `::has_many(association_name, options)`
80
+ example: `has_many :cats, :foreign_key => :owner_id`
81
+
82
+ `has_many_through(association_name, options)`
83
+ example: `has_many_through :cats, :humans, :cats`
84
+
85
+ `has_one_through(association_name, options)`
86
+
87
+ ### ActiveLeopard Query Methods
88
+
89
+ The following query methods are available after inheriting from ActiveLeopard::Base. They return Relation objects and can be chained on to each other. The query that is built is only triggered when the actually query result is needed. Relation objects have access to the Enumerables module.
90
+
91
+ - `::all`
92
+
93
+ - `::joins(association symbol or string)`
94
+ - `::select(string)`
95
+ - `::group(string)`
96
+ - `::limit(number)`
97
+ - `::from(string)`
98
+ - `::order(string)`
99
+ - `::where(string or hash)`
100
+
101
+ ```
102
+ #lib/activeleopard/modules/searchable.rb
103
+
104
+ def where(*params)
105
+ Relation.new(
106
+ {where: WhereClause.new(params)},
107
+ self
108
+ )
109
+ end
110
+ ```
111
+ - `::distinct`
112
+
113
+ The Relation object holds onto the query parameters inside of the `query` instance variable. Before executing the query, or when requested by the user for debugging, the Relation object calls `#as_sql` on each of the clause objects inside of the query hash to construct the sql query.
114
+ ```
115
+ #lib/activeleopard/relation.rb
116
+
117
+ def as_sql
118
+ Relation.ordered_clauses.map do |clause|
119
+ query[clause].as_sql
120
+ end.join(" \n ")
121
+ end
122
+ ```
123
+
124
+ Rather than returning a relation object, the following methods return the found records as object(s).
125
+
126
+ - `::first`
127
+ - `::last`
128
+ - `::find(id)`
129
+ - `::find_by(string or hash)`
130
+
131
+ ### CRUD Methods
132
+
133
+ - `::new(params_hash)`
134
+ - `save` ( returns true or false )
135
+ - `#valid?`
136
+ - `#destroy`
137
+ - `::destroy_all`
138
+
139
+ ### Lifecycle Callback Methods
140
+
141
+ - `::after_initialize(callback_method)` (callback method is invoked in last line of initialize)
142
+
143
+ ## Seeding
144
+
145
+ Add a `seeds.rb` in /db. You will have access to all the model classes you've defined when you run `bundle exec rake db:seed`.
146
+
147
+ ## Routes
148
+
149
+ Routes can be defined in `config/routes.rb`. You will need to make this file yourself. Define routes within a block passed to the `Gazebo::Router.draw` method. You need to write out the path as a regular expression, as the router will use regular expression to match wildcards in the path.
150
+
151
+ Example:
152
+ ```
153
+ Gazebo::Router.draw do
154
+ get Regexp.new("^/beats"), BeatsController, :index
155
+ delete Regexp.new("^/beats/(?<id>\\d+)$"), BeatsController, :destroy
156
+ end
157
+ ```
158
+
159
+ With the second route, any number after '/beats' will show up in params under a key of 'id'.
160
+
161
+ ## Controllers and ActionCondor
162
+
163
+ Controller file names should be the constantized form of the folder names in '/views'. Otherwise, ActionCondor will not be able to guess which template to render by default.
164
+
165
+ ### Session
166
+
167
+ `#session` exposes a Session object which provides an interface for setting keys in an application session cookie. This could be used to implement a basic auth pattern.
168
+
169
+ ### CSRF Protection
170
+
171
+ When `::protect_from_forgery` is invoked inside of a controller class definition, any non-get requests will be denied unless they carry the correct authenticity_token. authenticity_token can be sent up in forms by including a hidden input with the value given by `#form_authenticity_token`.
172
+
173
+ ### Rendering and Redirecting
174
+
175
+ The main purpose of the controller base is to build up a response. You can do this easily with the following methods.
176
+
177
+ Note: a params hash will be populated from wildcards in the url, or data from request. Use `#params` to access this information.
178
+
179
+ `render(template_name)` (only renders html views at this point)
180
+
181
+ `redirect_to(url)` (paths relative to project root work fine)
182
+
183
+ `render_content(content, content_type)` (with this you can render json or text/html)
184
+
185
+ ### Flash
186
+
187
+ Use `#flash` to expose a flash object. Anything set in the flash object using `[]=` will be available for the current and next req/res cycle. Key value pairs set in `#flash.now` will only be available in the current cycle.
188
+
189
+ ## Serving Static Assets
190
+
191
+ Place any static assets in `app/assets/`. Most MIME types are supported by the static asset server. You will need to provide the path relative to the root of the project directory. (e.g. `app/assets/images/some_image.jpg`)
@@ -2,7 +2,6 @@ require 'active_support'
2
2
  require 'active_support/core_ext'
3
3
  require 'active_support/inflector'
4
4
  require 'erb'
5
- require 'byebug'
6
5
  require 'rack'
7
6
  require 'json'
8
7
 
@@ -29,19 +29,24 @@ class DBConnection
29
29
  migrations.sort_by! { |fname| Integer(fname[0..1]) }
30
30
 
31
31
  migrations.each do |file_name|
32
- migration_name = file_name.match(/\w+/).to_s
32
+ run_migration_file(file_name)
33
+ end
34
+ end
33
35
 
34
- next if migration_name.empty? || already_run?(migration_name)
36
+ private
35
37
 
36
- file = File.join(Gazebo::ROOT, "db/migrations", file_name)
37
- migration_sql = File.read(file)
38
- execute(migration_sql)
38
+ def self.run_migration_file(file_name)
39
+ migration_name = file_name.match(/\w+/).to_s
39
40
 
40
- record_migration!(migration_name)
41
- end
41
+ return if migration_name.empty? || already_run?(migration_name)
42
+
43
+ file = File.join(Gazebo::ROOT, "db/migrations", file_name)
44
+ migration_sql = File.read(file)
45
+ execute(migration_sql)
46
+
47
+ record_migration!(migration_name)
42
48
  end
43
49
 
44
- private
45
50
  def self.database_name
46
51
  Gazebo::ROOT.split('/').last.gsub("-", "_") + '_development'
47
52
  end
data/lib/gazebo.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'byebug'
2
1
  require 'rack'
3
2
  require 'uri'
4
3
 
@@ -12,7 +11,7 @@ require_relative 'cli'
12
11
 
13
12
  module Gazebo
14
13
  Router = Router.new
15
- VERSION = "0.1.4"
14
+ VERSION = "0.1.5"
16
15
 
17
16
  def self.app
18
17
  fetch_routes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gazebo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tassos Bareiss