setter 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/setter/setter.rb +7 -7
- data/lib/setter/settings.rb +24 -3
- metadata +22 -7
- data/lib/setter/version.rb +0 -3
data/lib/setter/setter.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
module Setter
|
2
|
-
def set(receiver,
|
3
|
-
set_attributes(receiver) unless
|
4
|
-
set_attribute(receiver,
|
2
|
+
def set(receiver, name=nil)
|
3
|
+
set_attributes(receiver) unless name
|
4
|
+
set_attribute(receiver, name) if name
|
5
5
|
end
|
6
6
|
|
7
7
|
def set_attributes(receiver)
|
8
|
-
receiver.class.settings.each do |
|
9
|
-
set_attribute receiver,
|
8
|
+
receiver.class.settings.each do |name|
|
9
|
+
set_attribute receiver, name
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def set_attribute(receiver,
|
14
|
-
receiver.send :"#{
|
13
|
+
def set_attribute(receiver, name)
|
14
|
+
receiver.send :"#{name}=", (send name) if respond_to?(name)
|
15
15
|
end
|
16
16
|
end
|
data/lib/setter/settings.rb
CHANGED
@@ -1,13 +1,34 @@
|
|
1
|
+
require 'null_object'
|
2
|
+
|
1
3
|
module Setter
|
2
4
|
module Settings
|
5
|
+
|
3
6
|
def self.included(base)
|
4
7
|
base.extend ClassMethods
|
5
8
|
end
|
6
9
|
|
7
10
|
module ClassMethods
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
+
def null_object(implementation)
|
12
|
+
null_object_options = {}
|
13
|
+
implementation.instance_methods.each do |instance_method|
|
14
|
+
null_object_options[instance_method] = nil
|
15
|
+
end
|
16
|
+
NullObject.new null_object_options
|
17
|
+
end
|
18
|
+
|
19
|
+
def setting(name, options={})
|
20
|
+
setting_value = (options[:default] if options.is_a? Hash) || nil
|
21
|
+
setting_value ||= options
|
22
|
+
|
23
|
+
define_method "#{name}=" do |value|
|
24
|
+
setting_value = value
|
25
|
+
end
|
26
|
+
|
27
|
+
define_method name do
|
28
|
+
setting_value
|
29
|
+
end
|
30
|
+
|
31
|
+
settings << name
|
11
32
|
end
|
12
33
|
|
13
34
|
def settings
|
metadata
CHANGED
@@ -1,16 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: setter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- The Sans Collective
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
12
|
+
date: 2013-04-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: null_object
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '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: '0'
|
14
30
|
description:
|
15
31
|
email:
|
16
32
|
executables: []
|
@@ -19,9 +35,8 @@ extra_rdoc_files: []
|
|
19
35
|
files:
|
20
36
|
- lib/setter/setter.rb
|
21
37
|
- lib/setter/settings.rb
|
22
|
-
- lib/setter/version.rb
|
23
38
|
- lib/setter.rb
|
24
|
-
homepage:
|
39
|
+
homepage: https://github.com/Sans/setter
|
25
40
|
licenses: []
|
26
41
|
post_install_message:
|
27
42
|
rdoc_options: []
|
@@ -41,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
56
|
version: '0'
|
42
57
|
requirements: []
|
43
58
|
rubyforge_project:
|
44
|
-
rubygems_version: 1.8.
|
59
|
+
rubygems_version: 1.8.25
|
45
60
|
signing_key:
|
46
61
|
specification_version: 3
|
47
62
|
summary: Setter Library
|
data/lib/setter/version.rb
DELETED