-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotated EnumType Members #13
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.2 | ||
2.5.8 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,18 +46,23 @@ def namespace | |
# @return [Hash] | ||
def members | ||
@members ||= collect_members | ||
end | ||
|
||
def annotated_members | ||
@annotated_members ||= collect_annotated_members | ||
end | ||
|
||
# Returns the property class that implements this `EnumType`. | ||
# @return [Class < FrOData::Properties::Enum] | ||
def property_class | ||
@property_class ||= lambda { |type, members, is_flags| | ||
@property_class ||= lambda { |type, members, annotated_members, is_flags| | ||
klass = Class.new ::FrOData::Properties::Enum | ||
klass.send(:define_method, :type) { type } | ||
klass.send(:define_method, :members) { members } | ||
klass.send(:define_method, :annotated_members) { annotated_members } | ||
klass.send(:define_method, :is_flags?) { is_flags } | ||
klass | ||
}.call(type, members, is_flags?) | ||
}.call(type, members, annotated_members, is_flags?) | ||
end | ||
|
||
# Returns the value of the requested member. | ||
|
@@ -89,6 +94,18 @@ def collect_members | |
member_value = member_xml.attributes['Value'].andand.value.andand.to_i | ||
[member_value || index, member_name] | ||
end] | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def collect_annotated_members | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Complex method FrOData::Schema::EnumType#collect_annotated_members (35.9) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FrOData::Schema::EnumType#collect_annotated_members has approx 6 statements There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assignment Branch Condition size for collect_annotated_members is too high. [21.47/15] |
||
Hash[type_definition.xpath('./Member').map.with_index do |member_xml, index| | ||
member_name = member_xml.attributes['Name'].value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FrOData::Schema::EnumType#collect_annotated_members calls 'member_xml.attributes' 2 times There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FrOData::Schema::EnumType#collect_annotated_members refers to 'member_xml' more than self (maybe move it to another class?) |
||
member_value = member_xml.attributes['Value'].andand.value.andand.to_i | ||
annotation = nil | ||
if member_xml.element_children.count > 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FrOData::Schema::EnumType#collect_annotated_members calls 'member_xml.element_children' 2 times |
||
annotation = member_xml.element_children.last.attribute('String').value | ||
end | ||
[member_value || index, {name: member_name, annotation: annotation}] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space inside { missing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space inside } missing. |
||
end] | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'spec_helper' | ||
|
||
describe FrOData::Property do | ||
let(:service) do | ||
FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc', metadata_file: metadata_file) | ||
end | ||
let(:metadata_file) { 'spec/fixtures/files/metadata.xml' } | ||
|
||
describe '#type' do | ||
it 'returns the right type' do | ||
t = service.schemas['ODataDemo'].properties_for_entity('Product')['ProductStatus'].type | ||
expect(t).to eq('ODataDemo.ProductStatus') | ||
|
||
t = service.schemas['ODataDemo'].properties_for_entity('Product')['EthicalAttributes'].type | ||
expect(t).to eq('Collection(ODataDemo.EthicalAttribute)') | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'spec_helper' | ||
|
||
describe FrOData::Schema::EnumType, vcr: {cassette_name: 'schema/enum_type_specs'} do | ||
before(:example) do | ||
FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc', name: 'ODataDemo', metadata_file: metadata_file) | ||
end | ||
|
||
let(:metadata_file) { 'spec/fixtures/files/metadata.xml' } | ||
let(:service) { FrOData::ServiceRegistry['ODataDemo'] } | ||
|
||
let(:enum_type) { service.enum_types['ODataDemo.Vertical'] } | ||
let(:subject) { enum_type.property_class.new('Vertical', nil) } | ||
|
||
describe 'is properly parsed from service metadata' do | ||
it { expect(enum_type.name).to eq('Vertical') } | ||
it { expect(enum_type.namespace).to eq('ODataDemo') } | ||
it { expect(enum_type.type).to eq('ODataDemo.Vertical') } | ||
it { expect(enum_type.is_flags?).to eq(false) } | ||
it { expect(enum_type.underlying_type).to eq('Edm.Int64') } | ||
it { expect(enum_type.members.values).to eq(%w{OutdoorsAndNature HomeAndOffice}) } | ||
it { | ||
expect(enum_type.annotated_members).to eq({ | ||
1 => { name: 'OutdoorsAndNature', annotation: 'Outdoor and Nature Products' }, | ||
2 => { name: 'HomeAndOffice', annotation: 'Home and Office Products' } | ||
}) | ||
} | ||
end | ||
|
||
# Check property instance inheritance hierarchy | ||
it { expect(subject).to be_a(FrOData::Property) } | ||
it { expect(subject).to be_a(FrOData::Properties::Enum) } | ||
|
||
it { expect(subject).to respond_to(:name) } | ||
it { expect(subject).to respond_to(:type) } | ||
it { expect(subject).to respond_to(:members) } | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
end
at 49, 8 is not aligned withdef
at 47, 6.