carraway 0.12.0 → 1.0.0

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
  SHA256:
3
- metadata.gz: 65b145b7f19885a00a7a1cc9d3ed65bd274471107ee7a48cd2c27c5626bca3bb
4
- data.tar.gz: ed4141eb373c87f621c7b44f3fd6f6faf0e3dfbad768a0171201c48c40dc5cd5
3
+ metadata.gz: 9d55ca828b081c8af517e0428c2e6b4f24fa424415ad58da906ed1cb033dff9f
4
+ data.tar.gz: 28018ed8298581837bdb3e8084592d6ed1568d6d226d3e2898382440a1fd7022
5
5
  SHA512:
6
- metadata.gz: a9a6c383f5e5b8d07af2dcb214008bcf458ea0c623e9d3aaf358396ec94904ebf6055d1521f3b8b2d5dc9a3322adc2e56f29a6b89a591d9d7367728c2fb88b7d
7
- data.tar.gz: 6cd84e4f3de7b32302e1094d01fa13e3d6ec050580cfb31642772bddb17e3ceecb45ae4594905f210daa285da1869a57b3e3e156150b225d0e1b2e3275f0a49c
6
+ metadata.gz: 10031f4a10f37eeccf44a5aae91417e5919649a8bb50bb7651b9ecd40389ec8e0d80fe54971c561277b0e6460d573080da0ca306427497b4d20c87984a11cfd7
7
+ data.tar.gz: ace24608943448fc411f2cd7e7a29d1e3e6f86f63607b290ec7d2a95b67c5208b13e1b5e06147053e525014225e4eea4cac498ffbac315bf12a7c35e2c69b898
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.12.0](https://github.com/adorechic/carraway/tree/v0.12.0) (2019-02-15)
4
+ [Full Changelog](https://github.com/adorechic/carraway/compare/v0.11.0...v0.12.0)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - Support labels on file [\#9](https://github.com/adorechic/carraway/pull/9) ([adorechic](https://github.com/adorechic))
9
+
3
10
  ## [v0.11.0](https://github.com/adorechic/carraway/tree/v0.11.0) (2019-02-15)
4
11
  [Full Changelog](https://github.com/adorechic/carraway/compare/v0.10.0...v0.11.0)
5
12
 
data/lib/carraway/file.rb CHANGED
@@ -3,15 +3,17 @@ require 'aws-sdk-s3'
3
3
 
4
4
  module Carraway
5
5
  class File
6
- attr_reader :uid, :created, :file
7
- attr_accessor :title, :labels
6
+ attr_reader :uid, :created, :file, :published
7
+ attr_accessor :title, :labels, :category
8
8
 
9
- def initialize(title:, file: nil, uid: nil, created: nil, labels: nil)
9
+ def initialize(title:, file: nil, uid: nil, created: Time.now.to_i, labels: nil, published: nil, category: nil)
10
10
  @title = title
11
11
  @file = file
12
12
  @uid = uid || generate_uid
13
13
  @created = created
14
14
  @labels = labels
15
+ @published = published || created
16
+ @category = category || Category.all.first # FIXME validation
15
17
  end
16
18
 
17
19
  %i(created).each do |col|
@@ -27,6 +29,19 @@ module Carraway
27
29
  [Config.file_backend['prefix'], '/', @uid, ext].join
28
30
  end
29
31
 
32
+ def to_h
33
+ {
34
+ uid: @uid,
35
+ title: @title,
36
+ path: path,
37
+ labels: @labels,
38
+ record_type: 'file',
39
+ created: @created.to_i,
40
+ published: @published && @published.to_i,
41
+ category: @category.key,
42
+ }
43
+ end
44
+
30
45
  private
31
46
 
32
47
  # FIXME duplicate impl on Post
@@ -14,7 +14,9 @@ module Carraway
14
14
  uid: item['uid'],
15
15
  title: item['title'],
16
16
  created: item['created'],
17
- labels: item['labels']
17
+ labels: item['labels'],
18
+ published: item['published'],
19
+ category: Carraway::Category.find(item['category'])
18
20
  )
19
21
  end
20
22
  end
@@ -31,7 +33,9 @@ module Carraway
31
33
  uid: item['uid'],
32
34
  title: item['title'],
33
35
  created: item['created'],
34
- labels: item['labels']
36
+ labels: item['labels'],
37
+ published: item['published'],
38
+ category: Carraway::Category.find(item['category'])
35
39
  )
36
40
  end
37
41
  end
@@ -54,7 +58,9 @@ module Carraway
54
58
  record_type: 'file',
55
59
  title: file.title,
56
60
  created: file.created || at.to_i,
57
- labels: file.labels
61
+ labels: file.labels,
62
+ published: file.published,
63
+ category: file.category.key
58
64
  }
59
65
  )
60
66
  if file.file
data/lib/carraway/post.rb CHANGED
@@ -44,35 +44,56 @@ module Carraway
44
44
  post
45
45
  end
46
46
 
47
- def all(published_only: false)
48
- query = { table_name: Config.backend['table_name'] }
47
+ def all(published_only: false, include_file: false)
48
+ filter_expressions = []
49
+ expression_attribute_values = {}
50
+
51
+ unless include_file
52
+ filter_expressions << 'record_type = :type'
53
+ expression_attribute_values.merge!(':type' => 'post')
54
+ end
55
+
49
56
  if published_only
