mongify-mongoid 1.0.3 → 1.0.4

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: d258f7b7209471b3b095f479cfd6c5ed609a5008
4
- data.tar.gz: 3bdf8722185925908dd4925d431495038fbfcc42
3
+ metadata.gz: 2e6d0ed283fe1c834bddddb20ccfd3fb47f06feb
4
+ data.tar.gz: 6249ae1db708f6472dc0ef85f812e262b785d407
5
5
  SHA512:
6
- metadata.gz: 19fc47f468b15c691102f70b5a55aba7b961f0e077dbec524fd9d7f11f2961d32498cac071aaebd58cbc947c0895a32569e0466f0c01be5d874f1fd4466fa5cb
7
- data.tar.gz: 8c44b384ed37574af5a5b6a1e7237d77d193f008740e1b9e8d3824c13e469bae3d5a084b99f2d6e79a91f35a30daac4f8ca40e98ea918daa9e3b93cb344791ad
6
+ metadata.gz: 73272accb607d69e7e035d0cb18c3c4f8e15b15cf4f02536596a1014cdab090d5c3839532c41b87a143b77b0d5a3792a7bc0f884ff0f2d7f913b303359cc4851
7
+ data.tar.gz: 0e813eb4958e96d90554b638ef8d8fea8d338a1ce4ea87e876e2223820900558ea389b4e46b875a51b9a3ce6156e25a533f3c7d189105c61129771caeab859f3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.0.4 / 22 JUNE 2014
2
+
3
+ * Added Decimal translation
4
+ * Fixed issue were AS field was being ignored.
5
+ * Fixed typos
6
+
1
7
  ## 1.0.3 / 16 JUNE 2014
2
8
 
3
9
  * Fixed issue with during generation of files
@@ -5,7 +5,7 @@ module Mongify
5
5
  module Mongoid
6
6
  #
7
7
  # Class that will be used to define a mongoid model
8
- #
8
+ #
9
9
  class Model
10
10
  #default created at field name
11
11
  CREATED_AT_FIELD = 'created_at'
@@ -55,8 +55,8 @@ module Mongify
55
55
  end
56
56
  alias :name :class_name
57
57
 
58
- # Adds a field definition to the class,
59
- # e.g:
58
+ # Adds a field definition to the class,
59
+ # e.g:
60
60
  # add_field("field_name", "String", {rename_to: "name"})
61
61
  def add_field(name, type, options={})
62
62
  options.stringify_keys!
@@ -64,17 +64,18 @@ module Mongify
64
64
  check_for_timestamp(name)
65
65
  return if EXCLUDED_FIELDS.include?(name.to_s.downcase)
66
66
  name = options['rename_to'] if options['rename_to'].present?
67
+ type = options['as'] if options['as'].present?
67
68
  begin
68
- @fields[name.to_sym] = Field.new(name, type, options)
69
+ @fields[name.to_sym] = Field.new(name, type, options)
69
70
  rescue InvalidField => e
70
- raise InvalidField, "Unkown field type #{type} for #{name} in #{class_name}"
71
- end
71
+ raise InvalidField, "Unknown field type #{type} for #{name} in #{class_name}"
72
+ end
72
73
  end
73
74
 
74
- # Adds a relationship definition to the class,
75
- # e.g:
75
+ # Adds a relationship definition to the class,
76
+ # e.g:
76
77
  # add_relation("embedded_in", "users")
77
- #
78
+ #
78
79
  # @note Embedded relations will overpower related relations
79
80
  # @return [Relation] New generated relation
80
81
  def add_relation(relation_name, association, options={})
@@ -105,7 +106,7 @@ module Mongify
105
106
  #######
106
107
  private
107
108
  #######
108
-
109
+
109
110
  # Checks if given field name is a known timestamp field
110
111
  # @return [nil]
111
112
  def check_for_timestamp name
@@ -9,6 +9,7 @@ module Mongify
9
9
  ACCEPTED_TYPES = [
10
10
  "Array",
11
11
  "BigDecimal",
12
+ "Decimal",
12
13
  "Boolean",
13
14
  "Date",
14
15
  "DateTime",
@@ -29,6 +30,7 @@ module Mongify
29
30
  TRANSLATION_TYPES = {
30
31
  array: "Array",
31
32
  bigdecimal: "BigDecimal",
33
+ decimal: "String",
32
34
  boolean: "Boolean",
33
35
  date: "Date",
34
36
  datetime: "DateTime",
@@ -49,24 +51,23 @@ module Mongify
49
51
  attr_accessor :name, :type, :options
50
52
 
51
53
  def initialize(name, type, options={})
52
- type = translate_type(type)
53
- check_field_type(type)
54
54
  @name = name
55
- @type = type
56
55
  @options = options
56
+ @type = translate_type(type)
57
+ check_field_type(@type)
57
58
  end
58
59
 
59
60
  #######
60
61
  private
61
62
  #######
62
-
63
+
63
64
  # Tries to find a translation for a SQL type to a Mongoid Type
64
65
  # @param [String] name Name of type
65
66
  # @return [String] Translated field name or the same name if no translation is found
66
67
  def translate_type(name)
67
68
  TRANSLATION_TYPES[name.to_s.downcase.to_sym] || name
68
69
  end
69
-
70
+
70
71
  # Raises InvalidField if field type is unknown
71
72
  # @param [String] name Name of type
72
73
  # @raise InvalidField if name is not an accepted type
@@ -1,6 +1,6 @@
1
1
  module Mongify
2
2
  module Mongoid
3
3
  #Version number for Mongify-Mongoid
4
- VERSION = "1.0.3"
4
+ VERSION = "1.0.4"
5
5
  end
6
6
  end
@@ -5,15 +5,22 @@ describe Mongify::Mongoid::Model::Field do
5
5
  context "types" do
6
6
  context "validation" do
7
7
  it "doesn't raise error when valid value" do
8
- expect { Mongify::Mongoid::Model::Field.new("first_name", "String") }.to_not raise_error
8
+ expect { Mongify::Mongoid::Model::Field.new("first_name", "String") }.to_not raise_error
9
9
  end
10
10
  it "does raise error on invalid value" do
11
11
  expect { Mongify::Mongoid::Model::Field.new("first_name", "Limb") }.to raise_error(Mongify::Mongoid::InvalidField)
12
12
  end
13
13
  end
14
14
 
15
+ context "decimal" do
16
+ it "works" do
17
+ subject = Mongify::Mongoid::Model::Field.new("money", "Decimal")
18
+ expect(subject.type).to eq "String"
19
+ end
20
+ end
21
+
15
22
  context "translation" do
16
- [:array, :bigdecimal, :boolean, :date, :datetime, :float, :hash, :integer, :objectid, :binary, :range, :regexp, :string, :symbol, :time, :timewithzone].each do |type|
23
+ [:array, :bigdecimal, :decimal, :boolean, :date, :datetime, :float, :hash, :integer, :objectid, :binary, :range, :regexp, :string, :symbol, :time, :timewithzone].each do |type|
17
24
  it "for #{type} works" do
18
25
  field.send(:translate_type, type).should == Mongify::Mongoid::Model::Field::TRANSLATION_TYPES[type]
19
26
  end
@@ -26,6 +33,6 @@ describe Mongify::Mongoid::Model::Field do
26
33
  field.send(:translate_type, type).should == type
27
34
  end
28
35
  end
29
-
36
+
30
37
  end
31
38
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Mongify::Mongoid::Model do
4
4
  subject(:model) { Mongify::Mongoid::Model.new(:table_name => "users", :class_name => "User") }
5
-
5
+
6
6
  describe "initialize" do
7
7
  its(:class_name) { should == "User" }
8
8
  its(:table_name) { should == "users" }
@@ -28,10 +28,14 @@ describe Mongify::Mongoid::Model do
28
28
  model.add_field("user_id", "integer", {references: 'users'})
29
29
  model.should_not have_field("user_id")
30
30
  end
31
- it "raises error if field is unkown" do
31
+ it "works with as field type" do
32
+ subject.add_field("money", "Decimal", {as: "Integer"})
33
+ expect(subject).to have_field("money").of_type("Integer")
34
+ end
35
+ it "raises error if field is unknown" do
32
36
  expect { model.add_field("user_id", 'limb') }.to raise_error(
33
- Mongify::Mongoid::InvalidField,
34
- "Unkown field type limb for user_id in #{model.class_name}")
37
+ Mongify::Mongoid::InvalidField,
38
+ "Unknown field type limb for user_id in #{model.class_name}")
35
39
  end
36
40
  end
37
41
 
@@ -140,7 +144,7 @@ describe Mongify::Mongoid::Model do
140
144
  model.add_relation(Mongify::Mongoid::Model::Relation::HAS_MANY, association)
141
145
  model.relations.should have(1).relation
142
146
  end
143
-
147
+
144
148
  end
145
149
  end
146
150
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongify-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kalek
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-19 00:00:00.000000000 Z
12
+ date: 2014-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongify