lurker 0.5.2 → 0.5.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 283e1232ba94b0709c578cd9079df7752d246771
4
- data.tar.gz: 052b2c171edb907e97c14d33c0e06825525714fc
3
+ metadata.gz: 96e03cec0753864d2fba1831cef5a23e4e8f7ee6
4
+ data.tar.gz: 2c774884cdfceaab040541bf62587408186b3f8b
5
5
  SHA512:
6
- metadata.gz: ef36571fc15bc8b40b083f915a14ce602db250e8ff8d1bdace6d89da88c98a537fec81ced6a3db3cb599044e3a5f93f380a9f695874e4439e7cb4b5792484eb0
7
- data.tar.gz: 91fd578c50783ff3f4125e6a2f31bc562054c401bec74698409ce0ede15b7f524a8ee51edfa9a2c7a7c90dcd55af6238d73b363f1dbafcaac7f71deb6b7786bf
6
+ metadata.gz: 674d6b9eb0f82ed400c16dc63b251dc2640b75b5cefcc796f3bcf8053a8e5ddafa8b538d3dec7bda67bdd0b9e7463269ffcf7c0f022015f80eb7fb4aad1d83e6
7
+ data.tar.gz: 161d9b376e1e6a8c3497877655677ed97478be2fcc711af971c166a8c8d64f4c31c2bbb4015f6c01c40de5a204c55750a1d7b83a9841044dba5112ff8d914105
checksums.yaml.gz.asc CHANGED
@@ -2,11 +2,11 @@
2
2
  Version: GnuPG v1
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQEcBAABCgAGBQJTXvK5AAoJENcoxKfNVdjb5RoIAMetNDxFZ6KmLPkDpq50xeUt
6
- HZri9cCVeD+5zk2SqIGTzh8jI1pqg822e1gFOyPpkZaXMUKisA0Lbogc2EWjsjte
7
- HRjmH+ZL16VqFMhDFBoCX9Q1yXPm4wWhVcKK23fCbnY0x5HY2uHMUim8yDAN2bUO
8
- /X7KIkNAwMLcihR1sHg8vCkmRWpN+29qaAvAOjjiyLyiND+Z7doweWNVrvxIF5Ei
9
- L1jqEQouA+yXpSXtxYr4T+uQmwQCuL8TxDDm6EzMF8TuQFhLV2BwE2l8fQ5ZTtWq
10
- qbysZqac/GxHz47at7+d1ghokp+jQ8uNt90vvNlo+ISfNOCHdP5jMEVTt6m1+HI=
11
- =77ha
5
+ iQEcBAABCgAGBQJTYSdKAAoJENcoxKfNVdjbUYAH+wVE2NmE7ol3wWjmxHMRAyr5
6
+ Gc9vxOmbMPi70Cqf6IEC4L9pzn9Yy+qTDGjC98KolSDoULKKuvOn920eOJ1JOM5y
7
+ YjV0pke1UF/ohX8edCK6KT4vt3pgoC++65ZNaYvAEBJGjo7ImDIM6yD17RCOrr39
8
+ EhYFc3kMa403nnBK+XFYzhdeXFgI2f9yz8mOBlyKs009trRACih/vEJjrvWZtaKM
9
+ StbjHXL/1hMGzTkvJHYxg6EvoegUarMxuKfq0CsY9gvJVp/bg5egItI12jgiYeGn
10
+ Ucs//BpVz7uLaKDSmNi80s71pr3RRzZC4rBwnnR2Cp4BwQ5oa4GgqET6vAB4Pmc=
11
+ =d8yD
12
12
  -----END PGP SIGNATURE-----
data.tar.gz.asc CHANGED
@@ -2,11 +2,11 @@
2
2
  Version: GnuPG v1
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQEcBAABCgAGBQJTXvK2AAoJENcoxKfNVdjbkmkIAJPPUMpXPntfkoEtTB4WAgo7
6
- kFQwMJD5Lrz10tLwf7o8pkZWOEOMmHbZW46v2iLzgEXoXoBF5IOO8hBW0UmplWcK
7
- s9Jx8ws2BrMt21qI48qYHDLHmn+Wexjvj/pV5X31JgfilzW9BhgV7MSfS//RmDkv
8
- t5NCGdg84AJidKMGL95r4gxn7Uxp6q7oMZQONx9oaqXTAqLu7x9iuXTH1B3+1gNc
9
- vJq+By9GseQ+I/TEPkz1wllWM3adMWH2a9iMqCys8DWw13Dpam8xnLRdEO+ZVJSy
10
- hs2rVOKcGfEFEfI3gbwnd6VI7ItVxnFRlumNlEZ/V3ZkNANNQq+PEgOMBdasbgI=
11
- =9S7g
5
+ iQEcBAABCgAGBQJTYSdHAAoJENcoxKfNVdjbaXcH/0EznB410jliY+1FsQNauGfW
6
+ 0KrnVLUPNrouYI/LPJ43XCRDEXo4VG9zI741o3RDPCamLi64nRO6bOmh3OoEYBTJ
7
+ y+NE9h90zMJ4XtiBglNhMxo2OZz3C7DSw9ragA6+9VwCuhQUrYoSQ+X15YQXE1iE
8
+ sczxQ+qGAg52sXoYnYydi7Ip/kPWWVZV4P4DbUZmf5LYNDOY7rzWGKrTJcKhaThy
9
+ N5J3g+hWlap2v5bxP03G0xz+GF7K1ytWh5DZw8zT7p6P4Oo8aq1s7m+fCFcohEI3
10
+ u1LNQrhXxloiSjq4tnibSZPmiyYPZmD4xx6tchE8ZnyLZ8ErX4EimDFxoP/Q9Bk=
11
+ =T/zF
12
12
  -----END PGP SIGNATURE-----
data/.travis.yml CHANGED
@@ -7,8 +7,4 @@ cache:
7
7
  rvm:
8
8
  - 1.9.3
9
9
  - 2.0.0
10
- - 2.1.0
11
- matrix:
12
- allow_failures:
13
- - rvm: 1.9.3
14
- - rvm: 2.0.0
10
+ - 2.1.1
data/README.md CHANGED
@@ -46,7 +46,8 @@ and it fails if your code changes the api!
46
46
  - The property '#/user/last_sign_in_at' of type String did not match the following type:
47
47
  null in schema file:///.../lurker/api/v1/users-POST.json.yml#
48
48
 
49
- Let's run your `rails s` and visit [http://localhost:3000/lurker/](http://localhost:3000/lurker/) (or see [demo][demo_app])
49
+ Let's run your `rails s` and visit [http://localhost:3000/lurker/](http://localhost:3000/lurker/)
50
+ (or see [demo][demo_app2] for example)
50
51
 
51
52
  Now, you can test your API on-line (for real)
52
53
 
@@ -75,7 +76,7 @@ Now, you can test your API on-line (for real)
75
76
  # e.g. config/environtents/staging.rb
76
77
  config.middleware.use Lurker::Sandbox
77
78
 
78
- E.g. demo application runs with it: when creating, updating repos or users
79
+ E.g. demo application on Heroku runs with it: when creating, updating repos or users
79
80
  ids getting increased, but if you look into GET #index,
80
81
  new items are NOT showing up. **This is NOT a bug!** - sequences in postgres
81
82
  are increasing notwithstanding ROLLBACK is called. As such:
@@ -88,7 +89,7 @@ are increasing notwithstanding ROLLBACK is called. As such:
88
89
 
89
90
  You can clone the repo & run `rake build_example_docs`.
90
91
  It will generate testing rails application under `tmp/lurker_app`.
91
- Currently it is deployed [here][demo_app].
92
+ Currently it is deployed [here][demo_app] within sandbox mode and [here][demo_app2].
92
93
 
93
94
 
94
95
  ## Contributions
@@ -151,8 +152,9 @@ Also thanks to [React.js][reactjs] for two-way binding.
151
152
  [partial_example]: https://www.relishapp.com/razum2um/lurker/docs/docs-generation/partials
152
153
  [partial_example_demo]: http://lurker-app.herokuapp.com/lurker/api/v1/users/__user_id/repos-POST.html
153
154
  [evil_martians]: http://evilmartians.com/
154
- [demo_app]: http://lurker-app.herokuapp.com/lurker/
155
- [demo_live]: http://lurker-app.herokuapp.com/lurker/api/v1/users-POST.html
155
+ [demo_app]: http://lurker-app.herokuapp.com
156
+ [demo_app2]: http://lurker.razum2um.me
157
+ [demo_live]: http://lurker.razum2um.me/lurker/api/v1/users-POST.html
156
158
 
157
159
  [Gem Version]: https://rubygems.org/gems/lurker
158
160
  [Build Status]: https://travis-ci.org/razum2um/lurker
@@ -43,5 +43,8 @@ end
43
43
 
44
44
  After do |scenario|
45
45
  DatabaseCleaner.clean
46
+ end
47
+
48
+ After('@selenium') do |scenario|
46
49
  save_and_open_page if scenario.failed? && !ENV['BUNDLE_GEMFILE'].match(/Gemfile\.ci/)
47
50
  end
@@ -9,10 +9,13 @@ module Lurker
9
9
  included do
10
10
  # _describe = self # RSpec::ExampleGroups::... # class
11
11
  actions = [:get, :post, :put, :delete]
12
- actions << :patch if respond_to? :patch
12
+ if defined?(ActionDispatch::Request::HTTP_METHODS) && ActionDispatch::Request::HTTP_METHODS.include?('PATCH')
13
+ actions << :patch
14
+ end
13
15
  actions.each do |verb|
14
16
  send(:define_method, "#{verb}_with_lurker") do |*params|
15
17
  @__action, @__request_params = params
18
+ @__request_params ||= {}
16
19
 
17
20
  send("#{verb}_without_lurker", @__action, @__request_params)
18
21
 
@@ -23,6 +23,11 @@ class Lurker::Endpoint
23
23
  )
24
24
  end
25
25
 
26
+ def persist!
27
+ return unless ENV['LURKER_UPGRADE']
28
+ schema.write_to(endpoint_path)
29
+ end
30
+
26
31
  def indexed?
27
32
  prefix.present? && description.present?
28
33
  end
@@ -22,7 +22,7 @@ class Lurker::EndpointScaffold < Lurker::Endpoint
22
22
  end
23
23
 
24
24
  def persist!
25
- schema.write_to(endpoint_path)
25
+ schema.ordered!.write_to(endpoint_path)
26
26
  end
27
27
 
28
28
  def consume_request(params, successful = true)
data/lib/lurker/engine.rb CHANGED
@@ -3,8 +3,10 @@ require 'lurker/server'
3
3
  module Lurker
4
4
  class Engine < ::Rails::Engine
5
5
  config.after_initialize do |app|
6
- app.routes.prepend do
7
- mount Lurker::Server.to_rack(path: 'html'), at: "/#{Lurker::DEFAULT_URL_BASE}"
6
+ app.routes.append do
7
+ unless ::Rails.env.production? || app.routes.routes.map(&:app).any? { |e| e.is_a?(Class) && e.name.to_s.match(/Lurker::Rack/) }
8
+ mount Lurker::Server.to_rack(path: 'html'), at: "/#{Lurker::DEFAULT_URL_BASE}"
9
+ end
8
10
  end
9
11
  end
10
12
  end
@@ -9,7 +9,10 @@ module Lurker
9
9
  included do
10
10
  # _describe = self # RSpec::ExampleGroups::... # class
11
11
  actions = [:get, :post, :put, :delete]
12
- actions << :patch if respond_to? :patch
12
+ if defined?(ActionDispatch::Request::HTTP_METHODS) && ActionDispatch::Request::HTTP_METHODS.include?('PATCH')
13
+ actions << :patch
14
+ end
15
+
13
16
  actions.each do |verb|
14
17
  send(:define_method, "#{verb}_with_lurker") do |*params|
15
18
  @__action, @__request_params, @__env = params
@@ -18,12 +21,15 @@ module Lurker
18
21
  @__query_params ||= {}
19
22
  @__env ||= {}
20
23
 
21
- unless @__example.metadata.described_class.is_a?(Class)
22
- raise 'cannot determine request url: provide proper described class like: "describe MyController do"'
24
+ if @__action.is_a?(Symbol)
25
+ unless @__example.metadata.described_class.is_a?(Class)
26
+ raise 'cannot determine request url: provide proper described class like: "describe MyController do"'
27
+ end
28
+ controller_name = @__example.metadata.described_class.name.tableize.gsub(/_controllers$/, '')
29
+ @__action = URI.parse(url_for({ controller: controller_name, action: @__action }.merge(@__request_params))).path
23
30
  end
24
31
 
