Class: PageBuilder
- Inherits:
-
Object
- Object
- PageBuilder
- Defined in:
- app/models/page_builder.rb
Overview
Instance Attribute Summary collapse
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user, locale: nil, parent: nil) ⇒ PageBuilder
constructor
A new instance of PageBuilder.
- #page(name, options = {}, &block) ⇒ Object
- #run(&block) ⇒ Object
Constructor Details
#initialize(user, locale: nil, parent: nil) ⇒ PageBuilder
Returns a new instance of PageBuilder.
27 28 29 30 31 |
# File 'app/models/page_builder.rb', line 27 def initialize(user, locale: nil, parent: nil) @user = user @locale = locale || I18n.default_locale @parent = parent end |
Instance Attribute Details
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
18 19 20 |
# File 'app/models/page_builder.rb', line 18 def locale @locale end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
18 19 20 |
# File 'app/models/page_builder.rb', line 18 def parent @parent end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
18 19 20 |
# File 'app/models/page_builder.rb', line 18 def user @user end |
Class Method Details
.build(user, locale: nil, parent: nil, &block) ⇒ Object
21 22 23 24 |
# File 'app/models/page_builder.rb', line 21 def build(user, locale: nil, parent: nil, &block) new(user, locale: locale, parent: parent) .run(&block) end |
Instance Method Details
#page(name, options = {}, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/page_builder.rb', line 33 def page(name, = {}, &block) page = Page.create( { name: name }.merge().merge() ) if block_given? self.class .new(user, locale: locale, parent: page) .run(&block) end page end |
#run(&block) ⇒ Object
45 46 47 |
# File 'app/models/page_builder.rb', line 45 def run(&block) instance_eval(&block) end |