templatar 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +6 -0
- data/lib/templatar.rb +7 -0
- data/lib/templatar/model_additions.rb +23 -0
- data/lib/templatar/railtie.rb +10 -0
- data/lib/templatar/version.rb +4 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/templatar/model_additions_spec.rb +81 -0
- data/spec/templatar_spec.rb +6 -0
- data/templatar.gemspec +27 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 98ecf92d9971365c0a97a485b2b7ce00f21ea1bb
|
4
|
+
data.tar.gz: fe9b51266dc05bdeac6ec718a1a4109a0e925da8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4fa80cec85aeaebbda4dabd6e17a7b9cdcb407903923eab47c54bd080077f8db64f4d3a1015de7f8b89b73a5c181dae3fb83f35e229eb7b78e6b688fe0fa6112
|
7
|
+
data.tar.gz: 25e741f225e00f767f1ef5b4679de66b2108c20b1ed4802a4e21cb272d832f1e54fa9c168aa8ca696eb29d29501ad9b41c4927bbcd1b7c91ac6d72cf9d4a4751
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Andrea Salicetti
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Templatar
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/knightq/templatar.svg)](https://travis-ci.org/knightq/templatar)
|
4
|
+
|
5
|
+
TODO: Write a gem description
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'templatar'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install templatar
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/templatar/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/templatar.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Model additions
|
2
|
+
module Templatar
|
3
|
+
module ModelAdditions
|
4
|
+
def has_template
|
5
|
+
raise StandardError.new('Cannot add has_template to a non-AR model') unless self.respond_to?(:column_names)
|
6
|
+
|
7
|
+
self.send(:define_method, :template?) { @templatar }
|
8
|
+
|
9
|
+
metaclass = class << self; self; end
|
10
|
+
metaclass.send(:define_method, :template) do
|
11
|
+
@templatar_singleton ||= begin
|
12
|
+
t = self.new
|
13
|
+
t.instance_variable_set :@templatar, true
|
14
|
+
t_metaclass = class << t; self; end
|
15
|
+
self.column_names.each do |column|
|
16
|
+
t_metaclass.send(:define_method, column) { column.to_sym == :id ? '__ID__' : "#{column}__TEMPLATE__" }
|
17
|
+
end
|
18
|
+
t
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
class TestARModel < SuperModel::Base
|
5
|
+
def self.column_names
|
6
|
+
[:a, :b, :c, :id]
|
7
|
+
end
|
8
|
+
|
9
|
+
extend Templatar::ModelAdditions
|
10
|
+
has_template
|
11
|
+
|
12
|
+
def a
|
13
|
+
end
|
14
|
+
|
15
|
+
def b
|
16
|
+
end
|
17
|
+
|
18
|
+
def c
|
19
|
+
end
|
20
|
+
|
21
|
+
def id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Test2ARModel < SuperModel::Base
|
26
|
+
def self.column_names
|
27
|
+
[:x, :id]
|
28
|
+
end
|
29
|
+
|
30
|
+
extend Templatar::ModelAdditions
|
31
|
+
has_template
|
32
|
+
|
33
|
+
def x
|
34
|
+
end
|
35
|
+
|
36
|
+
def id
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Templatar::ModelAdditions do
|
41
|
+
|
42
|
+
it 'should produce a singleton' do
|
43
|
+
TestARModel.template.should === TestARModel.template
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should produce different singletons' do
|
47
|
+
TestARModel.template.should_not == Test2ARModel.template
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should inject a template method on the model class' do
|
51
|
+
TestARModel.new.should respond_to?(:template)
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'template object' do
|
55
|
+
let(:model) { TestARModel.template }
|
56
|
+
subject { model }
|
57
|
+
|
58
|
+
it { should be_template }
|
59
|
+
|
60
|
+
it "should retunr column_name + '_TEMPLATE'" do
|
61
|
+
model.a.should == 'a__TEMPLATE__'
|
62
|
+
model.b.should == 'b__TEMPLATE__'
|
63
|
+
model.c.should == 'c__TEMPLATE__'
|
64
|
+
model.id.should == '__ID__'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'non template object' do
|
69
|
+
let(:model) { TestARModel.new }
|
70
|
+
subject { model }
|
71
|
+
|
72
|
+
it { should_not be_template }
|
73
|
+
|
74
|
+
it 'should retunr standard value for column_names' do
|
75
|
+
model.a.should be_nil
|
76
|
+
model.b.should be_nil
|
77
|
+
model.c.should be_nil
|
78
|
+
model.id.should be_nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/templatar.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'templatar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "templatar"
|
8
|
+
spec.version = Templatar::VERSION
|
9
|
+
spec.authors = ["Andrea Salicetti"]
|
10
|
+
spec.email = ["andrea.salicetti@gmail.com"]
|
11
|
+
spec.summary = %q{Template object for ActiveRecord.}
|
12
|
+
spec.description = %q{A gem that adds an handful singleton to your AR model that responds to every column getter
|
13
|
+
with the name of the column, followed by '_TEMPLATE'.}
|
14
|
+
spec.homepage = "http://www.andreasalicetti.com"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "pry"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "supermodel"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: templatar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrea Salicetti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: supermodel
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: |-
|
84
|
+
A gem that adds an handful singleton to your AR model that responds to every column getter
|
85
|
+
with the name of the column, followed by '_TEMPLATE'.
|
86
|
+
email:
|
87
|
+
- andrea.salicetti@gmail.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- CHANGELOG.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- lib/templatar.rb
|
100
|
+
- lib/templatar/model_additions.rb
|
101
|
+
- lib/templatar/railtie.rb
|
102
|
+
- lib/templatar/version.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
- spec/templatar/model_additions_spec.rb
|
105
|
+
- spec/templatar_spec.rb
|
106
|
+
- templatar.gemspec
|
107
|
+
homepage: http://www.andreasalicetti.com
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.2.2
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Template object for ActiveRecord.
|
131
|
+
test_files:
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- spec/templatar/model_additions_spec.rb
|
134
|
+
- spec/templatar_spec.rb
|