has_bootstrap 0.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.
- data/LICENSE +20 -0
- data/README +21 -0
- data/Rakefile +44 -0
- data/lib/has_bootstrap.rb +42 -0
- metadata +69 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Thomas Boerger <tboerger@tbpro.de>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# has_bootstrap
|
2
|
+
|
3
|
+
Add bootstrap functionality to your ActiveRecord models. I'm using it to load country or language data into my database.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
gem 'has_bootstrap'
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
class Color < ActiveRecord::Base
|
12
|
+
bootstrap(
|
13
|
+
{:id => 1, :name => 'red'},
|
14
|
+
{:id => 2, :name => 'blue'},
|
15
|
+
{:id => 3, :name => 'green'}
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
## Credits
|
20
|
+
|
21
|
+
The project <tt>has_bootstrap</tt> have been inspired by pluginaweek. Take a look at the [git repositories](https://github.com/pluginaweek).
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Created by Thomas Boerger on 2011-07-01.
|
2
|
+
# Copyright (c) 2011. All rights reserved.
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
require "date"
|
6
|
+
require "rubygems/package_task"
|
7
|
+
require "rubygems/specification"
|
8
|
+
|
9
|
+
GEM_TITLE = "has_bootstrap"
|
10
|
+
GEM_VERSION = "0.0.1"
|
11
|
+
|
12
|
+
spec = Gem::Specification.new do |s|
|
13
|
+
s.name = GEM_TITLE
|
14
|
+
s.version = GEM_VERSION
|
15
|
+
s.extra_rdoc_files = ['README', 'LICENSE']
|
16
|
+
s.rdoc_options << '--line-numbers'
|
17
|
+
s.summary = 'Has bootstrap'
|
18
|
+
s.description = 'Bootstrap for ActiveRecord models'
|
19
|
+
s.author = 'Thomas Boerger'
|
20
|
+
s.email = 'tboerger@tbpro.de'
|
21
|
+
s.homepage = 'http://github.com/tbpro/has_bootstrap'
|
22
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob('{lib}/**/*')
|
23
|
+
end
|
24
|
+
|
25
|
+
Gem::PackageTask.new(spec) do |pkg|
|
26
|
+
pkg.gem_spec = spec
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Install the gem"
|
30
|
+
task :install => [:package] do
|
31
|
+
sh %{sudo gem install pkg/#{GEM_TITLE}-#{GEM_VERSION}}
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Create a gemspec"
|
35
|
+
task :writespec do
|
36
|
+
File.open("#{GEM_TITLE}.gemspec", "w") do |file|
|
37
|
+
file.puts spec.to_ruby
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "List all tasks"
|
42
|
+
task :default do
|
43
|
+
puts `rake -T`.grep(/^[^(].*$/)
|
44
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Created by Thomas Boerger on 2011-07-01.
|
2
|
+
# Copyright (c) 2011. All rights reserved.
|
3
|
+
|
4
|
+
module HasBootstrap
|
5
|
+
module MacroMethods
|
6
|
+
def has_bootstrap(*records)
|
7
|
+
primary_key = self.primary_key.to_sym
|
8
|
+
records.flatten!
|
9
|
+
|
10
|
+
ids = records.map { |record| record[primary_key] }.compact
|
11
|
+
delete_all(ids.any? ? ["#{primary_key} NOT IN (?)", ids] : nil)
|
12
|
+
|
13
|
+
existing = all.inject({}) { |existing, record| existing[record.send(primary_key)] = record; existing }
|
14
|
+
|
15
|
+
records.map! do |attributes|
|
16
|
+
attributes.symbolize_keys!
|
17
|
+
defaults = attributes.delete(:defaults)
|
18
|
+
|
19
|
+
record = if record = existing[attributes[primary_key]]
|
20
|
+
attributes.merge!(defaults.delete_if { |attribute, value| record.send("#{attribute}?") }) if defaults
|
21
|
+
record.attributes = attributes
|
22
|
+
|
23
|
+
record
|
24
|
+
else
|
25
|
+
attributes.merge!(defaults) if defaults
|
26
|
+
new(attributes)
|
27
|
+
end
|
28
|
+
|
29
|
+
record.send("#{primary_key}=", attributes[primary_key])
|
30
|
+
|
31
|
+
record.save!
|
32
|
+
record
|
33
|
+
end
|
34
|
+
|
35
|
+
records
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
ActiveRecord::Base.class_eval do
|
41
|
+
extend HasBootstrap::MacroMethods
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: has_bootstrap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Thomas Boerger
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-01 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Bootstrap for ActiveRecord models
|
22
|
+
email: tboerger@tbpro.de
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README
|
29
|
+
- LICENSE
|
30
|
+
files:
|
31
|
+
- LICENSE
|
32
|
+
- README
|
33
|
+
- Rakefile
|
34
|
+
- lib/has_bootstrap.rb
|
35
|
+
homepage: http://github.com/tbpro/has_bootstrap
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --line-numbers
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
hash: 3
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.7.2
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Has bootstrap
|
68
|
+
test_files: []
|
69
|
+
|