coerced_attr_writer 0.0.1-java

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,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ Gemfile.lock
6
+ InstalledFiles
7
+ coverage
8
+ doc/
9
+ lib/bundler/man
10
+ pkg
11
+ rdoc
12
+ spec/reports
13
+ test/tmp
14
+ test/version_tmp
15
+ tmp
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in coerced_attr_writer.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Brandon Dewitt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # CoercedAttrWriter
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'coerced_attr_writer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install coerced_attr_writer
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'coerced_attr_writer/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "coerced_attr_writer"
8
+ gem.version = CoercedAttrWriter::VERSION
9
+ gem.authors = ["Brandon Dewitt"]
10
+ gem.email = ["brandonsdewitt+coerced_attr_writer@gmail.com"]
11
+ gem.description = %q{ setters with type coercion for set* methods on java classes using the jruby coercion interface `to_java(java_type)` }
12
+ gem.summary = %q{ declarable coercible attr_writer methods for interacting with native java methods }
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.platform = "java"
20
+
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "pry-nav"
24
+ end
@@ -0,0 +1,4 @@
1
+ require "coerced_attr_writer/version"
2
+
3
+ module CoercedAttrWriter
4
+ end
@@ -0,0 +1,46 @@
1
+ class Class
2
+ def coerced_attr_writer(*attributes)
3
+ setter_methods = _coerced_attr_writer_setters
4
+
5
+ attributes.each do |attribute|
6
+ java_setter_name = _coerced_setter_name(attribute)
7
+ coercion_type = "#{setter_methods[java_setter_name]}"
8
+
9
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
10
+ def #{attribute}=(val)
11
+ unless val.is_a?(#{coercion_type})
12
+ val = val.to_java(#{coercion_type})
13
+ end
14
+
15
+ set_#{attribute}(val)
16
+ end
17
+ RUBY
18
+ end
19
+ end
20
+
21
+ alias_method :attr_writer_with_coercion, :coerced_attr_writer
22
+ alias_method :coercible_attr_writer, :coerced_attr_writer
23
+ alias_method :coercable_attr_writer, :coerced_attr_writer
24
+ alias_method :attr_writer_coerced, :coerced_attr_writer
25
+ alias_method :coerced_setters, :coerced_attr_writer
26
+ alias_method :coerce_setters, :coerced_attr_writer
27
+
28
+ private
29
+
30
+ def _coerced_attr_writer_setters
31
+ @_coerced_attr_writer_setters ||= java_class.java_instance_methods.inject({}) do |method_hash, method|
32
+ if method.arity == 1 && method.name =~ /\Aset.*\Z/
33
+ method_hash[method.name] = method.parameter_types.first
34
+ end
35
+
36
+ method_hash
37
+ end
38
+ end
39
+
40
+ def _coerced_setter_name(attribute)
41
+ string = attribute.to_s.dup
42
+ string = string.split(/[^a-z0-9]/i).map { |word| word.capitalize }.join
43
+ return "set#{string}"
44
+ end
45
+
46
+ end
@@ -0,0 +1,3 @@
1
+ module CoercedAttrWriter
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coerced_attr_writer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: java
7
+ authors:
8
+ - Brandon Dewitt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: !binary |-
21
+ MA==
22
+ none: false
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: !binary |-
28
+ MA==
29
+ none: false
30
+ prerelease: false
31
+ type: :development
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ version_requirements: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: !binary |-
39
+ MA==
40
+ none: false
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: !binary |-
46
+ MA==
47
+ none: false
48
+ prerelease: false
49
+ type: :development
50
+ - !ruby/object:Gem::Dependency
51
+ name: pry-nav
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: !binary |-
57
+ MA==
58
+ none: false
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: !binary |-
64
+ MA==
65
+ none: false
66
+ prerelease: false
67
+ type: :development
68
+ description: ! ' setters with type coercion for set* methods on java classes using
69
+ the jruby coercion interface `to_java(java_type)` '
70
+ email:
71
+ - brandonsdewitt+coerced_attr_writer@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - coerced_attr_writer.gemspec
82
+ - lib/coerced_attr_writer.rb
83
+ - lib/coerced_attr_writer/core_ext/class.rb
84
+ - lib/coerced_attr_writer/version.rb
85
+ homepage: ''
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: !binary |-
98
+ MA==
99
+ hash: 2
100
+ none: false
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: !binary |-
108
+ MA==
109
+ hash: 2
110
+ none: false
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.24
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: declarable coercible attr_writer methods for interacting with native java methods
117
+ test_files: []