smooth 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/Gemfile +1 -2
  4. data/README.md +150 -5
  5. data/Rakefile +16 -0
  6. data/app/assets/javascripts/smooth/index.js +5152 -0
  7. data/bin/smooth +9 -0
  8. data/{app/assets/javascripts/smooth → developer-tools}/.keep +0 -0
  9. data/developer-tools/bower.json +8 -0
  10. data/developer-tools/config.ru +3 -0
  11. data/developer-tools/dist/08d606864d3ad3f0b98660d391f5a1c2.gif +0 -0
  12. data/developer-tools/dist/2d66bcdc27cd89f71068e98a7a929712.gif +0 -0
  13. data/developer-tools/dist/3e9816417b11485d454f9b3662b06e7b.eot +0 -0
  14. data/developer-tools/dist/47de617fd1d745ad120ccb9e2924b98c.gif +0 -0
  15. data/developer-tools/dist/5ae23ad29b67289a1375d2043e289c52.eot +0 -0
  16. data/developer-tools/dist/60c2a8500e63bf211b7df9608f7613ea.svg +450 -0
  17. data/developer-tools/dist/645f50ba6c1e56f078fa018855d97eb0.gif +0 -0
  18. data/developer-tools/dist/71ab514d1cedda303417ad7a06472fea.ttf +0 -0
  19. data/developer-tools/dist/8cca2f02b0af2da365ff4d1755f29146.ttf +0 -0
  20. data/developer-tools/dist/939cf252f0eb4efbd2d170c974411c49.gif +0 -0
  21. data/developer-tools/dist/9af25aaeb6ca6d08d213b04841813eb5.gif +0 -0
  22. data/developer-tools/dist/b683029bafe0305ac2234038a03e1541.woff +0 -0
  23. data/developer-tools/dist/c9dec22105ad9330c811599b8b6464f8.woff +0 -0
  24. data/developer-tools/dist/ca279c55a51ab2641c4712a333633581.gif +0 -0
  25. data/developer-tools/dist/client.js +5152 -0
  26. data/developer-tools/dist/f5b27137d3f5e9b1d91b16b37386dd03.gif +0 -0
  27. data/developer-tools/dist/f99a231ed57ee113b50b1c3e9f9fcdc3.svg +399 -0
  28. data/developer-tools/dist/index.html +18 -0
  29. data/developer-tools/dist/inspector.js +38432 -0
  30. data/developer-tools/dist/jquery.min.js +9190 -0
  31. data/developer-tools/package.json +39 -0
  32. data/developer-tools/server.js +14 -0
  33. data/developer-tools/src/client.coffee +21 -0
  34. data/developer-tools/src/client/collection.coffee +14 -0
  35. data/developer-tools/src/client/model.coffee +11 -0
  36. data/developer-tools/src/client/resource.coffee +132 -0
  37. data/{app/controllers/.keep → developer-tools/src/client/runner.coffee} +0 -0
  38. data/developer-tools/src/dependencies.coffee +7 -0
  39. data/developer-tools/src/inspector.cjsx +49 -0
  40. data/developer-tools/src/inspector/models/interface_collection.coffee +31 -0
  41. data/developer-tools/src/inspector/pages/index.cjsx +31 -0
  42. data/developer-tools/src/inspector/pages/resources.cjsx +5 -0
  43. data/developer-tools/src/inspector/views/grid_sort.cjsx +23 -0
  44. data/developer-tools/src/inspector/views/icon_heading.cjsx +15 -0
  45. data/developer-tools/src/inspector/views/resource_card.cjsx +34 -0
  46. data/developer-tools/src/inspector/views/sidebar.cjsx +12 -0
  47. data/developer-tools/src/inspector/views/toolbar.cjsx +17 -0
  48. data/developer-tools/src/styles/index.scss +136 -0
  49. data/developer-tools/src/styles/views.scss +13 -0
  50. data/developer-tools/src/util.coffee +48 -0
  51. data/developer-tools/webpack.config.js +56 -0
  52. data/developer-tools/webpack.hot.config.js +65 -0
  53. data/lib/smooth.rb +209 -28
  54. data/lib/smooth/active_record/adapter.rb +24 -0
  55. data/lib/smooth/api.rb +272 -18
  56. data/lib/smooth/api/policy.rb +2 -2
  57. data/lib/smooth/api/tracking.rb +4 -4
  58. data/lib/smooth/application.rb +66 -0
  59. data/lib/smooth/cache.rb +1 -1
  60. data/lib/smooth/command.rb +267 -18
  61. data/lib/smooth/command/async_worker.rb +27 -0
  62. data/lib/smooth/command/instrumented.rb +6 -4
  63. data/lib/smooth/command/run_proxy.rb +21 -0
  64. data/lib/smooth/configuration.rb +63 -8
  65. data/lib/smooth/documentation.rb +3 -6
  66. data/lib/smooth/dsl.rb +1 -36
  67. data/lib/smooth/dsl_adapter.rb +34 -0
  68. data/lib/smooth/event.rb +8 -4
  69. data/lib/smooth/event/proxy.rb +9 -0
  70. data/lib/smooth/event/relay.rb +38 -0
  71. data/lib/smooth/example.rb +1 -1
  72. data/lib/smooth/ext/core.rb +16 -0
  73. data/lib/smooth/model_adapter.rb +31 -0
  74. data/lib/smooth/query.rb +143 -13
  75. data/lib/smooth/resource.rb +227 -52
  76. data/lib/smooth/resource/router.rb +217 -0
  77. data/lib/smooth/resource/templating.rb +62 -0
  78. data/lib/smooth/resource/tracking.rb +1 -1
  79. data/lib/smooth/response.rb +73 -0
  80. data/lib/smooth/serializer.rb +102 -11
  81. data/lib/smooth/user_adapter.rb +83 -0
  82. data/lib/smooth/util.rb +17 -0
  83. data/lib/smooth/version.rb +1 -1
  84. data/smooth.gemspec +6 -2
  85. data/spec/acceptance/books_routes_spec.rb +50 -0
  86. data/spec/acceptance/embedded_relationships_spec.rb +26 -0
  87. data/spec/dummy/app/apis/application_api.rb +8 -3
  88. data/spec/dummy/app/commands/create_book.rb +5 -0
  89. data/spec/dummy/app/models/book.rb +1 -0
  90. data/spec/dummy/app/models/library.rb +2 -0
  91. data/spec/dummy/app/models/user.rb +2 -0
  92. data/spec/dummy/app/queries/book_query.rb +13 -0
  93. data/spec/dummy/app/resources/{books.rb → books_definition.rb} +37 -12
  94. data/spec/dummy/db/migrate/20140824215902_create_users.rb +10 -0
  95. data/spec/dummy/db/migrate/20140826193259_create_libraries.rb +10 -0
  96. data/spec/dummy/db/schema.rb +8 -1
  97. data/spec/lib/smooth/api/async_spec.rb +21 -0
  98. data/spec/lib/smooth/api_spec.rb +8 -0
  99. data/spec/lib/smooth/command_spec.rb +87 -6
  100. data/spec/lib/smooth/configuration_spec.rb +4 -0
  101. data/spec/lib/smooth/event/relay_spec.rb +33 -0
  102. data/spec/lib/smooth/event_spec.rb +5 -8
  103. data/spec/lib/smooth/query_spec.rb +42 -0
  104. data/spec/lib/smooth/resource/router_spec.rb +14 -0
  105. data/spec/lib/smooth/resource_spec.rb +33 -1
  106. data/spec/lib/smooth/serializer_spec.rb +20 -0
  107. data/spec/lib/smooth/templating_spec.rb +23 -0
  108. data/spec/lib/smooth/util_spec.rb +22 -0
  109. data/spec/spec_helper.rb +1 -1
  110. metadata +151 -17
  111. data/app/helpers/.keep +0 -0
  112. data/app/mailers/.keep +0 -0
  113. data/app/models/.keep +0 -0
  114. data/app/views/.keep +0 -0
  115. data/spec/dummy/db/development.sqlite3 +0 -0
  116. data/spec/dummy/db/test.sqlite3 +0 -0
