rodakase 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +34 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +29 -0
  5. data/CHANGELOG.md +8 -0
  6. data/CODE_OF_CONDUCT.md +13 -0
  7. data/Gemfile +24 -0
  8. data/LICENSE +22 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +114 -0
  11. data/Rakefile +4 -0
  12. data/benchmarks/templates/button.erb +1 -0
  13. data/benchmarks/view.rb +27 -0
  14. data/lib/roda/plugins/flow.rb +71 -0
  15. data/lib/rodakase.rb +8 -0
  16. data/lib/rodakase/application.rb +32 -0
  17. data/lib/rodakase/cli.rb +9 -0
  18. data/lib/rodakase/component.rb +40 -0
  19. data/lib/rodakase/config.rb +21 -0
  20. data/lib/rodakase/container.rb +127 -0
  21. data/lib/rodakase/transaction.rb +43 -0
  22. data/lib/rodakase/transaction/matcher.rb +31 -0
  23. data/lib/rodakase/transaction/result.rb +52 -0
  24. data/lib/rodakase/version.rb +3 -0
  25. data/lib/rodakase/view.rb +2 -0
  26. data/lib/rodakase/view/layout.rb +98 -0
  27. data/lib/rodakase/view/part.rb +53 -0
  28. data/lib/rodakase/view/renderer.rb +67 -0
  29. data/rodakase.gemspec +34 -0
  30. data/skeletons/simple/Gemfile +9 -0
  31. data/skeletons/simple/Rakefile +4 -0
  32. data/skeletons/simple/bin/console +6 -0
  33. data/skeletons/simple/config.ru +3 -0
  34. data/skeletons/simple/config/application.yml +4 -0
  35. data/skeletons/simple/core/boot.rb +12 -0
  36. data/skeletons/simple/core/simple/application.rb +16 -0
  37. data/skeletons/simple/core/simple/container.rb +11 -0
  38. data/skeletons/simple/core/simple/import.rb +9 -0
  39. data/skeletons/simple/lib/entities/user.rb +3 -0
  40. data/skeletons/simple/log/.gitkeep +0 -0
  41. data/skeletons/simple/spec/routes/heartbeat_spec.rb +9 -0
  42. data/skeletons/simple/spec/spec_helper.rb +12 -0
  43. data/skeletons/simple/spec/unit/user_spec.rb +17 -0
  44. data/skeletons/simple/spec/web_helper.rb +20 -0
  45. data/skeletons/simple/web/routes/root.rb +3 -0
  46. data/spec/dummy/apps/main/core/boot.rb +9 -0
  47. data/spec/dummy/apps/main/core/main/application.rb +17 -0
  48. data/spec/dummy/apps/main/core/main/container.rb +12 -0
  49. data/spec/dummy/apps/main/core/main/import.rb +9 -0
  50. data/spec/dummy/apps/main/core/main/requests.rb +21 -0
  51. data/spec/dummy/apps/main/core/main/view.rb +19 -0
  52. data/spec/dummy/apps/main/lib/entities/user.rb +3 -0
  53. data/spec/dummy/apps/main/lib/persistence/repositories/users.rb +14 -0
  54. data/spec/dummy/apps/main/lib/transaction.rb +11 -0
  55. data/spec/dummy/apps/main/lib/transactions/register_user.rb +17 -0
  56. data/spec/dummy/apps/main/lib/views/users/index.rb +15 -0
  57. data/spec/dummy/apps/main/requests/users.rb +5 -0
  58. data/spec/dummy/apps/main/web/routes/users.rb +21 -0
  59. data/spec/dummy/apps/main/web/templates/layouts/app.slim +6 -0
  60. data/spec/dummy/apps/main/web/templates/users/index.slim +3 -0
  61. data/spec/dummy/apps/main/web/templates/users/index/_list.slim +3 -0
  62. data/spec/dummy/apps/main/web/templates/users/index/_list_item.slim +1 -0
  63. data/spec/dummy/bin/console +6 -0
  64. data/spec/dummy/config.ru +3 -0
  65. data/spec/dummy/config/application.yml +4 -0
  66. data/spec/dummy/core/boot.rb +15 -0
  67. data/spec/dummy/core/dummy/container.rb +14 -0
  68. data/spec/dummy/core/dummy/import.rb +9 -0
  69. data/spec/dummy/lib/persistence/db.rb +13 -0
  70. data/spec/dummy/log/.gitkeep +0 -0
  71. data/spec/fixtures/templates/hello.slim +1 -0
  72. data/spec/fixtures/templates/layouts/app.slim +6 -0
  73. data/spec/fixtures/templates/shared/_index_table.slim +2 -0
  74. data/spec/fixtures/templates/shared/_shared_hello.slim +1 -0
  75. data/spec/fixtures/templates/tasks.slim +3 -0
  76. data/spec/fixtures/templates/user.slim +2 -0
  77. data/spec/fixtures/templates/users.slim +3 -0
  78. data/spec/fixtures/templates/users/_row.slim +2 -0
  79. data/spec/fixtures/templates/users/_tbody.slim +5 -0
  80. data/spec/fixtures/test/core/boot/bar.rb +5 -0
  81. data/spec/fixtures/test/lib/test/dep.rb +4 -0
  82. data/spec/fixtures/test/lib/test/foo.rb +5 -0
  83. data/spec/fixtures/test/lib/test/models.rb +4 -0
  84. data/spec/fixtures/test/lib/test/models/book.rb +6 -0
  85. data/spec/fixtures/test/lib/test/models/user.rb +6 -0
  86. data/spec/integration/application_spec.rb +21 -0
  87. data/spec/integration/transaction_spec.rb +85 -0
  88. data/spec/integration/view_spec.rb +65 -0
  89. data/spec/request/users_spec.rb +35 -0
  90. data/spec/spec_helper.rb +44 -0
  91. data/spec/support/helpers.rb +15 -0
  92. data/spec/unit/component_spec.rb +60 -0
  93. data/spec/unit/container_spec.rb +51 -0
  94. data/spec/unit/view/layout_spec.rb +49 -0
  95. data/spec/unit/view/part_spec.rb +55 -0
  96. data/spec/unit/view/renderer_spec.rb +29 -0
  97. metadata +359 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 118203bac2270d4e6058be52a74b8b9ec54ec294
