strain 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +17 -0
  6. data/Guardfile +72 -0
  7. data/LICENSE +20 -0
  8. data/README.md +74 -0
  9. data/Rakefile +26 -0
  10. data/app/assets/javascripts/strain/jsonapi/articles.js +2 -0
  11. data/app/assets/javascripts/strain/jsonapi/variants.js +2 -0
  12. data/app/assets/stylesheets/strain/jsonapi/articles.css +4 -0
  13. data/app/assets/stylesheets/strain/jsonapi/variants.css +4 -0
  14. data/app/controllers/strain/application_controller.rb +5 -0
  15. data/app/controllers/strain/jsonapi/articles_controller.rb +6 -0
  16. data/app/controllers/strain/jsonapi/jsonapi_controller.rb +10 -0
  17. data/app/controllers/strain/jsonapi/variants_controller.rb +7 -0
  18. data/app/helpers/strain/jsonapi/articles_helper.rb +4 -0
  19. data/app/helpers/strain/jsonapi/variants_helper.rb +4 -0
  20. data/app/models/strain/article.rb +37 -0
  21. data/app/models/strain/variant.rb +32 -0
  22. data/app/resources/strain/jsonapi/article_resource.rb +21 -0
  23. data/app/resources/strain/jsonapi/variant_resource.rb +16 -0
  24. data/bin/_guard-core +16 -0
  25. data/bin/guard +16 -0
  26. data/bin/rails +12 -0
  27. data/bin/rake +16 -0
  28. data/bin/rspec +16 -0
  29. data/config/initializers/jsonapi_resources.rb +4 -0
  30. data/config/routes.rb +8 -0
  31. data/db/migrate/20151103060035_enable_uuid.rb +5 -0
  32. data/db/migrate/20151103060224_create_strain_variants.rb +11 -0
  33. data/db/migrate/20151104200908_create_strain_articles.rb +14 -0
  34. data/lib/json_schema/draft_4_meta_schema.json +150 -0
  35. data/lib/strain/engine.rb +21 -0
  36. data/lib/strain/schema_tools/defaults.rb +53 -0
  37. data/lib/strain/version.rb +3 -0
  38. data/lib/strain.rb +17 -0
  39. data/lib/tasks/strain_tasks.rake +4 -0
  40. data/spec/factories/strain_articles.rb +15 -0
  41. data/spec/factories/strain_variants.rb +34 -0
  42. data/spec/lib/strain/schema_tools/defaults_spec.rb +234 -0
  43. data/spec/models/strain/article_spec.rb +72 -0
  44. data/spec/models/strain/variant_spec.rb +42 -0
  45. data/spec/rails_helper.rb +59 -0
  46. data/spec/requests/strain/jsonapi/articles_spec.rb +220 -0
  47. data/spec/requests/strain/jsonapi/variants_spec.rb +159 -0
  48. data/spec/spec_helper.rb +99 -0
  49. data/spec/test_app/README.rdoc +28 -0
  50. data/spec/test_app/Rakefile +6 -0
  51. data/spec/test_app/app/assets/javascripts/application.js +13 -0
  52. data/spec/test_app/app/assets/stylesheets/application.css +15 -0
  53. data/spec/test_app/app/controllers/application_controller.rb +5 -0
  54. data/spec/test_app/app/helpers/application_helper.rb +2 -0
  55. data/spec/test_app/app/models/tweet.rb +4 -0
  56. data/spec/test_app/app/views/layouts/application.html.erb +14 -0
  57. data/spec/test_app/bin/bundle +3 -0
  58. data/spec/test_app/bin/rails +4 -0
  59. data/spec/test_app/bin/rake +4 -0
  60. data/spec/test_app/bin/setup +29 -0
  61. data/spec/test_app/config/application.rb +32 -0
  62. data/spec/test_app/config/boot.rb +5 -0
  63. data/spec/test_app/config/database.yml +85 -0
  64. data/spec/test_app/config/environment.rb +5 -0
  65. data/spec/test_app/config/environments/development.rb +41 -0
  66. data/spec/test_app/config/environments/production.rb +79 -0
  67. data/spec/test_app/config/environments/test.rb +42 -0
  68. data/spec/test_app/config/initializers/assets.rb +11 -0
  69. data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
  70. data/spec/test_app/config/initializers/cookies_serializer.rb +3 -0
  71. data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
  72. data/spec/test_app/config/initializers/inflections.rb +16 -0
  73. data/spec/test_app/config/initializers/mime_types.rb +4 -0
  74. data/spec/test_app/config/initializers/session_store.rb +3 -0
  75. data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
  76. data/spec/test_app/config/locales/en.yml +23 -0
  77. data/spec/test_app/config/routes.rb +4 -0
  78. data/spec/test_app/config/secrets.yml +22 -0
  79. data/spec/test_app/config.ru +4 -0
  80. data/spec/test_app/db/schema.rb +42 -0
  81. data/spec/test_app/log/development.log +2854 -0
  82. data/spec/test_app/log/test.log +40082 -0
  83. data/spec/test_app/public/404.html +67 -0
  84. data/spec/test_app/public/422.html +67 -0
  85. data/spec/test_app/public/500.html +66 -0
  86. data/spec/test_app/public/favicon.ico +0 -0
  87. metadata +262 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d8bd2143f350cd14055cb960e4a5417ecb399aa1
4
+ data.tar.gz: 33c4f04e99b02f07346ade026a40922459b2ea55
5
+ SHA512:
6
+ metadata.gz: af675aa2058612873c92964fc55fee788daff7785dab78cc7250c2ccf96bb6bb3b793034a3b7cd6f1ceeeaec74bc109c2c353cca65d1a21ad761fa260240247a
7
+ data.tar.gz: 93da7fab31a045e687a062b50a79a4a3ed172de27934a9b30498b6d54e17e5272a3acd5b1cc4ebff9ee4e31303258d640c1186437ad1f8280493352a246df38c
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ Gemfile.lock
2
+ *.gem
3
+
4
+ .bundle/
5
+ log/*.log
6
+ pkg/
7
+
8
+ spec/test_app/db/*.sqlite3
9
+ spec/test_app/db/*.sqlite3-journal
10
+ spec/test_app/log/*.log
11
+ spec/test_app/tmp/
12
+ spec/test_app/.sass-cache
13
+ spec/reports/
14
+ spec/examples.txt
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in strain.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use a debugger
14
+ gem 'pry-rails', group: [:development, :test]
15
+ # gem 'jsonapi-resources', path: '~/dev/opc/jr-new/jsonapi-resources'
16
+ # gem 'jsonapi-resources', :git => 'git://github.com/ggordon/jsonapi-resources.git', :ref => '7a943c883c9cc4cec748de39593ce368c467c7ab'
17
+ gem 'jsonapi-resources', :git => 'git://github.com/cerebris/jsonapi-resources.git', :ref => '730f751'
data/Guardfile ADDED
@@ -0,0 +1,72 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bin/rspec" do
28
+ clearing :on
29
+ require "guard/rspec/dsl"
30
+ dsl = Guard::RSpec::Dsl.new(self)
31
+
32
+ # Feel free to open issues for suggestions and improvements
33
+
34
+ # RSpec files
35
+ rspec = dsl.rspec
36
+ watch(rspec.spec_helper) { rspec.spec_dir }
37
+ watch(rspec.spec_support) { rspec.spec_dir }
38
+ watch(rspec.spec_files)
39
+
40
+ # Ruby files
41
+ ruby = dsl.ruby
42
+ dsl.watch_spec_files_for(ruby.lib_files)
43
+
44
+ # Rails files
45
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
46
+ dsl.watch_spec_files_for(rails.app_files)
47
+ dsl.watch_spec_files_for(rails.views)
48
+
49
+ watch(rails.controllers) do |m|
50
+ [
51
+ # rspec.spec.("routing/#{m[1]}_routing"),
52
+ # rspec.spec.("controllers/#{m[1]}_controller"),
53
+ # rspec.spec.("acceptance/#{m[1]}"),
54
+ rspec.spec.("requests/#{m[1]}")
55
+ ]
56
+ end
57
+
58
+ # Rails config changes
59
+ watch(rails.spec_helper) { rspec.spec_dir }
60
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
61
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
62
+
63
+ # Capybara features specs
64
+ # watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
65
+ # watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
66
+
67
+ # Turnip features and steps
68
+ # watch(%r{^spec/acceptance/(.+)\.feature$})
69
+ # watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
70
+ # Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
71
+ # end
72
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Adam Worrall
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Strain
2
+
3
+
4
+ ## Description
5
+
6
+ ### What does it do?
7
+
8
+
9
+ Strain is an experimental Rails engine that exposes [JSON API][1] endpoints for quickly defining and editing structured content. By providing a [JSON Schema][2] you get user-editable content types with shared server-side and client-side validation and, through the upcoming `Strain-admin` editor, autogenerated rich admin interfaces built with React.
10
+
11
+ Once your content models are stable, you can extend the underlying models with STI to add additional logic. In the future, Strain will be able to generate migrations to promote your content types to full-fledged ActiveRecord models.
12
+
13
+ _Note: This gem is experimental, and will be changing rapidly._
14
+
15
+ [1]: http://google.com/ "JSON API"
16
+ [2]: http://json-schema.org/ "JSON Schema"
17
+
18
+ ### Why do this?
19
+
20
+ http://alistapart.com/article/future-ready-content
21
+
22
+ TODO
23
+
24
+ ## Requirements
25
+
26
+ - Ruby 2.0.0
27
+ - PostgreSQL 9.4 (for `jsonb` support)
28
+ - Rails 4.2
29
+
30
+ ## Installation
31
+
32
+ ### Install Strain and its dependencies
33
+
34
+ Add Strain to your Rails application's `Gemfile`. As of 0.0.1, Strain also depends on a prerelease version of `jsonapi-resources` that needs to be added to your `Gemfile`. This requirement will be eliminated as soon as possible.
35
+
36
+ ``` ruby
37
+ gem 'strain'
38
+ gem 'jsonapi-resources', :git => 'git://github.com/cerebris/jsonapi-resources.git', :ref => '730f751'
39
+ ```
40
+
41
+ After adding the above lines to your `Gemfile`, run:
42
+
43
+ ```
44
+ $ bundle
45
+ ```
46
+
47
+ ### Install migrations
48
+
49
+ After installing the gem, install and run the migrations needed to set up the Strain database tables. This will also enable the Postgres UUID extension.
50
+
51
+ ```
52
+ $ rake strain:install:migrations
53
+ $ rake db:migrate
54
+ ```
55
+
56
+ ### Mount the engine
57
+
58
+ In `routes.rb`, specify the route that you'd like the Strain controller to handle:
59
+
60
+ ```
61
+ mount Strain::Engine => "/strain"
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ TODO
67
+
68
+ ## Feedback
69
+
70
+ I'd love to discuss any ideas or suggestions you might have. Please file an issue or get in touch with @remedy on Twitter.
71
+
72
+ ## License
73
+
74
+ Copyright 2015 Adam Worrall. MIT License (see LICENSE for details).
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Strain'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ # Bundler::GemHelper.install_tasks
26
+
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,5 @@
1
+ module Strain
2
+ class ApplicationController < ActionController::Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require_dependency "strain/application_controller"
2
+
3
+ module Strain
4
+ class Jsonapi::ArticlesController < Strain::Jsonapi::JsonapiController
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ # require_dependency "strain/application_controller"
2
+
3
+ module Strain
4
+ class Jsonapi::JsonapiController < Strain::ApplicationController
5
+
6
+ include JSONAPI::ActsAsResourceController
7
+
8
+ end
9
+ end
10
+
@@ -0,0 +1,7 @@
1
+ # require_dependency "strain/application_controller"
2
+
3
+ module Strain
4
+ class Jsonapi::VariantsController < Strain::Jsonapi::JsonapiController
5
+ end
6
+ end
7
+
@@ -0,0 +1,4 @@
1
+ module Strain
2
+ module Jsonapi::ArticlesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Strain
2
+ module Jsonapi::VariantsHelper
3
+ end
4
+ end
@@ -0,0 +1,37 @@
1
+ module Strain
2
+ class Article < ActiveRecord::Base
3
+ belongs_to :variant, inverse_of: :articles
4
+
5
+ self.inheritance_column = :strain_type
6
+
7
+ delegate :schema, to: :variant
8
+ delegate :name, to: :variant, prefix: true
9
+
10
+ before_validation :set_defaults_from_schema
11
+
12
+ validates_presence_of :slug, :variant, :body, :title
13
+ validates :slug, format: {
14
+ with: /\A[a-z0-9-]+\z/,
15
+ message: "must contain only letters, numbers, and hyphens."}
16
+ validates :slug, uniqueness: { case_sensitive: false }
17
+ validate :body_must_conform_to_variant_schema
18
+
19
+ private
20
+
21
+ def set_defaults_from_schema
22
+ return if variant.nil?
23
+ return if body.nil?
24
+ return if title.nil?
25
+ self.body = Strain::SchemaTools::Defaults.new(schema, body).data_with_defaults
26
+ end
27
+
28
+ def body_must_conform_to_variant_schema
29
+ return if variant.nil?
30
+ # JSON::Validator.fully_validate(schema, body.to_h, errors_as_objects: true)
31
+ unless JSON::Validator.validate(schema, body.to_h)
32
+ errors.add(:body, "does not conform to #{variant.name} schema.")
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ module Strain
2
+ class Variant < ActiveRecord::Base
3
+
4
+ has_many :articles, inverse_of: :variant
5
+
6
+ validates_presence_of :name
7
+ validates_presence_of :schema
8
+ validate :schema_must_be_valid
9
+ validate :schema_root_must_be_object
10
+ validates :name, uniqueness: { case_sensitive: false }
11
+
12
+ private
13
+
14
+ def schema_must_be_valid
15
+ meta_schema = JSON.load(
16
+ File.read("#{::Strain::Engine.root}/lib/json_schema/draft_4_meta_schema.json")
17
+ )
18
+ unless JSON::Validator.validate(meta_schema, self.schema)
19
+ errors.add(:schema, "must be a valid Draft 4 JSON Variant.")
20
+ end
21
+ end
22
+
23
+ def schema_root_must_be_object
24
+ return if schema.blank?
25
+ #TODO: check for schema w/o 'type' key set at all
26
+ unless schema.fetch("type") == "object"
27
+ errors.add(:schema, "must have an object as root element.")
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ module Strain
2
+ class Jsonapi::ArticleResource < JSONAPI::Resource
3
+ model_name "::Strain::Article"
4
+
5
+ attribute :slug
6
+ attribute :title
7
+ attribute :variant_id
8
+ # attribute :variant
9
+ attribute :schema
10
+ attribute :variant_name
11
+ attribute :body
12
+
13
+ relationship :variant, to: :one
14
+
15
+ # https://github.com/cerebris/jsonapi-resources/issues/523
16
+ def self.resource_type_for(model)
17
+ 'strain/jsonapi/article'
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ module Strain
2
+ class Jsonapi::VariantResource < JSONAPI::Resource
3
+ model_name "::Strain::Variant"
4
+
5
+ attribute :name
6
+ attribute :schema
7
+
8
+ relationship :articles, to: :many
9
+
10
+ # https://github.com/cerebris/jsonapi-resources/issues/523
11
+ def self.resource_type_for(model)
12
+ 'strain/jsonapi/variant'
13
+ end
14
+
15
+ end
16
+ end
data/bin/_guard-core ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application '_guard-core' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('guard', '_guard-core')
data/bin/guard ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'guard' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('guard', 'guard')
data/bin/rails ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/strain/engine', __FILE__)
6
+
7
+ # Set up gems listed in the Gemfile.
8
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
10
+
11
+ require 'rails/all'
12
+ require 'rails/engine/commands'
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -0,0 +1,4 @@
1
+ JSONAPI.configure do |config|
2
+ # Allowed values are :integer(default), :uuid, :string, or a proc
3
+ config.resource_key_type = :uuid
4
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,8 @@
1
+ Strain::Engine.routes.draw do
2
+
3
+ namespace :jsonapi do
4
+ jsonapi_resources :variants
5
+ jsonapi_resources :articles
6
+ end
7
+
8
+ end
@@ -0,0 +1,5 @@
1
+ class EnableUuid < ActiveRecord::Migration
2
+ def change
3
+ enable_extension 'uuid-ossp'
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class CreateStrainVariants < ActiveRecord::Migration
2
+ def change
3
+ create_table :strain_variants, id: :uuid do |t|
4
+ t.string :name, null: false
5
+ t.jsonb :schema, null: false
6
+
7
+ t.timestamps null: false
8
+ end
9
+ add_index :strain_variants, :name, :unique => true
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ class CreateStrainArticles < ActiveRecord::Migration
2
+ def change
3
+ create_table :strain_articles, id: :uuid do |t|
4
+ t.uuid :variant_id, index: true, foreign_key: true
5
+ t.string :strain_type, null: false, default: 'Strain::Article'
6
+ t.string :title, null: false
7
+ t.jsonb :body, null: false
8
+ t.string :slug, null: false
9
+
10
+ t.timestamps null: false
11
+ end
12
+ add_index :strain_articles, :slug, :unique => true
13
+ end
14
+ end