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
Class Method Details
.about_page ⇒ Object
55 56 57 |
# File 'app/models/content_block.rb', line 55 def about_page find_or_create_by(name: 'about_page') end |
.about_page=(value) ⇒ Object
59 60 61 |
# File 'app/models/content_block.rb', line 59 def about_page=(value) about_page.update(value: value) end |
.agreement_page ⇒ Object
63 64 65 66 |
# File 'app/models/content_block.rb', line 63 def agreement_page find_by(name: 'agreement_page') || create(name: 'agreement_page', value: default_agreement_text) end |
.agreement_page=(value) ⇒ Object
68 69 70 |
# File 'app/models/content_block.rb', line 68 def agreement_page=(value) agreement_page.update(value: value) end |
.announcement_text ⇒ Object
39 40 41 |
# File 'app/models/content_block.rb', line 39 def announcement_text find_or_create_by(name: 'announcement_text') end |
.announcement_text=(value) ⇒ Object
43 44 45 |
# File 'app/models/content_block.rb', line 43 def announcement_text=(value) announcement_text.update(value: value) end |
.default_agreement_text ⇒ Object
89 90 91 92 93 94 95 |
# File 'app/models/content_block.rb', line 89 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
97 98 99 100 101 102 103 |
# File 'app/models/content_block.rb', line 97 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
47 48 49 |
# File 'app/models/content_block.rb', line 47 def featured_researcher find_or_create_by(name: 'featured_researcher') end |
.featured_researcher=(value) ⇒ Object
51 52 53 |
# File 'app/models/content_block.rb', line 51 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
72 73 74 |
# File 'app/models/content_block.rb', line 72 def help_page find_or_create_by(name: 'help_page') end |
.help_page=(value) ⇒ Object
76 77 78 |
# File 'app/models/content_block.rb', line 76 def help_page=(value) help_page.update(value: value) end |
.marketing_text ⇒ Object
31 32 33 |
# File 'app/models/content_block.rb', line 31 def marketing_text find_or_create_by(name: 'marketing_text') end |
.marketing_text=(value) ⇒ Object
35 36 37 |
# File 'app/models/content_block.rb', line 35 def marketing_text=(value) marketing_text.update(value: value) end |
.registered?(key) ⇒ Boolean
27 28 29 |
# File 'app/models/content_block.rb', line 27 def registered?(key) NAME_REGISTRY.include?(key) end |
.terms_page ⇒ Object
80 81 82 83 |
# File 'app/models/content_block.rb', line 80 def terms_page find_by(name: 'terms_page') || create(name: 'terms_page', value: default_terms_text) end |
.terms_page=(value) ⇒ Object
85 86 87 |
# File 'app/models/content_block.rb', line 85 def terms_page=(value) terms_page.update(value: value) end |