Skip to content

Commit 3a87988

Browse files
committed
feat: build author_cell base
1 parent 45a6d20 commit 3a87988

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Plugins
2+
module Core
3+
class AuthorCell < Plugins::Core::Cell
4+
def input
5+
render
6+
end
7+
8+
private
9+
10+
def current_user
11+
"#{@options[:current_user].firstname} #{@options[:current_user].lastname}"
12+
end
13+
end
14+
end
15+
end

app/models/author_field_type.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class AuthorFieldType < FieldType
2+
attr_accessor :author_name
3+
jsonb_accessor :data, author_name: :string
4+
5+
validates :author_name, presence: true, if: :validate_presence?
6+
7+
def data=(data_hash)
8+
@author_name = data_hash.deep_symbolize_keys[:author_name]
9+
end
10+
11+
def field_item_as_indexed_json_for_field_type(field_item, options = {})
12+
json = {}
13+
json[mapping_field_author_name] = field_item.data['author_name']
14+
json
15+
end
16+
17+
def mapping
18+
{author_name: mapping_field_name, type: :string, analyzer: :snowball}
19+
end
20+
21+
private
22+
23+
def mapping_field_name
24+
"#{field_name.parameterize('_')}_author_name"
25+
end
26+
27+
def author_name_present
28+
errors.add(:author_name, 'must be present') if @author_name.empty?
29+
end
30+
31+
def validate_uniqueness?
32+
@validations.key? :uniqueness
33+
end
34+
35+
def validate_presence?
36+
@validations.key? :presence
37+
end
38+
39+
def validate_length?
40+
@validations.key? :length
41+
end
42+
end

0 commit comments

Comments
 (0)