Class: Viewmaster::TemplateVersion
- Inherits:
-
Object
- Object
- Viewmaster::TemplateVersion
- Defined in:
- lib/viewmaster/template_version.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
-
#transitions ⇒ Object
readonly
Returns the value of attribute transitions.
Class Method Summary collapse
Instance Method Summary collapse
- #can_transition_to?(transition_name) ⇒ Boolean
- #change_version_to(transition_name) ⇒ Object
-
#initialize(opts = {}) {|_self| ... } ⇒ TemplateVersion
constructor
A new instance of TemplateVersion.
- #transition(opts = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) {|_self| ... } ⇒ TemplateVersion
Returns a new instance of TemplateVersion.
7 8 9 10 11 12 13 |
# File 'lib/viewmaster/template_version.rb', line 7 def initialize(opts={}, &block) @template_path = opts[:template_path] @name = opts[:name] @transitions = [] @filter = opts[:filter] yield self if block_given? end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/viewmaster/template_version.rb', line 4 def name @name end |
#template_path ⇒ Object
Returns the value of attribute template_path.
3 4 5 |
# File 'lib/viewmaster/template_version.rb', line 3 def template_path @template_path end |
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
5 6 7 |
# File 'lib/viewmaster/template_version.rb', line 5 def transitions @transitions end |
Class Method Details
Instance Method Details
#can_transition_to?(transition_name) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/viewmaster/template_version.rb', line 28 def can_transition_to?(transition_name) #includes current transition name to the whitelist tt = ([transitions.map(&:to).uniq] + [name]).flatten transition = transitions.detect{ |t| t.to.include? transition_name} can_transition = tt.include?(transition_name) if (!transition.nil? && transition.filter.is_a?(Proc)) return can_transition && transition.filter.call(transition_name) else return can_transition end end |
#change_version_to(transition_name) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/viewmaster/template_version.rb', line 42 def change_version_to(transition_name) unless can_transition_to?(transition_name) raise "Can't transition to #{transition_name} from #{self.name}" end # @block_transition_before_change transitions.each{ |o| o.run_callback } # @block_transition_after_change end |
#transition(opts = {}) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/viewmaster/template_version.rb', line 15 def transition(opts={}) @transitions << Transition.new do |t| t.from = name t.to = opts[:to] t.callback = opts[:do] t.filter = opts[:filter] end end |