pethau 0.0.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/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Pethau
2
+
3
+ A bunch of code that we find useful to share amongst our projects.
4
+
5
+ This is the place that code lives when it doesn't have a larger purpose; in
6
+ less awesome teams this would be the "utility" package.
7
+
8
+ Pethau is Welsh for "things," which I think captures the general purpose
9
+ nature of this gem nicely.
10
+
11
+
12
+ ## Things
13
+
14
+ ### initialize\_with
15
+
16
+ A lot of my classes use the following initializer pattern:
17
+
18
+ class Foo
19
+ attr_accessor :bar
20
+ private :bar=, :bar
21
+ attr_accessor :baz
22
+ private :baz=, :baz
23
+
24
+ def initialize bar, baz
25
+ self.bar = bar
26
+ self.baz = baz
27
+ end
28
+ end
29
+
30
+ I've been doing this for a while now, and I believe it's established itself as
31
+ enough of a pattern that I want to pull out the implementation and DRY it up:
32
+
33
+ class Foo
34
+ include Pethau::InitializeWith
35
+ initialize_with :foo, :bar
36
+ end
37
+
38
+ ince this is used in a lot of places in my projects I tend to include it in
39
+ `Object` but I didn't want to make that decision for you.
@@ -0,0 +1,23 @@
1
+ module Pethau
2
+ module InitializeWith
3
+ def self.included into
4
+ into.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def initialize_with *args
9
+ args.each do |attribute|
10
+ attr_accessor attribute
11
+ private attribute, "#{attribute}="
12
+ end
13
+
14
+ define_method :initialize do |*initial_args|
15
+ args.each do |arg|
16
+ send "#{arg}=", initial_args.shift
17
+ end
18
+ end
19
+ end
20
+ private :initialize_with
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Pethau
2
+ VERSION = '0.0.1'
3
+ end
data/lib/pethau.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'pethau/version'
2
+ require 'pethau/initialize_with'
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pethau
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Craig R Webster
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-06 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Extracting a bunch of code that we use across our projects. In less awesome
15
+ teams this would be the utility package.
16
+ email:
17
+ - craig@barkingiguana.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/pethau/initialize_with.rb
23
+ - lib/pethau/version.rb
24
+ - lib/pethau.rb
25
+ - README.md
26
+ homepage:
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.10
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Useful bits of code that we use in lots of projects
50
+ test_files: []