persistent_settings 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ -fd
2
+ -c
data/README.md CHANGED
@@ -35,4 +35,6 @@ Reload your app:
35
35
 
36
36
  It accepts all kinds of objects as the value
37
37
 
38
+ # License
38
39
 
40
+ MIT License. Copyright 2011, Crowd Interactive http://www.crowdint.com
@@ -4,3 +4,11 @@ Feature: Settings class
4
4
  Given I assign "'a value'" to "a_key"
5
5
  Then Settings should respond to "a_key"
6
6
  Then "a_key" should hold "a value"
7
+
8
+ Scenario: Active key list
9
+ Given I assign "'a value'" to "a_key"
10
+ And I assign "'another value'" to "another_key"
11
+ Then Settings.keys should include:
12
+ | a_key |
13
+ | another_key |
14
+
@@ -9,3 +9,9 @@ end
9
9
  Then /^"([^"]*)" should hold "([^"]*)"$/ do |key, value|
10
10
  Settings.send(key).should eq(value)
11
11
  end
12
+
13
+ Then /^Settings\.keys should include:$/ do |table|
14
+ table.raw.flatten.each do |key|
15
+ Settings.keys.should include(key.to_sym)
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module PersistentSettings
2
+ VERSION = "1.0.2"
3
+ end
@@ -1,6 +1,6 @@
1
1
  require "active_record"
2
+ require "persistent_settings/version"
2
3
  require "settings"
3
- require "settings/version"
4
4
 
5
5
  unless ::Rails.version < "3.1"
6
6
  require "persistent_settings/rails/engine"
data/lib/settings.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  class Settings < ActiveRecord::Base
2
+ include ::PersistentSettings
3
+
2
4
  serialize :value
3
5
 
4
6
  def self.method_missing(method_name, *args)
@@ -44,5 +46,9 @@ class Settings < ActiveRecord::Base
44
46
  end
45
47
  end
46
48
 
49
+ def self.keys
50
+ Settings.select(:var).collect { |s| s.var.to_sym }
51
+ end
52
+
47
53
  load_from_persistance if connected? && table_exists?
48
54
  end
@@ -1,9 +1,10 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
+ require 'persistent_settings/version'
3
4
 
4
5
  Gem::Specification.new do |s|
5
6
  s.name = "persistent_settings"
6
- s.version = "1.0.1"
7
+ s.version = PersistentSettings::VERSION
7
8
  s.authors = ["David Padilla"]
8
9
  s.email = ["david@crowdint.com"]
9
10
  s.homepage = ""
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe PersistentSettings::MigrationGenerator do
4
+ let(:destination) { 'tmp' }
5
+ let(:filename) { File.join(destination, 'db', 'migrate', 'YYYYMMDDHHMM_create_settings_table.rb') }
6
+
7
+ before do
8
+ File.unlink(filename) if File.exists?(filename)
9
+ PersistentSettings::MigrationGenerator.stub(:next_migration_number).
10
+ and_return('YYYYMMDDHHMM')
11
+ PersistentSettings::MigrationGenerator.start([], :destination_root => destination)
12
+ end
13
+
14
+ it "creates the migration to create the settings table" do
15
+ File.exists?(filename).should be_true
16
+ end
17
+ end
@@ -81,4 +81,19 @@ describe Settings do
81
81
  end
82
82
  end
83
83
  end
84
+
85
+ describe :keys do
86
+ let(:settings) do
87
+ [ mock(:var => 'a_key'), mock(:var => 'another_key') ]
88
+ end
89
+
90
+ before do
91
+ Settings.should_receive(:select).with(:var).and_return(settings)
92
+ end
93
+
94
+ subject { Settings.keys }
95
+
96
+ specify { should include(:a_key) }
97
+ specify { should include(:another_key) }
98
+ end
84
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: persistent_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70238115921840 !ruby/object:Gem::Requirement
16
+ requirement: &70176505804880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70238115921840
24
+ version_requirements: *70176505804880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: cucumber
27
- requirement: &70238115921360 !ruby/object:Gem::Requirement
27
+ requirement: &70176505804380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.1.4
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70238115921360
35
+ version_requirements: *70176505804380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70238115920980 !ruby/object:Gem::Requirement
38
+ requirement: &70176505804000 !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: *70238115920980
46
+ version_requirements: *70176505804000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70238115920440 !ruby/object:Gem::Requirement
49
+ requirement: &70176505803460 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.7.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70238115920440
57
+ version_requirements: *70176505803460
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3
60
- requirement: &70238115936300 !ruby/object:Gem::Requirement
60
+ requirement: &70176505802960 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '1.3'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70238115936300
68
+ version_requirements: *70176505802960
69
69
  description: Simple global Settings class for ActiveRecord based applications
70
70
  email:
71
71
  - david@crowdint.com
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
+ - .rspec
77
78
  - .travis.yml
78
79
  - Gemfile
79
80
  - README.md
@@ -85,9 +86,10 @@ files:
85
86
  - lib/generators/persistent_settings/templates/create_settings_table.rb
86
87
  - lib/persistent_settings.rb
87
88
  - lib/persistent_settings/rails/engine.rb
89
+ - lib/persistent_settings/version.rb
88
90
  - lib/settings.rb
89
- - lib/settings/version.rb
90
91
  - persistent_settings.gemspec
92
+ - spec/generators/persistent_settings/migration_generator_spec.rb
91
93
  - spec/lib/settings_spec.rb
92
94
  - spec/spec_helper.rb
93
95
  homepage: ''
@@ -118,5 +120,6 @@ test_files:
118
120
  - features/settings.feature
119
121
  - features/step_definitions/settings_steps.rb
120
122
  - features/support/env.rb
123
+ - spec/generators/persistent_settings/migration_generator_spec.rb
121
124
  - spec/lib/settings_spec.rb
122
125
  - spec/spec_helper.rb
@@ -1,3 +0,0 @@
1
- class Settings < ActiveRecord::Base
2
- VERSION = "1.0.1"
3
- end