Replaced most attr_accessor calls by explicit setter methods.
authorTilman Sauerbeck <tilman@code-monkey.de>
Thu, 14 Apr 2005 19:42:06 +0000 (19:42 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Thu, 14 Apr 2005 19:42:06 +0000 (19:42 +0000)
This ensures type safety in some spots.

ChangeLog
lib/redact/part.rb
lib/redact/program.rb
lib/redact/redact.rb

index d0e42e5a77bc2afe7e92d5cb168203a8cc76b97f..89850bd09267d28ef0148be99aa9368c45696456 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,11 @@
 --
-$Id: ChangeLog 24 2005-04-09 13:53:14Z tilman $
+$Id: ChangeLog 25 2005-04-14 19:42:06Z tilman $
 ++
 
+2005-04-14 Tilman Sauerbeck (tilman at code-monkey de)
+        * lib/{redact,part,program}.rb: Replaced most attr_accessor
+          calls by explicit setter methods to ensure type safety
+
 2005-04-09 Tilman Sauerbeck (tilman at code-monkey de)
         * test/crossfade.rb: Updated for recent tween mode fixes
 
index f915a4b5edf1ba2f2139f66d63c13c18c4e4149c..bac1ba4e51da438d9789f80e636f16eb912807b0 100644 (file)
@@ -1,5 +1,5 @@
 #--
-# $Id: part.rb 22 2005-04-02 22:29:50Z tilman $
+# $Id: part.rb 25 2005-04-14 19:42:06Z tilman $
 #
 # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
 #
@@ -31,8 +31,8 @@ module Redact
 
                include Comparable
 
-               attr_reader :collection, :id, :name, :dragable, :clip
-               attr_accessor :mouse_events, :repeat_events
+               attr_reader :collection, :id, :name, :dragable, :clip,
+                           :mouse_events, :repeat_events
 
                def initialize(collection, id, name)
                        @collection = collection
@@ -57,6 +57,14 @@ module Redact
                        @id <=> b.id
                end
 
+               def mouse_events=(val)
+                       @mouse_events = (val == true)
+               end
+
+               def repeat_events=(val)
+                       @repeat_events = (val == true)
+               end
+
                def clip=(part)
                        if part == self
                                raise(ArgumentError, "cannot clip part to itself")
@@ -213,8 +221,8 @@ module Redact
        end
 
        class Description
-               attr_reader :rel, :aspect, :step
-               attr_accessor :visible, :aspect_preference, :color_class
+               attr_reader :rel, :aspect, :step, :visible, :color_class
+               attr_accessor :aspect_preference
 
                def initialize(name = "default", value = 0.0)
                        @name = name.to_str.dup.freeze
@@ -231,6 +239,14 @@ module Redact
                        @color_class = ""
                end
 
+               def visible=(v)
+                       @visible = (v == true)
+               end
+
+               def color_class=(v)
+                       @color_class = v.to_str.dup
+               end
+
                def set_step(x = 0, y = 0)
                        @step = [x, y]
                end
@@ -388,7 +404,7 @@ module Redact
        end
 
        class ImageDescription < Description
-               attr_reader :image, :auto_rel, :tweens
+               attr_reader :image, :auto_rel, :tweens, :border_fill_middle
 
                def initialize(name = "default", value = 0.0)
                        super
@@ -449,8 +465,7 @@ module Redact
        end
 
        class TextDescription < Description
-               attr_reader :font
-               attr_accessor :text, :font_size, :text_class
+               attr_reader :font, :text, :font_size, :text_class
 
                def initialize(name = "default", value = 0.0)
                        super
@@ -468,6 +483,18 @@ module Redact
                        @text_id_text_source = -1
                end
 
+               def text=(v)
+                       @text = v.to_str.dup
+               end
+
+               def font_size=(v)
+                       @font_size = v.to_int
+               end
+
+               def text_class=(v)
+                       @text_class = v.to_str.dup
+               end
+
                def set_fit(x = false, y = false)
                        @fit = [x, y]
                end
index d6038d9646b82d17c75a499fa3e361d8d87884fa..bde0c030b43fc8b4682ad559382d463e8d67842a 100644 (file)
@@ -1,5 +1,5 @@
 #--
-# $Id: program.rb 23 2005-04-02 23:20:32Z tilman $
+# $Id: program.rb 25 2005-04-14 19:42:06Z tilman $
 #
 # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
 #
@@ -35,8 +35,8 @@ module Redact
 
                include Comparable
 
-               attr_reader :collection, :id, :name, :after
-               attr_accessor :signal, :source, :in_from, :in_range
+               attr_reader :collection, :id, :name, :after, :signal, :source,
+                           :in_from, :in_range
 
                def initialize(collection, id, name)
                        @collection = collection
@@ -56,6 +56,34 @@ module Redact
                        @id <=> b.id
                end
 
+               def signal=(v)
+                       @signal = v.to_str.dup
+               end
+
+               def source=(v)
+                       @source = v.to_str.dup
+               end
+
+               def in_from=(v)
+                       unless v.is_a?(Float)
+                               raise(ArgumentError,
+                                     "wrong argument type #{v.class.name} " +
+                                     "(expected Float)")
+                       end
+
+                       @in_from = v
+               end
+
+               def in_range=(v)
+                       unless v.is_a?(Float)
+                               raise(ArgumentError,
+                                     "wrong argument type #{v.class.name} " +
+                                     "(expected Float)")
+                       end
+
+                       @in_range = v
+               end
+
                def to_eet_name
                        "Edje_Program"
                end
@@ -73,8 +101,8 @@ module Redact
        end
 
        class SetStateProgram < Program
-               attr_reader :targets
-               attr_accessor :state, :value, :mode, :time
+               attr_reader :targets, :state, :value, :time
+               attr_accessor :mode
 
                def initialize(collection, id, name)
                        super
@@ -87,6 +115,30 @@ module Redact
                        @targets = ProgramArgs.new(collection)
                end
 
+               def state=(v)
+                       @state = v.to_str.dup
+               end
+
+               def value=(v)
+                       unless v.is_a?(Float)
+                               raise(ArgumentError,
+                                     "wrong argument type #{v.class.name} " +
+                                     "(expected Float)")
+                       end
+
+                       @value = v
+               end
+
+               def time=(v)
+                       unless v.is_a?(Float)
+                               raise(ArgumentError,
+                                     "wrong argument type #{v.class.name} " +
+                                     "(expected Float)")
+                       end
+
+                       @time = v
+               end
+
                def to_eet_properties
                        mode = case @mode
                        when :linear: 1
@@ -120,7 +172,7 @@ module Redact
        end
 
        class EmitSignalProgram < Program
-               attr_accessor :emission_signal, :emission_source
+               attr_reader :emission_signal, :emission_source
 
                def initialize(collection, id, name)
                        super
@@ -130,6 +182,14 @@ module Redact
                        @emission_source = nil
                end
 
+               def emission_signal=(v)
+                       @emission_signal = v.to_str.dup
+               end
+
+               def emission_source=(v)
+                       @emission_source = v.to_str.dup
+               end
+
                def to_eet_properties
                        super.merge!(
                        {"state" => [@emission_signal],
@@ -138,7 +198,7 @@ module Redact
        end
 
        class ExecScriptProgram < Program
-               attr_accessor :script
+               attr_reader :script
 
                def initialize(collection, id, name)
                        super
@@ -146,6 +206,10 @@ module Redact
                        @type = TYPE_EXEC_SCRIPT
                        @script = nil
                end
+
+               def script=(v)
+                       @script = v.to_str.dup
+               end
        end
 
        class ProgramArgs < Array
index 499b7fdb64bfa705d138aaa5f10bb3f85cfd6f1b..260f34208c31afa73de7d7a2613406ac43c1b91b 100644 (file)
@@ -1,5 +1,5 @@
 #--
-# $Id: redact.rb 6 2005-03-26 20:24:40Z tilman $
+# $Id: redact.rb 25 2005-04-14 19:42:06Z tilman $
 #
 # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
 #
@@ -230,8 +230,8 @@ module Redact
        end
 
        class Collection
-               attr_reader :name, :id, :data, :min, :max, :parts, :programs
-               attr_accessor :script
+               attr_reader :name, :id, :data, :min, :max, :parts, :programs,
+                           :script
 
                def initialize(name, id)
                        @name = name.to_str.dup.freeze
@@ -247,6 +247,10 @@ module Redact
                        @script = nil
                end
 
+               def script=(v)
+                       @script = v.to_str.dup
+               end
+
                def part(name, type = :invalid) # :yields: part
                        p = @parts[name]
                        if p.nil?