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 CHANGED
@@ -1 +1,4 @@
1
- There is none
1
+ == 0.0.1 2009-04-24
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Rakefile CHANGED
@@ -23,7 +23,5 @@ end
23
23
  require 'newgem/tasks' # load /tasks/*.rake
24
24
  Dir['tasks/**/*.rake'].each { |t| load t }
25
25
 
26
-
27
-
28
26
  # TODO - want other tests/tasks run by default? Add them to the list
29
- task :default => [:spec, :features]
27
+ # task :default => [:spec, :features]
@@ -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 nil
14
- And the data category's data_categories should not be nil
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 not be nil
13
- And the profile category's profile_categories should not be nil
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
@@ -33,5 +33,5 @@ require "amee/profile_api/profile_category"
33
33
  require "amee/profile_api/profile"
34
34
 
35
35
  module Amee
36
- VERSION = '0.0.1'
36
+ VERSION = '0.0.4'
37
37
  end
@@ -35,14 +35,26 @@ module Amee
35
35
  item_definition && item_definition.drill_down
36
36
  end
37
37
 
38
- def paginate(options = {})
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
@@ -17,6 +17,7 @@ module Amee
17
17
  session.api_call(:get, "data.item", self.full_path) do |response|
18
18
  populate_from_hash!(response)
19
19
  end
20
+ @lazy_loaded = true
20
21
  end
21
22
 
22
23
  def kg_co2_per_kwh
@@ -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
@@ -18,6 +18,11 @@ module Amee
18
18
  def uid_found?
19
19
  choice_name == "uid"
20
20
  end
21
+
22
+ def lazy_loaded
23
+ true
24
+ end
25
+
21
26
  end
22
27
  end
23
28
  end
@@ -7,6 +7,10 @@ module Amee
7
7
 
8
8
  attr_accessor :from_profile, :from_data
9
9
  item_populators :value_definition => {:class => Amee::DataApi::ValueDefinition}
10
+
11
+ def lazy_loaded
12
+ true
13
+ end
10
14
 
11
15
  end
12
16
  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
- populator_getters(hash.keys)
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
- populator_getters(hash.keys)
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 populator_getters(pops)
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 && lazy_populators_populated?
102
+ @populated && lazy_loaded
91
103
  end
92
104
 
93
105
  def populate!
94
- raise NotImplementError, "#{self.class} included me and has not overriden me"
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
@@ -34,6 +34,11 @@ module Amee
34
34
  def full_path
35
35
  "#{self.class.path_prefix}/#{self.uid}"
36
36
  end
37
+
38
+ def lazy_loaded
39
+ true
40
+ end
41
+
37
42
  end
38
43
  end
39
44
  end
@@ -18,6 +18,7 @@ module Amee
18
18
  session.api_call(:get, "profile.category", self.full_path) do |response|
19
19
  populate_from_hash!(response)
20
20
  end
21
+ @lazy_loaded = true
21
22
  end
22
23
 
23
24
  def profile_uid
@@ -42,6 +42,11 @@ module Amee
42
42
  "#{self.class.path_prefix}/#{profile_uid}" + resource_path
43
43
  end
44
44
 
45
+ # its be default already totally loaded
46
+ def lazy_loaded
47
+ true
48
+ end
49
+
45
50
  end
46
51
  end
47
52
  end
data/tasks/yard.rake CHANGED
@@ -1,4 +1,4 @@
1
- require "yard"
2
- YARD::Rake::YardocTask.new do |t|
3
- t.files = ['lib/**/*.rb'] # optional
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.3
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://www.amee.com
158
+ homepage: http://github.com/hookercookerman/amee/tree/master
159
159
  post_install_message:
160
160
  rdoc_options:
161
161
  - --main