diff --git a/lib/fb_graph2/attribute_assigner.rb b/lib/fb_graph2/attribute_assigner.rb index 5fe63e5..b18cea0 100644 --- a/lib/fb_graph2/attribute_assigner.rb +++ b/lib/fb_graph2/attribute_assigner.rb @@ -5,14 +5,26 @@ module FbGraph2 included do extend ClassMethods attr_accessor :raw_attributes - cattr_accessor :registered_attributes end module ClassMethods def register_attributes(attributes) - self.registered_attributes = attributes + @registered_attributes ||= {} + attributes.each do |type, keys| + @registered_attributes[type] ||= [] + @registered_attributes[type] += keys + end send :attr_accessor, *attributes.values.flatten end + + def registered_attributes + @registered_attributes + end + + def inherited(child) + super + child.register_attributes registered_attributes + end end def assign(attributes) diff --git a/lib/fb_graph2/struct/app_link.rb b/lib/fb_graph2/struct/app_link.rb index 7ebf2f8..262011a 100644 --- a/lib/fb_graph2/struct/app_link.rb +++ b/lib/fb_graph2/struct/app_link.rb @@ -14,6 +14,8 @@ module FbGraph2 register_attributes( raw: [:app_store_id] ) + class IPhone < IOS; end + class IPad < IOS; end end class Android < Native @@ -24,7 +26,7 @@ module FbGraph2 class WindowsPhone < Native register_attributes( - raw: [:app_name] + raw: [:app_id] ) end end diff --git a/spec/fb_graph2/node_spec.rb b/spec/fb_graph2/node_spec.rb index 2b47c6f..5d801eb 100644 --- a/spec/fb_graph2/node_spec.rb +++ b/spec/fb_graph2/node_spec.rb @@ -60,7 +60,6 @@ describe FbGraph2::Node do subject { klass } it { should_not respond_to :register_attributes } it { should_not respond_to :registered_attributes } - it { should_not respond_to :registered_attributes= } end context 'instance' do diff --git a/spec/fb_graph2/node_subclass_spec.rb b/spec/fb_graph2/node_subclass_spec.rb index 15d651d..9dbcbef 100644 --- a/spec/fb_graph2/node_subclass_spec.rb +++ b/spec/fb_graph2/node_subclass_spec.rb @@ -13,7 +13,6 @@ describe FbGraph2::NodeSubClass do subject { klass } it { should respond_to :register_attributes } it { should respond_to :registered_attributes } - it { should respond_to :registered_attributes= } end context 'instance' do diff --git a/spec/fb_graph2/struct/app_link_spec.rb b/spec/fb_graph2/struct/app_link_spec.rb new file mode 100644 index 0000000..f735648 --- /dev/null +++ b/spec/fb_graph2/struct/app_link_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe FbGraph2::Struct::AppLink do + subject { described_class } + its(:registered_attributes) { should == {raw: [:url]} } + + describe FbGraph2::Struct::AppLink::Native do + its(:registered_attributes) { should == {raw: [:url, :app_name]} } + end + + describe FbGraph2::Struct::AppLink::Native::IOS do + its(:registered_attributes) { should == {raw: [:url, :app_name, :app_store_id]} } + + describe FbGraph2::Struct::AppLink::Native::IOS::IPhone do + its(:registered_attributes) { should == {raw: [:url, :app_name, :app_store_id]} } + end + end + + describe FbGraph2::Struct::AppLink::Native::Android do + its(:registered_attributes) { should == {raw: [:url, :app_name, :class, :package]} } + end + + describe FbGraph2::Struct::AppLink::Native::WindowsPhone do + its(:registered_attributes) { should == {raw: [:url, :app_name, :app_id]} } + end + + describe FbGraph2::Struct::AppLink::Web do + its(:registered_attributes) { should == {raw: [:url, :should_fallback]} } + end +end \ No newline at end of file