Class: Pop
- Inherits:
-
RestfulModel
- Object
- RestfulModel
- Pop
- Defined in:
- lib/pop.rb
Defined Under Namespace
Classes: AssetMustBeSaved, TemplateRequired
Instance Attribute Summary collapse
-
#clone_link_enabled ⇒ Object
Returns the value of attribute clone_link_enabled.
-
#clone_link_url ⇒ Object
Returns the value of attribute clone_link_url.
-
#collaboration_interstitial_text ⇒ Object
Returns the value of attribute collaboration_interstitial_text.
-
#collaboration_link_enabled ⇒ Object
Returns the value of attribute collaboration_link_enabled.
-
#collaboration_link_url ⇒ Object
Returns the value of attribute collaboration_link_url.
-
#collaboration_webhook ⇒ Object
Returns the value of attribute collaboration_webhook.
-
#custom_code ⇒ Object
Returns the value of attribute custom_code.
-
#custom_links ⇒ Object
Returns the value of attribute custom_links.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#label_names ⇒ Object
Returns the value of attribute label_names.
-
#name ⇒ Object
Returns the value of attribute name.
-
#newly_populated_regions ⇒ Object
readonly
Returns the value of attribute newly_populated_regions.
-
#newly_populated_tags ⇒ Object
readonly
Returns the value of attribute newly_populated_tags.
-
#password ⇒ Object
Returns the value of attribute password.
-
#published_pop_url ⇒ Object
Returns the value of attribute published_pop_url.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#template_id ⇒ Object
Returns the value of attribute template_id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#tracers ⇒ Object
Returns the value of attribute tracers.
-
#unpopulated_api_regions ⇒ Object
Returns the value of attribute unpopulated_api_regions.
-
#unpopulated_api_tags ⇒ Object
Returns the value of attribute unpopulated_api_tags.
Attributes inherited from RestfulModel
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #disable_cloning ⇒ Object
- #disable_collaboration ⇒ Object
- #enable_cloning! ⇒ Object
- #enable_collaboration!(interstitial_text = '', webhook = nil) ⇒ Object
- #has_unpopulated_region(region_identifier) ⇒ Object
- #has_unpopulated_tag(tag_identifier) ⇒ Object
- #inflate(json) ⇒ Object
-
#initialize(parent) ⇒ Pop
constructor
A new instance of Pop.
- #populate_region(region_identifier, assets) ⇒ Object
- #populate_tag(tag_identifier, tag_contents) ⇒ Object
- #publish! ⇒ Object
- #type_of_unpopulated_region(region_identifier) ⇒ Object
- #unpublish! ⇒ Object
Methods inherited from RestfulModel
#==, collection_name, #path, #save!, #update
Constructor Details
#initialize(parent) ⇒ Pop
Returns a new instance of Pop.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pop.rb', line 32 def initialize(parent) if parent.is_a?(Template) @_api = parent.instance_variable_get :@_api self.template_id = parent._id self.title = parent.title self.name = parent.name self.unpopulated_api_regions = parent.api_regions.dup self. = parent..dup self.custom_code = parent.custom_code self.custom_links = parent.custom_links.dup if parent.custom_links elsif parent.is_a?(RestfulModelCollection) @_api = parent.instance_variable_get :@_api elsif parent.is_a?(Populr) @_api = parent else raise "You must create a pop with a template, collection, or API model." end # We could choose to make parent the restfulModelCollection that is passed to us, # but that would result in PUTs and POSTs to /templates/:id/pops, which isn't # how the API is currently set up. For now, all pop PUTS, POSTs, etc... go to /pops/ @_parent = @_api.pops @newly_populated_regions = {} = {} end |
Instance Attribute Details
#clone_link_enabled ⇒ Object
Returns the value of attribute clone_link_enabled.
20 21 22 |
# File 'lib/pop.rb', line 20 def clone_link_enabled @clone_link_enabled end |
#clone_link_url ⇒ Object
Returns the value of attribute clone_link_url.
21 22 23 |
# File 'lib/pop.rb', line 21 def clone_link_url @clone_link_url end |
#collaboration_interstitial_text ⇒ Object
Returns the value of attribute collaboration_interstitial_text.
23 24 25 |
# File 'lib/pop.rb', line 23 def collaboration_interstitial_text @collaboration_interstitial_text end |
#collaboration_link_enabled ⇒ Object
Returns the value of attribute collaboration_link_enabled.
22 23 24 |
# File 'lib/pop.rb', line 22 def collaboration_link_enabled @collaboration_link_enabled end |
#collaboration_link_url ⇒ Object
Returns the value of attribute collaboration_link_url.
24 25 26 |
# File 'lib/pop.rb', line 24 def collaboration_link_url @collaboration_link_url end |
#collaboration_webhook ⇒ Object
Returns the value of attribute collaboration_webhook.
25 26 27 |
# File 'lib/pop.rb', line 25 def collaboration_webhook @collaboration_webhook end |
#custom_code ⇒ Object
Returns the value of attribute custom_code.
19 20 21 |
# File 'lib/pop.rb', line 19 def custom_code @custom_code end |
#custom_links ⇒ Object
Returns the value of attribute custom_links.
18 19 20 |
# File 'lib/pop.rb', line 18 def custom_links @custom_links end |
#domain ⇒ Object
Returns the value of attribute domain.
26 27 28 |
# File 'lib/pop.rb', line 26 def domain @domain end |
#label_names ⇒ Object
Returns the value of attribute label_names.
13 14 15 |
# File 'lib/pop.rb', line 13 def label_names @label_names end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/pop.rb', line 10 def name @name end |
#newly_populated_regions ⇒ Object (readonly)
Returns the value of attribute newly_populated_regions.
29 30 31 |
# File 'lib/pop.rb', line 29 def newly_populated_regions @newly_populated_regions end |
#newly_populated_tags ⇒ Object (readonly)
Returns the value of attribute newly_populated_tags.
30 31 32 |
# File 'lib/pop.rb', line 30 def end |
#password ⇒ Object
Returns the value of attribute password.
27 28 29 |
# File 'lib/pop.rb', line 27 def password @password end |
#published_pop_url ⇒ Object
Returns the value of attribute published_pop_url.
15 16 17 |
# File 'lib/pop.rb', line 15 def published_pop_url @published_pop_url end |
#slug ⇒ Object
Returns the value of attribute slug.
12 13 14 |
# File 'lib/pop.rb', line 12 def slug @slug end |
#template_id ⇒ Object
Returns the value of attribute template_id.
9 10 11 |
# File 'lib/pop.rb', line 9 def template_id @template_id end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/pop.rb', line 11 def title @title end |
#tracers ⇒ Object
Returns the value of attribute tracers.
14 15 16 |
# File 'lib/pop.rb', line 14 def tracers @tracers end |
#unpopulated_api_regions ⇒ Object
Returns the value of attribute unpopulated_api_regions.
16 17 18 |
# File 'lib/pop.rb', line 16 def unpopulated_api_regions @unpopulated_api_regions end |
#unpopulated_api_tags ⇒ Object
Returns the value of attribute unpopulated_api_tags.
17 18 19 |
# File 'lib/pop.rb', line 17 def end |
Instance Method Details
#as_json(options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pop.rb', line 68 def as_json( = {}) raise TemplateRequired.new if [:api_representation] && !template_id if [:api_representation] hash = {} hash[:pop] = super() hash[:populate_tags] = hash[:populate_regions] = @newly_populated_regions hash else super() end end |
#disable_cloning ⇒ Object
108 109 110 111 |
# File 'lib/pop.rb', line 108 def disable_cloning self.clone_link_enabled = false self.clone_link_url = nil # doesn't get saed, just for developer interface end |
#disable_collaboration ⇒ Object
98 99 100 101 |
# File 'lib/pop.rb', line 98 def disable_collaboration self.collaboration_link_enabled = false self.collaboration_link_url = nil end |
#enable_cloning! ⇒ Object
103 104 105 106 |
# File 'lib/pop.rb', line 103 def enable_cloning! self.clone_link_enabled = true self.save! # go and populate our model with the clone link end |
#enable_collaboration!(interstitial_text = '', webhook = nil) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/pop.rb', line 91 def enable_collaboration!(interstitial_text = '', webhook = nil) self.collaboration_link_enabled = true self.collaboration_webhook = webhook self.collaboration_interstitial_text = interstitial_text self.save! # go and populate our model with the collaboration link end |
#has_unpopulated_region(region_identifier) ⇒ Object
113 114 115 |
# File 'lib/pop.rb', line 113 def has_unpopulated_region(region_identifier) self.unpopulated_api_regions.include?(region_identifier) end |
#has_unpopulated_tag(tag_identifier) ⇒ Object
133 134 135 |
# File 'lib/pop.rb', line 133 def has_unpopulated_tag(tag_identifier) self..include?(tag_identifier) end |
#inflate(json) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/pop.rb', line 61 def inflate(json) super(json) self.tracers = RestfulModelCollection.new(Tracer, @_api, self) @newly_populated_regions = {} = {} end |
#populate_region(region_identifier, assets) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/pop.rb', line 122 def populate_region(region_identifier, assets) assets = [assets] unless assets.is_a?(Array) @newly_populated_regions[region_identifier] ||= [] @newly_populated_regions[region_identifier].concat(assets.map {|a| raise AssetMustBeSaved.new unless a._id a._id }) self.unpopulated_api_regions.delete(region_identifier) end |
#populate_tag(tag_identifier, tag_contents) ⇒ Object
137 138 139 140 |
# File 'lib/pop.rb', line 137 def populate_tag(tag_identifier, tag_contents) [tag_identifier] = tag_contents self..delete(tag_identifier) end |
#publish! ⇒ Object
83 84 85 |
# File 'lib/pop.rb', line 83 def publish! update('POST', 'publish') end |
#type_of_unpopulated_region(region_identifier) ⇒ Object
117 118 119 120 |
# File 'lib/pop.rb', line 117 def type_of_unpopulated_region(region_identifier) return false unless self.has_unpopulated_region(region_identifier) self.unpopulated_api_regions[region_identifier]['type'] end |
#unpublish! ⇒ Object
87 88 89 |
# File 'lib/pop.rb', line 87 def unpublish! update('POST', 'unpublish') end |