hookercookerman-amee 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -1
- data/Rakefile +1 -3
- data/features/data/data_category.feature +2 -2
- data/features/profile/profile_category.feature +2 -2
- data/lib/amee.rb +1 -1
- data/lib/amee/data_api/data_category.rb +14 -2
- data/lib/amee/data_api/data_item.rb +1 -0
- data/lib/amee/data_api/data_item_value.rb +5 -0
- data/lib/amee/data_api/drill_down.rb +5 -0
- data/lib/amee/data_api/item_value_definition.rb +4 -0
- data/lib/amee/model.rb +18 -14
- data/lib/amee/profile_api/profile.rb +5 -0
- data/lib/amee/profile_api/profile_category.rb +1 -0
- data/lib/amee/profile_api/profile_item.rb +5 -0
- data/tasks/yard.rake +4 -4
- metadata +2 -2
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -10,8 +10,8 @@ Feature: Get Amee Category
|
|
10
10
|
Then the data category should have: "path" with: ""
|
11
11
|
And the data category should have: "name" with: "Root"
|
12
12
|
And the data category should have: "uid" with: "CD310BEBAC52"
|
13
|
-
And the data category's data_items should be
|
14
|
-
And the data category's data_categories should not be
|
13
|
+
And the data category's data_items should be empty
|
14
|
+
And the data category's data_categories should not be empty
|
15
15
|
|
16
16
|
Scenario: Get Amee category with path /data/transport/plane/generic
|
17
17
|
Given I have a valid amee session
|
@@ -9,6 +9,6 @@ Feature: Get Amee Profile Category
|
|
9
9
|
|
10
10
|
Then the profile category should have: "total_amount_per_month" with: "0"
|
11
11
|
And the profile category should have: "resource_path" with: "/business"
|
12
|
-
And the profile category's profile_items should
|
13
|
-
And the profile category's profile_categories should not be
|
12
|
+
And the profile category's profile_items should be empty
|
13
|
+
And the profile category's profile_categories should not be empty
|
14
14
|
And the profile category's data_category should not be nil
|
data/lib/amee.rb
CHANGED
@@ -35,14 +35,26 @@ module Amee
|
|
35
35
|
item_definition && item_definition.drill_down
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
39
|
-
|
38
|
+
def paginate_data_items(options = {})
|
39
|
+
data_items = WillPaginate::Collection.create(
|
40
|
+
options[:page] || 1,
|
41
|
+
options[:per_page] || 10,
|
42
|
+
options[:total] || self.pager["items"]
|
43
|
+
) do |pager|
|
44
|
+
result = session.api_call(:get, "data_category", self.full_path,
|
45
|
+
:query => {:itemsPerPage => pager.per_page, :page => pager.current_page}
|
46
|
+
) do |response|
|
47
|
+
populate_from_hash!(response)
|
48
|
+
end
|
49
|
+
pager.replace(result.data_items)
|
50
|
+
end
|
40
51
|
end
|
41
52
|
|
42
53
|
def populate!
|
43
54
|
session.api_call(:get, "data.category", self.full_path) do |response|
|
44
55
|
populate_from_hash!(response)
|
45
56
|
end
|
57
|
+
@lazy_loaded = true
|
46
58
|
end
|
47
59
|
|
48
60
|
end
|
@@ -7,6 +7,11 @@ module Amee
|
|
7
7
|
|
8
8
|
attr_accessor :display_name, :description, :value, :display_path, :unit, :per_unit, :data_item
|
9
9
|
item_populators :item_value_definition => {:class => Amee::DataApi::ItemValueDefinition}
|
10
|
+
|
11
|
+
|
12
|
+
def lazy_loaded
|
13
|
+
true
|
14
|
+
end
|
10
15
|
|
11
16
|
end
|
12
17
|
end
|
data/lib/amee/model.rb
CHANGED
@@ -10,6 +10,7 @@ module Amee
|
|
10
10
|
base.__send__(:attr_accessor, :modified)
|
11
11
|
base.__send__(:attr_accessor, :created)
|
12
12
|
base.__send__(:attr_accessor, :resource_path)
|
13
|
+
base.__send__(:attr_accessor, :lazy_loaded)
|
13
14
|
|
14
15
|
base.class_eval do
|
15
16
|
class << base; attr_reader :lazy_populators end
|
@@ -28,7 +29,7 @@ module Amee
|
|
28
29
|
|
29
30
|
def item_populators(hash)
|
30
31
|
@lazy_populators ||= [] << hash.keys
|
31
|
-
|
32
|
+
populator_item_getter(hash.keys)
|
32
33
|
hash.each_pair do |key, value|
|
33
34
|
|
34
35
|
define_method("#{key}=") do |definition|
|
@@ -45,7 +46,7 @@ module Amee
|
|
45
46
|
|
46
47
|
def list_populators(hash)
|
47
48
|
@lazy_populators ||= [] << hash.keys
|
48
|
-
|
49
|
+
populator_lists_getter(hash.keys)
|
49
50
|
hash.each_pair do |key, value|
|
50
51
|
|
51
52
|
define_method("#{key}=") do |list|
|
@@ -60,7 +61,18 @@ module Amee
|
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
|
-
def
|
64
|
+
def populator_lists_getter(pops)
|
65
|
+
pops.each do |symbol|
|
66
|
+
define_method(symbol) do
|
67
|
+
if !populated? && self.resource_path
|
68
|
+
populate!
|
69
|
+
end
|
70
|
+
instance_variable_get("@#{symbol}") || []
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def populator_item_getter(pops)
|
64
76
|
pops.each do |symbol|
|
65
77
|
define_method(symbol) do
|
66
78
|
if !populated? && self.resource_path
|
@@ -87,11 +99,11 @@ module Amee
|
|
87
99
|
end
|
88
100
|
|
89
101
|
def populated?
|
90
|
-
@populated &&
|
102
|
+
@populated && lazy_loaded
|
91
103
|
end
|
92
104
|
|
93
105
|
def populate!
|
94
|
-
raise
|
106
|
+
raise ::NotImplementedError, "#{self.class} included me and has not overriden me"
|
95
107
|
end
|
96
108
|
|
97
109
|
def populate_from_hash!(hash)
|
@@ -115,14 +127,6 @@ module Amee
|
|
115
127
|
def populate_paths(resource_path, path)
|
116
128
|
self.resource_path, self.path = resource_path, path
|
117
129
|
end
|
118
|
-
|
119
|
-
# if the all the lazy populators have been set then
|
120
|
-
# we now when are populated!
|
121
|
-
def lazy_populators_populated?
|
122
|
-
if self.class.lazy_populators
|
123
|
-
self.class.lazy_populators.find_all {|pop| !instance_variable_get("@#{pop}").nil?} == self.class.lazy_populators
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
130
|
+
|
127
131
|
end
|
128
132
|
end
|
data/tasks/yard.rake
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "yard"
|
2
|
-
YARD::Rake::YardocTask.new do |t|
|
3
|
-
|
4
|
-
end
|
1
|
+
# require "yard"
|
2
|
+
# YARD::Rake::YardocTask.new do |t|
|
3
|
+
# t.files = ['lib/**/*.rb'] # optional
|
4
|
+
# end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hookercookerman-amee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Hooker
|
@@ -155,7 +155,7 @@ files:
|
|
155
155
|
- tasks/rspec.rake
|
156
156
|
- tasks/yard.rake
|
157
157
|
has_rdoc: true
|
158
|
-
homepage: http://
|
158
|
+
homepage: http://github.com/hookercookerman/amee/tree/master
|
159
159
|
post_install_message:
|
160
160
|
rdoc_options:
|
161
161
|
- --main
|