Class: Wizardz::Page
- Inherits:
-
Object
- Object
- Wizardz::Page
- Defined in:
- lib/wizardz/page.rb
Direct Known Subclasses
Defined Under Namespace
Classes: First
Instance Attribute Summary collapse
-
#page_data ⇒ Object
readonly
Returns the value of attribute page_data.
-
#wizard_inst ⇒ Object
Returns the value of attribute wizard_inst.
Class Method Summary collapse
- .load_pages(states, page_data, wizard_inst) ⇒ Object
- .subclass_element(class_obj, page_data, states, wizard_inst) ⇒ Object
Instance Method Summary collapse
- #get_valid_states(states) ⇒ Object
-
#initialize(data = {}, merge = true) ⇒ Page
constructor
A new instance of Page.
- #page_object ⇒ Object
- #partial ⇒ Object
- #transit(direction, states) ⇒ Object
- #update(data) ⇒ Object
- #valid?(allow_nil = true) ⇒ Boolean
Constructor Details
#initialize(data = {}, merge = true) ⇒ Page
41 42 43 |
# File 'lib/wizardz/page.rb', line 41 def initialize(data={},merge=true) @page_data = data || {} end |
Instance Attribute Details
#page_data ⇒ Object (readonly)
Returns the value of attribute page_data.
5 6 7 |
# File 'lib/wizardz/page.rb', line 5 def page_data @page_data end |
#wizard_inst ⇒ Object
Returns the value of attribute wizard_inst.
6 7 8 |
# File 'lib/wizardz/page.rb', line 6 def wizard_inst @wizard_inst end |
Class Method Details
.load_pages(states, page_data, wizard_inst) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/wizardz/page.rb', line 8 def self.load_pages(states, page_data, wizard_inst) return_val = {} wizard_inst.classes.each do |class_obj| return_val.merge!(self.subclass_element(class_obj,page_data, states, wizard_inst)) end return_val end |
.subclass_element(class_obj, page_data, states, wizard_inst) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/wizardz/page.rb', line 16 def self.subclass_element(class_obj, page_data,states,wizard_inst) id = class_obj::IDENTIFIER rescue nil return {} if id.nil? or !states.include?(id) obj = class_obj.new(page_data[id] || {}, page_data[:merge]) obj.wizard_inst = wizard_inst {id => obj} end |
Instance Method Details
#get_valid_states(states) ⇒ Object
37 38 39 |
# File 'lib/wizardz/page.rb', line 37 def get_valid_states(states) states end |
#page_object ⇒ Object
31 32 33 34 35 |
# File 'lib/wizardz/page.rb', line 31 def page_object obj = self.get_object obj.valid? unless @wizard_inst.unprocessed.include?(self.identifier) obj end |
#partial ⇒ Object
45 46 47 |
# File 'lib/wizardz/page.rb', line 45 def partial self.class::PARTIAL rescue "#{self.identifier.to_s}" end |
#transit(direction, states) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/wizardz/page.rb', line 58 def transit(direction, states) pos = states.index(self.identifier) raise 'Invalid States list' if pos.nil? pos += 1 if direction == 'next' and pos < states.size - 1 pos -= 1 if direction == 'prev' and pos > 0 states[pos] end |
#update(data) ⇒ Object
53 54 55 56 |
# File 'lib/wizardz/page.rb', line 53 def update(data) @page_data = data[:dataset] self.valid?(false) end |
#valid?(allow_nil = true) ⇒ Boolean
26 27 28 29 |
# File 'lib/wizardz/page.rb', line 26 def valid?(allow_nil=true) return allow_nil if @page_data.nil? self.get_object.valid? end |