Class: ContentBlock
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ContentBlock
- Defined in:
- app/models/content_block.rb
Constant Summary collapse
- NAME_REGISTRY =
The keys in this registry are “public” names for collaborator objects, and the values are reserved names of ContentBlock instances, which Hyrax uses as identifiers. Values also correspond to names of messages that can be sent to the ContentBlock class to return defined ContentBlock instances.
{ marketing: :marketing_text, researcher: :featured_researcher, announcement: :announcement_text, about: :about_page, help: :help_page, terms: :terms_page, agreement: :agreement_page }.freeze
Class Method Summary collapse
- .about_page ⇒ Object
- .about_page=(value) ⇒ Object
- .agreement_page ⇒ Object
- .agreement_page=(value) ⇒ Object
- .announcement_text ⇒ Object
- .announcement_text=(value) ⇒ Object
- .default_agreement_text ⇒ Object
- .default_terms_text ⇒ Object
- .featured_researcher ⇒ Object
- .featured_researcher=(value) ⇒ Object
-
.for(key) ⇒ Object
NOTE: method defined outside the metaclass wrapper below because ‘for` is a reserved word in Ruby.
- .help_page ⇒ Object
- .help_page=(value) ⇒ Object
- .marketing_text ⇒ Object
- .marketing_text=(value) ⇒ Object
- .registered?(key) ⇒ Boolean
- .terms_page ⇒ Object
- .terms_page=(value) ⇒ Object
- .whitelisted?(key) ⇒ Boolean deprecated Deprecated.
Class Method Details
.about_page ⇒ Object
61 62 63 |
# File 'app/models/content_block.rb', line 61 def about_page find_or_create_by(name: 'about_page') end |
.about_page=(value) ⇒ Object
65 66 67 |
# File 'app/models/content_block.rb', line 65 def about_page=(value) about_page.update(value: value) end |
.agreement_page ⇒ Object
69 70 71 72 |
# File 'app/models/content_block.rb', line 69 def agreement_page find_by(name: 'agreement_page') || create(name: 'agreement_page', value: default_agreement_text) end |
.agreement_page=(value) ⇒ Object
74 75 76 |
# File 'app/models/content_block.rb', line 74 def agreement_page=(value) agreement_page.update(value: value) end |
.announcement_text ⇒ Object
45 46 47 |
# File 'app/models/content_block.rb', line 45 def announcement_text find_or_create_by(name: 'announcement_text') end |
.announcement_text=(value) ⇒ Object
49 50 51 |
# File 'app/models/content_block.rb', line 49 def announcement_text=(value) announcement_text.update(value: value) end |
.default_agreement_text ⇒ Object
95 96 97 98 99 100 101 |
# File 'app/models/content_block.rb', line 95 def default_agreement_text ERB.new( IO.read( Hyrax::Engine.root.join('app', 'views', 'hyrax', 'content_blocks', 'templates', 'agreement.html.erb') ) ).result end |
.default_terms_text ⇒ Object
103 104 105 106 107 108 109 |
# File 'app/models/content_block.rb', line 103 def default_terms_text ERB.new( IO.read( Hyrax::Engine.root.join('app', 'views', 'hyrax', 'content_blocks', 'templates', 'terms.html.erb') ) ).result end |
.featured_researcher ⇒ Object
53 54 55 |
# File 'app/models/content_block.rb', line 53 def featured_researcher find_or_create_by(name: 'featured_researcher') end |
.featured_researcher=(value) ⇒ Object
57 58 59 |
# File 'app/models/content_block.rb', line 57 def featured_researcher=(value) featured_researcher.update(value: value) end |
.for(key) ⇒ Object
NOTE: method defined outside the metaclass wrapper below because ‘for` is a reserved word in Ruby.
20 21 22 23 24 |
# File 'app/models/content_block.rb', line 20 def self.for(key) key = key.respond_to?(:to_sym) ? key.to_sym : key raise ArgumentError, "#{key} is not a ContentBlock name" unless registered?(key) ContentBlock.public_send(NAME_REGISTRY[key]) end |
.help_page ⇒ Object
78 79 80 |
# File 'app/models/content_block.rb', line 78 def help_page find_or_create_by(name: 'help_page') end |
.help_page=(value) ⇒ Object
82 83 84 |
# File 'app/models/content_block.rb', line 82 def help_page=(value) help_page.update(value: value) end |
.marketing_text ⇒ Object
37 38 39 |
# File 'app/models/content_block.rb', line 37 def marketing_text find_or_create_by(name: 'marketing_text') end |
.marketing_text=(value) ⇒ Object
41 42 43 |
# File 'app/models/content_block.rb', line 41 def marketing_text=(value) marketing_text.update(value: value) end |
.registered?(key) ⇒ Boolean
33 34 35 |
# File 'app/models/content_block.rb', line 33 def registered?(key) NAME_REGISTRY.include?(key) end |
.terms_page ⇒ Object
86 87 88 89 |
# File 'app/models/content_block.rb', line 86 def terms_page find_by(name: 'terms_page') || create(name: 'terms_page', value: default_terms_text) end |
.terms_page=(value) ⇒ Object
91 92 93 |
# File 'app/models/content_block.rb', line 91 def terms_page=(value) terms_page.update(value: value) end |
.whitelisted?(key) ⇒ Boolean
Deprecated.
28 29 30 31 |
# File 'app/models/content_block.rb', line 28 def whitelisted?(key) Deprecation.warn(self, "Samvera is deprecating '#{self}.whitelisted?' in Hyrax 3.0. Use #{self}.registered? instead.") registered?(key) end |