sugar-high 0.4.4 → 0.4.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -9,9 +9,7 @@ begin
9
9
  gem.email = "kmandrup@gmail.com"
10
10
  gem.homepage = "http://github.com/kristianmandrup/sugar-high"
11
11
  gem.authors = ["Kristian Mandrup"]
12
- gem.add_development_dependency "rspec", ">= 2.4.1"
13
- # gem.add_dependency "require_all", "~> 1.2.0"
14
-
12
+ gem.add_development_dependency "rspec", ">= 2.5"
15
13
  end
16
14
  Jeweler::GemcutterTasks.new
17
15
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.4
1
+ 0.4.4.1
@@ -12,7 +12,6 @@ require 'sugar-high/file_mutate/append_content'
12
12
  require 'sugar-high/file_mutate/remove_content'
13
13
  require 'sugar-high/file_mutate/replace_content'
14
14
  require 'sugar-high/file_mutate/insert_content'
15
- require 'sugar-high/file_mutate/extras'
16
15
 
17
16
  require 'sugar-high/class_ext'
18
17
  require 'active_support/inflector'
@@ -28,31 +28,30 @@ module SugarHigh
28
28
  content = file.read.gsub(regexp, *args, &block)
29
29
  file.overwrite content
30
30
  end
31
- end
32
-
33
- protected
34
-
35
- def get_file file_name
36
- case file_name
37
- when PathString, String
38
- File.new file_name
39
- when File
40
- file_name
41
- else
42
- raise ArgumentError, "Could not be converted to a File object: #{file_name}"
43
- end
44
- end
45
-
46
- def get_filepath file
47
- case file
48
- when PathString, String
49
- file
50
- when File
51
- file.path
52
- else
53
- raise ArgumentError, "Could not be converted to a file path: #{file_name}"
31
+
32
+
33
+ def get_file file_name
34
+ case file_name
35
+ when PathString, String
36
+ File.new file_name
37
+ when File
38
+ file_name
39
+ else
40
+ raise ArgumentError, "Could not be converted to a File object: #{file_name}"
41
+ end
42
+ end
43
+
44
+ def get_filepath file
45
+ case file
46
+ when PathString, String
47
+ file
48
+ when File
49
+ file.path
50
+ else
51
+ raise ArgumentError, "Could not be converted to a file path: #{file_name}"
52
+ end
54
53
  end
55
- end
54
+ end
56
55
  end
57
56
  end
58
57
  end
@@ -0,0 +1,40 @@
1
+ # From: http://www.infoq.com/articles/properties-metaprogramming
2
+
3
+ module Properties
4
+ def self.extended(base)
5
+ base.class_eval %{
6
+ def fire_event_for(sym, arg)
7
+ return if !@listener[sym]
8
+ @listener[sym].each {|l| l.call(arg) }
9
+ end
10
+ }
11
+ end
12
+
13
+ # def property(sym, &predicate)
14
+ def property(sym, predicate=nil)
15
+ define_method(sym) do
16
+ instance_variable_get("@#{sym}")
17
+ end
18
+
19
+ define_method("#{sym}=") do |arg|
20
+ return if !predicate.call(arg) if predicate
21
+ instance_variable_set("@#{sym}", arg)
22
+ fire_event_for(sym, arg)
23
+ end
24
+
25
+ define_method("add_#{sym}_listener") do |x|
26
+ @listener ||= {}
27
+ @listener[sym] ||= []
28
+ @listener[sym] << x
29
+ end
30
+
31
+ define_method("remove_#{sym}_listener") do |x|
32
+ return if !@listener[sym]
33
+ @listener[sym].delete_at(x)
34
+ end
35
+ end
36
+
37
+ def is(test)
38
+ lambda {|val| test === val }
39
+ end
40
+ end
@@ -16,4 +16,7 @@ class Abc
16
16
 
17
17
 
18
18
 
19
+
20
+
21
+
19
22
  end
@@ -19,6 +19,8 @@ Fixtures::Application.routes.draw do
19
19
 
20
20
 
21
21
 
22
+
23
+
22
24
 
23
25
 
24
26
 
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'rspec/core'
1
+ require 'rspec'
2
2
  require 'sugar-high'
3
3
 
4
4
  RSpec.configure do |config|
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'sugar-high/file'
2
3
  require 'sugar-high/file_mutate'
3
4
  File.mutate_ext :all
4
5
 
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'sugar-high/properties'
3
+
4
+ class CruiseShip
5
+ extend Properties
6
+
7
+ property :direction
8
+ property :speed, is(0..300)
9
+ end
10
+
11
+ describe 'Properties pack' do
12
+ let (:ship) { CruiseShip.new }
13
+
14
+ before do
15
+ ship.add_direction_listener(lambda {|x| puts "Oy... someone changed the direction to #{x}"})
16
+ end
17
+
18
+ it 'should listen and react when changing direction' do
19
+ ship.direction = "north"
20
+ end
21
+
22
+ it 'should listen and react when changing speed' do
23
+ ship.add_speed_listener(lambda {|x| puts "Oy... someone changed the speed to #{x}"})
24
+ ship.add_speed_listener(lambda {|x| puts "Yo, dude... someone changed the speed to #{x}"})
25
+ end
26
+
27
+ it 'should reflect on speed settings if in range or not' do
28
+ ship.speed = 200
29
+ ship.speed = 300
30
+ ship.speed = 301
31
+ ship.speed = -1
32
+ ship.speed = 2000
33
+
34
+ puts ship.direction
35
+ puts ship.speed
36
+ end
37
+
38
+ it 'should remove listener' do
39
+ ship.remove_speed_listener(1)
40
+ ship.speed = 200
41
+ ship.speed = 350
42
+
43
+ puts ship.direction
44
+ puts ship.speed
45
+ end
46
+ end
47
+
48
+
data/sugar-high.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sugar-high}
8
- s.version = "0.4.4"
8
+ s.version = "0.4.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Kristian Mandrup}]
12
- s.date = %q{2011-06-01}
12
+ s.date = %q{2011-06-05}
13
13
  s.description = %q{More Ruby sugar - inspired by the 'zuker' project}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -48,6 +48,7 @@ Gem::Specification.new do |s|
48
48
  "lib/sugar-high/module.rb",
49
49
  "lib/sugar-high/not.rb",
50
50
  "lib/sugar-high/path.rb",
51
+ "lib/sugar-high/properties.rb",
51
52
  "lib/sugar-high/regexp.rb",
52
53
  "lib/sugar-high/rspec/configure.rb",
53
54
  "lib/sugar-high/rspec/matchers/have_aliases.rb",
@@ -82,25 +83,26 @@ Gem::Specification.new do |s|
82
83
  "spec/sugar-high/methods_spec.rb",
83
84
  "spec/sugar-high/module_spec.rb",
84
85
  "spec/sugar-high/path_spec.rb",
86
+ "spec/sugar-high/properties_spec.rb",
85
87
  "spec/sugar-high/regexp_spec.rb",
86
88
  "spec/sugar-high/string_spec.rb",
87
89
  "sugar-high.gemspec"
88
90
  ]
89
91
  s.homepage = %q{http://github.com/kristianmandrup/sugar-high}
90
92
  s.require_paths = [%q{lib}]
91
- s.rubygems_version = %q{1.8.3}
93
+ s.rubygems_version = %q{1.8.5}
92
94
  s.summary = %q{Ruby convenience sugar packs!}
93
95
 
94
96
  if s.respond_to? :specification_version then
95
97
  s.specification_version = 3
96
98
 
97
99
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
98
- s.add_development_dependency(%q<rspec>, [">= 2.4.1"])
100
+ s.add_development_dependency(%q<rspec>, [">= 2.5"])
99
101
  else
100
- s.add_dependency(%q<rspec>, [">= 2.4.1"])
102
+ s.add_dependency(%q<rspec>, [">= 2.5"])
101
103
  end
102
104
  else
103
- s.add_dependency(%q<rspec>, [">= 2.4.1"])
105
+ s.add_dependency(%q<rspec>, [">= 2.5"])
104
106
  end
105
107
  end
106
108
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugar-high
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,19 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-01 00:00:00.000000000Z
12
+ date: 2011-06-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2153218060 !ruby/object:Gem::Requirement
16
+ requirement: &2153188580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 2.4.1
21
+ version: '2.5'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2153218060
24
+ version_requirements: *2153188580
25
25
  description: More Ruby sugar - inspired by the 'zuker' project
26
26
  email: kmandrup@gmail.com
27
27
  executables: []
@@ -61,6 +61,7 @@ files:
61
61
  - lib/sugar-high/module.rb
62
62
  - lib/sugar-high/not.rb
63
63
  - lib/sugar-high/path.rb
64
+ - lib/sugar-high/properties.rb
64
65
  - lib/sugar-high/regexp.rb
65
66
  - lib/sugar-high/rspec/configure.rb
66
67
  - lib/sugar-high/rspec/matchers/have_aliases.rb
@@ -95,6 +96,7 @@ files:
95
96
  - spec/sugar-high/methods_spec.rb
96
97
  - spec/sugar-high/module_spec.rb
97
98
  - spec/sugar-high/path_spec.rb
99
+ - spec/sugar-high/properties_spec.rb
98
100
  - spec/sugar-high/regexp_spec.rb
99
101
  - spec/sugar-high/string_spec.rb
100
102
  - sugar-high.gemspec
@@ -118,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
120
  version: '0'
119
121
  requirements: []
120
122
  rubyforge_project:
121
- rubygems_version: 1.8.3
123
+ rubygems_version: 1.8.5
122
124
  signing_key:
123
125
  specification_version: 3
124
126
  summary: Ruby convenience sugar packs!