4
+ data.tar.gz: bb568d39550a8e72a0f506aeba67c9cb9ea96c17
5
+ SHA512:
6
+ metadata.gz: bbcc8bd412be7d243110aa66bb23750dd0efbde76b9b493d7bcdc0ac1e5b6210fcd20c721aad49555826909e95b0cc8d998870c0d23dddae907e276f1374bba4
7
+ data.tar.gz: 3b1de0df0d26a28c0205a0733b4fe53f69a4193e3a029fbb271d9b4e3663f78413dd6d259290ec714bf595cb9ee72bd3fd323f7b9c243e8a24fcf1301d8e594f
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --order random
3
+ --require ./spec/spec_helper.rb
@@ -0,0 +1,29 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ bundler_args: --without tools benchmarks
5
+ script:
6
+ - bundle exec rake spec
7
+ rvm:
8
+ - 2.0
9
+ - 2.1
10
+ - 2.2
11
+ - rbx-2
12
+ - jruby-9000
13
+ - ruby-head
14
+ - jruby-head
15
+ env:
16
+ global:
17
+ - JRUBY_OPTS='--dev -J-Xmx1024M'
18
+ matrix:
19
+ allow_failures:
20
+ - rvm: ruby-head
21
+ - rvm: jruby-head
22
+ notifications:
23
+ email: false
24
+ webhooks:
25
+ urls:
26
+ - https://webhooks.gitter.im/e/f3ae734607c915f30b21
27
+ on_success: change # options: [always|never|change] default: always
28
+ on_failure: always # options: [always|never|change] default: always
29
+ on_start: false # default: false
@@ -0,0 +1,8 @@
1
+ # v0.0.1 2015-11-13
2
+
3
+ Awesome, first release on Friday 13th. Let's be optimistic. This release ships with:
4
+
5
+ - `Rodakase::Container` API for dependency management and component loading
6
+ - `Rodakase::Application` customized `Roda::Application` API for web part
7
+ - `Rodakase::Transaction` for composing processing pipelines
8
+ - `Rodakase::View` an experimental, helper-less, template-as-data view layer
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rodakase.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'byebug', platform: :mri
8
+ gem 'rack-test'
9
+ gem 'slim'
10
+ gem 'anima', '~> 0.2.0' # >= 0.3.0 requires MRI >= 2.2
11
+
12
+ gem 'dry-data'
13
+
14
+ gem 'codeclimate-test-reporter', platform: :rbx
15
+ end
16
+
17
+ group :tools do
18
+ gem 'pry'
19
+ end
20
+
21
+ group :benchmarks do
22
+ gem 'benchmark-ips'
23
+ gem 'actionview'
24
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Piotr Solnica
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Piotr Solnica
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,114 @@
1
+ [gem]: https://rubygems.org/gems/rom
2
+ [travis]: https://travis-ci.org/solnic/rodakase
3
+ [gemnasium]: https://gemnasium.com/solnic/rodakase
4
+ [codeclimate]: https://codeclimate.com/github/solnic/rodakase
5
+ [inchpages]: http://inch-ci.org/github/solnic/rodakase/
6
+
7
+ # Rodakase [![Join the chat at https://gitter.im/solnic/rodakase](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/solnic/rodakase?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8
+
9
+ [![Gem Version](https://badge.fury.io/rb/rodakase.svg)][gem]
10
+ [![Build Status](https://travis-ci.org/solnic/rodakase.svg?branch=master)][travis]
11
+ [![Dependency Status](https://gemnasium.com/solnic/rodakase.svg)][gemnasium]
12
+ [![Code Climate](https://codeclimate.com/github/solnic/rodakase/badges/gpa.svg)][codeclimate]
13
+ [![Test Coverage](https://codeclimate.com/github/solnic/rodakase/badges/coverage.svg)][codeclimate]
14
+ [![Inline docs](http://inch-ci.org/github/solnic/rodakase.svg?branch=master&style=flat)][inchpages]
15
+
16
+ Rodakase is a lightweight web stack on top of Roda which gives you a foundation
17
+ for building robust web applications while decoupling your application code from
18
+ the framework.
19
+
20
+ There are a couple of core concepts in Rodakase which makes it stand out from the crowd:
21
+
22
+ * Container-based architecture where your application dependencies are accessible
23
+ through a simple IoC container
24
+ * Promotes simple, side-effect-less, functional objects with a built-in auto-injection
25
+ mechanism making it trivial to compose objects
26
+ * Roda routing is decoupled from core application logic and focuses purely on
27
+ http-related concerns (status codes, session, cookies etc.)
28
+ * Rendering is decoupled too, roda routing simply gets response body from *your*
29
+ objects
30
+ * Request processing and response construction in functional style as a series
31
+ of simple "function" calls
32
+ * Extreme focus on proper code organization and reusability, functionality of your
33
+ application should be easily accessible using clear APIs
34
+ * Uses ROM by default for persistence
35
+
36
+ Rodakase says **NO** to the following concepts:
37
+
38
+ * monkey-patching
39
+ * mutable global state
40
+ * hot-code reloading in dev mode leading to additional complexity, nasty gotchas
41
+ and silly constraints with regards to code organization
42
+ * implicit dependency handling through magical const-loading mechanisms
43
+ * tight coupling between web application logic and core domain logic
44
+ * tight coupling between persistence logic and core domain logic
45
+
46
+ ## Sample App
47
+
48
+ A sample rodakase-based web app is [right here](https://github.com/solnic/rodakase-blog).
49
+
50
+ ## Status
51
+
52
+ This project hasn't been released yet. It's under heavy development.
53
+
54
+ ## Tools
55
+
56
+ Rodakase is based on a bunch of awesome libraries:
57
+
58
+ * roda
59
+ * roda-flow
60
+ * dry-container
61
+ * dry-auto_inject
62
+ * tilt
63
+ * transflow
64
+
65
+ ## The Book
66
+
67
+ Rodakase will be described in ["Web Development with ROM and Roda"](https://leanpub.com/web-development-with-rom-and-roda) book
68
+ that I'm working on. If you're interested in the project and/or the book, feel free
69
+ to join [Rodakase gitter channel](https://gitter.im/solnic/rodakase).
70
+
71
+ ## LICENSE
72
+
73
+ See `LICENSE.txt` file.
74
+
75
+ ## Installation
76
+
77
+ Add this line to your application's Gemfile:
78
+
79
+ ```
80
+ gem 'rodakase'
81
+ ```
82
+
83
+ And then execute:
84
+
85
+ ```
86
+ $ bundle
87
+ ```
88
+
89
+ Or install it yourself as:
90
+
91
+ ```
92
+ $ gem install rodakase
93
+ ```
94
+
95
+ ## Development
96
+
97
+ To run the specs make sure the dummy app uses proper db configuration `spec/dummy/config/application.yml`.
98
+ Also you need to run the migrations, do following:
99
+
100
+ ```
101
+ $ cd spec/dummy
102
+ $ bundle install
103
+ $ rake db:migrate
104
+ ```
105
+
106
+ After that you can run the specs from rodakase root:
107
+
108
+ ```
109
+ $ bundle exec rspec
110
+ ```
111
+
112
+ ## Contributing
113
+
114
+ Bug reports and pull requests are welcome on GitHub at https://github.com/solnic/rodakase.
@@ -0,0 +1,4 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task default: [:spec]
@@ -0,0 +1 @@
1
+ <a href="/users/1">User</a>
@@ -0,0 +1,27 @@
1
+ require 'byebug'
2
+
3
+ require 'pathname'
4
+ require 'benchmark/ips'
5
+ require 'rodakase/view/renderer'
6
+ require 'action_view'
7
+
8
+ class ActionRender
9
+ include ActionView::Helpers
10
+
11
+ def button
12
+ link_to('User', '/users/1')
13
+ end
14
+ end
15
+
16
+ action_renderer = ActionRender.new
17
+ rodakase_renderer = Rodakase::View::Renderer.new(Pathname(__FILE__).dirname.join('templates'), engine: :erb)
18
+
19
+ template = rodakase_renderer.dir.join('button.erb')
20
+
21
+ SCOPE = {}
22
+
23
+ Benchmark.ips do |x|
24
+ x.report('actionview') { action_renderer.button }
25
+ x.report('rodakase') { rodakase_renderer.render(template, SCOPE) }
26
+ x.compare!
27
+ end
@@ -0,0 +1,71 @@
1
+ # this is taken from roda-flow plugin but it drops dependency on roda-container
2
+ class Roda
3
+ module RodaPlugins
4
+ module Flow
5
+ module RequestMethods
6
+ def resolve(*args, &block)
7
+ on(resolve: args, &block)
8
+ end
9
+
10
+ private
11
+
12
+ def match_resolve(resolve)
13
+ Array(resolve).flatten.each do |key|
14
+ @captures << roda_class.resolve(key)
15
+ end
16
+ end
17
+
18
+ def match_to(to)
19
+ container_key, @block_method = to.to_s.split('#')
20
+ @block_arg = roda_class.resolve(container_key)
21
+ end
22
+
23
+ def match_inject(inject)
24
+ @block_arg = @block_arg.call(*inject) if @block_arg
25
+ end
26
+
27
+ def match_call_with(call_with)
28
+ @captures.concat(call_with)
29
+ end
30
+
31
+ def if_match(*args, &block)
32
+ path = @remaining_path
33
+ # For every block, we make sure to reset captures so that
34
+ # nesting matchers won't mess with each other's captures.
35
+ @captures.clear
36
+
37
+ return unless match_all(args)
38
+ block_result(get_block(&block).call(*captures))
39
+ throw :halt, response.finish
40
+ ensure
41
+ @remaining_path = path
42
+ end
43
+
44
+ def always(&block)
45
+ super(&get_block(&block))
46
+ end
47
+
48
+ def get_block(&block)
49
+ if block_given?
50
+ block
51
+ elsif @block_arg
52
+ if @block_method
53
+ block_arg = @block_arg.method(@block_method)
54
+ else
55
+ block_arg = @block_arg
56
+ end
57
+ clear_block_args
58
+ block_arg
59
+ end
60
+ end
61
+
62
+ def clear_block_args
63
+ @block_arg = nil
64
+ @block_method = nil
65
+ end
66
+ end
67
+ end
68
+
69
+ register_plugin(:flow, Flow)
70
+ end
71
+ end
@@ -0,0 +1,8 @@
1
+ require 'roda'
2
+ require 'roda/plugins/flow'
3
+
4
+ require 'logger'
5
+
6
+ require 'rodakase/version'
7
+ require 'rodakase/container'
8
+ require 'rodakase/application'
@@ -0,0 +1,32 @@
1
+ require 'roda'
2
+ require 'dry-configurable'
3
+
4
+ module Rodakase
5
+ class Application < Roda
6
+ extend Dry::Configurable
7
+
8
+ setting :container
9
+ setting :routes
10
+
11
+ plugin :multi_route
12
+ plugin :all_verbs
13
+
14
+ plugin :flow
15
+
16
+ def self.resolve(name)
17
+ config.container[name]
18
+ end
19
+
20
+ def self.[](name)
21
+ resolve(name)
22
+ end
23
+
24
+ def self.load_routes!
25
+ Dir[root.join("#{config.routes}/**/*.rb")].each { |f| require f }
26
+ end
27
+
28
+ def self.root
29
+ config.container.config.root
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ require 'pry'
2
+
3
+ module Rodakase
4
+ class Cli
5
+ def self.start
6
+ Pry.start
7
+ end
8
+ end
9
+ end