cistern 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -130,7 +130,7 @@ module Cistern::Attributes
130
130
  elsif self.respond_to?("#{key}=", true)
131
131
  send("#{key}=", value)
132
132
  else
133
- attributes[key] = value
133
+ # ignore data: unknown attribute : attributes[key] = value
134
134
  end
135
135
  end
136
136
  end
data/lib/cistern/model.rb CHANGED
@@ -4,16 +4,8 @@ class Cistern::Model
4
4
 
5
5
  attr_accessor :collection, :connection
6
6
 
7
- def self.formatter
8
- @formatter ||= Cistern::Formatter::Default
9
- end
10
-
11
- def self.formatter=(formatter)
12
- @formatter = formatter
13
- end
14
-
15
7
  def inspect
16
- self.class.formatter.call(self)
8
+ Cistern.formatter.call(self)
17
9
  end
18
10
 
19
11
  def initialize(attributes={})
@@ -1,9 +1,10 @@
1
1
  class Cistern::Service
2
- def self.mock!; @mocking= true; end
2
+
3
+ def self.mock!; @mocking = true; end
3
4
  def self.mocking?; @mocking; end
4
- def self.unmock!; @mocking= false; end
5
- module Collections
5
+ def self.unmock!; @mocking = false; end
6
6
 
7
+ module Collections
7
8
  def collections
8
9
  service.collections
9
10
  end
@@ -15,8 +16,8 @@ class Cistern::Service
15
16
  def requests
16
17
  service.requests
17
18
  end
18
-
19
19
  end
20
+
20
21
  class << self
21
22
  def inherited(klass)
22
23
  klass.class_eval <<-EOS, __FILE__, __LINE__
@@ -32,6 +33,7 @@ class Cistern::Service
32
33
  end
33
34
  EOS
34
35
  end
36
+
35
37
  def model_path(model_path)
36
38
  @model_path = model_path
37
39
  end
@@ -68,8 +70,8 @@ class Cistern::Service
68
70
  self.recognized_arguments.concat(args)
69
71
  end
70
72
 
71
- def model(model_name)
72
- models << model_name
73
+ def model(model_name, options={})
74
+ models << [model_name, options]
73
75
  end
74
76
 
75
77
  def mocked_requests
@@ -100,8 +102,14 @@ class Cistern::Service
100
102
  def setup_requirements
101
103
  @required ||= false
102
104
  unless @required
103
- models.each do |model|
104
- require File.join(@model_path, model.to_s)
105
+ models.each do |model, options|
106
+ require File.join(@model_path, model.to_s) unless options[:require] == false
107
+ class_name = model.to_s.split("_").map(&:capitalize).join
108
+ self.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__
109
+ def #{model}(attributes={})
110
+ #{service}::#{class_name}.new({connection: self}.merge(attributes))
111
+ end
112
+ EOS
105
113
  end
106
114
  requests.each do |request|
107
115
  require File.join(@request_path, request.to_s)
@@ -1,3 +1,3 @@
1
1
  module Cistern
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/cistern.rb CHANGED
@@ -14,12 +14,8 @@ module Cistern
14
14
 
15
15
  autoload :Formatter, 'cistern/formatter'
16
16
 
17
-
18
- def self.timeout=(timeout)
19
- @timeout= timeout
20
- end
21
-
22
- def self.timeout
23
- @timeout || 0
24
- end
17
+ def self.timeout=(timeout); @timeout= timeout; end
18
+ def self.timeout; @timeout || 0; end
19
+ def self.formatter; @formatter ||= Cistern::Formatter::Default; end
20
+ def self.formatter=(formatter); @formatter = formatter; end
25
21
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe "inspection engine" do
4
+ class Inspector < Cistern::Model
5
+ identity :id
6
+ attribute :name
7
+ end
8
+
9
+ after(:all) do
10
+ Cistern.formatter= Cistern::Formatter::Default
11
+ end
12
+
13
+ it "should default to default formatter" do
14
+ Cistern.formatter.should == Cistern::Formatter::Default
15
+ end
16
+
17
+ it "should use default" do
18
+ Inspector.new(id: 1, name: "name").inspect.should match /#<Inspector:0x[0-9a-f]+ attributes={id:1,name:\"name\"}/
19
+ end
20
+
21
+ it "should use awesome_print" do
22
+ defined?(AwesomePrint).should be_false # don't require if not used
23
+ Cistern.formatter= Cistern::Formatter::AwesomePrint
24
+
25
+ Inspector.new(id: 1, name: "name").inspect.match /(?x-mi:\#<Inspector:0x[0-9a-f]+>\ {\n\ \ \ \ \ \ :id\x1B\[0;37m\ =>\ \x1B\[0m\x1B\[1;34m1\x1B\[0m,\n\ \ \ \ :name\x1B\[0;37m\ =>\ \x1B\[0m\x1B\[0;33m"name"\x1B\[0m\n})/
26
+ end
27
+
28
+ it "should use formatador" do
29
+ defined?(Formatador).should be_false # don't require if not used
30
+ Cistern.formatter= Cistern::Formatter::Formatador
31
+
32
+ Inspector.new(id: 1, name: "name").inspect.should == " <Inspector\n id=1,\n name=\"name\"\n >"
33
+ end
34
+ end
data/spec/model_spec.rb CHANGED
@@ -71,38 +71,9 @@ describe "Cistern::Model" do
71
71
  it "should squash and cast" do
72
72
  TypeSpec.new({"squash" => {"id" => "12"}}).butternut.should == 12
73
73
  end
74
- end
75
-
76
- context "inspection engine" do
77
- class InspectorSpec < Cistern::Model
78
- identity :id
79
- attribute :name
80
- end
81
-
82
- after(:all) do
83
- InspectorSpec.formatter= Cistern::Formatter::Default
84
- end
85
-
86
- it "should default to default formatter" do
87
- InspectorSpec.formatter.should == Cistern::Formatter::Default
88
- end
89
-
90
- it "should use default" do
91
- InspectorSpec.new(id: 1, name: "name").inspect.should match /#<InspectorSpec:0x[0-9a-f]+ attributes={id:1,name:\"name\"}/
92
- end
93
-
94
- it "should use awesome_print" do
95
- defined?(AwesomePrint).should be_false # don't require if not used
96
- InspectorSpec.formatter= Cistern::Formatter::AwesomePrint
97
-
98
- InspectorSpec.new(id: 1, name: "name").inspect.match /(?x-mi:\#<InspectorSpec:0x[0-9a-f]+>\ {\n\ \ \ \ \ \ :id\x1B\[0;37m\ =>\ \x1B\[0m\x1B\[1;34m1\x1B\[0m,\n\ \ \ \ :name\x1B\[0;37m\ =>\ \x1B\[0m\x1B\[0;33m"name"\x1B\[0m\n})/
99
- end
100
-
101
- it "should use formatador" do
102
- defined?(Formatador).should be_false # don't require if not used
103
- InspectorSpec.formatter= Cistern::Formatter::Formatador
104
74
 
105
- InspectorSpec.new(id: 1, name: "name").inspect.should == " <InspectorSpec\n id=1,\n name=\"name\"\n >"
75
+ it "should slice out unaccounted for attributes" do
76
+ TypeSpec.new({"something" => {"id" => "12"}}).attributes.keys.should_not include("something")
106
77
  end
107
78
  end
108
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cistern
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -38,6 +38,7 @@ files:
38
38
  - lib/cistern/service.rb
39
39
  - lib/cistern/version.rb
40
40
  - lib/cistern/wait_for.rb
41
+ - spec/cistern_spec.rb
41
42
  - spec/collection_spec.rb
42
43
  - spec/model_spec.rb
43
44
  - spec/spec_helper.rb
@@ -66,6 +67,7 @@ signing_key:
66
67
  specification_version: 3
67
68
  summary: API client framework
68
69
  test_files:
70
+ - spec/cistern_spec.rb
69
71
  - spec/collection_spec.rb
70
72
  - spec/model_spec.rb
71
73
  - spec/spec_helper.rb