magic_attributes 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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/magic_attributes.rb +38 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec905bc3ec280e7e84aa8bf88afb720402006d8d
4
+ data.tar.gz: 45cabca2702eeee28a42c39d76d3e51d81313930
5
+ SHA512:
6
+ metadata.gz: ce55f1813787af044ab22786d2a29cac5dee6fb4bbd593b061360cc30a9d4abd4f43bc84a3f5e5d5aabbe64ea0eb824965e5891ef8b69bd29acbcef7feadcc57
7
+ data.tar.gz: 731f2e9edbac58ac671e6b47fabacae19c1c770c8a7e2c3de9be4805f71af9118f816568de174dc3a08f1815ccc755aca27aa741912947da56996f85a80075ca
@@ -0,0 +1,38 @@
1
+
2
+ module MagicAttributes
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+
9
+
10
+
11
+ def magic_attributes(*attrs)
12
+ attrs = attrs.first if attrs.is_a?(Array)
13
+
14
+ attrs.each_key do |attr_name|
15
+ if attrs[attr_name].is_a?(Array)
16
+ define_method(attr_name) do
17
+ calls = attrs[attr_name].dup
18
+ obj = self # start with the current object
19
+ calls.each do |call|
20
+ obj = obj.send(call)
21
+ return nil if obj.nil?
22
+ end
23
+ return obj
24
+ end
25
+
26
+ elsif attrs[attr_name].is_a?(Proc)
27
+ define_method(attr_name) do
28
+ attrs[attr_name].call(self)
29
+ end
30
+ end
31
+ end
32
+
33
+
34
+ end
35
+ end
36
+
37
+ end
38
+
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magic_attributes
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Roberts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Magic Attributes is a quick way of defining a bunch of methods to a a
14
+ class.
15
+ email: tyler@westernlap.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/magic_attributes.rb
21
+ homepage: http://github.com/bdeve/magic_attributes
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: See Github page for examples.
45
+ test_files: []