shaf 0.4.0 → 0.4.1

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
- SHA256:
3
- metadata.gz: 749585960501bd61a7e7f4f22c2a90c2108f86c6cf0698ec87f495bb78d87389
4
- data.tar.gz: da5fc9e7f87876f12654d5ea8473e7f0cd4a9dc3daba88055a51f7aaf0a794a5
2
+ SHA1:
3
+ metadata.gz: 33b4f2f8ba33dcc7d3f8abe950745897fca2439e
4
+ data.tar.gz: d677b6e4db2843c764027e91b00ee384a24baa60
5
5
  SHA512:
6
- metadata.gz: '017559afb07a1d9e142a96c09c406cd697b6c797732661c8f431a1b2803c5c9e8c9c04cd7718037638a440ad077a55eaf1b382a9cdb47687b4bef7921b6ae4c5'
7
- data.tar.gz: 3d2a16944a04292fd9039b2dbe5f482950296b7f1dd853e383cdbed972f33755243b16a89b5b081f53da43d456c4b1c8f081ac31ecdbcea66fce3076b2b6ec78
6
+ metadata.gz: 24eaf2fb8f70443206460d48853ea44d304c1616a65be60defb33147ee09e53923ee13b3563efc0ad00ce41976d7acd6048047d3b1f6d0323341fc9946900546
7
+ data.tar.gz: 7714930986d85adea752deb9bd7c200a3a7f06cb10826f4e39c9b066dd96b4fd58bae7e327c8fe8bc5e276ab781a9112e8d123e2787a4676fec09a06d10954fd
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/shaf/command.rb CHANGED
@@ -62,3 +62,4 @@ require 'shaf/command/upgrade'
62
62
  require 'shaf/command/server'
63
63
  require 'shaf/command/console'
64
64
  require 'shaf/command/generate'
65
+ require 'shaf/command/version'
@@ -1,7 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'yaml'
3
3
  require 'erb'
4
- require 'shaf/version'
5
4
 
6
5
  module Shaf
7
6
  module Command
@@ -0,0 +1,25 @@
1
+ module Shaf
2
+ module Command
3
+ class Version < Base
4
+
5
+ identifier %r(\Av(ersion)?\Z)
6
+ usage 'version'
7
+
8
+ def call
9
+ print_shaf_version
10
+ print_project_version
11
+ end
12
+
13
+ def print_shaf_version
14
+ puts "Installed Shaf version: #{Shaf::VERSION}"
15
+ end
16
+
17
+ def print_project_version
18
+ path = project_root
19
+ return if path.nil?
20
+ project = path.split('/').last
21
+ puts "Project '#{project}' created with Shaf version: #{read_shaf_version}"
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/shaf/errors.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  module Shaf
2
+ class Error < StandardError; end
3
+
2
4
  module Errors
3
- class ServerError < StandardError
5
+ class ServerError < Error
4
6
  attr_reader :code, :title
5
7
 
6
8
  def http_status
@@ -10,6 +10,7 @@ module Shaf
10
10
  raise "Please provide a resource name when using the scaffold generator!"
11
11
  end
12
12
 
13
+ options[:specs] = true if options[:specs].nil?
13
14
  Generator::Factory.create('model', *args).call(options)
14
15
  Generator::Factory.create('controller', *controller_args).call(options)
15
16
  end
@@ -72,16 +72,25 @@ module Shaf
72
72
  return name == '_method'
73
73
  end
74
74
 
75
- def respond_with_collection(resource, status: 200, serializer: nil)
76
- respond_with(resource, status: status, serializer: serializer, collection: true)
75
+ def respond_with_collection(resource, status: 200, serializer: nil, **kwargs)
76
+ respond_with(
77
+ resource,
78
+ status: status,
79
+ serializer: serializer,
80
+ collection: true,
81
+ **kwargs
82
+ )
77
83
  end
78
84
 
79
- def respond_with(resource, status: 200, serializer: nil, collection: false)
85
+ def respond_with(resource, status: 200, serializer: nil, collection: false, **kwargs)
80
86
  status(status)
81
87
 
82
88
  preferred_response = preferred_response_type(resource)
83
89
  serialized = serialize(resource, serializer, collection)
84
90
 
91
+ http_cache = kwargs.fetch(:http_cache, Settings.http_cache)
92
+ add_cache_headers(serialized) if http_cache
93
+
85
94
  if preferred_response == mime_type(:html)
86
95
  respond_with_html(resource, serialized)
87
96
  else
@@ -108,12 +117,18 @@ module Shaf
108
117
  log.debug "Responding with html. Output payload (#{resource.class}): #{serialized}"
109
118
  content_type :html
110
119
  case resource
111
- when Shaf::Formable::Form
120
+ when Formable::Form
112
121
  body erb(:form, locals: {form: resource, serialized: serialized})
113
122
  else
114
123
  body erb(:payload, locals: {serialized: serialized})
115
124
  end
116
125
  end
117
126
 
