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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98ecf92d9971365c0a97a485b2b7ce00f21ea1bb
4
- data.tar.gz: fe9b51266dc05bdeac6ec718a1a4109a0e925da8
3
+ metadata.gz: 0b2e2ce5052ee80385aa3e2df5f8caac1efbac8d
4
+ data.tar.gz: 7bb03cfd98e5e8bfbf7e6812dee8e112f4636a5c
5
5
  SHA512:
6
- metadata.gz: 4fa80cec85aeaebbda4dabd6e17a7b9cdcb407903923eab47c54bd080077f8db64f4d3a1015de7f8b89b73a5c181dae3fb83f35e229eb7b78e6b688fe0fa6112
7
- data.tar.gz: 25e741f225e00f767f1ef5b4679de66b2108c20b1ed4802a4e21cb272d832f1e54fa9c168aa8ca696eb29d29501ad9b41c4927bbcd1b7c91ac6d72cf9d4a4751
6
+ metadata.gz: 0a6eae29824fe2eb073fba465e3b44568947c150f4dd9fd747ade8e4745200659d2ec8b9eed5bf2897bf3b4f806a6630a8eb0b73738629f6ec1e176da5058a1e
7
+ data.tar.gz: dadb5ad0b0ff9031f96f40b4fc0db605d4e9156a074e791ab442140cb1b7b0a2beaf4232098b3690bdc4642e5b1c330c6f1b12aaecfd833b31c24a8462451a63
@@ -1,4 +1,9 @@
1
+ ## v0.0.3
2
+
3
+ * Adds custom method
4
+
1
5
  ## v0.0.2
6
+
2
7
  * Fixes serious bug on tempate: when `has_template` was added on several AR models, each model class returned the same object.
3
8
 
4
9
  ## v0.0.1
@@ -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 |column|
16
- t_metaclass.send(:define_method, column) { column.to_sym == :id ? '__ID__' : "#{column}__TEMPLATE__" }
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
@@ -1,4 +1,4 @@
1
1
  # Gem version
2
2
  module Templatar
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
@@ -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 retunr column_name + '_TEMPLATE'" do
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.2
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-08-28 00:00:00.000000000 Z
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler