-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2757 from projecthydra/content_block_concern
ContentBlockBehavior
- Loading branch information
Showing
2 changed files
with
48 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module Sufia | ||
module ContentBlockBehavior | ||
extend ActiveSupport::Concern | ||
|
||
MARKETING = 'marketing_text'.freeze | ||
RESEARCHER = 'featured_researcher'.freeze | ||
ANNOUNCEMENT = 'announcement_text'.freeze | ||
|
||
def external_key_name | ||
self.class.external_keys.fetch(name) { 'External Key' } | ||
end | ||
|
||
class_methods do | ||
def marketing_text | ||
find_or_create_by(name: MARKETING) | ||
end | ||
|
||
def marketing_text=(value) | ||
marketing_text.update(value: value) | ||
end | ||
|
||
def announcement_text | ||
find_or_create_by(name: ANNOUNCEMENT) | ||
end | ||
|
||
def announcement_text=(value) | ||
announcement_text.update(value: value) | ||
end | ||
|
||
def recent_researchers | ||
where(name: RESEARCHER).order('created_at DESC') | ||
end | ||
|
||
def featured_researcher | ||
recent_researchers.first_or_create(name: RESEARCHER) | ||
end | ||
|
||
def featured_researcher=(value) | ||
create(name: RESEARCHER, value: value) | ||
end | ||
|
||
def external_keys | ||
{ RESEARCHER => 'User' } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,3 @@ | ||
class ContentBlock < ActiveRecord::Base | ||
MARKETING = 'marketing_text'.freeze | ||
RESEARCHER = 'featured_researcher'.freeze | ||
ANNOUNCEMENT = 'announcement_text'.freeze | ||
|
||
def self.marketing_text | ||
find_or_create_by(name: MARKETING) | ||
end | ||
|
||
def self.marketing_text=(value) | ||
marketing_text.update(value: value) | ||
end | ||
|
||
def self.announcement_text | ||
find_or_create_by(name: ANNOUNCEMENT) | ||
end | ||
|
||
def self.announcement_text=(value) | ||
announcement_text.update(value: value) | ||
end | ||
|
||
def self.recent_researchers | ||
where(name: RESEARCHER).order('created_at DESC') | ||
end | ||
|
||
def self.featured_researcher | ||
recent_researchers.first_or_create(name: RESEARCHER) | ||
end | ||
|
||
def self.featured_researcher=(value) | ||
create(name: RESEARCHER, value: value) | ||
end | ||
|
||
def self.external_keys | ||
{ RESEARCHER => 'User' } | ||
end | ||
|
||
def external_key_name | ||
self.class.external_keys.fetch(name) { 'External Key' } | ||
end | ||
include Sufia::ContentBlockBehavior | ||
end |