@@ -0,0 +1,12 @@
1
+ Link = require('react-router-component').Link
2
+
3
+ module.exports = Sidebar = React.createClass
4
+ componentDidMount: ->
5
+ $(@getDOMNode()).sidebar()
6
+
7
+ render: ->
8
+ <div className="ui sidebar #{ @props.style }">
9
+ <Link className="item" href="/resources">
10
+ <i className="icon lab" />
11
+ </Link>
12
+ </div>
@@ -0,0 +1,17 @@
1
+ module.exports = Toolbar = React.createClass
2
+ render: ->
3
+ options = @props.resourceGroups.map (groupName)->
4
+ <option>{groupName}</option>
5
+
6
+ <div className="ui my-toolbar">
7
+ <div className="ui icon input">
8
+ <input type="text" name="search" placeholder="Search..."/>
9
+ <i className="search icon" />
10
+ </div>
11
+ <div className="ui dropdown">
12
+ <select>
13
+ {options}
14
+ </select>
15
+ </div>
16
+ </div>
17
+
@@ -0,0 +1,136 @@
1
+ ::-webkit-selection {
2
+ background-color: #FFFFCC;
3
+ color: #555555;
4
+ }
5
+ ::-moz-selection {
6
+ background-color: #FFFFCC;
7
+ color: #555555;
8
+ }
9
+ ::selection {
10
+ background-color: #FFFFCC;
11
+ color: #555555;
12
+ }
13
+
14
+ h1::-moz-selection,
15
+ h2::-moz-selection,
16
+ h3::-moz-selection {
17
+ background-color: #F1C1C2;
18
+ color: #222222;
19
+ }
20
+ h1::selection,
21
+ h2::selection,
22
+ h3::selection {
23
+ background-color: #F1C1C2;
24
+ color: #222222;
25
+ }
26
+ .ui *::-moz-selection {
27
+ background-color: #CCE2FF;
28
+ }
29
+ .ui *::selection {
30
+ background-color: #CCE2FF;
31
+ }
32
+
33
+ /*******************************
34
+ Global
35
+ *******************************/
36
+
37
+ html,
38
+ body {
39
+ font-size: 16px;
40
+ }
41
+
42
+ body {
43
+ font-family: "Open Sans", "Helvetica Neue", "Helvetica", "Arial", sans-serif/*rtl:prepend:"Droid Arabic Kufi","Droid Sans", */;
44
+ background: #FCFCFC;
45
+ margin: 0px;
46
+ padding: 0px;
47
+ color: #555555;
48
+ min-width: 320px;
49
+ }
50
+
51
+ h1,
52
+ h2,
53
+ h3,
54
+ h4,
55
+ h5 {
56
+ font-family: "Source Sans Pro", "Helvetica Neue", "Helvetica", "Arial", sans-serif/*rtl:prepend:"Droid Arabic Kufi","Droid Sans", */;
57
+ }
58
+
59
+ /*
60
+ p,
61
+ ul,
62
+ .ui.grid,
63
+ li {
64
+ font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
65
+ font-size-adjust: none;
66
+ }*/
67
+
68
+
69
+ ul.list {
70
+ list-style-type: disc;
71
+ }
72
+ ul.list li {
73
+ list-style-position: outside;
74
+ }
75
+
76
+
77
+ /* text and headers */
78
+ h1 {
79
+ margin: 0px 0px 20px;
80
+ padding: 50px 0px 5px;
81
+ border-bottom: 1px solid rgba(0, 0, 0, 0.1);
82
+ }
83
+ h4 + p {
84
+ margin: 0px 0px 20px;
85
+ }
86
+ pre {
87
+ background-color: #F0F0F0;
88
+ }
89
+ /*rtl:ignore*/
90
+ pre.console {
91
+ background-color: transparent;
92
+ line-height: 1.6;
93
+ font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
94
+ height: 300px;
95
+ overflow: auto;
96
+ direction:ltr;
97
+ }
98
+ code {
99
+ background-color: rgba(0, 0, 0, 0.02);
100
+ border: 1px solid rgba(0, 0, 0, 0.1);
101
+ display: inline-block;
102
+ font-family: Courier New;
103
+ font-size: 14px;
104
+ margin: 0.25em;
105
+ padding: 0.125em 0.5em;
106
+ vertical-align: middle;
107
+ }
108
+ pre code {
109
+ border: none;
110
+ padding: 0px;
111
+ }
112
+ table pre,
113
+ table code {
114
+ margin: 0px !important;
115
+ padding: 0px;
116
+ background-color: transparent;
117
+ }
118
+ p {
119
+ margin: 1em 0em;
120
+ }
121
+ p:first-child {
122
+ margin-top: 0em;
123
+ }
124
+ p:last-child {
125
+ margin-bottom: 0em;
126
+ }
127
+ /* links */
128
+ a {
129
+ color: #009FDA;
130
+ text-decoration: none;
131
+ }
132
+ a:hover {
133
+ color: #00BAFF;
134
+ }
135
+
136
+ @import "./views.scss";
@@ -0,0 +1,13 @@
1
+ .resource-card {
2
+ margin-top: 32px;
3
+ }
4
+
5
+ .resource-card h3 {
6
+ border-bottom: 1px solid;
7
+ border-bottom-color: rgba(0,0,0, 0.1) !important;
8
+ padding-bottom: 8px;
9
+ }
10
+
11
+ .route-table {
12
+ font-size: 0.79em;
13
+ }
@@ -0,0 +1,48 @@
1
+ _ = require "underscore"
2
+
3
+ module.exports = util = {}
4
+
5
+ _.extend(util, inflections: require("inflection"), string:require("underscore.string"))
6
+
7
+ util.chunk = (data, size)->
8
+ _.chain(data).groupBy((element, index)-> Math.floor(index/size)).toArray().value()
9
+
10
+ util.classify = (string, forceSingular = true)->
11
+ string = util.singularize(string) if forceSingular
12
+ classified = util.string.capitalize(util.string.camelize(string))
13
+ classified
14
+
15
+ # A safe way of arriving at a value from a string
16
+ # that does not use eval
17
+ util.resolve = (string, root)->
18
+ parts = string.split('.')
19
+ _(parts).reduce (memo,part)->
20
+ memo[part]
21
+ , root
22
+
23
+ util.read = (value)->
24
+ if _.isFunction(value) then value() else value
25
+
26
+ util.wordsForNumber = (number)->
27
+ number = 0 if number is 0
28
+ number = number - 1 if number > 1
29
+
30
+ [
31
+ "one"
32
+ "two"
33
+ "three"
34
+ "four"
35
+ "five"
36
+ "six"
37
+ "seven"
38
+ "eight"
39
+ "nine"
40
+ "ten"
41
+ "eleven"
42
+ "twelve"
43
+ "thirteen"
44
+ "fourteen"
45
+ "fifteen"
46
+ "sixteen"
47
+ "seventeen"
48
+ ][number]
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @see http://webpack.github.io/docs/configuration.html
3
+ * for webpack configuration options
4
+ */
5
+ var webpack = require("webpack");
6
+
7
+ module.exports = {
8
+ context: __dirname,
9
+
10
+ entry: {
11
+ client: "./src/client.coffee",
12
+ inspector: "./src/inspector.cjsx"
13
+ },
14
+
15
+ output: {
16
+ path: __dirname + "/dist",
17
+ filename: "[name].js",
18
+ library: ["Smooth","[name]"],
19
+ libraryTarget: "umd",
20
+ publicPath: "/smooth-developer-tools/"
21
+ },
22
+
23
+ resolve: {
24
+ extensions: ["",".js",".coffee",".cjsx",".scss",".html"],
25
+ modulesDirectories: [
26
+ 'node_modules',
27
+ 'bower_components'
28
+ ],
29
+ },
30
+
31
+ plugins: [
32
+ new webpack.ProvidePlugin({
33
+ "_": "underscore",
34
+ "Backbone": "backbone",
35
+ "React": "react"
36
+ })
37
+ ],
38
+
39
+ externals:{
40
+ "jquery": "var jQuery",
41
+ "$" : "var jQuery"
42
+ },
43
+
44
+ // The 'module' and 'loaders' options tell webpack to use loaders.
45
+ // @see http://webpack.github.io/docs/using-loaders.html
46
+ module: {
47
+ loaders: [
48
+ { test: /\.coffee$/, loaders: ["coffee-loader"] },
49
+ { test: /\.cjsx$/, loaders: ["coffee-loader","cjsx-loader"] },
50
+ { test: /\.scss$/, loader: "style!css!sass?outputStyle=expanded"},
51
+ { test: /\.css$/, loader: "style!css!sass?outputStyle=expanded"},
52
+ {test: /\.(jpg|png|gif|svg)/, loader: 'file-loader?path=smooth-developer-tools'},
53
+ {test: /\.(eot|ttf|woff)/, loader: 'file-loader?path=smooth-developer-tools'}
54
+ ]
55
+ }
56
+ };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @see http://webpack.github.io/docs/configuration.html
3
+ * for webpack configuration options
4
+ */
5
+ var webpack = require("webpack");
6
+
7
+ module.exports = {
8
+ context: __dirname,
9
+
10
+ node: {
11
+ fs: "empty",
12
+ child_process:"empty",
13
+ net: "empty",
14
+ hiredis: "empty",
15
+ msgpack: "empty"
16
+ },
17
+
18
+ entry: {
19
+ dev: "webpack-dev-server/client?http://localhost:4000",
20
+ hot_dev: "webpack/hot/dev-server",
21
+ client: "./src/client.coffee",
22
+ inspector: "./src/inspector.cjsx"
23
+ },
24
+
25
+ output: {
26
+ filename: "express-bundle.js",
27
+ path: __dirname + "/dist"
28
+ },
29
+
30
+ resolve: {
31
+ extensions: ["",".js",".coffee",".cjsx",".scss",".html"],
32
+ modulesDirectories: [
33
+ 'node_modules',
34
+ 'bower_components'
35
+ ],
36
+ },
37
+
38
+ plugins: [
39
+ new webpack.HotModuleReplacementPlugin(),
40
+ new webpack.ProvidePlugin({
41
+ "_": "underscore",
42
+ "Backbone": "backbone",
43
+ "React": "react",
44
+ "Backbone.React.Component": "backbone-react-component"
45
+ })
46
+ ],
47
+
48
+ externals:{
49
+ "jquery": "var jQuery",
50
+ "$" : "var jQuery"
51
+ },
52
+
53
+ // The 'module' and 'loaders' options tell webpack to use loaders.
54
+ // @see http://webpack.github.io/docs/using-loaders.html
55
+ module: {
56
+ loaders: [
57
+ { test: /\.coffee$/, loaders: ["coffee-loader"] },
58
+ { test: /\.cjsx$/, loaders: ["react-hot","coffee-loader","cjsx-loader"] },
59
+ { test: /\.scss$/, loader: "style!css!sass?outputStyle=expanded"},
60
+ { test: /\.css$/, loader: "style!css!sass?outputStyle=expanded"},
61
+ {test: /\.(jpg|png|gif|svg)/, loader: 'file-loader?path=smooth-developer-tools'},
62
+ {test: /\.(eot|ttf|woff)/, loader: 'file-loader?path=smooth-developer-tools'}
63
+ ]
64
+ }
65
+ };
@@ -1,64 +1,245 @@
1
- $:.unshift File.dirname(__FILE__)
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
2
 
3
- begin
4
- require 'hashie'
3
+ load_rails_dependencies = lambda do
5
4
  require 'active_support/core_ext'
6
5
  require 'active_support/notifications'
6
+ require 'active_record'
7
+ end
8
+
9
+ load_dependencies = lambda do
7
10
  require 'active_model_serializers'
11
+ require 'hashie'
8
12
  require 'mutations'
9
- require 'pry'
10
- rescue LoadError
13
+ require 'logger'
14
+ require 'sinatra'
15
+ require 'singleton'
16
+ require 'yaml'
17
+ require 'escape_utils'
18
+ require 'uri_template'
19
+ require 'ffaker'
20
+ require 'factory_girl'
21
+ end
22
+
23
+ begin
24
+ load_dependencies.call
25
+ load_rails_dependencies.call unless defined?(::Rails)
26
+ rescue
11
27
  require 'rubygems'
12
- require 'hashie'
13
- require 'active_support/core_ext'
14
- require 'pry'
28
+
29
+ load_dependencies.call
30
+ load_rails_dependencies.call unless defined?(::Rails)
15
31
  end
16
32
 
33
+ require 'smooth/ext/core'
34
+ require 'smooth/util'
35
+
36
+ require 'smooth/documentation'
37
+ require 'smooth/event'
38
+
39
+ require 'smooth/api'
40
+ require 'smooth/api/policy'
41
+ require 'smooth/api/tracking'
42
+
43
+ require 'smooth/cache'
44
+
45
+ require 'smooth/ext/mutations'
46
+ require 'smooth/command/instrumented'
47
+ require 'smooth/command'
17
48
 
18
- require "smooth/ext/core"
19
- require "smooth/documentation"
20
- require "smooth/event"
49
+ require 'smooth/example'
50
+ require 'smooth/response'
21
51
 
22
- require "smooth/api"
23
- require "smooth/cache"
24
- require "smooth/command"
25
- require "smooth/example"
26
- require "smooth/query"
27
- require "smooth/resource"
28
- require "smooth/serializer"
52
+ require 'smooth/query'
53
+ require 'smooth/resource'
54
+ require 'smooth/serializer'
29
55
 
30
- require "smooth/configuration"
31
- require "smooth/version"
56
+ require 'smooth/dsl_adapter'
57
+ require 'smooth/active_record/adapter'
58
+ require 'smooth/model_adapter'
59
+ require 'smooth/user_adapter'
60
+
61
+ require 'smooth/configuration'
62
+ require 'smooth/version'
32
63
 
33
64
  module Smooth
34
65
  extend Smooth::Api::Tracking
35
66
  extend Smooth::Resource::Tracking
36
67
  extend Smooth::Event::Adapter
68
+ extend Smooth::DslAdapter
37
69
 
70
+ # Returns a reference to the base Command class
38
71
  def self.command
39
72
  config.command_class
40
73
  end
41
74
 
75
+ # Returns a reference to the base Query class
42
76
  def self.query
43
77
  config.query_class
44
78
  end
45
79
 
80
+ # Returns a reference to the base Serializer class
46
81
  def self.serializer
47
82
  config.serializer_class
48
83
  end
49
84
 
50
- def self.config
51
- Smooth::Configuration.instance
85
+ # Fakers can be used to generate fake API data, in our
86
+ # automated tests and in our documentation for example.
87
+ def self.fakers
88
+ @fakers ||= Smooth::Resource::Templating.fakers
52
89
  end
53
90
 
54
- class Engine < ::Rails::Engine
55
- initializer 'smooth.load_resources', :before => :build_middleware_stack do |app|
56
- app_root = app.config.root.join("app")
91
+ # Gets the faker generator for a given data type.
92
+ def self.faker(token, force_string = true)
93
+ group, meth = token.split('.')
94
+
95
+ group = group.camelize.to_sym
96
+
97
+ value = begin
98
+ Faker.const_get(group).send(meth)
99
+ rescue
100
+ Faker::Company.catch_phrase
101
+ end
102
+
103
+ value = value.join("\n") if value.is_a?(Array) && force_string
104
+ value
105
+ end
106
+
107
+ def self.util
108
+ Smooth::Util
109
+ end
110
+
111
+ def self.config(&block)
112
+ block_given = block_given?
113
+ Smooth::Configuration.instance.tap do |cfg|
114
+ cfg.instance_eval(&block) if block_given
115
+ end
116
+ end
117
+
118
+ def self.events
119
+ Smooth::Event::Proxy
120
+ end
121
+
122
+ def self.eager_load_from_app_folders
123
+ return unless config.eager_load_app_folders
124
+
125
+ config.app_folder_paths.each do |folder|
126
+ next unless folder.exist?
127
+
128
+ folder.children.select { |p| p.extname == '.rb' }.each { |f| require(f) }
129
+ end
130
+ end
131
+
132
+ def self.app
133
+ @application || fail('Application not initialized')
134
+ end
135
+
136
+ def self.application(options = {}, &block)
137
+ @application ||= Smooth::Application.new(options, &block)
138
+ end
57
139
 
