glib-eventable 0.1.0

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.
@@ -0,0 +1,4 @@
1
+ pkg/
2
+ doc/
3
+ .DS_Store
4
+ .yardoc
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create ruby-1.9.3@glib-eventable
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ glib-eventable (0.1.0)
5
+ glib2 (~> 1.1.5)
6
+ version (~> 1.0.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ coderay (1.0.8)
12
+ glib2 (1.1.5)
13
+ pkg-config
14
+ guard (1.5.4)
15
+ listen (>= 0.4.2)
16
+ lumberjack (>= 1.0.2)
17
+ pry (>= 0.9.10)
18
+ thor (>= 0.14.6)
19
+ guard-yard (2.0.1)
20
+ guard (>= 1.1.0)
21
+ yard (>= 0.7.0)
22
+ listen (0.5.3)
23
+ lumberjack (1.0.2)
24
+ method_source (0.8.1)
25
+ pkg-config (1.1.4)
26
+ pry (0.9.10)
27
+ coderay (~> 1.0.5)
28
+ method_source (~> 0.8)
29
+ slop (~> 3.3.1)
30
+ rake (0.9.4)
31
+ redcarpet (2.2.2)
32
+ slop (3.3.3)
33
+ thor (0.16.0)
34
+ version (1.0.0)
35
+ yard (0.8.3)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ glib-eventable!
42
+ guard-yard (~> 2.0.1)
43
+ rake (~> 0.9)
44
+ redcarpet (~> 2.2.2)
@@ -0,0 +1,5 @@
1
+ guard 'yard' do
2
+ watch(%r{app/.+\.rb})
3
+ watch(%r{lib/.+\.rb})
4
+ watch(%r{ext/.+\.c})
5
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Ryan Scott Lewis <ryan@rynet.us>.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ # Glib-Eventable
2
+
3
+ This is a helper gem for [ruby-gnome2][gtk] applications.
4
+
5
+ Instead of writing:
6
+
7
+ ```ruby
8
+ class Window < Gtk::Window
9
+ def initialize
10
+ signal_connect('destroy') { Gtk.main_quit }
11
+ end
12
+ end
13
+ ```
14
+
15
+ This allows you to write:
16
+
17
+ ```ruby
18
+ class Window < Gtk::Window
19
+ event destroy: :on_destroy
20
+
21
+ def on_destroy
22
+ Gtk.main_quit
23
+ end
24
+ end
25
+ ```
26
+
27
+ This allows you to create subclasses of `Gtk` objects in a more OOP style.
28
+
29
+ ## Install
30
+
31
+ ### Bundler: `gem 'glib-eventable'`
32
+
33
+ ### RubyGems: `gem install glib-eventable`
34
+
35
+ ## Usage
36
+
37
+ ```ruby
38
+ require 'glib/eventable'
39
+
40
+ class MyToggleRenderer < Gtk::CellRendererToggle
41
+ event toggled: :on_toggle
42
+
43
+ def initialize(column)
44
+ @column = column
45
+
46
+ super()
47
+ end
48
+
49
+ def on_toggle(path)
50
+ iter = @column.tree_view.model.get_iter(path)
51
+
52
+ iter[1] = case iter[1]
53
+ when 'Running' then 'Stopped'
54
+ when 'Stopped' then 'Running'
55
+ end
56
+ end
57
+ end
58
+ ```
59
+ ## Contributing
60
+
61
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
62
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
63
+ * Fork the project
64
+ * Start or switch to a testing/unstable/feature/bugfix branch
65
+ * Commit and push until you are happy with your contribution
66
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
67
+ * Please try not to mess with the Rakefile, VERSION or gemspec.
68
+
69
+ ## Copyright
70
+
71
+ Copyright © 2012 Ryan Scott Lewis <ryan@rynet.us>.
72
+
73
+ The MIT License (MIT) - See LICENSE for further details.
74
+
75
+ [gtk]: http://ruby-gnome2.sourceforge.jp/
@@ -0,0 +1,54 @@
1
+ require 'pathname'
2
+
3
+ def require_task(path)
4
+ begin
5
+ require path
6
+
7
+ yield
8
+ rescue LoadError
9
+ puts '', "Could not load '#{path}'.", 'Try to `rake gem:spec` and `bundle install` and try again.', ''
10
+ end
11
+ end
12
+
13
+ spec = Gem::Specification.new do |s|
14
+ s.name = 'glib-eventable'
15
+ s.version = Pathname.new(__FILE__).dirname.join('VERSION').read.strip
16
+ s.author = 'Ryan Scott Lewis'
17
+ s.email = 'ryan@rynet.us'
18
+ s.homepage = "http://github.com/c00lryguy/#{s.name}"
19
+ s.description = 'This is a helper gem for ruby-gnome2 applications that allows developers to easily connect signals to methods.'
20
+ s.summary = 'This is a helper gem for ruby-gnome2 applications.'
21
+ s.require_path = 'lib'
22
+ s.files = `git ls-files`.lines.to_a.collect { |s| s.strip }
23
+ s.executables = `git ls-files -- bin/*`.lines.to_a.collect { |s| File.basename(s.strip) }
24
+
25
+ s.add_dependency 'version', '~> 1.0.0'
26
+ s.add_dependency 'glib2', '~> 1.1.5'
27
+ s.add_development_dependency 'rake', '~> 0.9'
28
+ s.add_development_dependency 'guard-yard', '~> 2.0.1'
29
+ s.add_development_dependency 'redcarpet', '~> 2.2.2'
30
+ end
31
+
32
+ require_task 'rake/version_task' do
33
+ Rake::VersionTask.new do |t|
34
+ t.with_git_tag = true
35
+ t.with_gemspec = spec
36
+ end
37
+ end
38
+
39
+ namespace :gem do
40
+ desc 'Generate the gemspec defined in this Rakefile'
41
+ task :spec do
42
+ Pathname.new("#{spec.name}.gemspec").open('w') { |f| f.write(spec.to_ruby) }
43
+ end
44
+ end
45
+
46
+ require 'rubygems/package_task'
47
+ Gem::PackageTask.new(spec) do |t|
48
+ t.need_zip = false
49
+ t.need_tar = false
50
+ end
51
+
52
+ task :default do
53
+ puts `rake -T`
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "glib-eventable"
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ryan Scott Lewis"]
9
+ s.date = "2012-11-18"
10
+ s.description = "This is a helper gem for ruby-gnome2 applications that allows developers to easily connect signals to methods."
11
+ s.email = "ryan@rynet.us"
12
+ s.files = [".gitignore", ".rvmrc", "Gemfile", "Gemfile.lock", "Guardfile", "LICENSE", "README.md", "Rakefile", "VERSION", "glib-eventable.gemspec", "lib/glib-eventable.rb", "lib/glib/eventable.rb"]
13
+ s.homepage = "http://github.com/c00lryguy/glib-eventable"
14
+ s.require_paths = ["lib"]
15
+ s.rubygems_version = "1.8.24"
16
+ s.summary = "This is a helper gem for ruby-gnome2 applications."
17
+
18
+ if s.respond_to? :specification_version then
19
+ s.specification_version = 3
20
+
21
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
22
+ s.add_runtime_dependency(%q<version>, ["~> 1.0.0"])
23
+ s.add_runtime_dependency(%q<glib2>, ["~> 1.1.5"])
24
+ s.add_development_dependency(%q<rake>, ["~> 0.9"])
25
+ s.add_development_dependency(%q<guard-yard>, ["~> 2.0.1"])
26
+ s.add_development_dependency(%q<redcarpet>, ["~> 2.2.2"])
27
+ else
28
+ s.add_dependency(%q<version>, ["~> 1.0.0"])
29
+ s.add_dependency(%q<glib2>, ["~> 1.1.5"])
30
+ s.add_dependency(%q<rake>, ["~> 0.9"])
31
+ s.add_dependency(%q<guard-yard>, ["~> 2.0.1"])
32
+ s.add_dependency(%q<redcarpet>, ["~> 2.2.2"])
33
+ end
34
+ else
35
+ s.add_dependency(%q<version>, ["~> 1.0.0"])
36
+ s.add_dependency(%q<glib2>, ["~> 1.1.5"])
37
+ s.add_dependency(%q<rake>, ["~> 0.9"])
38
+ s.add_dependency(%q<guard-yard>, ["~> 2.0.1"])
39
+ s.add_dependency(%q<redcarpet>, ["~> 2.2.2"])
40
+ end
41
+ end
@@ -0,0 +1,6 @@
1
+ require 'pathname'
2
+
3
+ __LIB__ ||= Pathname.new(__FILE__).join('..', '..', 'lib')
4
+ $:.unshift(__LIB__.to_s) unless $:.include?(__LIB__.to_s)
5
+
6
+ require 'glib/eventable'
@@ -0,0 +1,46 @@
1
+ require 'bundler/setup'
2
+ require 'version'
3
+
4
+ # Add Eventable to GLib
5
+ module GLib
6
+
7
+ # This allows you to create subclasses of `Gtk` objects in a more OOP style.
8
+ module Eventable
9
+ is_versionable
10
+
11
+ # Connect a signal to a method or return all connected events.
12
+ #
13
+ # @return [Hash] a Hash where the key is the signal and the value is the method name.
14
+ def event(event_hash=nil)
15
+ @events ||= {}
16
+ return @events if event_hash.nil?
17
+
18
+ raise TypeError, 'event_hash must respond to :to_hash or :to_h' unless [:to_hash, :to_h].any? { |method_name| event_hash.respond_to?(method_name) }
19
+ event_hash = event_hash.to_hash rescue event_hash.to_h
20
+
21
+ @events = event_hash.merge(@events)
22
+ end
23
+ alias_method :events, :event
24
+
25
+ # Connect signals to events before initialization.
26
+ def new(*args)
27
+ super.instance_eval do
28
+ self.class.events.each do |event_name, method_name|
29
+ # TODO: These should be /defined/ as this, not read as this
30
+ event_name = event_name.to_s.downcase.strip
31
+ method_name = method_name.to_s.downcase.strip.to_sym
32
+
33
+ signal_connect(event_name) { |object, *args| send(method_name, *args)}
34
+ end
35
+
36
+ self
37
+ end
38
+ end
39
+ end
40
+
41
+ # Modify all Instantiatable with Eventable
42
+ class Instantiatable
43
+ extend Eventable
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glib-eventable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Scott Lewis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: version
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: glib2
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.1.5
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.9'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.0.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.0.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: redcarpet
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.2.2
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 2.2.2
94
+ description: This is a helper gem for ruby-gnome2 applications that allows developers
95
+ to easily connect signals to methods.
96
+ email: ryan@rynet.us
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rvmrc
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - Guardfile
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - VERSION
110
+ - glib-eventable.gemspec
111
+ - lib/glib-eventable.rb
112
+ - lib/glib/eventable.rb
113
+ homepage: http://github.com/c00lryguy/glib-eventable
114
+ licenses: []
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.24
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: This is a helper gem for ruby-gnome2 applications.
137
+ test_files: []