Class: Ken::Resource
- Includes:
- Extlib::Assertions
- Defined in:
- lib/ken/resource.rb
Constant Summary collapse
- FETCH_SCHEMA_QUERY =
{ # :id => id, # needs to be merge!d in instance method :name => nil, :"ken:type" => [{ :id => nil, :name => nil, :properties => [{ :id => nil, :name => nil, :expected_type => nil, :unique => nil }] }] }
- FETCH_ATTRIBUTES_QUERY =
{ # :id => id # needs to be merg!d in instance method :"/type/reflect/any_master" => [ { :id => nil, :link => nil, :name => nil } ], :"/type/reflect/any_reverse" => [ { :id => nil, :link => nil, :name => nil } ], :"/type/reflect/any_value" => [ { :link => nil, :value => nil # TODO: support multiple language # :lang => "/lang/en", # :type => "/type/text" } ] }
Instance Method Summary collapse
-
#attributes ⇒ Object
returns all attributes for every type the resource is an instance of.
-
#attributes_loaded? ⇒ Boolean
returns true if attributes are already loaded.
-
#id ⇒ Object
resource id.
-
#initialize(data) ⇒ Resource
constructor
initializes a resource using a json result.
- #inspect ⇒ Object
-
#name ⇒ Object
resource name.
-
#properties ⇒ Object
returns all the properties from all assigned types.
-
#schema_loaded? ⇒ Boolean
returns true if type information is already loaded.
- #to_s ⇒ Object
-
#types ⇒ Object
returns all assigned types.
-
#views ⇒ Object
returns all available views based on the assigned types.
Constructor Details
#initialize(data) ⇒ Resource
initializes a resource using a json result
48 49 50 51 52 |
# File 'lib/ken/resource.rb', line 48 def initialize(data) assert_kind_of 'data', data, Hash # intialize lazy if there is no type supplied @schema_loaded, @attributes_loaded, @data = false, false, data end |
Instance Method Details
#attributes ⇒ Object
returns all attributes for every type the resource is an instance of
101 102 103 104 |
# File 'lib/ken/resource.rb', line 101 def attributes load_attributes! unless attributes_loaded? @attributes.values end |
#attributes_loaded? ⇒ Boolean
returns true if attributes are already loaded
114 115 116 |
# File 'lib/ken/resource.rb', line 114 def attributes_loaded? @attributes_loaded end |
#id ⇒ Object
resource id
56 57 58 |
# File 'lib/ken/resource.rb', line 56 def id @data["id"] || "" end |
#inspect ⇒ Object
72 73 74 |
# File 'lib/ken/resource.rb', line 72 def inspect result = "#<Resource id=\"#{id}\" name=\"#{name || "nil"}\">" end |
#name ⇒ Object
resource name
62 63 64 |
# File 'lib/ken/resource.rb', line 62 def name @data["name"] || "" end |
#properties ⇒ Object
returns all the properties from all assigned types
91 92 93 94 95 96 97 |
# File 'lib/ken/resource.rb', line 91 def properties @properties = Ken::Collection.new types.each do |type| @properties.concat(type.properties) end @properties end |
#schema_loaded? ⇒ Boolean
returns true if type information is already loaded
108 109 110 |
# File 'lib/ken/resource.rb', line 108 def schema_loaded? @schema_loaded end |
#types ⇒ Object
returns all assigned types
78 79 80 81 |
# File 'lib/ken/resource.rb', line 78 def types load_schema! unless schema_loaded? @types end |
#views ⇒ Object
returns all available views based on the assigned types
85 86 87 |
# File 'lib/ken/resource.rb', line 85 def views @views ||= Ken::Collection.new(types.map { |type| Ken::View.new(self, type) }) end |