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
- .terms_page ⇒ Object
- .terms_page=(value) ⇒ Object
- .whitelisted?(key) ⇒ Boolean
Class Method Details
.about_page ⇒ Object
54 55 56 |
# File 'app/models/content_block.rb', line 54 def about_page find_or_create_by(name: 'about_page') end |
.about_page=(value) ⇒ Object
58 59 60 |
# File 'app/models/content_block.rb', line 58 def about_page=(value) about_page.update(value: value) end |
.agreement_page ⇒ Object
62 63 64 65 |
# File 'app/models/content_block.rb', line 62 def agreement_page find_by(name: 'agreement_page') || create(name: 'agreement_page', value: default_agreement_text) end |
.agreement_page=(value) ⇒ Object
67 68 69 |
# File 'app/models/content_block.rb', line 67 def agreement_page=(value) agreement_page.update(value: value) end |
.announcement_text ⇒ Object
38 39 40 |
# File 'app/models/content_block.rb', line 38 def announcement_text find_or_create_by(name: 'announcement_text') end |
.announcement_text=(value) ⇒ Object
42 43 44 |
# File 'app/models/content_block.rb', line 42 def announcement_text=(value) announcement_text.update(value: value) end |
.default_agreement_text ⇒ Object
88 89 90 91 92 93 94 |
# File 'app/models/content_block.rb', line 88 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
96 97 98 99 100 101 102 |
# File 'app/models/content_block.rb', line 96 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
46 47 48 |
# File 'app/models/content_block.rb', line 46 def featured_researcher find_or_create_by(name: 'featured_researcher') end |
.featured_researcher=(value) ⇒ Object
50 51 52 |
# File 'app/models/content_block.rb', line 50 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.
19 20 21 22 23 |
# File 'app/models/content_block.rb', line 19 def self.for(key) key = key.respond_to?(:to_sym) ? key.to_sym : key raise ArgumentError, "#{key} is not a ContentBlock name" unless whitelisted?(key) ContentBlock.public_send(NAME_REGISTRY[key]) end |
.help_page ⇒ Object
71 72 73 |
# File 'app/models/content_block.rb', line 71 def help_page find_or_create_by(name: 'help_page') end |
.help_page=(value) ⇒ Object
75 76 77 |
# File 'app/models/content_block.rb', line 75 def help_page=(value) help_page.update(value: value) end |
.marketing_text ⇒ Object
30 31 32 |
# File 'app/models/content_block.rb', line 30 def marketing_text find_or_create_by(name: 'marketing_text') end |
.marketing_text=(value) ⇒ Object
34 35 36 |
# File 'app/models/content_block.rb', line 34 def marketing_text=(value) marketing_text.update(value: value) end |
.terms_page ⇒ Object
79 80 81 82 |
# File 'app/models/content_block.rb', line 79 def terms_page find_by(name: 'terms_page') || create(name: 'terms_page', value: default_terms_text) end |
.terms_page=(value) ⇒ Object
84 85 86 |
# File 'app/models/content_block.rb', line 84 def terms_page=(value) terms_page.update(value: value) end |
.whitelisted?(key) ⇒ Boolean
26 27 28 |
# File 'app/models/content_block.rb', line 26 def whitelisted?(key) NAME_REGISTRY.include?(key) end |