bean 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,6 @@
1
+ .yardoc/
2
+ doc/
3
+ pkg/
4
+
1
5
  *.gem
2
6
 
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2011 dan sinclair
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File without changes
@@ -0,0 +1,24 @@
1
+ require 'rake/gempackagetask'
2
+ require 'yard'
3
+
4
+ spec = eval(File.open("bean.gemspec").read)
5
+ Rake::GemPackageTask.new(spec) do |pkg|
6
+ pkg.need_tar = true
7
+ end
8
+
9
+ desc 'Generate documentation'
10
+ YARD::Rake::YardocTask.new do |t|
11
+ t.files = ['lib/**/*.rb', '-', 'LICENSE']
12
+ t.options = ['--main', 'README.md', '--no-private']
13
+ end
14
+
15
+ task :tag do
16
+ sh "git tag -m 'Tagging release: #{Bean::VERSION}' -a v#{Bean::VERSION}"
17
+ end
18
+
19
+ namespace :gem do
20
+ desc 'Upload gem to rubygems.org'
21
+ task :push => [:package, :tag] do
22
+ sh "gem push pkg/bean-#{Bean::VERSION}.gem"
23
+ end
24
+ end
@@ -5,16 +5,19 @@ require 'bean/version'
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'bean'
7
7
  s.version = Bean::VERSION
8
+ s.platform = Gem::Platform::RUBY
8
9
 
9
10
  s.authors = ['dan sinclair']
10
11
  s.email = ['dj2@everburning.com']
11
12
 
12
- s.homepage = 'http://github.com/dj2/Bean.git'
13
+ s.homepage = 'http://github.com/dj2/Bean'
13
14
  s.summary = 'Cocoa Additions for MacRuby Applications'
14
15
  s.description = s.summary
15
16
 
16
17
  s.required_ruby_version = '>=1.9.2'
17
18
 
19
+ s.add_development_dependency 'yard'
20
+
18
21
  s.files = `git ls-files`.split("\n")
19
22
  s.require_paths = ['lib']
20
23
  end
@@ -1,10 +1,11 @@
1
+ require 'bean/nsindexset_additions'
2
+ require 'bean/nsmutableurlrequest_additions'
1
3
  require 'bean/nsnotificationcenter_additions'
2
4
  require 'bean/nstableview_additions'
3
5
  require 'bean/nstextfield_additions'
4
6
  require 'bean/nstoolbaritem_additions'
5
7
  require 'bean/nsurl_connection_additions'
6
8
  require 'bean/nsuserdefaults_additions'
7
- require 'bean/nsview_additions'
8
9
  require 'bean/nsxmlnode_additions'
9
10
 
10
11
  require 'bean/table_data_source'
@@ -0,0 +1,22 @@
1
+ # Extensions to the NSIndexSet class
2
+ class NSIndexSet
3
+ include Enumerable
4
+
5
+ #
6
+ # Iterate over each of the items in the NSIndexSet
7
+ #
8
+ # @example
9
+ # s = NSIndexSet.indexSetWithIndexesInRange(NSMakeRange(0, 10))
10
+ # s.each { |i| puts i }
11
+ #
12
+ # @yield [i] Provides the current index to the given block
13
+ # @yieldparam [Fixnum] i The index
14
+ # @return [nil]
15
+ def each
16
+ i = self.firstIndex
17
+ until i == NSNotFound
18
+ yield i
19
+ i = self.indexGreaterThanIndex(i)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ # Extensions to the NSMutableRequest class
2
+ class NSMutableURLRequest
3
+ #
4
+ # Create a POST request
5
+ #
6
+ # @example
7
+ # req = NSMutableURLRequest.post("https://example.com",
8
+ # :body => "foo=1&bar=2&baz=3",
9
+ # :head => { 'Content-Type' => 'application/x-www-form-urlencoded' })
10
+ #
11
+ # @param url [String] The domain to post too
12
+ # @param opts [Hash] Any options for the post
13
+ # @option opts [String] :body The body to send with the POST request
14
+ # @option opts [Hash] :head Any headers to send with the request
15
+ # @return [NSMutableURLRequest] The request object
16
+ def self.post(url, opts)
17
+ req = NSMutableURLRequest.requestWithURL(NSURL.URLWithString(url))
18
+ req.setHTTPMethod('POST')
19
+
20
+ if opts[:head]
21
+ opts[:head].each_pair do |k, v|
22
+ req.setValue(v, forHTTPHeaderField:k)
23
+ end
24
+ end
25
+
26
+ req.setHTTPBody(opts[:body].to_data) if opts[:body]
27
+ req
28
+ end
29
+ end
@@ -1,10 +1,37 @@
1
+ # Extensions to the NSNotificationCenter class
1
2
  class NSNotificationCenter
3
+ #
4
+ # Post a notification to the default center.
5
+ #
6
+ # NSNotificationCenter.post provides a convenience wrapper around
7
+ # posting messages to the defaultCenter.
8
+ #
9
+ # @example
10
+ # NSNotificationCenter.post(:name => :my_message, :info => {:hi => 1})
11
+ #
12
+ # @param options [Hash] Options for the notification
13
+ # @option options [String|Symbol] :name The notification name to send
14
+ # @option options [String] :object The object to send
15
+ # @option options [String] :info The userInfo to send
16
+ # @return [nil]
2
17
  def self.post(options)
3
18
  NSNotificationCenter.defaultCenter.postNotificationName(options[:name],
4
19
  object:options[:object],
5
20
  userInfo:options[:info])
6
21
  end
7
22
 
23
+ #
24
+ # Setup an observer for the given notification and execute block when seen. Then
25
+ # block will be passed the notification object.
26
+ #
27
+ # @example
28
+ # NSNotificationCenter.observe(:my_message) do |notice|
29
+ # puts "My Message Received: #{notice.userInfo.inspect}"
30
+ # end
31
+ #
32
+ # @param name [String|Symbol] The notification name to listen for
33
+ # @param blk [Proc] The block to execute when notification is +received
34
+ # @return [nil]
8
35
  def self.observe(name, &blk)
9
36
  @observers ||= []
10
37
  @observers << Class.new do
@@ -1,13 +1,27 @@
1
+ # Extensions to the NSTableView class
1
2
  class NSTableView
2
- alias dataSource= setDataSource
3
3
  alias reload reloadData
4
4
 
5
+ #
6
+ # Helper for adding a double click handler to the table
7
+ #
8
+ # The block will be called and provided the sender, clicked column and clicked row
9
+ #
10
+ # @param blk [Proc] The block to execute
11
+ # @return [Nil]
5
12
  def on_double_click(&blk)
6
13
  @on_double_action = blk
7
14
  def self.performDoubleAction(sender); @on_double_action.call(sender, self.clickedColumn, self.clickedRow); end
8
15
  setDoubleAction("performDoubleAction:")
9
16
  end
10
17
 
18
+ #
19
+ # Helper for adding a click handler to the table
20
+ #
21
+ # The block will be called and provided the sender, clicked column and clicked row
22
+ #
23
+ # @param blk [Proc] The block to execute
24
+ # @return [Nil]
11
25
  def on_click(&blk)
12
26
  @on_action = blk
13
27
  def self.performAction(sender); @on_action.call(sender, self.clickedColumn, self.clickedRow); end
@@ -1,3 +1,4 @@
1
+ # Extensions to the NSTextField class
1
2
  class NSTextField
2
3
  alias to_s stringValue
3
4
  alias to_f floatValue
@@ -1,4 +1,12 @@
1
+ # Extensions to the NSToolbarItem class
1
2
  class NSToolbarItem
3
+ #
4
+ # Shortcut for adding an on click handler to the toolbar item.
5
+ #
6
+ # The provided block will be provided the sender when executed.
7
+ #
8
+ # @param blk [Proc] The block to execute on click
9
+ # @return [Nil]
2
10
  def on_click(&blk)
3
11
  @on_action = blk
4
12
  def self.performAction(sender); @on_action.call(sender); end
@@ -1,4 +1,15 @@
1
+ # Extensions to the NSURLConnection class
1
2
  class NSURLConnection
3
+ #
4
+ # Helper method for creating a NSURLConnection.
5
+ #
6
+ # Using this method will cause the URL Connection to use itself
7
+ # as the delegate. You can then add error and success handlers to
8
+ # be called when the download is finished.
9
+ #
10
+ # @param req [NSURLRequest] The URL Request
11
+ # @param blk [Proc] The success block to hookup
12
+ # @return [NSURLConnection] The URL Connection
2
13
  def initWithRequest(req, &blk)
3
14
  @error = nil
4
15
  @response = nil
@@ -10,33 +21,59 @@ class NSURLConnection
10
21
  initWithRequest(req, delegate:self)
11
22
  end
12
23
 
24
+ #
25
+ # Attach an error handler to the connection.
26
+ #
27
+ # The error handler will be executed in case of a connection
28
+ # error. The handler can be attached after the connection is
29
+ # completed.
30
+ #
31
+ # @param blk [Proc] The block to execute
32
+ # @return [Nil]
33
+ def on_error(&blk)
34
+ @on_error = blk
35
+ @on_error.call(@error) if @error
36
+ end
37
+
38
+ #
39
+ # Attach a success handler to the connection.
40
+ #
41
+ # The success handler will be executed when the connection is
42
+ # complete. The handler can be attached after the connection is
43
+ # completed.
44
+ #
45
+ # @param blk [Proc] The block to execute
46
+ # @return [Nil]
47
+ def on_success(&blk)
48
+ @on_success = blk
49
+ @on_success.call(@response) if @response
50
+ end
51
+
52
+ # Response received callback
53
+ # @api private
13
54
  def connection(conn, didReceiveResponse:resp)
14
55
  @data.setLength(0)
15
56
  end
16
57
 
58
+ # Data received callback
59
+ # @api private
17
60
  def connection(conn, didReceiveData:rcv)
18
61
  @data.appendData(rcv)
19
62
  end
20
63
 
64
+ # Connection failed callback
65
+ # @api private
21
66
  def connection(conn, didFailWithError:error)
22
67
  return unless @on_error
23
68
  @on_error.call(error)
24
69
  @error = error
25
70
  end
26
71
 
72
+ # Connection finished callback
73
+ # @api private
27
74
  def connectionDidFinishLoading(conn)
28
75
  @response = NSString.alloc.initWithData(@data, encoding:NSUTF8StringEncoding)
29
76
  @on_success.call(@response) if @on_success
30
77
  @data = nil
31
78
  end
32
-
33
- def on_error(&blk)
34
- @on_error = blk
35
- @on_error.call(@error) if @error
36
- end
37
-
38
- def on_success(&blk)
39
- @on_success = blk
40
- @on_success.call(@response) if @response
41
- end
42
79
  end
@@ -1,16 +1,53 @@
1
+ # Extensions to the NSUserDefaults class
1
2
  class NSUserDefaults
2
- def self.[]=(key,value)
3
+ #
4
+ # Shortcut for setting a key/value into the standardUserDefaults
5
+ #
6
+ # @example
7
+ # NSUserDefaults[:foo] = 'bar'
8
+ #
9
+ # @param key [String|Symbol] The key to set
10
+ # @param value [Object] The object to set
11
+ # @return [Nil]
12
+ def self.[]=(key, value)
3
13
  standardUserDefaults[key] = value
4
14
  end
5
15
 
16
+ #
17
+ # Shortcut for retrieving a key from the standardUserDefaults
18
+ #
19
+ # @example
20
+ # NSUserDefaults[:foo]
21
+ #
22
+ # @param key [String|Symbol] The key to retrieve
23
+ # @return [Object] The value for the given key
6
24
  def self.[](key)
7
25
  standardUserDefaults[key]
8
26
  end
9
27
 
28
+ #
29
+ # Short cut for deleting a key from the standardUserDefaults
30
+ #
31
+ # @example
32
+ # NSUserDefaults.delete(:foo)
33
+ #
34
+ # @param key [String|Symbol] The key to delete
35
+ # @return [Nil]
10
36
  def delete(key)
11
37
  standardUserDefaults.delete(key)
12
38
  end
13
39
 
40
+ #
41
+ # Helper method for setting data into the user defaults
42
+ #
43
+ # If the value is provided, the given key will be set. If the value
44
+ # is nil the given key will be deleted.
45
+ #
46
+ # This method always synchronizes the defaults.
47
+ #
48
+ # @param key [String|Symbol] The key to set or delete
49
+ # @param value [Object|Nil] The value to set
50
+ # @return [Nil]
14
51
  def []=(key, value)
15
52
  if value
16
53
  setObject(value, forKey:key.to_s)
@@ -20,17 +57,35 @@ class NSUserDefaults
20
57
  sync
21
58
  end
22
59
 
60
+ #
61
+ # Helper method for retrieving an object from the defaults
62
+ #
63
+ # @note I'm not using the standard MacRuby sugaring here as
64
+ # I need to to_s the key. Keeps everything constent.
65
+ #
66
+ # @param key [String|Symbol] The key to retrieve
67
+ # @return [Object] The value for the given key
23
68
  def [](key)
24
69
  objectForKey(key.to_s)
25
70
  end
26
71
 
72
+ #
73
+ # Helper to remove an object from the defaults.
74
+ #
75
+ # This method always synchronizes the defaults.
76
+ #
77
+ # @param key [String|Symbol] The key to remove.
78
+ # @return [Nil]
27
79
  def delete(key)
28
- removeObjectForKey(key)
80
+ removeObjectForKey(key.to_s)
29
81
  sync
30
82
  end
31
83
 
32
84
  private
33
85
 
86
+ #
87
+ # Wrapper for synchronize that outputs a message on failure.
88
+ # @api private
34
89
  def sync
35
90
  puts "Failed to synchronize" unless synchronize
36
91
  end
@@ -1,10 +1,20 @@
1
+ # Extensions to the NSXMLNode class
1
2
  class NSXMLNode
2
3
  alias to_xml XMLString
3
4
 
5
+ #
6
+ # Returns the child at the given index.
7
+ #
8
+ # @param key [Fixnum] The child index to retrieve
9
+ # @return [NSXMLNode] The node at the given child index.
4
10
  def [](key)
5
11
  childAtIndex(key)
6
12
  end
7
13
 
14
+ #
15
+ # Returns the number of children for this code
16
+ #
17
+ # @return [Fixnum] The number of child nodes
8
18
  def length
9
19
  childCount
10
20
  end
@@ -1,21 +1,49 @@
1
- class TableDataSource
2
- attr_reader :data
1
+ module Bean
2
+ # A simple table data source. Provided an array it will handle the needed
3
+ # calbacks for the table.
4
+ class TableDataSource
5
+ # The data to provide to the table
6
+ attr_reader :data
3
7
 
4
- def initialize(data)
5
- @data = data
6
- end
8
+ #
9
+ # Create the table data source
10
+ #
11
+ # The elements of the provided data source either need to
12
+ # respond to [] and provide each of the needed keys or,
13
+ # need to respond to methods based on the key names.
14
+ #
15
+ # @param data [Array] The data to be provided to the table
16
+ # @return [Bean::TableDataSource] The new data source
17
+ def initialize(data)
18
+ @data = data
19
+ end
7
20
 
8
- def numberOfRowsInTableView(tableView)
9
- data.length
10
- end
21
+ #
22
+ # Returns the number of rows in the table
23
+ # @api private
24
+ def numberOfRowsInTableView(table)
25
+ data.length
26
+ end
27
+
28
+ #
29
+ # Returns the value for the given row and column of the table
30
+ # @api private
31
+ def tableView(table, objectValueForTableColumn:column, row:i)
32
+ ident = column.identifier
11
33
 
12
- def tableView(view, objectValueForTableColumn:column, row:i)
13
- ident = column.identifier
34
+ if data[i].respond_to?(:[])
35
+ data[i][ident.intern]
36
+ elsif data[i].respond_to?(ident.to_sym)
37
+ data[i].send(ident.to_sym)
38
+ end
39
+ end
14
40
 
15
- if data[i].respond_to?(:[])
16
- data[i][ident.intern]
17
- elsif data[i].respond_to?(ident.to_sym)
18
- data[i].send(ident.to_sym)
41
+ #
42
+ # Sorts the data based on the current table sort descriptors
43
+ # @api private
44
+ def tableView(table, sortDescriptorsDidChange:old_descriptors)
45
+ data.sortUsingDescriptors(table.sortDescriptors)
46
+ table.reloadData
19
47
  end
20
48
  end
21
- end
49
+ end
@@ -1,3 +1,6 @@
1
+ #
2
+ # Any non-cocoa additions will be added in the Bean module.
1
3
  module Bean
2
- VERSION = '0.0.1'
3
- end
4
+ # The current version of Bean
5
+ VERSION = '0.0.2'
6
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bean
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 1
10
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
11
10
  platform: ruby
12
11
  authors:
13
12
  - dan sinclair
@@ -15,10 +14,21 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-03-25 00:00:00 -04:00
17
+ date: 2011-03-26 00:00:00 -04:00
19
18
  default_executable:
20
- dependencies: []
21
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: yard
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
22
32
  description: Cocoa Additions for MacRuby Applications
23
33
  email:
24
34
  - dj2@everburning.com
@@ -30,21 +40,24 @@ extra_rdoc_files: []
30
40
 
31
41
  files:
32
42
  - .gitignore
33
- - README
43
+ - LICENSE
44
+ - README.md
45
+ - Rakefile
34
46
  - bean.gemspec
35
47
  - lib/bean.rb
48
+ - lib/bean/nsindexset_additions.rb
49
+ - lib/bean/nsmutableurlrequest_additions.rb
36
50
  - lib/bean/nsnotificationcenter_additions.rb
37
51
  - lib/bean/nstableview_additions.rb
38
52
  - lib/bean/nstextfield_additions.rb
39
53
  - lib/bean/nstoolbaritem_additions.rb
40
54
  - lib/bean/nsurl_connection_additions.rb
41
55
  - lib/bean/nsuserdefaults_additions.rb
42
- - lib/bean/nsview_additions.rb
43
56
  - lib/bean/nsxmlnode_additions.rb
44
57
  - lib/bean/table_data_source.rb
45
58
  - lib/bean/version.rb
46
59
  has_rdoc: true
47
- homepage: http://github.com/dj2/Bean.git
60
+ homepage: http://github.com/dj2/Bean
48
61
  licenses: []
49
62
 
50
63
  post_install_message:
@@ -53,29 +66,25 @@ rdoc_options: []
53
66
  require_paths:
54
67
  - lib
55
68
  required_ruby_version: !ruby/object:Gem::Requirement
56
- none: false
57
69
  requirements:
58
70
  - - ">="
59
71
  - !ruby/object:Gem::Version
60
- hash: 55
61
72
  segments:
62
73
  - 1
63
74
  - 9
64
75
  - 2
65
76
  version: 1.9.2
66
77
  required_rubygems_version: !ruby/object:Gem::Requirement
67
- none: false
68
78
  requirements:
69
79
  - - ">="
70
80
  - !ruby/object:Gem::Version
71
- hash: 3
72
81
  segments:
73
82
  - 0
74
83
  version: "0"
75
84
  requirements: []
76
85
 
77
86
  rubyforge_project:
78
- rubygems_version: 1.3.7
87
+ rubygems_version: 1.3.6
79
88
  signing_key:
80
89
  specification_version: 3
81
90
  summary: Cocoa Additions for MacRuby Applications
@@ -1,3 +0,0 @@
1
- class NSView
2
- alias hidden? isHidden
3
- end