vundabar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a40d667bbf9462b66e3a9db53f164f05014bac50
4
+ data.tar.gz: a6a1a243025c5428612d45400475520172cbba5b
5
+ SHA512:
6
+ metadata.gz: 460a0417ca149659dae914e826061e9a163b3a69637feabccbbbad2b36075501662c90105e826c09cfb92e141ec635d3adf4d041a9996ca1baa1280a01e3939e
7
+ data.tar.gz: 12374f2a117928e638559c34a223d7c1a3683162e8be02c1306fe3a2bc78f7446b798c1e9b5a9437bf86c2a2dc92efff1e0e2ffc7a53770897739b06ba6115c2
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,237 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "vendor/**/*"
4
+ - "db/schema.rb"
5
+ - "Gemfile"
6
+ - "config/**/*"
7
+ - "spec/rails_helper.rb"
8
+ - "spec/spec_helper.rb"
9
+ UseCache: false
10
+ Style/CollectionMethods:
11
+ Description: Preferred collection methods.
12
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
13
+ Enabled: true
14
+ PreferredMethods:
15
+ collect: map
16
+ collect!: map!
17
+ find: detect
18
+ find_all: select
19
+ reduce: inject
20
+ Style/DotPosition:
21
+ Description: Checks the position of the dot in multi-line method calls.
22
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
23
+ Enabled: true
24
+ EnforcedStyle: trailing
25
+ SupportedStyles:
26
+ - leading
27
+ - trailing
28
+ Style/FileName:
29
+ Description: Use snake_case for source file names.
30
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
31
+ Enabled: false
32
+ Exclude: []
33
+ Style/GuardClause:
34
+ Description: Check for conditionals that can be replaced with guard clauses
35
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
36
+ Enabled: false
37
+ MinBodyLength: 1
38
+ Style/IfUnlessModifier:
39
+ Description: Favor modifier if/unless usage when you have a single-line body.
40
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
41
+ Enabled: false
42
+ MaxLineLength: 80
43
+ Style/OptionHash:
44
+ Description: Don't use option hashes when you can use keyword arguments.
45
+ Enabled: false
46
+ Style/PercentLiteralDelimiters:
47
+ Description: Use `%`-literal delimiters consistently
48
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
49
+ Enabled: false
50
+ PreferredDelimiters:
51
+ "%": "()"
52
+ "%i": "()"
53
+ "%q": "()"
54
+ "%Q": "()"
55
+ "%r": "{}"
56
+ "%s": "()"
57
+ "%w": "()"
58
+ "%W": "()"
59
+ "%x": "()"
60
+ Style/PredicateName:
61
+ Description: Check the names of predicate methods.
62
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
63
+ Enabled: true
64
+ NamePrefix:
65
+ - is_
66
+ - has_
67
+ - have_
68
+ NamePrefixBlacklist:
69
+ - is_
70
+ Exclude:
71
+ - spec/**/*
72
+ Style/RaiseArgs:
73
+ Description: Checks the arguments passed to raise/fail.
74
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
75
+ Enabled: false
76
+ EnforcedStyle: exploded
77
+ SupportedStyles:
78
+ - compact
79
+ - exploded
80
+ Style/SignalException:
81
+ Description: Checks for proper usage of fail and raise.
82
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
83
+ Enabled: false
84
+ EnforcedStyle: semantic
85
+ SupportedStyles:
86
+ - only_raise
87
+ - only_fail
88
+ - semantic
89
+ Style/SingleLineBlockParams:
90
+ Description: Enforces the names of some block params.
91
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
92
+ Enabled: false
93
+ Methods:
94
+ - reduce:
95
+ - a
96
+ - e
97
+ - inject:
98
+ - a
99
+ - e
100
+ Style/SingleLineMethods:
101
+ Description: Avoid single-line methods.
102
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
103
+ Enabled: false
104
+ AllowIfMethodIsEmpty: true
105
+ Style/StringLiterals:
106
+ Description: Checks if uses of quotes match the configured preference.
107
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
108
+ Enabled: true
109
+ EnforcedStyle: double_quotes
110
+ SupportedStyles:
111
+ - single_quotes
112
+ - double_quotes
113
+ Style/StringLiteralsInInterpolation:
114
+ Description: Checks if uses of quotes inside expressions in interpolated strings
115
+ match the configured preference.
116
+ Enabled: true
117
+ EnforcedStyle: single_quotes
118
+ SupportedStyles:
119
+ - single_quotes
120
+ - double_quotes
121
+ Style/TrailingCommaInLiteral:
122
+ Description: Checks for trailing comma in parameter lists and literals.
123
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
124
+ Enabled: false
125
+ EnforcedStyleForMultiline: no_comma
126
+ SupportedStyles:
127
+ - comma
128
+ - no_comma
129
+ Metrics/AbcSize:
130
+ Description: A calculated magnitude based on number of assignments, branches, and
131
+ conditions.
132
+ Enabled: false
133
+ Max: 15
134
+ Metrics/ClassLength:
135
+ Description: Avoid classes longer than 100 lines of code.
136
+ Enabled: false
137
+ CountComments: false
138
+ Max: 100
139
+ Metrics/ModuleLength:
140
+ CountComments: false
141
+ Max: 100
142
+ Description: Avoid modules longer than 100 lines of code.
143
+ Enabled: false
144
+ Metrics/CyclomaticComplexity:
145
+ Description: A complexity metric that is strongly correlated to the number of test
146
+ cases needed to validate a method.
147
+ Enabled: false
148
+ Max: 6
149
+ Metrics/MethodLength:
150
+ Description: Avoid methods longer than 10 lines of code.
151
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
152
+ Enabled: false
153
+ CountComments: false
154
+ Max: 10
155
+ Metrics/ParameterLists:
156
+ Description: Avoid parameter lists longer than three or four parameters.
157
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
158
+ Enabled: false
159
+ Max: 5
160
+ CountKeywordArgs: true
161
+ Metrics/PerceivedComplexity:
162
+ Description: A complexity metric geared towards measuring complexity for a human
163
+ reader.
164
+ Enabled: false
165
+ Max: 7
166
+ Lint/AssignmentInCondition:
167
+ Description: Don't use assignment in conditions.
168
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
169
+ Enabled: false
170
+ AllowSafeAssignment: true
171
+ Style/InlineComment:
172
+ Description: Avoid inline comments.
173
+ Enabled: false
174
+ Style/AccessorMethodName:
175
+ Description: Check the naming of accessor methods for get_/set_.
176
+ Enabled: false
177
+ Style/Alias:
178
+ Description: Use alias_method instead of alias.
179
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
180
+ Enabled: false
181
+ Style/Documentation:
182
+ Description: Document classes and non-namespace modules.
183
+ Enabled: false
184
+ Style/DoubleNegation:
185
+ Description: Checks for uses of double negation (!!).
186
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
187
+ Enabled: false
188
+ Style/EachWithObject:
189
+ Description: Prefer `each_with_object` over `inject` or `reduce`.
190
+ Enabled: false
191
+ Style/EmptyLiteral:
192
+ Description: Prefer literals to Array.new/Hash.new/String.new.
193
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
194
+ Enabled: false
195
+ Style/ModuleFunction:
196
+ Description: Checks for usage of `extend self` in modules.
197
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
198
+ Enabled: false
199
+ Style/OneLineConditional:
200
+ Description: Favor the ternary operator(?:) over if/then/else/end constructs.
201
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
202
+ Enabled: false
203
+ Style/PerlBackrefs:
204
+ Description: Avoid Perl-style regex back references.
205
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
206
+ Enabled: false
207
+ Style/Send:
208
+ Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
209
+ may overlap with existing methods.
210
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
211
+ Enabled: false
212
+ Style/SpecialGlobalVars:
213
+ Description: Avoid Perl-style global variables.
214
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
215
+ Enabled: false
216
+ Style/VariableInterpolation:
217
+ Description: Don't interpolate global, instance and class variables directly in
218
+ strings.
219
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
220
+ Enabled: false
221
+ Style/WhenThen:
222
+ Description: Use when x then ... for one-line cases.
223
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
224
+ Enabled: false
225
+ Lint/EachWithObjectArgument:
226
+ Description: Check for immutable argument given to each_with_object.
227
+ Enabled: true
228
+ Lint/HandleExceptions:
229
+ Description: Don't suppress exception.
230
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
231
+ Enabled: false
232
+ Lint/LiteralInCondition:
233
+ Description: Checks of literals used in conditions.
234
+ Enabled: false
235
+ Lint/LiteralInInterpolation:
236
+ Description: Checks for literals used in interpolation.
237
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install:
5
+ - gem install activesupport -v '4.2.6'
6
+ - gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in vundabar.gemspec
4
+ gemspec
5
+ gem "pry"
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Vundabar
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
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vundabar'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vundabar
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
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.
30
+
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
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vundabar.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
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
data/bin/vundabar ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vundabar"
5
+ require_relative File.join(__dir__, "..", "generators", "generators")
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+ Vundabar::Generators.start ARGV
data/circle.yml ADDED
@@ -0,0 +1,8 @@
1
+ dependencies:
2
+ pre:
3
+ - gem install bundler
4
+ - gem install mime-types-data -v '3.2016.0221'
5
+
6
+ machine:
7
+ ruby:
8
+ version: 2.2.2
@@ -0,0 +1,72 @@
1
+ require "thor"
2
+ module Vundabar
3
+ class Generators < Thor
4
+ include Thor::Actions
5
+ attr_reader :app
6
+ def self.source_root
7
+ File.dirname(__FILE__) + "/templates"
8
+ end
9
+
10
+ desc "server", "Starts vundabar server"
11
+
12
+ def server
13
+ exec "rackup"
14
+ end
15
+ map %w(s, server) => "server"
16
+
17
+ desc "new APP_NAME", "create the app boiler plate file structure"
18
+
19
+ def new(app_name)
20
+ @app = app_name.downcase
21
+ say "creating your new app #{app}"
22
+ create_app_directory
23
+
24
+ create_config_files
25
+ empty_directory "#{app}/db"
26
+ create_public_directory
27
+ add_files_to_root_folders
28
+ end
29
+
30
+ desc "version", "display the current version of the vundabar gem"
31
+
32
+ def version
33
+ say "Vundabar #{Vundabar::VERSION}"
34
+ end
35
+ map %w(-v --version) => "version"
36
+
37
+ private
38
+
39
+ def create_app_directory
40
+ empty_directory app.to_s
41
+ empty_directory "#{app}/app"
42
+ empty_directory "#{app}/app/controllers"
43
+ empty_directory "#{app}/app/models"
44
+ create_views_folders
45
+ end
46
+
47
+ def create_views_folders
48
+ empty_directory "#{app}/app/views/layouts"
49
+ copy_file(
50
+ "application.html.erb",
51
+ "#{app}/app/views/layouts/application.html.erb"
52
+ )
53
+ end
54
+
55
+ def create_config_files
56
+ say "creating config folder"
57
+ empty_directory "#{app}/config"
58
+ copy_file "application.rb", "#{app}/config/application.rb"
59
+ copy_file "routes.rb", "#{app}/config/routes.rb"
60
+ end
61
+
62
+ def create_public_directory
63
+ empty_directory "#{app}/public"
64
+ copy_file "invalid_route.html.erb", "#{app}/public/invalid_route.html.erb"
65
+ end
66
+
67
+ def add_files_to_root_folders
68
+ copy_file "config.ru", "#{app}/config.ru"
69
+ copy_file "Gemfile", "#{app}/Gemfile"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "vundabar"
4
+ gem "pry"
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title> <%= title %> </title>
5
+ <meta charset= "UTF-8">
6
+ </head>
7
+ <body>
8
+ <%= yield %>
9
+ </body>
10
+ </html>
@@ -0,0 +1,6 @@
1
+ require "vundabar"
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "app", "controllers")
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "app", "models")
4
+
5
+ class Application < Vundabar::Application
6
+ end
@@ -0,0 +1,6 @@
1
+ APP_ROOT = __dir__
2
+ require_relative "config/application.rb"
3
+ use Rack::MethodOverride
4
+ VundabarApp = Vundabar::Application.new
5
+ require_relative "config/routes.rb"
6
+ run VundabarApp
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset= "UTF-8">
5
+ <title>Invalid Route</title>
6
+ <style >
7
+ body {
8
+ background-color: #ffffff;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+ div.error_box {
15
+ margin: auto;
16
+ font-weight: bolder;
17
+ width: 60%;
18
+ border: 3px solid #ff3333;
19
+ padding: 10px;
20
+ background-color: #ff3333;
21
+ margin-top: 5%;
22
+
23
+ }
24
+
25
+ </style>
26
+ </head>
27
+ <body>
28
+ <div class="error_box">
29
+ OOOPPSSSS!!!, the path "<%= path %>", you seek is not available, Old sport Check the list f the available paths and choose your path.
30
+ </div>
31
+
32
+ <div class="routes-list">
33
+ <% endpoints.each do |method, route_info| %>
34
+
35
+ <%end %>
36
+ </div>
37
+ </body>
38
+ </html>
@@ -0,0 +1,14 @@
1
+ VundabarApp.routes.draw do
2
+ # define your routes here
3
+ # use root to define you landing routes
4
+ # Example: root "pages#index"
5
+ # This will ensure that the index action of the pagesController is your
6
+ # default action
7
+ # Available routes requests are get, post, put and delete
8
+ # Each takes in an alias the first parameter and a hash as the second
9
+ # The hash key is "to" while the value is the controller and action
10
+ # Example get "user", to: "sessions#index"
11
+ # You should define routes
12
+ # You can also define routes with resources. just add resources :name and you
13
+ # will have access to all restful urls
14
+ end
@@ -0,0 +1,69 @@
1
+ require "tilt/erb"
2
+ module Vundabar
3
+ class BaseController
4
+ attr_reader :request
5
+ def initialize(request)
6
+ @request = request
7
+ end
8
+
9
+ def params
10
+ request.params
11
+ end
12
+
13
+ def redirect_to(address, status: 301)
14
+ response([], status, "Location" => address)
15
+ end
16
+
17
+ def render(*args)
18
+ response(render_template(*args))
19
+ end
20
+
21
+ def response(body, status = 200, header = {})
22
+ @response = Rack::Response.new(body, status, header)
23
+ end
24
+
25
+ def get_response
26
+ @response
27
+ end
28
+
29
+ def invalid_route(endpoints)
30
+ template = File.join(APP_ROOT, "public", "invalid_route.html.erb")
31
+ locals = { path: request.path_info, endpoints: endpoints }
32
+ Tilt::ERBTemplate.new(template).render(self, locals)
33
+ end
34
+
35
+ def render_template(view_name, locals = {})
36
+ layout_template, view_template = prepare_view_template(view_name)
37
+ title = view_name.to_s.tr("_", " ").capitalize
38
+ layout_template.render(self, title: title) do
39
+ view_template.render(self, locals)
40
+ end
41
+ end
42
+
43
+ def prepare_view_template(view_name)
44
+ layout_file = File.join(
45
+ APP_ROOT,
46
+ "app",
47
+ "views",
48
+ "layouts",
49
+ "application.html.erb"
50
+ )
51
+ layout_template = Tilt::ERBTemplate.new(layout_file)
52
+ view = "#{view_name}.html.erb"
53
+ view_file = File.join(
54
+ APP_ROOT,
55
+ "app",
56
+ "views",
57
+ controller_name,
58
+ view
59
+ )
60
+ view_template = Tilt::ERBTemplate.new(view_file)
61
+ [layout_template, view_template]
62
+ end
63
+
64
+ def controller_name
65
+ klass = self.class.to_s.gsub(/Controller$/, "")
66
+ klass.to_snake_case
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,6 @@
1
+ class Object
2
+ def self.const_missing(const)
3
+ require const.to_s.to_snake_case
4
+ Object.const_get(const)
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ module Vundabar
2
+ module Associations
3
+ def has_many(name, options = {})
4
+ define_method(name) do
5
+ class_name = name.to_s.singularize.capitalize
6
+ model = options.fetch(:class_name, class_name).to_constant
7
+ foreign_key_column = self.class.to_s.downcase + "_id"
8
+ foreign_key = options.fetch(:foreign_key, foreign_key_column)
9
+ model.where("#{foreign_key} LIKE ?", id)
10
+ end
11
+ end
12
+
13
+
14
+ def belongs_to(model_name, options = {})
15
+ define_method(model_name) do
16
+ class_name = model_name.to_s.singularize.capitalize
17
+ model = options.fetch(:class_name, class_name).to_constant
18
+ foreign_key = model_name.to_s.concat("_id")
19
+ value = send(foreign_key)
20
+ model.find_by(id: value)
21
+ end
22
+ end
23
+ end
24
+ end