Class: SBF::Client::Page
- Inherits:
-
TopLevelEntity
- Object
- BaseEntity
- TopLevelEntity
- SBF::Client::Page
- Includes:
- Entities::DefaultCacheable
- Defined in:
- lib/stbaldricks/entities/page.rb
Defined Under Namespace
Classes: Content
Constant Summary
Constants inherited from TopLevelEntity
TopLevelEntity::DEFAULT_CLASS_ACTIONS, TopLevelEntity::DEFAULT_CRUD_ACTIONS, TopLevelEntity::DEFAULT_ENDPOINT, TopLevelEntity::DEFAULT_INSTANCE_ACTIONS
Constants inherited from BaseEntity
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#locked_at ⇒ Object
Returns the value of attribute locked_at.
-
#locked_by_profile_id ⇒ Object
Returns the value of attribute locked_by_profile_id.
-
#lookup ⇒ Object
Returns the value of attribute lookup.
-
#may_edit ⇒ Object
readonly
Returns the value of attribute may_edit.
-
#title ⇒ Object
Returns the value of attribute title.
-
#title_tag ⇒ Object
Returns the value of attribute title_tag.
Attributes inherited from BaseEntity
Instance Method Summary collapse
- #add_draft_sections(sections) ⇒ Object
- #draft_content ⇒ Object
- #editor_content ⇒ Object
- #lock_expired?(ttl = 300) ⇒ Boolean
- #meta_content ⇒ Object
- #published_content ⇒ Object
Methods included from Entities::DefaultCacheable
Methods inherited from TopLevelEntity
_endpoint, action, actions, blacklist_action, class_action, define_endpoint, endpoint, #endpoint, instance_action
Methods included from Entities::Cacheable
Methods inherited from BaseEntity
allow_instantiation?, attr_accessor, attr_reader, attr_writer, collection_attributes, defined_attributes, #destroyed?, #dirty_data, entity_attr_accessor, entity_attr_reader, entity_attr_writer, entity_attributes, entity_collection_attr_accessor, entity_collection_attr_reader, entity_collection_attr_writer, #error, inherited, #initialize, #keys_hash, #model_name, multitype_attr_accessor, multitype_attr_reader, multitype_attr_writer, multitype_collection_attr_accessor, multitype_collection_attr_reader, multitype_collection_attr_writer, #not_provided_attributes, optional_attributes, #persisted?, #reload!, #reload_recursive, #rollback!, #to_hash, #to_json, #to_partial
Methods included from EntityResponseConcern
#add_errors, #data, #error?, #errors?, #errors_http_code=, #http_code, #success?
Constructor Details
This class inherits a constructor from SBF::Client::BaseEntity
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
26 27 28 |
# File 'lib/stbaldricks/entities/page.rb', line 26 def id @id end |
#locked_at ⇒ Object
Returns the value of attribute locked_at.
31 32 33 |
# File 'lib/stbaldricks/entities/page.rb', line 31 def locked_at @locked_at end |
#locked_by_profile_id ⇒ Object
Returns the value of attribute locked_by_profile_id.
30 31 32 |
# File 'lib/stbaldricks/entities/page.rb', line 30 def locked_by_profile_id @locked_by_profile_id end |
#lookup ⇒ Object
Returns the value of attribute lookup.
28 29 30 |
# File 'lib/stbaldricks/entities/page.rb', line 28 def lookup @lookup end |
#may_edit ⇒ Object (readonly)
Returns the value of attribute may_edit.
32 33 34 |
# File 'lib/stbaldricks/entities/page.rb', line 32 def may_edit @may_edit end |
#title ⇒ Object
Returns the value of attribute title.
27 28 29 |
# File 'lib/stbaldricks/entities/page.rb', line 27 def title @title end |
#title_tag ⇒ Object
Returns the value of attribute title_tag.
29 30 31 |
# File 'lib/stbaldricks/entities/page.rb', line 29 def title_tag @title_tag end |
Instance Method Details
#add_draft_sections(sections) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/stbaldricks/entities/page.rb', line 62 def add_draft_sections(sections) sections.each do |cid, data| # convert symbol to integer cid = cid.to_s.to_i content = published_content.find { |c| c.id == cid } update_draft_content_section(content, data, cid) unless content.nil? end end |
#draft_content ⇒ Object
48 49 50 |
# File 'lib/stbaldricks/entities/page.rb', line 48 def draft_content content.select { |x| x.is_draft == true } end |
#editor_content ⇒ Object
52 53 54 55 56 |
# File 'lib/stbaldricks/entities/page.rb', line 52 def editor_content published_content.map do |published| draft_content.find { |d| published.id == d.id } || published end end |
#lock_expired?(ttl = 300) ⇒ Boolean
58 59 60 |
# File 'lib/stbaldricks/entities/page.rb', line 58 def lock_expired?(ttl = 300) locked_at.nil? || Time.now >= Time.parse(locked_at) + ttl end |
#meta_content ⇒ Object
35 36 37 |
# File 'lib/stbaldricks/entities/page.rb', line 35 def content.select { |x| x.type == SBF::Client::Page::Content::Type::META } end |
#published_content ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/stbaldricks/entities/page.rb', line 39 def published_content # Sort content so meta type is at the bottom. This preserves order for rendering on page content.select { |x| x.is_draft == false }.sort! do |a, b| next b.type <=> a.type unless b.type == a.type a.sort_order <=> b.sort_order end end |