127
+ def add_cache_headers(payload)
128
+ return if payload.nil? || payload.empty?
129
+
130
+ sha1 = Digest::SHA1.hexdigest payload
131
+ etag sha1, :weak # Weak or Strong??
132
+ end
118
133
  end
119
134
  end
@@ -36,13 +36,13 @@ module Shaf
36
36
  private
37
37
 
38
38
  def target_versions
39
- return @target_versions if @target_versions
39
+ return @target_versions if defined? @target_versions
40
40
 
41
41
  files = Dir[File.join(UPGRADE_FILES_PATH, '*.tar.gz')]
42
- @target_versions = files.each_with_object([]) do |file, versions|
42
+ @target_versions = files.map do |file|
43
43
  str = File.basename(file, '.tar.gz')
44
- versions << Version.new(str)
45
- end
44
+ Version.new(str)
45
+ end.sort
46
46
  end
47
47
 
48
48
  def strip_suffix(file)
data/lib/shaf/utils.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'shaf/version'
2
+
1
3
  module Shaf
2
4
  module Utils
3
5
  class ProjectRootNotFound < StandardError; end
@@ -24,18 +26,19 @@ module Shaf
24
26
  noun[0..-2]
25
27
  end
26
28
 
29
+ def pluralize(noun)
30
+ Utils::pluralize(noun)
31
+ end
32
+
27
33
  def gem_root
28
34
  self.class.gem_root
29
35
  end
30
36
 
31
37
  def project_root
38
+ return @project_root if defined? @project_root
32
39
  dir = Dir.pwd
33
- 20.times do
34
- if is_project_root?(dir)
35
- return dir
36
- elsif dir == '/'
37
- break
38
- end
40
+ while dir != '/' do
41
+ return @project_root = dir if is_project_root?(dir)
39
42
  dir = File.expand_path("..", dir)
40
43
  end
41
44
  end
@@ -68,16 +71,18 @@ module Shaf
68
71
  end
69
72
  end
70
73
 
71
- def pluralize(noun)
72
- Utils::pluralize(noun)
73
- end
74
-
75
74
  def read_shaf_file
76
75
  return {} unless File.exist? SHAF_VERSION_FILE
77
76
  str = File.read(SHAF_VERSION_FILE)
78
77
  YAML.load(str) || {}
79
78
  end
80
79
 
80
+ def read_shaf_file!
81
+ in_project_root do
82
+ read_shaf_file
83
+ end
84
+ end
85
+
81
86
  def write_shaf_file(data = {})
82
87
  data = read_shaf_file.merge(data)
83
88
  File.write SHAF_VERSION_FILE,
data/lib/shaf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Shaf
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -1,8 +1,10 @@
1
1
  class RootController < BaseController
2
2
 
3
- register_uri :root, '/'
3
+ HTTP_CACHE_MAX_AGE = 86400 # 60 * 60 * 24 = 1 day
4
+ register_uri :root, '/'
4
5
 
5
6
  get root_uri do
7
+ cache_control(:private, max_age: HTTP_CACHE_MAX_AGE) if Shaf::Settings.http_cache
6
8
  respond_with nil, serializer: RootSerializer
7
9
  end
8
10
  end
@@ -7,6 +7,7 @@ default: &default
7
7
  migrations_dir: db/migrations
8
8
  fixtures_dir: spec/fixtures
9
9
  paginate_per_page: 25
10
+ http_cache: on
10
11
 
11
12
  production:
12
13
  <<: *default
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sammy Henningsson
@@ -30,7 +30,7 @@ cert_chain:
30
30
  ZMhjYR7sRczGJx+GxGU2EaR0bjRsPVlC4ywtFxoOfRG3WaJcpWGEoAoMJX6Z0bRv
31
31
  M40=
32
32
  -----END CERTIFICATE-----
33
- date: 2018-07-16 00:00:00.000000000 Z
33
+ date: 2018-07-22 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: rake
@@ -71,6 +71,7 @@ files:
71
71
  - lib/shaf/command/server.rb
72
72
  - lib/shaf/command/templates/Gemfile.erb
73
73
  - lib/shaf/command/upgrade.rb
74
+ - lib/shaf/command/version.rb
74
75
  - lib/shaf/doc_model.rb
75
76
  - lib/shaf/errors.rb
76
77
  - lib/shaf/extensions.rb
@@ -157,6 +158,7 @@ files:
157
158
  - templates/spec/integration/root_spec.rb
158
159
  - templates/spec/serializers/root_serializer_spec.rb
159
160
  - templates/spec/spec_helper.rb
161
+ - upgrades/0.4.0.tar.gz
160
162
  homepage: https://github.com/sammyhenningsson/shaf
161
163
  licenses:
162
164
  - MIT
@@ -178,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
180
  version: '0'
179
181
  requirements: []
180
182
  rubyforge_project:
181
- rubygems_version: 2.7.3
183
+ rubygems_version: 2.6.14
182
184
  signing_key:
183
185
  specification_version: 4
184
186
  summary: Sinatra Hypermedia Api Framework
metadata.gz.sig CHANGED
Binary file