setler 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,17 +5,6 @@ module Setler
5
5
  define_method scopename do
6
6
  Setler::ScopedSettings.for_thing(self)
7
7
  end
8
-
9
- define_method "#{scopename}=" do |hash|
10
- hash.each do |key,value|
11
- Setler::Settings.find_or_create_by_thing_id_and_thing_type_and_var(
12
- self.id,
13
- self.class,
14
- key,
15
- value: value
16
- )
17
- end
18
- end
19
8
  end
20
9
 
21
10
  end
@@ -15,9 +15,22 @@ module Setler
15
15
  else
16
16
  method_name = method.to_s
17
17
  if method_name.ends_with?("=")
18
- thing_scoped.find_or_create_by_var(method_name[0..-2]).update_attribute(:value, args.first)
18
+ # THIS IS BAD
19
+ # thing_scoped.find_or_create_by_var(method_name[0..-2]) should work but doesnt for some reason
20
+ # When @object is present, thing_scoped sets the where scope for the polymorphic association
21
+ # but the find_or_create_by wasn't using the thing_type and thing_id
22
+ thing_scoped.find_or_create_by_var_and_thing_type_and_thing_id(
23
+ method_name[0..-2],
24
+ @object.try(:class).try(:base_class).try(:to_s),
25
+ @object.try(:id)
26
+ ).update_attribute(:value, args.first)
19
27
  else
20
- thing_scoped.find_by_var(method_name).try(:value) || @@defaults[method_name]
28
+ the_setting = thing_scoped.find_by_var(method_name)
29
+ if the_setting.nil?
30
+ return @@defaults[method_name]
31
+ else
32
+ return the_setting.value
33
+ end
21
34
  end
22
35
  end
23
36
  end
@@ -33,7 +46,7 @@ module Setler
33
46
  end
34
47
 
35
48
  def self.all
36
- Hash[thing_scoped.all.collect{ |s| [s.var, s.value] }].merge(@@defaults)
49
+ @@defaults.merge(Hash[thing_scoped.all.collect{ |s| [s.var, s.value] }])
37
50
  end
38
51
 
39
52
  def self.thing_scoped
@@ -1,3 +1,3 @@
1
1
  module Setler
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: setler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-08-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70271069152000 !ruby/object:Gem::Requirement
16
+ requirement: &70364807212080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70271069152000
24
+ version_requirements: *70364807212080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70271069151500 !ruby/object:Gem::Requirement
27
+ requirement: &70364807211580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70271069151500
35
+ version_requirements: *70364807211580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70271069151120 !ruby/object:Gem::Requirement
38
+ requirement: &70364807211200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70271069151120
46
+ version_requirements: *70364807211200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70271069150660 !ruby/object:Gem::Requirement
49
+ requirement: &70364807210740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70271069150660
57
+ version_requirements: *70364807210740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: cover_me
60
- requirement: &70271069150240 !ruby/object:Gem::Requirement
60
+ requirement: &70364807210320 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70271069150240
68
+ version_requirements: *70364807210320
69
69
  description: Setler is a Gem that lets one easily implement the "Feature Flags" pattern,
70
70
  or add settings to individual models. This is a cleanroom implementation of what
71
71
  the 'rails-settings' gem does. It's been forked all over the place, and my favorite