58
- %w{smooth apis resources}.each do |check_folder|
59
- app_root.join(check_folder).children.each {|f| require(f) } if app_root.join(check_folder).exist?
140
+ def self.root
141
+ Smooth.config.root
142
+ end
143
+
144
+ def self.models_path
145
+ config.models_path
146
+ end
147
+
148
+ def self.active_record
149
+ Smooth::AR::Adapter
150
+ end
151
+
152
+ def self.env
153
+ ENV['SMOOTH_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
154
+ end
155
+
156
+ def self.gem_root
157
+ Pathname(File.dirname(__FILE__))
158
+ end
159
+
160
+ def self.developer_tools_root
161
+ gem_root.join('..', 'developer-tools')
162
+ end
163
+
164
+ if defined?(::Rails)
165
+ def self.root
166
+ ::Rails.root
167
+ end
168
+
169
+ class Middleware
170
+ def initialize(app, _options = {})
171
+ @app = app
172
+ @dist = Smooth.developer_tools_root.join('dist')
173
+ @static = Rack::Directory.new(@dist)
174
+ end
175
+
176
+ def call(env)
177
+ path = env['PATH_INFO']
178
+
179
+ if path.match(/smooth-developer-tools/)
180
+
181
+ if path == '/smooth-developer-tools'
182
+ env['PATH_INFO'] = '/index.html'
183
+ end
184
+
185
+ env['PATH_INFO'].gsub!('/smooth-developer-tools/', '/')
186
+
187
+ path = env['PATH_INFO']
188
+ path_exists = @dist.join("#{ path }".gsub(/^\//, '')).exist?
189
+
190
+ if path == '/'
191
+ path = '/index.html'
192
+ elsif path.match(/\.\w+/)
193
+
194
+ elsif !path_exists
195
+ path = '/index.html'
196
+ end
197
+
198
+ env['PATH_INFO'] = path
199
+
200
+ @static.call(env)
201
+ else
202
+ @app.call(env)
203
+ end
204
+ end
205
+ end
206
+
207
+ class Engine < ::Rails::Engine
208
+ initializer 'smooth.load_resources' do |app|
209
+
210
+ app.middleware.use Middleware, my_option: 1
211
+
212
+ %w(app/apis app/resources).each do |check|
213
+ if (folder = app.root.join(check)).exist?
214
+ folder.children.select { |f| f.extname == '.rb' }.each do |f|
215
+ require(f)
216
+ end
217
+ end
218
+ end
219
+ # Smooth.eager_load_from_app_folders()
60
220
  end
61
221
  end
222
+ end
223
+
224
+ ActiveRecord::Base.send(:include, Smooth::ModelAdapter) if defined?(ActiveRecord::Base)
225
+ end
62
226
 
63
- end if defined?(::Rails)
227
+ class Object
228
+ # Provides a global helper for looking up things in the Smooth object system.
229
+ #
230
+ # Example:
231
+ #
232
+ # Smooth() #=> returns the current api
233
+ # Smooth('books') #=> returns the books resource
234
+ # Smooth('books.create') #=> returns the create command, for the books resource
235
+ #
236
+ def Smooth(api_or_resource_name = nil)
237
+ return Smooth.current_api if api_or_resource_name.nil?
238
+
239
+ if api_or_resource_name.to_s.include?(Smooth.config.object_path_separator)
240
+ return Smooth.current_api.lookup_object_by(api_or_resource_name)
241
+ end
242
+
243
+ Smooth.fetch_api(api_or_resource_name) || Smooth.current_api.resource(api_or_resource_name)
244
+ end
64
245
  end