50
- query[:filter_expression] = <<~FILTER
51
- record_type = :type
52
- AND attribute_exists(published)
53
- AND (NOT attribute_type(published, :t))
54
- AND published < :now
55
- FILTER
56
- query[:expression_attribute_values] = { ':t' => 'NULL', ':now' => Time.now.to_i, ':type' => 'post' }
57
- else
58
- query[:filter_expression] = <<~FILTER
59
- record_type = :type
60
- FILTER
61
- query[:expression_attribute_values] = { ':type' => 'post' }
57
+ filter_expressions << 'attribute_exists(published)'
58
+ filter_expressions << '(NOT attribute_type(published, :t))'
59
+ filter_expressions << 'published < :now'
60
+ expression_attribute_values.merge!(':t' => 'NULL', ':now' => Time.now.to_i)
62
61
  end
63
62
 
64
- client.scan(query).items.map do |item|
65
- new(
66
- uid: item['uid'],
67
- title: item['title'],
68
- body: item['body'],
69
- labels: item['labels'],
70
- category: Category.find(item['category']),
71
- created: Time.at(item['created']),
72
- updated: Time.at(item['updated']),
73
- published: item['published'] && Time.at(item['published'])
63
+ query = { table_name: Config.backend['table_name'] }
64
+ unless filter_expressions.empty?
65
+ query.merge!(
66
+ filter_expression: filter_expressions.join(' AND '),
67
+ expression_attribute_values: expression_attribute_values
74
68
  )
75
69
  end
70
+
71
+ client.scan(query).items.map do |item|
72
+ case item['record_type']
73
+ when 'post'
74
+ new(
75
+ uid: item['uid'],
76
+ title: item['title'],
77
+ body: item['body'],
78
+ labels: item['labels'],
79
+ category: Category.find(item['category']),
80
+ created: Time.at(item['created']),
81
+ updated: Time.at(item['updated']),
82
+ published: item['published'] && Time.at(item['published'])
83
+ )
84
+ when 'file'
85
+ Carraway::File.new(
86
+ uid: item['uid'],
87
+ title: item['title'],
88
+ created: item['created'],
89
+ labels: item['labels'],
90
+ published: item['published'],
91
+ category: Category.find(item['category']),
92
+ )
93
+ else
94
+ raise 'Unknown record_type'
95
+ end
96
+ end
76
97
  end
77
98
 
78
99
  def find(uid)
@@ -25,8 +25,7 @@ module Carraway
25
25
  end
26
26
 
27
27
  get '/carraway/api/posts' do
28
- posts = Post.all(published_only: true).map(&:to_h)
29
-
28
+ posts = Post.all(published_only: true, include_file: true).map(&:to_h)
30
29
  # HACK Expand plugin
31
30
  transformed = params[:view] == 'html'
32
31
  if transformed
@@ -140,6 +139,7 @@ module Carraway
140
139
  # FIXME validation
141
140
  file.title = params[:title]
142
141
  file.labels = params[:labels]
142
+ file.category = Category.find(params[:category])
143
143
  repository.save(file)
144
144
  redirect "/carraway/files/#{file.uid}"
145
145
  end
@@ -153,7 +153,12 @@ module Carraway
153
153
  end
154
154
 
155
155
  post '/carraway/files' do
156
- file = File.new(title: params[:title], file: params[:file], labels: params[:labels])
156
+ file = File.new(
157
+ title: params[:title],
158
+ file: params[:file],
159
+ labels: params[:labels],
160
+ category: Category.find(params[:category]),
161
+ )
157
162
  # FIXME validation and error
158
163
  FileRepository.new.save(file)
159
164
  flash[:message] = "Saved #{file.path}"
@@ -1,3 +1,3 @@
1
1
  module Carraway
2
- VERSION = "0.12.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -9,6 +9,12 @@
9
9
  <label for="title">ファイルタイトル</label>
10
10
  </div>
11
11
  </div>
12
+ <label>記事カテゴリー</label>
13
+ <select name="category" class="browser-default">
14
+ <% Carraway::Category.all.each do |category| %>
15
+ <option value="<%= category.key %>"<%= category == @file.category ? 'selected' : nil%>><%= category.title %></option>
16
+ <% end %>
17
+ </select>
12
18
  <% Carraway::Config.labels.each do |key, title| %>
13
19
  <p>
14
20
  <label>
@@ -9,6 +9,13 @@
9
9
  <div class="input-field col s12">
10
10
  <input type="file" id="file" name="file" placeholder="ファイル">
11
11
  </div>
12
+ <label>記事カテゴリー</label>
13
+ <select name="category" class="browser-default">
14
+ <option value="" disabled selected>記事カテゴリーを選択</option>
15
+ <% Carraway::Category.all.each do |category| %>
16
+ <option value="<%= category.key %>"><%= category.title %></option>
17
+ <% end %>
18
+ </select>
12
19
  <% Carraway::Config.labels.each do |key, title| %>
13
20
  <p>
14
21
  <label>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carraway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - adorechic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-15 00:00:00.000000000 Z
11
+ date: 2019-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor