vundabar 0.1.0 → 0.2.0

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: a40d667bbf9462b66e3a9db53f164f05014bac50
4
- data.tar.gz: a6a1a243025c5428612d45400475520172cbba5b
3
+ metadata.gz: 383d22761f7d3f810fa8b75e482d557e4594a231
4
+ data.tar.gz: 1b019deff9b54eebd8458a21a1061efacfbb4446
5
5
  SHA512:
6
- metadata.gz: 460a0417ca149659dae914e826061e9a163b3a69637feabccbbbad2b36075501662c90105e826c09cfb92e141ec635d3adf4d041a9996ca1baa1280a01e3939e
7
- data.tar.gz: 12374f2a117928e638559c34a223d7c1a3683162e8be02c1306fe3a2bc78f7446b798c1e9b5a9437bf86c2a2dc92efff1e0e2ffc7a53770897739b06ba6115c2
6
+ metadata.gz: 89cdf283e7de312a7b79706a4b992f251f597e9b9be5e0623b5ded9e5b6b9f9993a79b3c289cf097383c03dcb09ecf013e1441ae6f05d8cdcf9a3ffb00fdb44a
7
+ data.tar.gz: 609c138c146bbb68332b05baa45f13a168d82e36c9740dab8c83457eb29f71bb5dcaada9fbc741e4c36a74a53c9b699d9e8340f60565c19239d727892be6b0cd
data/.rubocop.yml CHANGED
@@ -2,10 +2,7 @@ AllCops:
2
2
  Exclude:
3
3
  - "vendor/**/*"
4
4
  - "db/schema.rb"
5
- - "Gemfile"
6
- - "config/**/*"
7
- - "spec/rails_helper.rb"
8
- - "spec/spec_helper.rb"
5
+ - "*.gemspec"
9
6
  UseCache: false
10
7
  Style/CollectionMethods:
11
8
  Description: Preferred collection methods.
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # Vundabar
1
+ # Vundabar [![Code Climate](https://codeclimate.com/github/andela-oeyiowuawi/Vundabar/badges/gpa.svg)](https://codeclimate.com/github/andela-oeyiowuawi/Vundabar) [![Coverage Status](https://coveralls.io/repos/github/andela-oeyiowuawi/Vundabar/badge.svg?branch=master)](https://coveralls.io/github/andela-oeyiowuawi/Vundabar?branch=master) [![CircleCI](https://circleci.com/gh/andela-oeyiowuawi/Vundabar.svg?style=svg)](https://circleci.com/gh/andela-oeyiowuawi/Vundabar)
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/vundabar`. To experiment with that code, run `bin/console` for an interactive prompt.
4
3
 
5
- TODO: Delete this and the text above, and describe your gem
4
+ Vundabar is a lightweight portable ruby web framework modelled after Rails and inspired by Sinatra. It is an attempt to understand the awesome features of Rails by reimplementing something similar from scratch.
5
+
6
+ Vundabar is ligthweight and hence fit for simple and quick applications. Since it is a light weight framework it is very fast.
7
+
6
8
 
7
9
  ## Installation
8
10
 
@@ -22,15 +24,148 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ When creating a new Vundabar app, a few things need to be setup and a few rules adhered to. Vundabar basically follows the same folder structure as a typical rails app with all of the model, view and controller code packed inside of an app folder, configuration based code placed inside a config folder and the main database file in a db folder.
28
+
29
+ View a sample app built using Vundabar framework [Here](https://github.com/andela-oeyiowuawi/Todo)
30
+
31
+ ## Key Features
32
+
33
+ ### Routing
34
+ Routing with Vundabar deals with directing requests to the appropriate controllers. A sample route file is:
35
+
36
+ ```ruby
37
+ TodoApplication.routes.draw do
38
+ get "/todo", to: "todo#index"
39
+ get "/todo/new", to: "todo#new"
40
+ post "/todo", to: "todo#create"
41
+ get "/todo/:id", to: "todo#show"
42
+ get "/todo/:id/edit", to: "todo#edit"
43
+ patch "/todo/:id", to: "todo#update"
44
+ put "/todo/:id", to: "todo#update"
45
+ delete "/todo/:id", to: "todo#destroy"
46
+ end
47
+ ```
48
+ Vundabar supports GET, DELETE, PATCH, POST, PUT requests.
49
+
50
+
51
+ ### Models
52
+ All models to be used with the Vundabar framework are to inherit from the BaseModel class provided by Vundabar, in order to access the rich ORM functionalities provided. The BaseModel class acts as an interface between the model class and its database representation. A sample model file is provided below:
53
+
54
+ ```ruby
55
+ class Todo < Vundabar::BaseModel
56
+ to_table :todos
57
+ property :id, type: :integer, primary_key: true
58
+ property :title, type: :text, nullable: false
59
+ property :body, type: :text, nullable: false
60
+ property :status, type: :text, nullable: false
61
+ property :created_at, type: :text, nullable: false
62
+ create_table
63
+ end
64
+ ```
65
+ The `to_table` method provided stores the table name used while creating the table record in the database.
66
+
67
+ The `property` method is provided to declare table columns, and their properties. The first argument to `property` is the column name, while subsequent hash arguments are used to provide information about properties.
68
+
69
+ The `type` argument represents the data type of the column. Supported data types by Vundabar are:
70
+
71
+ * integer (for numeric values)
72
+ * boolean (for boolean values [true or false])
73
+ * text (for alphanumeric values)
74
+
75
+ The `primary_key` argument is used to specify that the column should be used as the primary key of the table. If this is an integer, the value is auto-incremented by the database.
76
+
77
+ The `nullable` argument is used to specify whether a column should have null values, or not.
78
+
79
+
80
+ On passing in the table name, and its properties, a call should be made to the `create_table` method to persist the model to database by creating the table.
81
+
82
+
83
+ ### Controllers
84
+ Controllers are key to the MVC structure, as they handle receiving requests, interacting with the database, and providing responses. Controllers are placed in the controllers folder, which is nested in the app folder.
85
+
86
+ All controllers should inherit from the BaseController class provided by Vundabar to inherit methods which simplify accessing request parameters and returning responses by rendering views.
87
+
88
+ A sample structure for a controller file is:
89
+
90
+ ```ruby
91
+ class TodoController < Vundabar::BaseController
92
+ def index
93
+ @todos = Todo.all
94
+ end
95
+
96
+ def new
97
+ end
98
+
99
+ def show
100
+ todo = Todo.find(params[:id])
101
+ end
102
+
103
+ def destroy
104
+ todo.destroy
105
+ redirect_to "/"
106
+ end
107
+ end
108
+ ```
109
+
110
+ Instance variables set by the controllers are passed to the routes while rendering responses.
111
+
112
+ Explicitly calling `render` to render template files is optional. If it's not called by the controller action, then it's done automatically by the framework with an argument that's the same name as the action. Thus, you can decide to call `render` explicitly when you want to render a view with a name different from the action.
113
+ You can also use relationships similar to rails. `has_many` and `belongs_to` are available.
114
+
115
+
116
+ ### Views
117
+ Currently, view templates are handled through the Tilt gem, with the Erubis template engine. See https://github.com/rtomayko/tilt for more details.
118
+
119
+ View templates are mapped to controller actions and must assume the same nomenclature as their respective actions.Erbuis is used as the templating engine and files which are views are required to have the .erb file extension after the .html extension. Views are placed inside the `app/views` folder. A view to be rendered for the new action in the todoController for example is saved as `new.html.erb` in the todo folder, nested in the views folder.
120
+
121
+ ### External Dependencies
122
+ The Vundabar framework has a few dependencies. These are listed below, with links to source pages for each.
123
+
124
+ * sqlite3 - https://github.com/sparklemotion/sqlite3-ruby
125
+ * erubis - https://rubygems.org/gems/erubis
126
+ * bundler - https://github.com/bundler/bundler
127
+ * rake - https://github.com/ruby/rake
128
+ * rack - https://github.com/rack/rack
129
+ * rack-test - https://github.com/brynary/rack-test
130
+ * rspec - https://github.com/rspec/rspec
131
+ * tilt - https://github.com/rtomayko/tilt
132
+
133
+ ## Running the tests
134
+
135
+ Test files are placed inside the spec folder and have been split into two sub folders, one for unit tests and the other for integration tests. You can run the tests from your command line client by typing `rspec spec`
136
+ ## Generators
137
+ There are a few generators available in the vundabar framework.
138
+
139
+ `new` generator similar to rails is used to create the skeleton of the whole app. To use this generator, run
140
+ `vundabar new <app_name>`.
141
+ This will create a folder called `<app_name>` with the neccesary structure for your new app.
142
+ `version` generator can be used to check the version of the gem that you are using.
143
+ `server` generator can be used to start the server to your new application. To use this, run
144
+ `vundabar server` or simply `vundabar s`.
26
145
 
27
146
  ## Development
28
147
 
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.
148
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
149
 
31
150
  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
151
 
152
+ ##Limitations
153
+
154
+ This version of the gem does not implement callbacks, support migration generation and generating schema.
155
+
33
156
  ## Contributing
34
157
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vundabar.
158
+ To contribute to this work:
159
+
160
+ 1. Fork it ( https://github.com/[andela-oeyiowuawi]/Vundabar )
161
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
162
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
163
+ 4. Push to the branch (`git push origin my-new-feature`)
164
+ 5. Create a new Pull Request
165
+ 6. Wait
166
+
167
+
168
+
169
+ ## License
36
170
 
171
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -12,7 +12,7 @@ module Vundabar
12
12
  def server
13
13
  exec "rackup"
14
14
  end
15
- map %w(s, server) => "server"
15
+ map %w(s server) => "server"
16
16
 
17
17
  desc "new APP_NAME", "create the app boiler plate file structure"
18
18
 
@@ -20,7 +20,7 @@ module Vundabar
20
20
  @app = app_name.downcase
21
21
  say "creating your new app #{app}"
22
22
  create_app_directory
23
-
23
+
24
24
  create_config_files
25
25
  empty_directory "#{app}/db"
26
26
  create_public_directory
data/lib/vundabar.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "vundabar/version"
2
- require 'active_support/inflector'
2
+ require "json"
3
+ require "active_support/inflector"
3
4
  require "vundabar/utilities"
4
5
  require "vundabar/dependencies"
5
6
  require "vundabar/routing/routing"
@@ -22,6 +23,9 @@ module Vundabar
22
23
  def call(env)
23
24
  request = Rack::Request.new(env)
24
25
  route = mapper.find_route(request)
26
+ # return invalid_route_processor(request) unless route
27
+ # call_controller_and_action(request, route[:klass_and_method])
28
+ #
25
29
  if route
26
30
  call_controller_and_action(request, route[:klass_and_method])
27
31
  else
@@ -15,7 +15,11 @@ module Vundabar
15
15
  end
16
16
 
17
17
  def render(*args)
18
- response(render_template(*args))
18
+ if args[0].instance_of? Hash
19
+ return process_hash(args[0])
20
+ else
21
+ response(render_template(*args))
22
+ end
19
23
  end
20
24
 
21
25
  def response(body, status = 200, header = {})
@@ -65,5 +69,16 @@ module Vundabar
65
69
  klass = self.class.to_s.gsub(/Controller$/, "")
66
70
  klass.to_snake_case
67
71
  end
72
+
73
+ def process_hash(hash)
74
+ status = hash.fetch(:status, 200)
75
+ body = hash[:json].to_hsh
76
+ suuplied_header = hash.fetch(:headers, {})
77
+ headers = suuplied_header.merge!("Content-Type" => "application/json")
78
+ if hash.key? :json
79
+ [:headers, :json, :status].each {|key| hash.delete(key) }
80
+ response(body.merge!(hash).to_json, status, headers)
81
+ end
82
+ end
68
83
  end
69
84
  end
@@ -10,7 +10,6 @@ module Vundabar
10
10
  end
11
11
  end
12
12
 
13
-
14
13
  def belongs_to(model_name, options = {})
15
14
  define_method(model_name) do
16
15
  class_name = model_name.to_s.singularize.capitalize
@@ -59,6 +59,14 @@ module Vundabar
59
59
  Database.execute_query query, values
60
60
  end
61
61
 
62
+ def to_hsh
63
+ model_hsh = {}
64
+ self.class.properties.keys.each do |key|
65
+ model_hsh[key] = send(key)
66
+ end
67
+ model_hsh
68
+ end
69
+
62
70
  alias save! save
63
71
 
64
72
  def self.all
@@ -1,5 +1,4 @@
1
1
  class Validations
2
2
  def initialize
3
-
4
3
  end
5
4
  end
@@ -47,7 +47,7 @@ module Vundabar
47
47
  end
48
48
 
49
49
  def controller_and_action(to)
50
- controller, action = to.split('#')
50
+ controller, action = to.split("#")
51
51
  controller = "#{controller.to_camel_case}Controller"
52
52
  [controller, action]
53
53
  end
@@ -1,3 +1,3 @@
1
1
  module Vundabar
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vundabar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eyiowuawi Olalekan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-22 00:00:00.000000000 Z
11
+ date: 2016-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -279,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
279
  version: '0'
280
280
  requirements: []
281
281
  rubyforge_project:
282
- rubygems_version: 2.4.6
282
+ rubygems_version: 2.6.6
283
283
  signing_key:
284
284
  specification_version: 4
285
285
  summary: A simple rack-based MVC framework