templatar 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/templatar/model_additions.rb +5 -3
- data/lib/templatar/version.rb +1 -1
- data/spec/templatar/model_additions_spec.rb +8 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b2e2ce5052ee80385aa3e2df5f8caac1efbac8d
|
4
|
+
data.tar.gz: 7bb03cfd98e5e8bfbf7e6812dee8e112f4636a5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a6eae29824fe2eb073fba465e3b44568947c150f4dd9fd747ade8e4745200659d2ec8b9eed5bf2897bf3b4f806a6630a8eb0b73738629f6ec1e176da5058a1e
|
7
|
+
data.tar.gz: dadb5ad0b0ff9031f96f40b4fc0db605d4e9156a074e791ab442140cb1b7b0a2beaf4232098b3690bdc4642e5b1c330c6f1b12aaecfd833b31c24a8462451a63
|
data/CHANGELOG.md
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
# Model additions
|
2
2
|
module Templatar
|
3
3
|
module ModelAdditions
|
4
|
-
def has_template
|
4
|
+
def has_template(options = {})
|
5
5
|
raise StandardError.new('Cannot add has_template to a non-AR model') unless self.respond_to?(:column_names)
|
6
6
|
|
7
7
|
self.send(:define_method, :template?) { @templatar }
|
8
8
|
|
9
|
+
custom_methods = options.fetch(:methods, [])
|
10
|
+
|
9
11
|
metaclass = class << self; self; end
|
10
12
|
metaclass.send(:define_method, :template) do
|
11
13
|
@templatar_singleton ||= begin
|
12
14
|
t = self.new
|
13
15
|
t.instance_variable_set :@templatar, true
|
14
16
|
t_metaclass = class << t; self; end
|
15
|
-
self.column_names.each do |
|
16
|
-
t_metaclass.send(:define_method,
|
17
|
+
(self.column_names + custom_methods).each do |getter|
|
18
|
+
t_metaclass.send(:define_method, getter) { getter.to_sym == :id ? '__ID__' : "#{getter}__TEMPLATE__" }
|
17
19
|
end
|
18
20
|
t
|
19
21
|
end
|
data/lib/templatar/version.rb
CHANGED
@@ -7,7 +7,7 @@ class TestARModel < SuperModel::Base
|
|
7
7
|
end
|
8
8
|
|
9
9
|
extend Templatar::ModelAdditions
|
10
|
-
has_template
|
10
|
+
has_template methods: [:x, :y]
|
11
11
|
|
12
12
|
def a
|
13
13
|
end
|
@@ -57,12 +57,18 @@ describe Templatar::ModelAdditions do
|
|
57
57
|
|
58
58
|
it { should be_template }
|
59
59
|
|
60
|
-
it "should
|
60
|
+
it "should return column_name + '_TEMPLATE'" do
|
61
61
|
model.a.should == 'a__TEMPLATE__'
|
62
62
|
model.b.should == 'b__TEMPLATE__'
|
63
63
|
model.c.should == 'c__TEMPLATE__'
|
64
64
|
model.id.should == '__ID__'
|
65
65
|
end
|
66
|
+
|
67
|
+
it "should return method_name + '_TEMPLATE' for custom methods" do
|
68
|
+
model.x.should == 'x__TEMPLATE__'
|
69
|
+
model.y.should == 'y__TEMPLATE__'
|
70
|
+
expect { model.z }.to raise_error(NoMethodError)
|
71
|
+
end
|
66
72
|
end
|
67
73
|
|
68
74
|
context 'non template object' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: templatar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrea Salicetti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|