25
- controller_name = @__example.metadata.described_class.name.tableize.gsub(/_controllers$/, '')
26
- @__query_params.merge! Rack::Utils.parse_query URI.parse(@__action).query
32
+ @__query_params.merge! ::Rack::Utils.parse_query URI.parse(@__action).query
27
33
 
28
34
  send("#{verb}_without_lurker", @__action, @__request_params, @__env)
29
35
 
data/lib/lurker/schema.rb CHANGED
@@ -17,7 +17,7 @@ module Lurker
17
17
  def initialize(json_schema_hash, extensions={})
18
18
  @hash = json_schema_hash
19
19
  @extensions = if extensions.blank? && @hash.has_key?(KEY)
20
- @hash.delete(KEY)
20
+ @hash.delete(KEY) || {}
21
21
  else
22
22
  extensions
23
23
  end
@@ -50,12 +50,22 @@ module Lurker
50
50
  FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
51
51
 
52
52
  File.open(path, "w") do |file|
53
- file.write(YAML.dump(Hash[@hash.sort].merge(
54
- KEY => Hash[@extensions.sort]
55
- )))
53
+ file.write(to_yaml)
56
54
  end
57
55
  end
58
56
 
57
+ def to_yaml
58
+ YAML.dump(@hash.merge(
59
+ KEY => @extensions
60
+ ))
61
+ end
62
+
63
+ def ordered!
64
+ @hash = Hash[@hash.sort]
65
+ @extensions = Hash[@extensions.sort]
66
+ self
67
+ end
68
+
59
69
  protected
60
70
 
61
71
  def serialized_for_diff
data/lib/lurker/server.rb CHANGED
@@ -28,15 +28,15 @@ module Lurker
28
28
  def self.to_rack(options = {})
29
29
  default_path = options[:path] || Lurker::DEFAULT_SERVICE_PATH
30
30
 
31
- Class.new(Sinatra::Base) do
31
+ cls = Class.new(Sinatra::Base) do
32
32
 
33
33
  if !Rails.env.development? && (username, password = options.values_at(:username, :password)).all?(&:present?)
34
- use Rack::Auth::Basic, "Protected Area" do |u, p|
34
+ use ::Rack::Auth::Basic, "Protected Area" do |u, p|
35
35
  username == u && password == p
36
36
  end
37
37
  end
38
38
 
39
- use Rack::Deflater
39
+ use ::Rack::Deflater
40
40
 
41
41
  use TryStatic,
42
42
  :root => "#{::Rails.root}/#{default_path}", # static files root dir
@@ -48,6 +48,8 @@ module Lurker
48
48
  :try => ['.html', 'index.html', '/index.html'] # try these postfixes sequentially
49
49
 
50
50
  end
51
+ Lurker.const_set("Rack_#{rand 10}_#{Time.now.to_i}", cls)
52
+ cls
51
53
  end
52
54
  end
53
55
  end
@@ -11,17 +11,17 @@ class Lurker::Service
11
11
  end
12
12
 
13
13
  def initialize(service_dir, service_name = nil)
14
- @name = service_name
15
14
  @opened_endpoints = []
16
15
  @service_dir = File.expand_path(service_dir)
16
+ @service_filename = service_name
17
17
  @schema = if persisted? && (schema = YAML.load_file(service_path)).is_a?(Hash)
18
18
  Lurker::Schema.new(schema)
19
19
  else
20
20
  Lurker::Schema.new({
21
- 'name' => name,
21
+ 'name' => service_filename,
22
22
  'basePath' => '',
23
23
  'description' => '',
24
- 'domains' => {'/' => 'This host'}
24
+ 'domains' => {}
25
25
  })
26
26
  end
27
27
  end
@@ -31,7 +31,11 @@ class Lurker::Service
31
31
  end
32
32
 
33
33
  def service_path
34
- @service_path ||= "#{service_dir}/#{name}#{SUFFIX}"
34
+ @service_path ||= "#{service_dir}/#{service_filename}#{SUFFIX}"
35
+ end
36
+
37
+ def service_filename
38
+ @service_filename ||= Pathname.new(Dir["#{service_dir}/*#{SUFFIX}"].first.to_s).basename.to_s.gsub(SUFFIX, '').presence || 'application'
35
39
  end
36
40
 
37
41
  def persist!
@@ -90,9 +94,7 @@ class Lurker::Service
90
94
  end
91
95
 
92
96
  def name
93
- @name ||= (@schema.try(:[], 'name') ||
94
- Pathname.new(Dir["#{service_dir}/*#{SUFFIX}"].first.to_s).basename.to_s.gsub(SUFFIX, '').presence ||
95
- 'application')
97
+ schema['name']
96
98
  end
97
99
 
98
100
  def base_path
@@ -1,3 +1,3 @@
1
1
  module Lurker
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
data/lurker.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency("sinatra", "~> 1.4")
27
27
 
28
28
  # testing
29
+ spec.add_development_dependency("psych", "~> 2.0")
29
30
  spec.add_development_dependency("bundler", "~> 1.3")
30
31
  spec.add_development_dependency("rails", "~> 4.1")
31
32
  spec.add_development_dependency("rake", "~> 10.2")
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Yaml dump' do
4
+ it 'dumps strings with slashes' do
5
+ hash = { "extensions" => { "path_info" => "/api/v1/users/1/repos/1" } }
6
+ expect(Psych.dump(hash)).to eq(
7
+ '---
8
+ extensions:
9
+ path_info: "/api/v1/users/1/repos/1"
10
+ '
11
+ )
12
+ end
13
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  ENV['RAILS_ENV'] = 'test'
2
+ require 'bundler/setup'
2
3
  require 'lurker'
3
4
 
4
5
  require 'simplecov'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lurker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Bokov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-29 00:00:00.000000000 Z
11
+ date: 2014-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: psych
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: bundler
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -420,6 +434,7 @@ files:
420
434
  - lib/lurker/version.rb
421
435
  - lurker.gemspec
422
436
  - spec/lurker/endpoint_spec.rb
437
+ - spec/lurker/yaml_spec.rb
423
438
  - spec/spec_helper.rb
424
439
  - templates/generate_stuff.rb
425
440
  - templates/lurker_app.rb
@@ -463,5 +478,6 @@ test_files:
463
478
  - features/step_definitions/additional_cli_steps.rb
464
479
  - features/support/env.rb
465
480
  - spec/lurker/endpoint_spec.rb
481
+ - spec/lurker/yaml_spec.rb
466
482
  - spec/spec_helper.rb
467
483
  has_rdoc:
metadata.gz.asc CHANGED
@@ -2,11 +2,11 @@
2
2
  Version: GnuPG v1
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQEcBAABCgAGBQJTXvKuAAoJENcoxKfNVdjblTIIAOhjx5x43TlPapSL7bVRj/Ln
6
- Z8e4j9pZLwWe22Buecz6TeuXEJcEsw++RdmSjviVdicD02yAhkHAjvwFgYuMx9FI
7
- q/Jhn2SZpE6sBdgP4UUMw9iXGr8ajImh/tAR7S5GVlzXpjvU3vC8MZlyNabvl6QP
8
- VV4N8RSzYvhUFMSfW8z1Sov7gZTmXQtpvjgjh9mIXAav1rjE+5mZuTKPvonLjxXN
9
- 0CJu8SOsKlrSbYjoqvq1ZVxuKPW9j01ROe6HSUVAGF9Y5KcYG/EPkIOzFD7Sq3iz
10
- /OvlhsQpyASUnsXW0MsE4ESqzzXbhWwSF86MoW8m+Dmb1yysanLu9tgzBfro7Og=
11
- =CdmZ
5
+ iQEcBAABCgAGBQJTYSdDAAoJENcoxKfNVdjbTd0H/ikPlNf2LUQtakmpxDMxCZKo
6
+ iT3v87Ssz07yZcgt8wZDF64rVBZZ1yM2bssQftCLOvVqKGzXzlemwp7dO4m2hcBE
7
+ 8QoeueyTieMo9gN+p2/sNk3RaMwsUy4X24Q1ZSUdBiez/K8QPnjSnSeReVHBwI3X
8
+ GDag9EdC+i79eTM+/06Ab5ReY4Wxn7w5pxRATWFrv4s0r3yElaOaARQQbH2RLe66
9
+ KCkKSmh6QVG3f08rRkvnXyx0CbpQqSIxz6jN696z1PfeWecRBs9LYfxRSM/0BgCW
10
+ KDSFDju69n2mNdGKNsOIicpguq8RNlG+7o3JzYyPru/4qEZfDS4uFsnZIuPxSfE=
11
+ =kKPC
12
12
  -----END PGP SIGNATURE-----