diff --git a/.profile b/.profile new file mode 100644 index 0000000..5a28696 --- /dev/null +++ b/.profile @@ -0,0 +1,2 @@ +export RUBYOPT=rubygems + diff --git a/Rakefile b/Rakefile index b610bb3..339af09 100644 --- a/Rakefile +++ b/Rakefile @@ -1,16 +1,16 @@ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f } -require File.dirname(__FILE__) + '/lib/ruby-plc' +require File.dirname(__FILE__) + '/lib/machines' # Generate all the Rake tasks # Run 'rake -T' to see list of generated tasks (from gem root directory) -$hoe = Hoe.new('ruby-plc', RubyPlc::VERSION) do |p| - p.developer('FIXME full name', 'FIXME email') +$hoe = Hoe.new('machines', Machines::VERSION) do |p| + p.developer('Tallak Tveide', 'tallak@tveide.net') p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n") p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required p.rubyforge_name = p.name # TODO this is default value - # p.extra_deps = [ - # ['activesupport','>= 2.0.2'], - # ] + p.extra_deps = [ + ['rbtree','>= 0.2.1'], + ] p.extra_dev_deps = [ ['newgem', ">= #{::Newgem::VERSION}"] ] @@ -24,5 +24,12 @@ end require 'newgem/tasks' # load /tasks/*.rake Dir['tasks/**/*.rake'].each { |t| load t } +desc "Look for TODO and FIXME tags in the code" +task :todo do + FileList['**/*.rb'].egrep(/#.*(FIXME|TODO|TBD)/) +end + + # TODO - want other tests/tasks run by default? Add them to the list # task :default => [:spec, :features] +task :default => [:spec, :todo] diff --git a/lib/machines/timedomain/analog.rb b/lib/machines/timedomain/analog.rb index 1a7f6fe..40ce789 100644 --- a/lib/machines/timedomain/analog.rb +++ b/lib/machines/timedomain/analog.rb @@ -1,8 +1,10 @@ require 'machines/timedomain/timer' require 'machines/etc/notify' +require 'machines/timedomain/discrete' + module Machines - module TimeDomain + module Timedomain class Analog extend Notify attr_accessor :name, :description diff --git a/lib/machines/timedomain/analog_value.rb b/lib/machines/timedomain/analog_value.rb index 26cf9b4..a6f1965 100644 --- a/lib/machines/timedomain/analog_value.rb +++ b/lib/machines/timedomain/analog_value.rb @@ -1,16 +1,10 @@ -include 'machines/timedomain/analog' -include 'machines/timedomain/timer' -include 'machines/etc/notify' +require 'machines/timedomain/analog' +require 'machines/timedomain/timer' +require 'machines/etc/notify' module Machines - module Physical - module AnalogValue < Analog - extend Notify - include Analog - - attr_accessor :name, :description - notify :change - + module Timedomain + class AnalogValue < Analog def initialize(value = nil) @name, @description = nil @v = value diff --git a/lib/machines/timedomain/binary_op_discrete.rb b/lib/machines/timedomain/binary_op_discrete.rb index 2986c30..9594ea4 100644 --- a/lib/machines/timedomain/binary_op_discrete.rb +++ b/lib/machines/timedomain/binary_op_discrete.rb @@ -1,7 +1,7 @@ require 'machines/timedomain/discrete_base' module Machines - module TimeDomain + module Timedomain class DiscreteBase #:nodoc: # forward Declaration end diff --git a/lib/machines/timedomain/discrete.rb b/lib/machines/timedomain/discrete.rb index 0f212a0..910cd4e 100644 --- a/lib/machines/timedomain/discrete.rb +++ b/lib/machines/timedomain/discrete.rb @@ -1,7 +1,7 @@ require 'machines/timedomain/discrete_base' module Machines - module TimeDomain + module Timedomain class Discrete < DiscreteBase def initialize(vv = false) @v = vv diff --git a/lib/machines/timedomain/discrete_base.rb b/lib/machines/timedomain/discrete_base.rb index 5d6ad3a..f46de37 100644 --- a/lib/machines/timedomain/discrete_base.rb +++ b/lib/machines/timedomain/discrete_base.rb @@ -4,7 +4,7 @@ require 'machines/etc/notify' module Machines - module TimeDomain + module Timedomain class DiscreteBase extend Notify diff --git a/lib/machines/timedomain/discrete_sink.rb b/lib/machines/timedomain/discrete_sink.rb index fe461bc..37fe1ea 100644 --- a/lib/machines/timedomain/discrete_sink.rb +++ b/lib/machines/timedomain/discrete_sink.rb @@ -1,7 +1,7 @@ require 'machines/timedomain/discrete_base' module Machines - module TimeDomain + module Timedomain class DiscreteSink < DiscreteBase attr_reader :source diff --git a/lib/machines/timedomain/negated_discrete.rb b/lib/machines/timedomain/negated_discrete.rb index d38eabf..0747d6d 100644 --- a/lib/machines/timedomain/negated_discrete.rb +++ b/lib/machines/timedomain/negated_discrete.rb @@ -1,7 +1,7 @@ require 'machines/timedomain/discrete_base' module Machines - module TimeDomain + module Timedomain class DiscreteBase #:nodoc: # forward Declaration end diff --git a/lib/machines/timedomain/sampler.rb b/lib/machines/timedomain/sampler.rb index 95a9f81..45c4e6e 100644 --- a/lib/machines/timedomain/sampler.rb +++ b/lib/machines/timedomain/sampler.rb @@ -2,7 +2,7 @@ include 'machines/timedomain/sequencer' module Machines - module TimeDomain + module Timedomain # The Sample class will notify all listeners to the #on_sample function # at even intervals diff --git a/lib/machines/timedomain/scheduler.rb b/lib/machines/timedomain/scheduler.rb index 4bf0690..d142763 100644 --- a/lib/machines/timedomain/scheduler.rb +++ b/lib/machines/timedomain/scheduler.rb @@ -2,7 +2,7 @@ require 'monitor' module Machines - module TimeDomain + module Timedomain class Scheduler class Entry attr_accessor :time, :tag, :callback diff --git a/lib/machines/timedomain/timer.rb b/lib/machines/timedomain/timer.rb index e9b3d8e..77f6da9 100644 --- a/lib/machines/timedomain/timer.rb +++ b/lib/machines/timedomain/timer.rb @@ -2,7 +2,7 @@ require 'machines/etc/notify' module Machines - module TimeDomain + module Timedomain class Timer extend Notify diff --git a/script/console b/script/console index b82acd4..64f00bd 100755 --- a/script/console +++ b/script/console @@ -5,6 +5,6 @@ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb' libs = " -r irb/completion" # Perhaps use a console_lib to store any extra methods I may want available in the cosole # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}" -libs << " -r #{File.dirname(__FILE__) + '/../lib/ruby-plc.rb'}" -puts "Loading ruby-plc gem" -exec "#{irb} #{libs} --simple-prompt" \ No newline at end of file +libs << " -r #{File.dirname(__FILE__) + '/../lib/machines.rb'}" +puts "Loading machines gem" +exec "#{irb} #{libs} --simple-prompt" diff --git a/spec/analog_2_spec.rb b/spec/analog_2_spec.rb new file mode 100644 index 0000000..e162ba9 --- /dev/null +++ b/spec/analog_2_spec.rb @@ -0,0 +1,24 @@ +require File.dirname(__FILE__) + '/spec_helper.rb' +require 'machines/timedomain/analog_value' + +include Machines::Timedomain + + +describe 'Analog signals' do + before(:each) do + @a = AnalogValue.new 0.0 + @b = AnalogValue.new 0.0 + @d = Discrete.new + end + + it 'should report on change' do + ok = nil + @a.on_change { ok = :ok } + @a.v = 5.0 + ok.should == :ok + ok = nil + @a.v = 10.0 + ok.should == :ok + end + +end diff --git a/spec/analog_spec.rb b/spec/analog_spec.rb index cb85a52..a21089e 100644 --- a/spec/analog_spec.rb +++ b/spec/analog_spec.rb @@ -1,13 +1,13 @@ require File.dirname(__FILE__) + '/spec_helper.rb' -require 'machines/timedomain/analog' +require 'machines/timedomain/analog_value' -include Machines::TimeDomain +include Machines::Timedomain describe 'Analog signals' do before(:each) do - @a = Analog.new 0.0 - @b = Analog.new 0.0 + @a = AnalogValue.new 0.0 + @b = AnalogValue.new 0.0 @d = Discrete.new end diff --git a/spec/discrete_spec.rb b/spec/discrete_spec.rb index ac2f586..9ab94d5 100644 --- a/spec/discrete_spec.rb +++ b/spec/discrete_spec.rb @@ -2,7 +2,7 @@ require 'machines/timedomain/discrete' require 'machines/timedomain/discrete_sink' -include Machines::TimeDomain +include Machines::Timedomain describe 'Discrete signals' do diff --git a/spec/scheduler_nowait_spec.rb b/spec/scheduler_nowait_spec.rb index 2a17559..10da5ff 100644 --- a/spec/scheduler_nowait_spec.rb +++ b/spec/scheduler_nowait_spec.rb @@ -3,7 +3,7 @@ require 'benchmark' require 'timeout' -include Machines::TimeDomain +include Machines::Timedomain describe Scheduler do before(:each) do diff --git a/spec/scheduler_spec.rb b/spec/scheduler_spec.rb index 00e3c36..32aa43f 100644 --- a/spec/scheduler_spec.rb +++ b/spec/scheduler_spec.rb @@ -3,6 +3,8 @@ require 'benchmark' require 'timeout' +include Machines::Timedomain + describe Scheduler do before(:each) do end diff --git a/spec/step_base_spec.rb b/spec/step_base_spec.rb index 0b2e3dd..f6ed1ed 100644 --- a/spec/step_base_spec.rb +++ b/spec/step_base_spec.rb @@ -3,7 +3,7 @@ require 'machines/sequences/step' include Machines::Sequences -include Machines::TimeDomain +include Machines::Timedomain describe StepBase do before(:each) do diff --git a/spec/timer_spec.rb b/spec/timer_spec.rb index 38e554a..1466944 100644 --- a/spec/timer_spec.rb +++ b/spec/timer_spec.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/spec_helper.rb' require 'machines/timedomain/timer' -include Machines::TimeDomain +include Machines::Timedomain describe Timer do before(:each) do