acts_as_configurable 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ 0.0.3 (2010-04-16)
2
+
3
+ * Modified gemspec
4
+ * Added documentation for installation
5
+
6
+ 0.0.2 (2010-04-16)
7
+
8
+ * Added gemspec
9
+
10
+ 0.0.1 (2010-04-15)
11
+
12
+ * Initial release
@@ -0,0 +1,6 @@
1
+ CHANGELOG.rdoc
2
+ Manifest
3
+ README.rdoc
4
+ Rakefile
5
+ lib/acts_as_configurable.rb
6
+ lib/dummy_access.rb
@@ -0,0 +1,32 @@
1
+ == Acts as configurable
2
+
3
+ Provides the capabilities of defining configuration values for a model.
4
+
5
+ == Installation
6
+
7
+ gem install acts_as_configurable
8
+
9
+ == Initialisation
10
+
11
+ Migration:
12
+
13
+ create_table :configurations do |t|
14
+ t.string :name, :value, :null => false
15
+ t.string :configurable_type
16
+ t.integer :configurable_id
17
+ end
18
+
19
+ Configuration model:
20
+
21
+ class Configuration < ActiveRecord::Base
22
+ belongs_to :configurable, :polymorphic => true
23
+ end
24
+
25
+ == Usage
26
+
27
+ class User < ActiveRecord::Base
28
+ acts_as_configurable :class_name => 'Configuration'
29
+ end
30
+
31
+ user.configure.name = 'Name'
32
+ user.configure.name # => Name
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('acts_as_configurable', '0.0.3') do |p|
6
+ p.summary = 'Storage of configuration values in database'
7
+ p.description = 'Storage of configuration values in database'
8
+ p.author = 'Philipp Ullmann'
9
+ p.url = 'http://www.create.at'
10
+ p.email = 'philipp.ullmann@create.at'
11
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{acts_as_configurable}
5
+ s.version = "0.0.3"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Philipp Ullmann"]
9
+ s.date = %q{2010-04-16}
10
+ s.description = %q{Storage of configuration values in database}
11
+ s.email = %q{philipp.ullmann@create.at}
12
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc", "lib/acts_as_configurable.rb", "lib/dummy_access.rb"]
13
+ s.files = ["CHANGELOG.rdoc", "Manifest", "README.rdoc", "Rakefile", "lib/acts_as_configurable.rb", "lib/dummy_access.rb", "acts_as_configurable.gemspec"]
14
+ s.homepage = %q{http://www.create.at}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Acts_as_configurable", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{acts_as_configurable}
18
+ s.rubygems_version = %q{1.3.6}
19
+ s.summary = %q{Storage of configuration values in database}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ require 'dummy_access'
2
+
3
+ module ActsAsConfigurable
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ # This +acts_as+ extension provides the capabilities of defining configuration values.
9
+ #
10
+ # Example:
11
+ #
12
+ # class User < ActiveRecord::Base
13
+ # acts_as_configurable :class_name => 'Ste::Configuration'
14
+ # end
15
+ #
16
+ # user.configure.name = 'Name'
17
+ # user.configure.name => Name
18
+ module ClassMethods
19
+ def acts_as_configurable(options={})
20
+ configuration = { :as => :configurable, :dependent => :destroy, :class_name => 'Configuration' }
21
+ configuration.update(options) if options.is_a? Hash
22
+
23
+ class_eval <<-EOV
24
+ include ActsAsConfigurable::InstanceMethods
25
+
26
+ has_many :configs, configuration
27
+ accepts_nested_attributes_for :configs, :allow_destroy => true
28
+ EOV
29
+ end
30
+ end
31
+
32
+ # All the methods available to a record that has had <tt>acts_as_configurable</tt> specified.
33
+ module InstanceMethods
34
+ def configurable?
35
+ true
36
+ end
37
+
38
+ def configure
39
+ return ::DummyAccess.new self
40
+ end
41
+ end
42
+ end
43
+
44
+ ActiveRecord::Base.class_eval { include ActsAsConfigurable }
@@ -0,0 +1,19 @@
1
+ # Class to ease the getting and setting of configuration values
2
+ class DummyAccess
3
+ def initialize(mod)
4
+ @mod = mod
5
+ end
6
+
7
+ def method_missing(method_name, *args)
8
+ method_name = method_name.to_s
9
+ name = method_name.chomp '='
10
+ conf = @mod.configs.find_by_name name
11
+
12
+ if method_name.ends_with? '='
13
+ conf ? conf.update_attribute(:value, args[0]) : @mod.configs.create!(:name => name, :value => args[0])
14
+ conf
15
+ else
16
+ conf ? conf.value : raise("Configuration attribute '#{method_name}' doesn't exists")
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_configurable
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 3
9
+ version: 0.0.3
10
+ platform: ruby
11
+ authors:
12
+ - Philipp Ullmann
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-16 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Storage of configuration values in database
22
+ email: philipp.ullmann@create.at
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - CHANGELOG.rdoc
29
+ - README.rdoc
30
+ - lib/acts_as_configurable.rb
31
+ - lib/dummy_access.rb
32
+ files:
33
+ - CHANGELOG.rdoc
34
+ - Manifest
35
+ - README.rdoc
36
+ - Rakefile
37
+ - lib/acts_as_configurable.rb
38
+ - lib/dummy_access.rb
39
+ - acts_as_configurable.gemspec
40
+ has_rdoc: true
41
+ homepage: http://www.create.at
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --line-numbers
47
+ - --inline-source
48
+ - --title
49
+ - Acts_as_configurable
50
+ - --main
51
+ - README.rdoc
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 1
67
+ - 2
68
+ version: "1.2"
69
+ requirements: []
70
+
71
+ rubyforge_project: acts_as_configurable
72
+ rubygems_version: 1.3.6
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Storage of configuration values in database
76
+ test_files: []
77
+