fasta 0.1.10 → 0.2.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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +11 -0
  3. data/.idea/fasta.iml +30 -0
  4. data/.idea/misc.xml +7 -0
  5. data/.idea/modules.xml +8 -0
  6. data/.idea/vcs.xml +6 -0
  7. data/.rspec +3 -0
  8. data/.travis.yml +7 -0
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/Gemfile +6 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +43 -0
  13. data/Rakefile +7 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/exe/fasta +5 -0
  17. data/fasta.gemspec +49 -0
  18. data/lib/fasta/app/endpoints/model/create.rb +5 -0
  19. data/lib/fasta/app/endpoints/model/delete.rb +7 -0
  20. data/lib/fasta/app/endpoints/model/index.rb +5 -0
  21. data/lib/fasta/app/endpoints/model/patch.rb +7 -0
  22. data/lib/fasta/app/endpoints/model/put.rb +7 -0
  23. data/lib/fasta/app/endpoints/model/show.rb +7 -0
  24. data/lib/fasta/app/endpoints/model.rb +17 -0
  25. data/lib/fasta/cli.rb +23 -0
  26. data/lib/fasta/server/actions/create.rb +17 -0
  27. data/lib/fasta/server/actions/delete.rb +22 -0
  28. data/lib/fasta/server/actions/index.rb +13 -0
  29. data/lib/fasta/server/actions/patch.rb +18 -0
  30. data/lib/fasta/server/actions/put.rb +23 -0
  31. data/lib/fasta/server/actions/show.rb +14 -0
  32. data/lib/fasta/server/actions.rb +13 -0
  33. data/lib/fasta/server/core/read.rb +13 -0
  34. data/lib/fasta/server/core/responder.rb +100 -0
  35. data/lib/fasta/server/core/write.rb +38 -0
  36. data/lib/fasta/version.rb +3 -0
  37. data/lib/fasta.rb +7 -0
  38. data/tasks/console.rake +4 -0
  39. data/tasks/database.rake +65 -0
  40. data/templates/Gemfile +4 -0
  41. data/templates/Procfile +1 -0
  42. data/templates/Rakefile +2 -0
  43. data/templates/app/endpoints/user/boards.rb +11 -0
  44. data/templates/app/endpoints/user/create.rb +5 -0
  45. data/templates/app/endpoints/user/delete.rb +5 -0
  46. data/templates/app/endpoints/user/index.rb +3 -0
  47. data/templates/app/endpoints/user/patch.rb +5 -0
  48. data/templates/app/endpoints/user/put.rb +5 -0
  49. data/templates/app/endpoints/user/show.rb +5 -0
  50. data/templates/app/endpoints/user.rb +3 -0
  51. data/templates/application.rb +6 -0
  52. data/templates/boot.ru +3 -0
  53. data/templates/config/database.yml +22 -0
  54. data/templates/config/environment.rb +12 -0
  55. data/templates/config/environments/development.rb +2 -0
  56. data/templates/config/environments/production.rb +4 -0
  57. data/templates/config/environments/test.rb +2 -0
  58. data/templates/config/puma.rb +12 -0
  59. data/templates/config/routes.rb +19 -0
  60. data/templates/db/migrations/001_create_users_table.rb +12 -0
  61. metadata +66 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5aa1d081c41fa9c775bb6d4846b5e042bb57e0a6d141a850e8e27215b5aa577a
4
- data.tar.gz: 21609322e0e814f1a60fafd6cc03ae7f2566f27c5db7dc3fe0cdf8df14ca263b
3
+ metadata.gz: 6c2f7615a59c09de670681ad097127dbba4037ba56233ff43f7749dac2d1dbf1
4
+ data.tar.gz: db49b244813e1d8cb2174108edd09e889ec3dfdc24b1dd3f16c8ac47a2a4f004
5
5
  SHA512:
6
- metadata.gz: a142769b448649fc248ae6be510e020c171f2c5caa0f996fd512bcc739f6b911c8d1e802dc75ce6bd73f69b1be78a5d91f8e725cd0783195631854c16752668f
7
- data.tar.gz: ee6c9bffa62c271aa06aaca4c2e2afe653f93a14bcf5a4bee4554a1972076556402a65a0d9e9bfed0f9d524007d14547885c3fb499717cb989468c0da2051c26
6
+ metadata.gz: 6ecaea5fae3621e17c7b0f155bcea18ea3fd33399add3b9c5241a1d38131cf11ee52699ceef65b730039d4b6f2bfb9432615cdd7efb35347fb8c5b58096a8529
7
+ data.tar.gz: c9535b8eec35c5d130418a0bd8f73db6990918366b9c7138bfbd2db8bef1814bc852faa085559dafddfc25ce18f40309c161f4e04fcd0e7224c6651f93b32494
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.idea/fasta.iml ADDED
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$" />
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.0.5, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
11
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
12
+ <orderEntry type="library" scope="PROVIDED" name="hanami-router (v1.2.0, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
13
+ <orderEntry type="library" scope="PROVIDED" name="http_router (v0.11.2, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="logger (v1.2.8, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="oj (v3.6.11, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="pg (v1.1.3, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="puma (v3.12.0, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="rack (v2.0.5, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.8.0, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.8.0, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.8.1, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.8.0, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.8.0, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="sequel (v5.13.0, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="thor (v0.20.0, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="transproc (v1.0.2, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="url_mount (v0.2.1, RVM: ruby-2.5.1 [fasta]) [gem]" level="application" />
29
+ </component>
30
+ </module>
data/.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptSettings">
4
+ <option name="languageLevel" value="ES6" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.5.1 [fasta]" project-jdk-type="RUBY_SDK" />
7
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/fasta.iml" filepath="$PROJECT_DIR$/.idea/fasta.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.17.0.pre.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at yaroslavo@softwareplanetgroup.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in fasta.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 YaroslavO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Fasta
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/fasta`. 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 'fasta'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fasta
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]/fasta. 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.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Fasta project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/fasta/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ Dir.glob('tasks/*.rake').each { |r| load r}
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fasta"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
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/exe/fasta ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/fasta/cli'
4
+ Fasta::Installer.start( ARGV )
5
+ require "fasta" rescue 0
data/fasta.gemspec ADDED
@@ -0,0 +1,49 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fasta/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fasta"
8
+ spec.version = Fasta::VERSION
9
+ spec.authors = ["Yaro"]
10
+ spec.email = ["osyaroslav@gmail.com"]
11
+
12
+ spec.summary = %q{Fasta is a mini web framework}
13
+ spec.description = %q{Rack Server API}
14
+ spec.homepage = "http://github.com/vergilet/fasta"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "#: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.files += Dir['tasks/*']
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_dependency "thor", "~> 0.20"
37
+ spec.add_dependency "oj", "~> 3.6"
38
+ spec.add_dependency "sequel", '~> 5.0'
39
+ spec.add_dependency "logger", '~> 1.0'
40
+ spec.add_dependency "pg", '~> 1.0'
41
+ spec.add_dependency 'hanami-router', '~> 1.3'
42
+ spec.add_dependency 'rack', '~> 2.0'
43
+
44
+ spec.add_dependency 'puma', '~>3.0'
45
+
46
+ spec.add_development_dependency "bundler", "~> 1.17"
47
+ spec.add_development_dependency "rake", "~> 10.0"
48
+ spec.add_development_dependency "rspec", "~> 3.0"
49
+ end
@@ -0,0 +1,5 @@
1
+ module Fasta
2
+ module Model
3
+ class Create < Server::Actions::Create; end
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Fasta
2
+ module Model
3
+ class Delete < Server::Actions::Delete
4
+ validate_fields :id
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Fasta
2
+ module Model
3
+ class Index < Server::Actions::Index; end
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Fasta
2
+ module Model
3
+ class Patch < Server::Actions::Patch
4
+ validate_fields :id
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Fasta
2
+ module Model
3
+ class Put < Server::Actions::Put
4
+ validate_fields :id
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Fasta
2
+ module Model
3
+ class Show < Server::Actions::Show
4
+ validate_fields :id
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ require 'fasta/server/actions'
2
+ require 'fasta/app/endpoints/model/create'
3
+ require 'fasta/app/endpoints/model/delete'
4
+ require 'fasta/app/endpoints/model/index'
5
+ require 'fasta/app/endpoints/model/patch'
6
+ require 'fasta/app/endpoints/model/put'
7
+ require 'fasta/app/endpoints/model/show'
8
+
9
+ # Do @@db_table_name as table name for current module
10
+
11
+ module Fasta
12
+ module Model
13
+ def db_table_name
14
+ (self.name.downcase + 's').gsub('::', '_').to_sym
15
+ end
16
+ end
17
+ end
data/lib/fasta/cli.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'thor'
2
+
3
+ module Fasta
4
+ class Installer < Thor
5
+ include Thor::Actions
6
+ source_root File.expand_path("../../../templates",__FILE__)
7
+
8
+ desc 'plz NAME', 'Unpack Project'
9
+ def plz(name)
10
+ @name = name
11
+ directory 'config', "#{name}/config"
12
+ create_file "#{name}/app/endpoints/.keep"
13
+ create_file "#{name}/log/db.log"
14
+ directory 'app', "#{name}/app"
15
+ copy_file 'db/migrations/001_create_users_table.rb', "#{name}/db/migrations/001_create_users_table.rb"
16
+ copy_file 'application.rb', "#{name}/application.rb"
17
+ copy_file 'boot.ru', "#{name}/boot.ru"
18
+ copy_file 'Gemfile', "#{name}/Gemfile"
19
+ copy_file 'Procfile', "#{name}/Procfile"
20
+ copy_file 'Rakefile', "#{name}/Rakefile"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ require 'fasta/server/core/write'
2
+
3
+ module Fasta
4
+ module Server
5
+ module Actions
6
+ class Create < Server::Core::Write
7
+ def default_response_code
8
+ 201
9
+ end
10
+
11
+ def success
12
+ db_table.insert(params.merge(default_attributes))
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ require 'fasta/server/core/write'
2
+
3
+ module Fasta
4
+ module Server
5
+ module Actions
6
+ class Delete < Server::Core::Write
7
+ def default_response_code
8
+ 204
9
+ end
10
+
11
+ def success
12
+ if db_table.first(id: params[:id])
13
+ db_table.where(id: params[:id]).delete
14
+ else
15
+ @response_code = 404
16
+ nil
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ require 'fasta/server/core/read'
2
+
3
+ module Fasta
4
+ module Server
5
+ module Actions
6
+ class Index < Server::Core::Read
7
+ def fetch
8
+ db_table.all
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require 'fasta/server/core/write'
2
+
3
+ module Fasta
4
+ module Server
5
+ module Actions
6
+ class Patch < Server::Core::Write
7
+ def default_response_code
8
+ 200
9
+ end
10
+
11
+ def success
12
+ db_table.where(id: params[:id]).update(params.merge(default_updated_at))
13
+ db_table.first(id: params[:id])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'fasta/server/core/write'
2
+
3
+ module Fasta
4
+ module Server
5
+ module Actions
6
+ class Put < Server::Core::Write
7
+ def default_response_code
8
+ 201
9
+ end
10
+
11
+ def success
12
+ if instance = db_table.where(id: params[:id])
13
+ instance.update(params.merge(default_updated_at))
14
+ @response_code = 204
15
+ nil
16
+ else
17
+ db_table.insert(params.merge(default_attributes))
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'fasta/server/core/read'
2
+
3
+ module Fasta
4
+ module Server
5
+ module Actions
6
+ class Show < Server::Core::Read
7
+ def fetch
8
+ @response_code = 404 unless instance = db_table.first(id: params[:id])
9
+ instance
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'fasta/server/actions/create'
2
+ require 'fasta/server/actions/delete'
3
+ require 'fasta/server/actions/index'
4
+ require 'fasta/server/actions/patch'
5
+ require 'fasta/server/actions/put'
6
+ require 'fasta/server/actions/show'
7
+
8
+ module Fasta
9
+ module Server
10
+ module Actions
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'fasta/server/core/responder'
2
+
3
+ module Fasta
4
+ module Server
5
+ module Core
6
+ class Read < Responder
7
+ def call
8
+ @body = fetch
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,100 @@
1
+ require 'oj'
2
+ require 'sequel'
3
+ require 'logger'
4
+ require 'pg'
5
+ require 'yaml'
6
+ require 'erb'
7
+
8
+ db_log_file = File.open('log/db.log', File::WRONLY | File::APPEND | File::CREAT) rescue 0
9
+ request_log_file = File.open('log/request.log', File::WRONLY | File::APPEND | File::CREAT) rescue 0
10
+ $logger = ::Logger.new(request_log_file)
11
+ $logger.level = Logger::INFO
12
+
13
+ $db_hash = YAML.load(ERB.new(File.read(File.join("config","database.yml"))).result)[ENV.fetch('RACK_ENV', 'development')]
14
+ $database = Sequel.connect($db_hash.merge(logger: ::Logger.new(db_log_file)))
15
+
16
+ module Fasta
17
+ module Server
18
+ module Core
19
+ class Responder
20
+ DB = $database
21
+
22
+ class << self
23
+ def validate_fields(*fields)
24
+ @fields = fields
25
+ end
26
+
27
+ def call(env)
28
+ request = Rack::Request.new(env)
29
+ instance = new(request)
30
+ instance.call
31
+ instance.to_rack_array
32
+ end
33
+ end
34
+
35
+ attr_reader :request, :params, :headers
36
+
37
+ def initialize(request)
38
+ $logger.info request
39
+ @request = request
40
+ @params = request.env['router.params']
41
+ @headers = default_response_headers
42
+ end
43
+
44
+ def db_table
45
+ DB[db_table_name]
46
+ end
47
+
48
+ def db_table_name
49
+ Object.const_get(self.class.to_s.rpartition('::').first).db_table_name
50
+ end
51
+
52
+ def call; end
53
+
54
+ def to_rack_array
55
+ [http_response_code, http_response_headers, http_response_body]
56
+ end
57
+
58
+ def response_code
59
+ @response_code || default_response_code
60
+ end
61
+
62
+ def body
63
+ {
64
+ code: http_response_code,
65
+ result: @body,
66
+ meta: meta
67
+ }
68
+ end
69
+
70
+ private
71
+
72
+ def meta
73
+ {
74
+ server_time: Time.now.to_i
75
+ }
76
+ end
77
+
78
+ def default_response_code
79
+ 200
80
+ end
81
+
82
+ def http_response_code
83
+ params['suppress_response_code'] ? 200 : response_code
84
+ end
85
+
86
+ def default_response_headers
87
+ { 'Content-Type' => 'application/json' }.dup
88
+ end
89
+
90
+ def http_response_headers
91
+ @headers
92
+ end
93
+
94
+ def http_response_body
95
+ [Oj.dump(body, mode: :compat)]
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,38 @@
1
+ require 'fasta/server/core/responder'
2
+
3
+ module Fasta
4
+ module Server
5
+ module Core
6
+ class Write < Responder
7
+ def call
8
+ @body = valid_params? ? success : failure
9
+ end
10
+
11
+ private
12
+
13
+ def valid_params?
14
+ params_fields.map { |field| params[field] }.all?
15
+ end
16
+
17
+ def params_fields
18
+ self.class.instance_variable_get(:@fields)
19
+ end
20
+
21
+ def success; end
22
+
23
+ def failure
24
+ @response_code = 400
25
+ { error: 'Invalid params' }
26
+ end
27
+
28
+ def default_updated_at
29
+ { updated_at: Time.now }
30
+ end
31
+
32
+ def default_attributes
33
+ { created_at: Time.now }.merge(default_updated_at)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Fasta
2
+ VERSION = "0.2.0"
3
+ end
data/lib/fasta.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'fasta/cli'
2
+ require 'fasta/version'
3
+ require 'fasta/app/endpoints/model'
4
+
5
+ module Fasta
6
+ class Error < StandardError; end
7
+ end
@@ -0,0 +1,4 @@
1
+ task :console do
2
+ puts 'starting console'
3
+ sh "irb -r ./application.rb"
4
+ end
@@ -0,0 +1,65 @@
1
+ require 'yaml'
2
+ require "sequel"
3
+
4
+ namespace :db do
5
+ env = ENV.fetch('RACK_ENV', 'development')
6
+ puts "Processing task in #{env} environment."
7
+
8
+ $db_hash = YAML.load(File.read("config/database.yml"))[env] rescue {}
9
+ encoding = $db_hash['encoding'] || ENV['CHARSET'] || 'utf8'
10
+ Sequel.extension :migration
11
+ DB = -> { Sequel.connect($db_hash) }
12
+
13
+ desc 'Create db'
14
+ task :create do
15
+ begin
16
+ system("createdb", "-E", encoding, "-h", $db_hash['host'], $db_hash['database'])
17
+ Sequel.connect($db_hash)
18
+ puts 'Database created:', $db_hash['database']
19
+ rescue => e
20
+ puts e
21
+ puts "Oops"
22
+ end
23
+ end
24
+
25
+ desc 'Drop db'
26
+ task :drop do
27
+ begin
28
+ DB.call.disconnect
29
+ system("dropdb", "-h", $db_hash['host'], $db_hash['database'])
30
+ puts 'Database dropped:', $db_hash['database']
31
+ rescue => e
32
+ puts e
33
+ puts "Oops"
34
+ end
35
+ end
36
+
37
+ desc "Prints current schema version"
38
+ task :version do
39
+ version = if DB.call.tables.include?(:schema_info)
40
+ DB.call[:schema_info].first[:version]
41
+ end || 0
42
+ puts "Schema Version: #{version}"
43
+ end
44
+
45
+ desc "Perform migration up to latest migration available"
46
+ task :migrate do
47
+ Sequel::Migrator.run(DB.call, "db/migrations")
48
+ Rake::Task['db:version'].execute
49
+ end
50
+
51
+ desc "Perform rollback to specified target or full rollback as default"
52
+ task :rollback, :target do |t, args|
53
+ args.with_defaults(:target => 0)
54
+
55
+ Sequel::Migrator.run(DB.call, "db/migrations", :target => args[:target].to_i)
56
+ Rake::Task['db:version'].execute
57
+ end
58
+
59
+ desc "Perform migration reset (full rollback and migration)"
60
+ task :reset do
61
+ Sequel::Migrator.run(DB.call, "db/migrations", :target => 0)
62
+ Sequel::Migrator.run(DB.call, "db/migrations")
63
+ Rake::Task['db:version'].execute
64
+ end
65
+ end
data/templates/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.5.1'
3
+
4
+ gem 'fasta'
@@ -0,0 +1 @@
1
+ web: puma boot.ru -e production -p $PORT
@@ -0,0 +1,2 @@
1
+ spec = Gem::Specification.find_by_name 'fasta'
2
+ load "#{spec.gem_dir}/tasks/database.rake"
@@ -0,0 +1,11 @@
1
+ module User
2
+ class Boards < Fasta::Model::Show
3
+ validate_fields :id
4
+
5
+ def fetch
6
+ user_id = params[:id]
7
+ through = DB[:users_boards].where(user_id: user_id)
8
+ DB[:boards].where(id: through.select(:board_id)).to_a
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module User
2
+ class Create < Fasta::Model::Create
3
+ validate_fields :email, :phone_number
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module User
2
+ class Delete < Fasta::Model::Delete
3
+ validate_fields :id
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module User
2
+ class Index < Fasta::Model::Index; end
3
+ end
@@ -0,0 +1,5 @@
1
+ module User
2
+ class Patch < Fasta::Model::Patch
3
+ validate_fields :id
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module User
2
+ class Put < Fasta::Model::Put
3
+ validate_fields :id
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module User
2
+ class Show < Fasta::Model::Show
3
+ validate_fields :id
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module User
2
+ extend Fasta::Model
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'fasta'
2
+ require './config/environment'
3
+ Dir['./app/endpoints/**/*.rb'].each { |file| require file }
4
+ Dir['./app/endpoints/**/**/*.rb'].each { |file| require file }
5
+
6
+ require './config/routes.rb'
data/templates/boot.ru ADDED
@@ -0,0 +1,3 @@
1
+ require './application.rb'
2
+
3
+ run $router
@@ -0,0 +1,22 @@
1
+ development:
2
+ adapter: :postgres
3
+ host: localhost
4
+ port: 5432
5
+ database: 'dodoshka_development'
6
+ max_connections: 10
7
+
8
+ production:
9
+ adapter: :postgres
10
+ host: 'ec2-79-125-119-70.eu-west-1.compute.amazonaws.com'
11
+ port: 5432
12
+ database: 'd9pseukhs9ukkm'
13
+ user: 'pruwpijfbzumyl'
14
+ password: 'ff435e3a4ac5a829b4b7f39e845af3d66c8a404a9de521387ca1faefc1201ad5'
15
+ max_connections: 10
16
+
17
+ test:
18
+ adapter: :postgres
19
+ host: localhost
20
+ port: 5432
21
+ database: 'dodoshka_test'
22
+ max_connections: 10
@@ -0,0 +1,12 @@
1
+ # Load environment
2
+ # Development by default
3
+
4
+ if ENV.fetch('RACK_ENV', nil).nil?
5
+ require_relative 'environments/development.rb'
6
+ else
7
+ begin
8
+ require_relative "environments/#{ENV.fetch('RACK_ENV')}.rb"
9
+ rescue LoadError
10
+ require_relative 'environments/development.rb'
11
+ end
12
+ end
@@ -0,0 +1,2 @@
1
+ ENV['RACK_ENV'] = 'development'
2
+ puts "Load #{ENV['RACK_ENV']} mode"
@@ -0,0 +1,4 @@
1
+ # Use strings to set values
2
+
3
+ ENV['RACK_ENV'] = 'production'
4
+ puts "Load #{ENV['RACK_ENV']} mode"
@@ -0,0 +1,2 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+ puts "Load #{ENV['RACK_ENV']} mode"
@@ -0,0 +1,12 @@
1
+ # threads_count = ENV.fetch('RAILS_MAX_THREADS') { 64 }.to_i
2
+ # threads threads_count, threads_count
3
+ # port ENV.fetch('PORT') { $PORT }
4
+
5
+ # ENV = {}
6
+
7
+ # environment ENV.fetch('RACK_ENV', 'development') # default development
8
+ # puts ENV
9
+ # workers ENV.fetch("WEB_CONCURRENCY") { 1 }
10
+ # preload_app!
11
+
12
+ # plugin :tmp_restart
@@ -0,0 +1,19 @@
1
+ require 'hanami/router'
2
+
3
+ $router = Hanami::Router.new(parsers: [:json]) do
4
+ action = ->(klass) { ->(env) { klass.call(env) } }
5
+
6
+ root to: ->(_env) { [200, {}, ['Welcome to API']] }
7
+
8
+ get '/users', to: action.call(User::Index)
9
+ post '/users', to: action.call(User::Create)
10
+ get '/users/:id', to: action.call(User::Show)
11
+ put '/users/:id', to: action.call(User::Put)
12
+ patch '/users/:id', to: action.call(User::Patch)
13
+ delete '/users/:id', to: action.call(User::Delete)
14
+ get '/users/:id/boards', to: action.call(User::Boards)
15
+
16
+ # get '/accounts', to: action.call(Account::Index)
17
+ # get '/accounts/:id', to: action.call(Account::Show)
18
+ # get 'team/users', to: action.call(Team::User::Index)
19
+ end
@@ -0,0 +1,12 @@
1
+ Sequel.migration do
2
+ change do
3
+ create_table(:users) do
4
+ primary_key :id
5
+ String :name, size: 20, null: false
6
+ String :email, size: 60, null: true
7
+ String :phone_number, size: 20, null: true
8
+ DateTime :created_at, null: false
9
+ DateTime :updated_at, null: false
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fasta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaro
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.2'
89
+ version: '1.3'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.2'
96
+ version: '1.3'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rack
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -167,10 +167,70 @@ dependencies:
167
167
  description: Rack Server API
168
168
  email:
169
169
  - osyaroslav@gmail.com
170
- executables: []
170
+ executables:
171
+ - fasta
171
172
  extensions: []
172
173
  extra_rdoc_files: []
173
- files: []
174
+ files:
175
+ - ".gitignore"
176
+ - ".idea/fasta.iml"
177
+ - ".idea/misc.xml"
178
+ - ".idea/modules.xml"
179
+ - ".idea/vcs.xml"
180
+ - ".rspec"
181
+ - ".travis.yml"
182
+ - CODE_OF_CONDUCT.md
183
+ - Gemfile
184
+ - LICENSE.txt
185
+ - README.md
186
+ - Rakefile
187
+ - bin/console
188
+ - bin/setup
189
+ - exe/fasta
190
+ - fasta.gemspec
191
+ - lib/fasta.rb
192
+ - lib/fasta/app/endpoints/model.rb
193
+ - lib/fasta/app/endpoints/model/create.rb
194
+ - lib/fasta/app/endpoints/model/delete.rb
195
+ - lib/fasta/app/endpoints/model/index.rb
196
+ - lib/fasta/app/endpoints/model/patch.rb
197
+ - lib/fasta/app/endpoints/model/put.rb
198
+ - lib/fasta/app/endpoints/model/show.rb
199
+ - lib/fasta/cli.rb
200
+ - lib/fasta/server/actions.rb
201
+ - lib/fasta/server/actions/create.rb
202
+ - lib/fasta/server/actions/delete.rb
203
+ - lib/fasta/server/actions/index.rb
204
+ - lib/fasta/server/actions/patch.rb
205
+ - lib/fasta/server/actions/put.rb
206
+ - lib/fasta/server/actions/show.rb
207
+ - lib/fasta/server/core/read.rb
208
+ - lib/fasta/server/core/responder.rb
209
+ - lib/fasta/server/core/write.rb
210
+ - lib/fasta/version.rb
211
+ - tasks/console.rake
212
+ - tasks/database.rake
213
+ - templates/Gemfile
214
+ - templates/Procfile
215
+ - templates/Rakefile
216
+ - templates/app/endpoints/user.rb
217
+ - templates/app/endpoints/user/boards.rb
218
+ - templates/app/endpoints/user/create.rb
219
+ - templates/app/endpoints/user/delete.rb
220
+ - templates/app/endpoints/user/index.rb
221
+ - templates/app/endpoints/user/patch.rb
222
+ - templates/app/endpoints/user/put.rb
223
+ - templates/app/endpoints/user/show.rb
224
+ - templates/application.rb
225
+ - templates/boot.ru
226
+ - templates/config/database.yml
227
+ - templates/config/environment.rb
228
+ - templates/config/environments/development.rb
229
+ - templates/config/environments/production.rb
230
+ - templates/config/environments/test.rb
231
+ - templates/config/puma.rb
232
+ - templates/config/routes.rb
233
+ - templates/db/migrations/001_create_users_table.rb
174
234
  homepage: http://github.com/vergilet/fasta
175
235
  licenses:
176
236
  - MIT
@@ -179,7 +239,6 @@ post_install_message:
179
239
  rdoc_options: []
180
240
  require_paths:
181
241
  - lib
182
- - tasks
183
242
  required_ruby_version: !ruby/object:Gem::Requirement
184
243
  requirements:
185
244
  - - ">="
@@ -192,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
251
  version: '0'
193
252
  requirements: []
194
253
  rubyforge_project:
195
- rubygems_version: 2.7.3
254
+ rubygems_version: 2.7.7
196
255
  signing_key:
197
256
  specification_version: 4
198
257
  summary: Fasta is a mini web framework